Commit 39f5f79e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move native context field into {WasmInstanceObject}.

R=clemensh@chromium.org
BUG=v8:7424

Change-Id: I334d0521982e173650da7dd5da0627197dff171b
Reviewed-on: https://chromium-review.googlesource.com/1035124
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52890}
parent 67f451aa
......@@ -3114,21 +3114,8 @@ bool WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
Node* callable_node = LOAD_FIXED_ARRAY_SLOT(callables_node, index);
Node* undefined_node =
jsgraph()->Constant(handle(isolate->heap()->undefined_value(), isolate));
Node* compiled_module =
LOAD_INSTANCE_FIELD(CompiledModule, MachineType::TaggedPointer());
// TODO(wasm): native context is only weak because of recycling compiled
// modules.
Node* weak_native_context = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::TaggedPointer()), compiled_module,
jsgraph()->Int32Constant(WasmCompiledModule::kNativeContextOffset -
kHeapObjectTag),
*effect_, *control_);
Node* native_context = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::TaggedPointer()),
weak_native_context,
jsgraph()->Int32Constant(WeakCell::kValueOffset - kHeapObjectTag),
*effect_, *control_);
Node* native_context =
LOAD_INSTANCE_FIELD(NativeContext, MachineType::TaggedPointer());
if (!wasm::IsJSCompatibleSignature(sig_)) {
// Throw a TypeError.
......
......@@ -1335,8 +1335,7 @@ Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const {
}
Handle<Context> FrameSummary::WasmFrameSummary::native_context() const {
return handle(wasm_instance()->compiled_module()->native_context(),
isolate());
return handle(wasm_instance()->native_context(), isolate());
}
FrameSummary::WasmCompiledFrameSummary::WasmCompiledFrameSummary(
......@@ -1915,7 +1914,7 @@ int WasmInterpreterEntryFrame::position() const {
}
Object* WasmInterpreterEntryFrame::context() const {
return compiled_module()->native_context();
return wasm_instance()->native_context();
}
Address WasmInterpreterEntryFrame::GetCallerStackPointer() const {
......
......@@ -1509,7 +1509,6 @@ void Tuple3::Tuple3Verify() {
void WasmCompiledModule::WasmCompiledModuleVerify() {
CHECK(IsWasmCompiledModule());
VerifyObjectField(kSharedOffset);
VerifyObjectField(kNativeContextOffset);
VerifyObjectField(kExportWrappersOffset);
VerifyObjectField(kNextInstanceOffset);
VerifyObjectField(kPrevInstanceOffset);
......
......@@ -43,9 +43,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
}
Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate)
->compiled_module()
->native_context();
return GetWasmInstanceOnStackTop(isolate)->native_context();
}
class ClearThreadInWasmScope {
......@@ -79,7 +77,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
// Set the current isolate's context.
DCHECK_NULL(isolate->context());
isolate->set_context(instance->compiled_module()->native_context());
isolate->set_context(instance->native_context());
return *isolate->factory()->NewNumberFromInt(WasmMemoryObject::Grow(
isolate, handle(instance->memory_object(), isolate), delta_pages));
......@@ -248,7 +246,7 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
// Set the current isolate's context.
DCHECK_NULL(isolate->context());
isolate->set_context(instance->compiled_module()->native_context());
isolate->set_context(instance->native_context());
// Find the frame pointer of the interpreter entry.
Address frame_pointer = 0;
......
......@@ -1655,9 +1655,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
TRACE("Reusing existing instance %zu\n",
compiled_module_->GetNativeModule()->instance_id);
}
Handle<WeakCell> weak_native_context =
isolate_->factory()->NewWeakCell(isolate_->native_context());
compiled_module_->set_weak_native_context(*weak_native_context);
}
base::Optional<wasm::NativeModuleModificationScope>
native_module_modification_scope;
......@@ -3124,9 +3121,9 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
case CompilationEvent::kFinishedBaselineCompilation:
if (job->DecrementAndCheckFinisherCount()) {
SaveContext saved_context(job->isolate());
job->isolate()->set_context(
job->compiled_module_->native_context());
// TODO(mstarzinger): Make {AsyncCompileJob::context} point
// to the native context and also rename to {native_context}.
job->isolate()->set_context(job->context_->native_context());
job->FinishCompile();
}
return;
......@@ -3151,8 +3148,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
->baseline_compilation_finished());
SaveContext saved_context(job->isolate());
job->isolate()->set_context(
job->compiled_module_->native_context());
job->isolate()->set_context(job->context_->native_context());
Handle<Object> error = thrower->Reify();
DeferredHandleScope deferred(job->isolate());
......
......@@ -774,8 +774,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
NewFunctionArgs args = NewFunctionArgs::ForWasm(
name, new_entry_code, isolate->sloppy_function_map());
Handle<JSFunction> new_entry = isolate->factory()->NewFunction(args);
new_entry->set_context(
debug_info->wasm_instance()->compiled_module()->native_context());
new_entry->set_context(debug_info->wasm_instance()->native_context());
new_entry->shared()->set_internal_formal_parameter_count(
compiler::CWasmEntryParameters::kNumParameters);
entries->set(index, *new_entry);
......
......@@ -128,6 +128,7 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset)
ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
ACCESSORS(WasmInstanceObject, native_context, Context, kNativeContextOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
kMemoryObjectOffset)
ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
......@@ -219,7 +220,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
// WasmCompiledModule
WCM_OBJECT(WasmSharedModuleData, shared, kSharedOffset)
WCM_WEAK_LINK(Context, native_context, kNativeContextOffset)
WCM_OBJECT(FixedArray, export_wrappers, kExportWrappersOffset)
WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
......
......@@ -777,6 +777,7 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
instance->set_indirect_function_table_sig_ids(nullptr);
instance->set_indirect_function_table_targets(nullptr);
instance->set_compiled_module(*compiled_module);
instance->set_native_context(*isolate->native_context());
return instance;
}
......@@ -1362,9 +1363,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
wasm::ModuleEnv& env) {
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
Handle<WeakCell> weak_native_context =
isolate->factory()->NewWeakCell(isolate->native_context());
compiled_module->set_weak_native_context(*weak_native_context);
if (!export_wrappers.is_null()) {
compiled_module->set_export_wrappers(*export_wrappers);
}
......@@ -1389,7 +1387,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
ret->set_shared(module->shared());
ret->set_weak_native_context(module->weak_native_context());
ret->set_export_wrappers(module->export_wrappers());
ret->set_weak_wasm_module(module->weak_wasm_module());
ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
......
......@@ -262,6 +262,7 @@ class WasmInstanceObject : public JSObject {
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject)
DECL_ACCESSORS(native_context, Context)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, FixedArray)
......@@ -286,6 +287,7 @@ class WasmInstanceObject : public JSObject {
#define WASM_INSTANCE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \
V(kExportsObjectOffset, kPointerSize) \
V(kNativeContextOffset, kPointerSize) \
V(kMemoryObjectOffset, kPointerSize) \
V(kGlobalsBufferOffset, kPointerSize) \
V(kImportedMutableGlobalsBuffersOffset, kPointerSize) \
......@@ -492,7 +494,6 @@ class WasmCompiledModule : public Struct {
// Layout description.
#define WASM_COMPILED_MODULE_FIELDS(V) \
V(kSharedOffset, kPointerSize) \
V(kNativeContextOffset, kPointerSize) \
V(kExportWrappersOffset, kPointerSize) \
V(kNextInstanceOffset, kPointerSize) \
V(kPrevInstanceOffset, kPointerSize) \
......@@ -530,7 +531,6 @@ class WasmCompiledModule : public Struct {
// By default, instance values go to WasmInstanceObject, however, if
// we embed the generated code with a value, then we track that value here.
WCM_OBJECT(WasmSharedModuleData, shared)
WCM_WEAK_LINK(Context, native_context)
WCM_OBJECT(FixedArray, export_wrappers)
WCM_CONST_OBJECT(WasmCompiledModule, next_instance)
WCM_CONST_OBJECT(WasmCompiledModule, prev_instance)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment