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, ...@@ -3114,21 +3114,8 @@ bool WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
Node* callable_node = LOAD_FIXED_ARRAY_SLOT(callables_node, index); Node* callable_node = LOAD_FIXED_ARRAY_SLOT(callables_node, index);
Node* undefined_node = Node* undefined_node =
jsgraph()->Constant(handle(isolate->heap()->undefined_value(), isolate)); jsgraph()->Constant(handle(isolate->heap()->undefined_value(), isolate));
Node* native_context =
Node* compiled_module = LOAD_INSTANCE_FIELD(NativeContext, MachineType::TaggedPointer());
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_);
if (!wasm::IsJSCompatibleSignature(sig_)) { if (!wasm::IsJSCompatibleSignature(sig_)) {
// Throw a TypeError. // Throw a TypeError.
......
...@@ -1335,8 +1335,7 @@ Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const { ...@@ -1335,8 +1335,7 @@ Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const {
} }
Handle<Context> FrameSummary::WasmFrameSummary::native_context() const { Handle<Context> FrameSummary::WasmFrameSummary::native_context() const {
return handle(wasm_instance()->compiled_module()->native_context(), return handle(wasm_instance()->native_context(), isolate());
isolate());
} }
FrameSummary::WasmCompiledFrameSummary::WasmCompiledFrameSummary( FrameSummary::WasmCompiledFrameSummary::WasmCompiledFrameSummary(
...@@ -1915,7 +1914,7 @@ int WasmInterpreterEntryFrame::position() const { ...@@ -1915,7 +1914,7 @@ int WasmInterpreterEntryFrame::position() const {
} }
Object* WasmInterpreterEntryFrame::context() const { Object* WasmInterpreterEntryFrame::context() const {
return compiled_module()->native_context(); return wasm_instance()->native_context();
} }
Address WasmInterpreterEntryFrame::GetCallerStackPointer() const { Address WasmInterpreterEntryFrame::GetCallerStackPointer() const {
......
...@@ -1509,7 +1509,6 @@ void Tuple3::Tuple3Verify() { ...@@ -1509,7 +1509,6 @@ void Tuple3::Tuple3Verify() {
void WasmCompiledModule::WasmCompiledModuleVerify() { void WasmCompiledModule::WasmCompiledModuleVerify() {
CHECK(IsWasmCompiledModule()); CHECK(IsWasmCompiledModule());
VerifyObjectField(kSharedOffset); VerifyObjectField(kSharedOffset);
VerifyObjectField(kNativeContextOffset);
VerifyObjectField(kExportWrappersOffset); VerifyObjectField(kExportWrappersOffset);
VerifyObjectField(kNextInstanceOffset); VerifyObjectField(kNextInstanceOffset);
VerifyObjectField(kPrevInstanceOffset); VerifyObjectField(kPrevInstanceOffset);
......
...@@ -43,9 +43,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { ...@@ -43,9 +43,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
} }
Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) { Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate) return GetWasmInstanceOnStackTop(isolate)->native_context();
->compiled_module()
->native_context();
} }
class ClearThreadInWasmScope { class ClearThreadInWasmScope {
...@@ -79,7 +77,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { ...@@ -79,7 +77,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
// Set the current isolate's context. // Set the current isolate's context.
DCHECK_NULL(isolate->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( return *isolate->factory()->NewNumberFromInt(WasmMemoryObject::Grow(
isolate, handle(instance->memory_object(), isolate), delta_pages)); isolate, handle(instance->memory_object(), isolate), delta_pages));
...@@ -248,7 +246,7 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { ...@@ -248,7 +246,7 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
// Set the current isolate's context. // Set the current isolate's context.
DCHECK_NULL(isolate->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. // Find the frame pointer of the interpreter entry.
Address frame_pointer = 0; Address frame_pointer = 0;
......
...@@ -1655,9 +1655,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1655,9 +1655,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
TRACE("Reusing existing instance %zu\n", TRACE("Reusing existing instance %zu\n",
compiled_module_->GetNativeModule()->instance_id); 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> base::Optional<wasm::NativeModuleModificationScope>
native_module_modification_scope; native_module_modification_scope;
...@@ -3124,9 +3121,9 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -3124,9 +3121,9 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
case CompilationEvent::kFinishedBaselineCompilation: case CompilationEvent::kFinishedBaselineCompilation:
if (job->DecrementAndCheckFinisherCount()) { if (job->DecrementAndCheckFinisherCount()) {
SaveContext saved_context(job->isolate()); SaveContext saved_context(job->isolate());
job->isolate()->set_context( // TODO(mstarzinger): Make {AsyncCompileJob::context} point
job->compiled_module_->native_context()); // to the native context and also rename to {native_context}.
job->isolate()->set_context(job->context_->native_context());
job->FinishCompile(); job->FinishCompile();
} }
return; return;
...@@ -3151,8 +3148,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -3151,8 +3148,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
->baseline_compilation_finished()); ->baseline_compilation_finished());
SaveContext saved_context(job->isolate()); SaveContext saved_context(job->isolate());
job->isolate()->set_context( job->isolate()->set_context(job->context_->native_context());
job->compiled_module_->native_context());
Handle<Object> error = thrower->Reify(); Handle<Object> error = thrower->Reify();
DeferredHandleScope deferred(job->isolate()); DeferredHandleScope deferred(job->isolate());
......
...@@ -774,8 +774,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry( ...@@ -774,8 +774,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
NewFunctionArgs args = NewFunctionArgs::ForWasm( NewFunctionArgs args = NewFunctionArgs::ForWasm(
name, new_entry_code, isolate->sloppy_function_map()); name, new_entry_code, isolate->sloppy_function_map());
Handle<JSFunction> new_entry = isolate->factory()->NewFunction(args); Handle<JSFunction> new_entry = isolate->factory()->NewFunction(args);
new_entry->set_context( new_entry->set_context(debug_info->wasm_instance()->native_context());
debug_info->wasm_instance()->compiled_module()->native_context());
new_entry->shared()->set_internal_formal_parameter_count( new_entry->shared()->set_internal_formal_parameter_count(
compiler::CWasmEntryParameters::kNumParameters); compiler::CWasmEntryParameters::kNumParameters);
entries->set(index, *new_entry); entries->set(index, *new_entry);
......
...@@ -128,6 +128,7 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets, ...@@ -128,6 +128,7 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule, ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset) kCompiledModuleOffset)
ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset) ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
ACCESSORS(WasmInstanceObject, native_context, Context, kNativeContextOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject, OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
kMemoryObjectOffset) kMemoryObjectOffset)
ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer, ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
...@@ -219,7 +220,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -219,7 +220,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
// WasmCompiledModule // WasmCompiledModule
WCM_OBJECT(WasmSharedModuleData, shared, kSharedOffset) WCM_OBJECT(WasmSharedModuleData, shared, kSharedOffset)
WCM_WEAK_LINK(Context, native_context, kNativeContextOffset)
WCM_OBJECT(FixedArray, export_wrappers, kExportWrappersOffset) WCM_OBJECT(FixedArray, export_wrappers, kExportWrappersOffset)
WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset) WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset) WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
......
...@@ -777,6 +777,7 @@ Handle<WasmInstanceObject> WasmInstanceObject::New( ...@@ -777,6 +777,7 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
instance->set_indirect_function_table_sig_ids(nullptr); instance->set_indirect_function_table_sig_ids(nullptr);
instance->set_indirect_function_table_targets(nullptr); instance->set_indirect_function_table_targets(nullptr);
instance->set_compiled_module(*compiled_module); instance->set_compiled_module(*compiled_module);
instance->set_native_context(*isolate->native_context());
return instance; return instance;
} }
...@@ -1362,9 +1363,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1362,9 +1363,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
wasm::ModuleEnv& env) { wasm::ModuleEnv& env) {
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast( Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED)); 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()) { if (!export_wrappers.is_null()) {
compiled_module->set_export_wrappers(*export_wrappers); compiled_module->set_export_wrappers(*export_wrappers);
} }
...@@ -1389,7 +1387,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1389,7 +1387,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED)); isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
ret->set_shared(module->shared()); ret->set_shared(module->shared());
ret->set_weak_native_context(module->weak_native_context());
ret->set_export_wrappers(module->export_wrappers()); ret->set_export_wrappers(module->export_wrappers());
ret->set_weak_wasm_module(module->weak_wasm_module()); ret->set_weak_wasm_module(module->weak_wasm_module());
ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell()); ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
......
...@@ -262,6 +262,7 @@ class WasmInstanceObject : public JSObject { ...@@ -262,6 +262,7 @@ class WasmInstanceObject : public JSObject {
DECL_ACCESSORS(compiled_module, WasmCompiledModule) DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject) DECL_ACCESSORS(exports_object, JSObject)
DECL_ACCESSORS(native_context, Context)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject) DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer) DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, FixedArray) DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, FixedArray)
...@@ -286,6 +287,7 @@ class WasmInstanceObject : public JSObject { ...@@ -286,6 +287,7 @@ class WasmInstanceObject : public JSObject {
#define WASM_INSTANCE_OBJECT_FIELDS(V) \ #define WASM_INSTANCE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \ V(kCompiledModuleOffset, kPointerSize) \
V(kExportsObjectOffset, kPointerSize) \ V(kExportsObjectOffset, kPointerSize) \
V(kNativeContextOffset, kPointerSize) \
V(kMemoryObjectOffset, kPointerSize) \ V(kMemoryObjectOffset, kPointerSize) \
V(kGlobalsBufferOffset, kPointerSize) \ V(kGlobalsBufferOffset, kPointerSize) \
V(kImportedMutableGlobalsBuffersOffset, kPointerSize) \ V(kImportedMutableGlobalsBuffersOffset, kPointerSize) \
...@@ -492,7 +494,6 @@ class WasmCompiledModule : public Struct { ...@@ -492,7 +494,6 @@ class WasmCompiledModule : public Struct {
// Layout description. // Layout description.
#define WASM_COMPILED_MODULE_FIELDS(V) \ #define WASM_COMPILED_MODULE_FIELDS(V) \
V(kSharedOffset, kPointerSize) \ V(kSharedOffset, kPointerSize) \
V(kNativeContextOffset, kPointerSize) \
V(kExportWrappersOffset, kPointerSize) \ V(kExportWrappersOffset, kPointerSize) \
V(kNextInstanceOffset, kPointerSize) \ V(kNextInstanceOffset, kPointerSize) \
V(kPrevInstanceOffset, kPointerSize) \ V(kPrevInstanceOffset, kPointerSize) \
...@@ -530,7 +531,6 @@ class WasmCompiledModule : public Struct { ...@@ -530,7 +531,6 @@ class WasmCompiledModule : public Struct {
// By default, instance values go to WasmInstanceObject, however, if // By default, instance values go to WasmInstanceObject, however, if
// we embed the generated code with a value, then we track that value here. // we embed the generated code with a value, then we track that value here.
WCM_OBJECT(WasmSharedModuleData, shared) WCM_OBJECT(WasmSharedModuleData, shared)
WCM_WEAK_LINK(Context, native_context)
WCM_OBJECT(FixedArray, export_wrappers) WCM_OBJECT(FixedArray, export_wrappers)
WCM_CONST_OBJECT(WasmCompiledModule, next_instance) WCM_CONST_OBJECT(WasmCompiledModule, next_instance)
WCM_CONST_OBJECT(WasmCompiledModule, prev_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