Commit a1fcd777 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Dehandlify WasmCompiledModule interface

The interface of {WasmCompiledModule} currently mostly receives and
provides handles to the contained data. Other interfaces don't (see
{object-macros.h}.
This leads to performance and memory overhead for chained accesses like
{instance->compiled_module()->shared()->script()}, because intermediate
accessors allocate Handles for no reason. It also breaks the
constraints that lower-case accessors should be trivial to execute, but
allocating a handle is not trivial (should not be done in a loop if not
needed).
It also silences gcmole errors, as documented in
https://crrev.com/c/832268.

R=ahaas@chromium.org, mtrofin@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ib82fb295977a47b4a8ab9bae9c9b6e2b235ad5e5
Reviewed-on: https://chromium-review.googlesource.com/832387
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50173}
parent 8e8d8623
...@@ -9703,7 +9703,7 @@ bool debug::Script::GetPossibleBreakpoints( ...@@ -9703,7 +9703,7 @@ bool debug::Script::GetPossibleBreakpoints(
CHECK(!start.IsEmpty()); CHECK(!start.IsEmpty());
i::Handle<i::Script> script = Utils::OpenHandle(this); i::Handle<i::Script> script = Utils::OpenHandle(this);
if (script->type() == i::Script::TYPE_WASM) { if (script->type() == i::Script::TYPE_WASM) {
i::Handle<i::WasmSharedModuleData> shared = i::WasmSharedModuleData* shared =
i::WasmCompiledModule::cast(script->wasm_compiled_module())->shared(); i::WasmCompiledModule::cast(script->wasm_compiled_module())->shared();
return shared->GetPossibleBreakpoints(start, end, locations); return shared->GetPossibleBreakpoints(start, end, locations);
} }
......
...@@ -1237,8 +1237,8 @@ WASM_SUMMARY_DISPATCH(int, byte_offset) ...@@ -1237,8 +1237,8 @@ WASM_SUMMARY_DISPATCH(int, byte_offset)
#undef WASM_SUMMARY_DISPATCH #undef WASM_SUMMARY_DISPATCH
int FrameSummary::WasmFrameSummary::SourcePosition() const { int FrameSummary::WasmFrameSummary::SourcePosition() const {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
wasm_instance()->compiled_module()->shared(); wasm_instance()->compiled_module()->shared(), isolate());
return WasmSharedModuleData::GetSourcePosition( return WasmSharedModuleData::GetSourcePosition(
shared, function_index(), byte_offset(), at_to_number_conversion()); shared, function_index(), byte_offset(), at_to_number_conversion());
} }
...@@ -1248,14 +1248,15 @@ Handle<Script> FrameSummary::WasmFrameSummary::script() const { ...@@ -1248,14 +1248,15 @@ Handle<Script> FrameSummary::WasmFrameSummary::script() const {
} }
Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const { Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
wasm_instance()->compiled_module()->shared(); wasm_instance()->compiled_module()->shared(), isolate());
return WasmSharedModuleData::GetFunctionName(shared->GetIsolate(), shared, return WasmSharedModuleData::GetFunctionName(isolate(), shared,
function_index()); function_index());
} }
Handle<Context> FrameSummary::WasmFrameSummary::native_context() const { Handle<Context> FrameSummary::WasmFrameSummary::native_context() const {
return wasm_instance()->compiled_module()->native_context(); return handle(wasm_instance()->compiled_module()->native_context(),
isolate());
} }
FrameSummary::WasmCompiledFrameSummary::WasmCompiledFrameSummary( FrameSummary::WasmCompiledFrameSummary::WasmCompiledFrameSummary(
...@@ -1701,8 +1702,7 @@ void WasmCompiledFrame::Print(StringStream* accumulator, PrintMode mode, ...@@ -1701,8 +1702,7 @@ void WasmCompiledFrame::Print(StringStream* accumulator, PrintMode mode,
.start() .start()
: LookupCode()->instruction_start(); : LookupCode()->instruction_start();
int pc = static_cast<int>(this->pc() - instruction_start); int pc = static_cast<int>(this->pc() - instruction_start);
WasmSharedModuleData* shared = WasmSharedModuleData* shared = wasm_instance()->compiled_module()->shared();
wasm_instance()->compiled_module()->ptr_to_shared();
Vector<const uint8_t> raw_func_name = Vector<const uint8_t> raw_func_name =
shared->GetRawFunctionName(this->function_index()); shared->GetRawFunctionName(this->function_index());
const int kMaxPrintedFunctionName = 64; const int kMaxPrintedFunctionName = 64;
...@@ -1815,8 +1815,7 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) { ...@@ -1815,8 +1815,7 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) {
isolate()->wasm_engine()->code_manager()->LookupCode(pc()); isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (!code->IsAnonymous()) { if (!code->IsAnonymous()) {
Object* table_entry = Object* table_entry =
code->owner()->compiled_module()->ptr_to_handler_table()->get( code->owner()->compiled_module()->handler_table()->get(code->index());
code->index());
if (table_entry->IsHandlerTable()) { if (table_entry->IsHandlerTable()) {
HandlerTable* table = HandlerTable::cast(table_entry); HandlerTable* table = HandlerTable::cast(table_entry);
int pc_offset = static_cast<int>(pc() - code->instructions().start()); int pc_offset = static_cast<int>(pc() - code->instructions().start());
...@@ -1882,7 +1881,7 @@ int WasmInterpreterEntryFrame::position() const { ...@@ -1882,7 +1881,7 @@ int WasmInterpreterEntryFrame::position() const {
} }
Object* WasmInterpreterEntryFrame::context() const { Object* WasmInterpreterEntryFrame::context() const {
return wasm_instance()->compiled_module()->ptr_to_native_context(); return wasm_instance()->compiled_module()->native_context();
} }
Address WasmInterpreterEntryFrame::GetCallerStackPointer() const { Address WasmInterpreterEntryFrame::GetCallerStackPointer() const {
......
...@@ -767,8 +767,8 @@ class CaptureStackTraceHelper { ...@@ -767,8 +767,8 @@ class CaptureStackTraceHelper {
const FrameSummary::WasmFrameSummary& summ) { const FrameSummary::WasmFrameSummary& summ) {
Handle<StackFrameInfo> info = factory()->NewStackFrameInfo(); Handle<StackFrameInfo> info = factory()->NewStackFrameInfo();
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
summ.wasm_instance()->compiled_module()->shared(); summ.wasm_instance()->compiled_module()->shared(), isolate_);
Handle<String> name = WasmSharedModuleData::GetFunctionName( Handle<String> name = WasmSharedModuleData::GetFunctionName(
isolate_, shared, summ.function_index()); isolate_, shared, summ.function_index());
info->set_function_name(*name); info->set_function_name(*name);
...@@ -1704,7 +1704,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1704,7 +1704,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
elements->IsAsmJsWasmFrame(i) && elements->IsAsmJsWasmFrame(i) &&
elements->Flags(i)->value() & FrameArray::kAsmJsAtNumberConversion; elements->Flags(i)->value() & FrameArray::kAsmJsAtNumberConversion;
int pos = WasmSharedModuleData::GetSourcePosition( int pos = WasmSharedModuleData::GetSourcePosition(
compiled_module->shared(), func_index, byte_offset, handle(compiled_module->shared(), this), func_index, byte_offset,
is_at_number_conversion); is_at_number_conversion);
Handle<Script> script(compiled_module->shared()->script()); Handle<Script> script(compiled_module->shared()->script());
......
...@@ -672,8 +672,8 @@ Handle<Object> WasmStackFrame::GetFunction() const { ...@@ -672,8 +672,8 @@ Handle<Object> WasmStackFrame::GetFunction() const {
Handle<Object> WasmStackFrame::GetFunctionName() { Handle<Object> WasmStackFrame::GetFunctionName() {
Handle<Object> name; Handle<Object> name;
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
wasm_instance_->compiled_module()->shared(); wasm_instance_->compiled_module()->shared(), isolate_);
if (!WasmSharedModuleData::GetFunctionNameOrNull(isolate_, shared, if (!WasmSharedModuleData::GetFunctionNameOrNull(isolate_, shared,
wasm_func_index_) wasm_func_index_)
.ToHandle(&name)) { .ToHandle(&name)) {
...@@ -685,8 +685,8 @@ Handle<Object> WasmStackFrame::GetFunctionName() { ...@@ -685,8 +685,8 @@ Handle<Object> WasmStackFrame::GetFunctionName() {
MaybeHandle<String> WasmStackFrame::ToString() { MaybeHandle<String> WasmStackFrame::ToString() {
IncrementalStringBuilder builder(isolate_); IncrementalStringBuilder builder(isolate_);
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
wasm_instance_->compiled_module()->shared(); wasm_instance_->compiled_module()->shared(), isolate_);
MaybeHandle<String> module_name = MaybeHandle<String> module_name =
WasmSharedModuleData::GetModuleNameOrNull(isolate_, shared); WasmSharedModuleData::GetModuleNameOrNull(isolate_, shared);
MaybeHandle<String> function_name = MaybeHandle<String> function_name =
...@@ -782,8 +782,8 @@ int AsmJsWasmStackFrame::GetPosition() const { ...@@ -782,8 +782,8 @@ int AsmJsWasmStackFrame::GetPosition() const {
? Handle<AbstractCode>::cast(code_.GetCode())->SourcePosition(offset_) ? Handle<AbstractCode>::cast(code_.GetCode())->SourcePosition(offset_)
: FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition( : FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
code_.GetWasmCode(), offset_); code_.GetWasmCode(), offset_);
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
wasm_instance_->compiled_module()->shared(); wasm_instance_->compiled_module()->shared(), isolate_);
DCHECK_LE(0, byte_offset); DCHECK_LE(0, byte_offset);
return WasmSharedModuleData::GetSourcePosition( return WasmSharedModuleData::GetSourcePosition(
shared, wasm_func_index_, static_cast<uint32_t>(byte_offset), shared, wasm_func_index_, static_cast<uint32_t>(byte_offset),
......
...@@ -1187,7 +1187,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) { ...@@ -1187,7 +1187,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
CONVERT_ARG_CHECKED(WasmInstanceObject, instance, 0); CONVERT_ARG_CHECKED(WasmInstanceObject, instance, 0);
WasmSharedModuleData* shared = instance->compiled_module()->ptr_to_shared(); WasmSharedModuleData* shared = instance->compiled_module()->shared();
CHECK(shared->has_lazy_compilation_orchestrator()); CHECK(shared->has_lazy_compilation_orchestrator());
auto* orchestrator = Managed<wasm::LazyCompilationOrchestrator>::cast( auto* orchestrator = Managed<wasm::LazyCompilationOrchestrator>::cast(
shared->lazy_compilation_orchestrator()) shared->lazy_compilation_orchestrator())
......
...@@ -46,7 +46,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { ...@@ -46,7 +46,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
Context* GetWasmContextOnStackTop(Isolate* isolate) { Context* GetWasmContextOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate) return GetWasmInstanceOnStackTop(isolate)
->compiled_module() ->compiled_module()
->ptr_to_native_context(); ->native_context();
} }
class ClearThreadInWasmScope { class ClearThreadInWasmScope {
...@@ -80,7 +80,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { ...@@ -80,7 +80,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()->ptr_to_native_context()); isolate->set_context(instance->compiled_module()->native_context());
return *isolate->factory()->NewNumberFromInt( return *isolate->factory()->NewNumberFromInt(
WasmInstanceObject::GrowMemory(isolate, instance, delta_pages)); WasmInstanceObject::GrowMemory(isolate, instance, delta_pages));
...@@ -249,7 +249,7 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { ...@@ -249,7 +249,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()->ptr_to_native_context()); isolate->set_context(instance->compiled_module()->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;
......
...@@ -447,9 +447,10 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) { ...@@ -447,9 +447,10 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
if (compiled_module->use_trap_handler()) { if (compiled_module->use_trap_handler()) {
// TODO(6792): No longer needed once WebAssembly code is off heap. // TODO(6792): No longer needed once WebAssembly code is off heap.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap()); CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
Handle<FixedArray> code_table = compiled_module->code_table(); DisallowHeapAllocation no_gc;
FixedArray* code_table = compiled_module->code_table();
for (int i = 0; i < code_table->length(); ++i) { for (int i = 0; i < code_table->length(); ++i) {
Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); Code* code = Code::cast(code_table->get(i));
int index = code->trap_handler_index()->value(); int index = code->trap_handler_index()->value();
if (index >= 0) { if (index >= 0) {
trap_handler::ReleaseHandlerData(index); trap_handler::ReleaseHandlerData(index);
...@@ -459,7 +460,7 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) { ...@@ -459,7 +460,7 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
} }
} }
} }
WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); WeakCell* weak_wasm_module = compiled_module->weak_wasm_module();
// Since the order of finalizers is not guaranteed, it can be the case // Since the order of finalizers is not guaranteed, it can be the case
// that {instance->compiled_module()->module()}, which is a // that {instance->compiled_module()->module()}, which is a
...@@ -492,7 +493,7 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) { ...@@ -492,7 +493,7 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
WasmCompiledModule::Reset(isolate, compiled_module); WasmCompiledModule::Reset(isolate, compiled_module);
} else { } else {
WasmModuleObject::cast(wasm_module) WasmModuleObject::cast(wasm_module)
->set_compiled_module(compiled_module->ptr_to_next_instance()); ->set_compiled_module(compiled_module->next_instance());
} }
} }
} }
...@@ -776,7 +777,9 @@ Address CompileLazy(Isolate* isolate) { ...@@ -776,7 +777,9 @@ Address CompileLazy(Isolate* isolate) {
DCHECK_EQ(wasm::WasmCode::kLazyStub, lazy_stub_or_copy->kind()); DCHECK_EQ(wasm::WasmCode::kLazyStub, lazy_stub_or_copy->kind());
if (!lazy_stub_or_copy->IsAnonymous()) { if (!lazy_stub_or_copy->IsAnonymous()) {
// Then it's an indirect call or via JS->wasm wrapper. // Then it's an indirect call or via JS->wasm wrapper.
instance = lazy_stub_or_copy->owner()->compiled_module()->owning_instance(); instance =
handle(lazy_stub_or_copy->owner()->compiled_module()->owning_instance(),
isolate);
func_index_to_compile = Just(lazy_stub_or_copy->index()); func_index_to_compile = Just(lazy_stub_or_copy->index());
exp_deopt_data_entry = exp_deopt_data_entry =
handle(instance->compiled_module()->lazy_compile_data()->get( handle(instance->compiled_module()->lazy_compile_data()->get(
...@@ -803,8 +806,9 @@ Address CompileLazy(Isolate* isolate) { ...@@ -803,8 +806,9 @@ Address CompileLazy(Isolate* isolate) {
// Then this is a direct call (otherwise we would have attached the // Then this is a direct call (otherwise we would have attached the
// instance via deopt data to the lazy compile stub). Just use the // instance via deopt data to the lazy compile stub). Just use the
// instance of the caller. // instance of the caller.
instance = instance = handle(
wasm_caller_code->owner()->compiled_module()->owning_instance(); wasm_caller_code->owner()->compiled_module()->owning_instance(),
isolate);
} }
} }
...@@ -897,8 +901,8 @@ compiler::ModuleEnv CreateModuleEnvFromCompiledModule( ...@@ -897,8 +901,8 @@ compiler::ModuleEnv CreateModuleEnvFromCompiledModule(
int num_function_tables = static_cast<int>(module->function_tables.size()); int num_function_tables = static_cast<int>(module->function_tables.size());
for (int i = 0; i < num_function_tables; ++i) { for (int i = 0; i < num_function_tables; ++i) {
FixedArray* ft = compiled_module->ptr_to_function_tables(); FixedArray* ft = compiled_module->function_tables();
FixedArray* st = compiled_module->ptr_to_signature_tables(); FixedArray* st = compiled_module->signature_tables();
// TODO(clemensh): defer these handles for concurrent compilation. // TODO(clemensh): defer these handles for concurrent compilation.
function_tables.push_back(WasmCompiledModule::GetTableValue(ft, i)); function_tables.push_back(WasmCompiledModule::GetTableValue(ft, i));
...@@ -2147,7 +2151,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal( ...@@ -2147,7 +2151,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
if (lazy_compile && FLAG_wasm_jit_to_native) { if (lazy_compile && FLAG_wasm_jit_to_native) {
Handle<FixedArray> lazy_compile_data = isolate_->factory()->NewFixedArray( Handle<FixedArray> lazy_compile_data = isolate_->factory()->NewFixedArray(
static_cast<int>(module_->functions.size()), TENURED); static_cast<int>(module_->functions.size()), TENURED);
compiled_module->set_lazy_compile_data(lazy_compile_data); compiled_module->set_lazy_compile_data(*lazy_compile_data);
} }
if (!lazy_compile) { if (!lazy_compile) {
...@@ -2304,13 +2308,13 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -2304,13 +2308,13 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
TRACE("Cloning from %zu\n", original->GetNativeModule()->instance_id); TRACE("Cloning from %zu\n", original->GetNativeModule()->instance_id);
compiled_module_ = WasmCompiledModule::Clone(isolate_, original); compiled_module_ = WasmCompiledModule::Clone(isolate_, original);
native_module = compiled_module_->GetNativeModule(); native_module = compiled_module_->GetNativeModule();
wrapper_table = compiled_module_->export_wrappers(); wrapper_table = handle(compiled_module_->export_wrappers(), isolate_);
} else { } else {
TRACE("Cloning from %d\n", original->instance_id()); TRACE("Cloning from %d\n", original->instance_id());
old_code_table = original->code_table(); old_code_table = handle(original->code_table(), isolate_);
compiled_module_ = WasmCompiledModule::Clone(isolate_, original); compiled_module_ = WasmCompiledModule::Clone(isolate_, original);
code_table = compiled_module_->code_table(); code_table = handle(compiled_module_->code_table(), isolate_);
wrapper_table = compiled_module_->export_wrappers(); wrapper_table = handle(compiled_module_->export_wrappers(), isolate_);
// Avoid creating too many handles in the outer scope. // Avoid creating too many handles in the outer scope.
HandleScope scope(isolate_); HandleScope scope(isolate_);
...@@ -2360,21 +2364,20 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -2360,21 +2364,20 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
} else { } else {
// There was no owner, so we can reuse the original. // There was no owner, so we can reuse the original.
compiled_module_ = original; compiled_module_ = original;
wrapper_table = compiled_module_->export_wrappers(); wrapper_table = handle(compiled_module_->export_wrappers(), isolate_);
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
old_module = compiled_module_->GetNativeModule(); old_module = compiled_module_->GetNativeModule();
native_module = old_module; native_module = old_module;
TRACE("Reusing existing instance %zu\n", TRACE("Reusing existing instance %zu\n",
compiled_module_->GetNativeModule()->instance_id); compiled_module_->GetNativeModule()->instance_id);
} else { } else {
old_code_table = code_table = handle(compiled_module_->code_table(), isolate_);
factory->CopyFixedArray(compiled_module_->code_table()); old_code_table = factory->CopyFixedArray(code_table);
code_table = compiled_module_->code_table();
TRACE("Reusing existing instance %d\n", TRACE("Reusing existing instance %d\n",
compiled_module_->instance_id()); compiled_module_->instance_id());
} }
} }
compiled_module_->set_native_context(isolate_->native_context()); compiled_module_->set_native_context(*isolate_->native_context());
} }
base::Optional<wasm::NativeModuleModificationScope> base::Optional<wasm::NativeModuleModificationScope>
native_module_modification_scope; native_module_modification_scope;
...@@ -2602,7 +2605,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -2602,7 +2605,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
compiled_module_->InsertInChain(*module_object_); compiled_module_->InsertInChain(*module_object_);
} }
module_object_->set_compiled_module(*compiled_module_); module_object_->set_compiled_module(*compiled_module_);
compiled_module_->set_weak_owning_instance(link_to_owning_instance); compiled_module_->set_weak_owning_instance(*link_to_owning_instance);
GlobalHandles::MakeWeak(global_handle.location(), global_handle.location(), GlobalHandles::MakeWeak(global_handle.location(), global_handle.location(),
instance_finalizer_callback_, instance_finalizer_callback_,
v8::WeakCallbackType::kFinalizer); v8::WeakCallbackType::kFinalizer);
...@@ -2612,8 +2615,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -2612,8 +2615,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Debugging support. // Debugging support.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Set all breakpoints that were set on the shared module. // Set all breakpoints that were set on the shared module.
WasmSharedModuleData::SetBreakpointsOnNewInstance(compiled_module_->shared(), WasmSharedModuleData::SetBreakpointsOnNewInstance(
instance); handle(compiled_module_->shared(), isolate_), instance);
if (FLAG_wasm_interpret_all && module_->is_wasm()) { if (FLAG_wasm_interpret_all && module_->is_wasm()) {
Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo> debug_info =
...@@ -3194,7 +3197,8 @@ bool InstanceBuilder::NeedsWrappers() const { ...@@ -3194,7 +3197,8 @@ bool InstanceBuilder::NeedsWrappers() const {
void InstanceBuilder::ProcessExports( void InstanceBuilder::ProcessExports(
Handle<WasmInstanceObject> instance, Handle<WasmInstanceObject> instance,
Handle<WasmCompiledModule> compiled_module) { Handle<WasmCompiledModule> compiled_module) {
Handle<FixedArray> wrapper_table = compiled_module->export_wrappers(); Handle<FixedArray> wrapper_table(compiled_module->export_wrappers(),
isolate_);
if (NeedsWrappers()) { if (NeedsWrappers()) {
// Fill the table to cache the exported JSFunction wrappers. // Fill the table to cache the exported JSFunction wrappers.
js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(), js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(),
...@@ -3225,14 +3229,15 @@ void InstanceBuilder::ProcessExports( ...@@ -3225,14 +3229,15 @@ void InstanceBuilder::ProcessExports(
// Store weak references to all exported functions. // Store weak references to all exported functions.
Handle<FixedArray> weak_exported_functions; Handle<FixedArray> weak_exported_functions;
if (compiled_module->has_weak_exported_functions()) { if (compiled_module->has_weak_exported_functions()) {
weak_exported_functions = compiled_module->weak_exported_functions(); weak_exported_functions =
handle(compiled_module->weak_exported_functions(), isolate_);
} else { } else {
int export_count = 0; int export_count = 0;
for (WasmExport& exp : module_->export_table) { for (WasmExport& exp : module_->export_table) {
if (exp.kind == kExternalFunction) ++export_count; if (exp.kind == kExternalFunction) ++export_count;
} }
weak_exported_functions = isolate_->factory()->NewFixedArray(export_count); weak_exported_functions = isolate_->factory()->NewFixedArray(export_count);
compiled_module->set_weak_exported_functions(weak_exported_functions); compiled_module->set_weak_exported_functions(*weak_exported_functions);
} }
// Process each export in the export table. // Process each export in the export table.
...@@ -3240,7 +3245,7 @@ void InstanceBuilder::ProcessExports( ...@@ -3240,7 +3245,7 @@ void InstanceBuilder::ProcessExports(
for (WasmExport& exp : module_->export_table) { for (WasmExport& exp : module_->export_table) {
Handle<String> name = Handle<String> name =
WasmSharedModuleData::ExtractUtf8StringFromModuleBytes( WasmSharedModuleData::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_->shared(), exp.name) isolate_, handle(compiled_module_->shared(), isolate_), exp.name)
.ToHandleChecked(); .ToHandleChecked();
Handle<JSObject> export_to; Handle<JSObject> export_to;
if (module_->is_asm_js() && exp.kind == kExternalFunction && if (module_->is_asm_js() && exp.kind == kExternalFunction &&
...@@ -3262,9 +3267,11 @@ void InstanceBuilder::ProcessExports( ...@@ -3262,9 +3267,11 @@ void InstanceBuilder::ProcessExports(
MaybeHandle<String> func_name; MaybeHandle<String> func_name;
if (module_->is_asm_js()) { if (module_->is_asm_js()) {
// For modules arising from asm.js, honor the names section. // For modules arising from asm.js, honor the names section.
func_name = WasmSharedModuleData::ExtractUtf8StringFromModuleBytes( func_name =
isolate_, compiled_module_->shared(), function.name) WasmSharedModuleData::ExtractUtf8StringFromModuleBytes(
.ToHandleChecked(); isolate_, handle(compiled_module_->shared(), isolate_),
function.name)
.ToHandleChecked();
} }
js_function = WasmExportedFunction::New( js_function = WasmExportedFunction::New(
isolate_, instance, func_name, function.func_index, isolate_, instance, func_name, function.func_index,
...@@ -3365,11 +3372,13 @@ void InstanceBuilder::InitializeTables( ...@@ -3365,11 +3372,13 @@ void InstanceBuilder::InitializeTables(
FLAG_wasm_jit_to_native ? native_module->signature_tables() : empty; FLAG_wasm_jit_to_native ? native_module->signature_tables() : empty;
Handle<FixedArray> old_function_tables_gc = Handle<FixedArray> old_function_tables_gc =
FLAG_wasm_jit_to_native ? Handle<FixedArray>::null() FLAG_wasm_jit_to_native
: compiled_module_->function_tables(); ? Handle<FixedArray>::null()
: handle(compiled_module_->function_tables(), isolate_);
Handle<FixedArray> old_signature_tables_gc = Handle<FixedArray> old_signature_tables_gc =
FLAG_wasm_jit_to_native ? Handle<FixedArray>::null() FLAG_wasm_jit_to_native
: compiled_module_->signature_tables(); ? Handle<FixedArray>::null()
: handle(compiled_module_->signature_tables(), isolate_);
// function_table_count is 0 or 1, so we just create these objects even if not // function_table_count is 0 or 1, so we just create these objects even if not
// needed for native wasm. // needed for native wasm.
...@@ -3481,8 +3490,8 @@ void InstanceBuilder::InitializeTables( ...@@ -3481,8 +3490,8 @@ void InstanceBuilder::InitializeTables(
native_module->function_tables() = new_function_tables; native_module->function_tables() = new_function_tables;
native_module->signature_tables() = new_signature_tables; native_module->signature_tables() = new_signature_tables;
} else { } else {
compiled_module_->set_function_tables(new_function_tables_gc); compiled_module_->set_function_tables(*new_function_tables_gc);
compiled_module_->set_signature_tables(new_signature_tables_gc); compiled_module_->set_signature_tables(*new_signature_tables_gc);
} }
} }
...@@ -3568,7 +3577,8 @@ void InstanceBuilder::LoadTableSegments(Handle<FixedArray> code_table, ...@@ -3568,7 +3577,8 @@ void InstanceBuilder::LoadTableSegments(Handle<FixedArray> code_table,
// For modules arising from asm.js, honor the names section. // For modules arising from asm.js, honor the names section.
func_name = func_name =
WasmSharedModuleData::ExtractUtf8StringFromModuleBytes( WasmSharedModuleData::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_->shared(), function->name) isolate_, handle(compiled_module_->shared(), isolate_),
function->name)
.ToHandleChecked(); .ToHandleChecked();
} }
Handle<WasmExportedFunction> js_function = Handle<WasmExportedFunction> js_function =
...@@ -4356,13 +4366,15 @@ void CompileJsToWasmWrappers(Isolate* isolate, ...@@ -4356,13 +4366,15 @@ void CompileJsToWasmWrappers(Isolate* isolate,
Counters* counters) { Counters* counters) {
JSToWasmWrapperCache js_to_wasm_cache; JSToWasmWrapperCache js_to_wasm_cache;
int wrapper_index = 0; int wrapper_index = 0;
Handle<FixedArray> export_wrappers = compiled_module->export_wrappers(); Handle<FixedArray> export_wrappers(compiled_module->export_wrappers(),
isolate);
Handle<FixedArray> code_table(compiled_module->code_table(), isolate);
NativeModule* native_module = compiled_module->GetNativeModule(); NativeModule* native_module = compiled_module->GetNativeModule();
for (auto exp : compiled_module->shared()->module()->export_table) { for (auto exp : compiled_module->shared()->module()->export_table) {
if (exp.kind != kExternalFunction) continue; if (exp.kind != kExternalFunction) continue;
WasmCodeWrapper wasm_code = EnsureExportedLazyDeoptData( WasmCodeWrapper wasm_code =
isolate, Handle<WasmInstanceObject>::null(), EnsureExportedLazyDeoptData(isolate, Handle<WasmInstanceObject>::null(),
compiled_module->code_table(), native_module, exp.index); code_table, native_module, exp.index);
Handle<Code> wrapper_code = js_to_wasm_cache.CloneOrCompileJSToWasmWrapper( Handle<Code> wrapper_code = js_to_wasm_cache.CloneOrCompileJSToWasmWrapper(
isolate, compiled_module->shared()->module(), wasm_code, exp.index, isolate, compiled_module->shared()->module(), wasm_code, exp.index,
compiled_module->use_trap_handler()); compiled_module->use_trap_handler());
......
...@@ -250,14 +250,16 @@ void NativeModule::ResizeCodeTableForTest(size_t last_index) { ...@@ -250,14 +250,16 @@ void NativeModule::ResizeCodeTableForTest(size_t last_index) {
code_table_.resize(new_size); code_table_.resize(new_size);
int grow_by = static_cast<int>(new_size) - int grow_by = static_cast<int>(new_size) -
compiled_module()->source_positions()->length(); compiled_module()->source_positions()->length();
Handle<FixedArray> source_positions = compiled_module()->source_positions(); Handle<FixedArray> source_positions(compiled_module()->source_positions(),
isolate);
source_positions = isolate->factory()->CopyFixedArrayAndGrow( source_positions = isolate->factory()->CopyFixedArrayAndGrow(
source_positions, grow_by, TENURED); source_positions, grow_by, TENURED);
compiled_module()->set_source_positions(source_positions); compiled_module()->set_source_positions(*source_positions);
Handle<FixedArray> handler_table = compiled_module()->handler_table(); Handle<FixedArray> handler_table(compiled_module()->handler_table(),
isolate);
handler_table = isolate->factory()->CopyFixedArrayAndGrow(handler_table, handler_table = isolate->factory()->CopyFixedArrayAndGrow(handler_table,
grow_by, TENURED); grow_by, TENURED);
compiled_module()->set_handler_table(handler_table); compiled_module()->set_handler_table(*handler_table);
} }
} }
...@@ -307,10 +309,10 @@ WasmCode* NativeModule::AddCodeCopy(Handle<Code> code, WasmCode::Kind kind, ...@@ -307,10 +309,10 @@ WasmCode* NativeModule::AddCodeCopy(Handle<Code> code, WasmCode::Kind kind,
WasmCode* ret = AddAnonymousCode(code, kind); WasmCode* ret = AddAnonymousCode(code, kind);
SetCodeTable(index, ret); SetCodeTable(index, ret);
ret->index_ = Just(index); ret->index_ = Just(index);
compiled_module()->ptr_to_source_positions()->set( compiled_module()->source_positions()->set(static_cast<int>(index),
static_cast<int>(index), code->source_position_table()); code->source_position_table());
compiled_module()->ptr_to_handler_table()->set(static_cast<int>(index), compiled_module()->handler_table()->set(static_cast<int>(index),
code->handler_table()); code->handler_table());
return ret; return ret;
} }
......
...@@ -60,7 +60,7 @@ class PatchDirectCallsHelper { ...@@ -60,7 +60,7 @@ class PatchDirectCallsHelper {
: source_pos_it(code->SourcePositionTable()), decoder(nullptr, nullptr) { : source_pos_it(code->SourcePositionTable()), decoder(nullptr, nullptr) {
FixedArray* deopt_data = code->deoptimization_data(); FixedArray* deopt_data = code->deoptimization_data();
DCHECK_EQ(2, deopt_data->length()); DCHECK_EQ(2, deopt_data->length());
WasmSharedModuleData* shared = instance->compiled_module()->ptr_to_shared(); WasmSharedModuleData* shared = instance->compiled_module()->shared();
int func_index = Smi::ToInt(deopt_data->get(1)); int func_index = Smi::ToInt(deopt_data->get(1));
func_bytes = shared->module_bytes()->GetChars() + func_bytes = shared->module_bytes()->GetChars() +
shared->module()->functions[func_index].code.offset(); shared->module()->functions[func_index].code.offset();
...@@ -117,8 +117,8 @@ bool CodeSpecialization::ApplyToWholeInstance( ...@@ -117,8 +117,8 @@ bool CodeSpecialization::ApplyToWholeInstance(
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = instance->compiled_module(); WasmCompiledModule* compiled_module = instance->compiled_module();
NativeModule* native_module = compiled_module->GetNativeModule(); NativeModule* native_module = compiled_module->GetNativeModule();
FixedArray* code_table = compiled_module->ptr_to_code_table(); FixedArray* code_table = compiled_module->code_table();
WasmSharedModuleData* shared = compiled_module->ptr_to_shared(); WasmSharedModuleData* shared = compiled_module->shared();
WasmModule* module = shared->module(); WasmModule* module = shared->module();
std::vector<WasmFunction>* wasm_functions = &shared->module()->functions; std::vector<WasmFunction>* wasm_functions = &shared->module()->functions;
DCHECK_EQ(compiled_module->export_wrappers()->length(), DCHECK_EQ(compiled_module->export_wrappers()->length(),
...@@ -263,8 +263,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code, ...@@ -263,8 +263,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
patch_direct_calls_helper->decoder, patch_direct_calls_helper->decoder,
patch_direct_calls_helper->func_bytes + byte_pos); patch_direct_calls_helper->func_bytes + byte_pos);
FixedArray* code_table = FixedArray* code_table =
relocate_direct_calls_instance->compiled_module() relocate_direct_calls_instance->compiled_module()->code_table();
->ptr_to_code_table();
Code* new_code = Code::cast(code_table->get(called_func_index)); Code* new_code = Code::cast(code_table->get(called_func_index));
it.rinfo()->set_target_address(new_code->GetIsolate(), it.rinfo()->set_target_address(new_code->GetIsolate(),
new_code->instruction_start(), new_code->instruction_start(),
......
...@@ -70,8 +70,8 @@ MaybeHandle<String> GetLocalName(Isolate* isolate, ...@@ -70,8 +70,8 @@ MaybeHandle<String> GetLocalName(Isolate* isolate,
DCHECK_LE(0, func_index); DCHECK_LE(0, func_index);
DCHECK_LE(0, local_index); DCHECK_LE(0, local_index);
if (!debug_info->has_locals_names()) { if (!debug_info->has_locals_names()) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
debug_info->wasm_instance()->compiled_module()->shared(); debug_info->wasm_instance()->compiled_module()->shared(), isolate);
Handle<FixedArray> locals_names = wasm::DecodeLocalNames(isolate, shared); Handle<FixedArray> locals_names = wasm::DecodeLocalNames(isolate, shared);
debug_info->set_locals_names(*locals_names); debug_info->set_locals_names(*locals_names);
} }
...@@ -309,8 +309,8 @@ class InterpreterHandle { ...@@ -309,8 +309,8 @@ class InterpreterHandle {
// Check whether we hit a breakpoint. // Check whether we hit a breakpoint.
if (isolate_->debug()->break_points_active()) { if (isolate_->debug()->break_points_active()) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
GetInstanceObject()->compiled_module()->shared(); GetInstanceObject()->compiled_module()->shared(), isolate_);
int position = GetTopPosition(shared); int position = GetTopPosition(shared);
Handle<FixedArray> breakpoints; Handle<FixedArray> breakpoints;
if (WasmSharedModuleData::CheckBreakPoints(isolate_, shared, position) if (WasmSharedModuleData::CheckBreakPoints(isolate_, shared, position)
...@@ -627,7 +627,7 @@ void RedirectCallsitesInInstanceGC(Isolate* isolate, ...@@ -627,7 +627,7 @@ void RedirectCallsitesInInstanceGC(Isolate* isolate,
CodeRelocationMapGC& map) { CodeRelocationMapGC& map) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
// Redirect all calls in wasm functions. // Redirect all calls in wasm functions.
FixedArray* code_table = instance->compiled_module()->ptr_to_code_table(); FixedArray* code_table = instance->compiled_module()->code_table();
for (int i = 0, e = GetNumFunctions(instance); i < e; ++i) { for (int i = 0, e = GetNumFunctions(instance); i < e; ++i) {
RedirectCallsitesInCodeGC(Code::cast(code_table->get(i)), map); RedirectCallsitesInCodeGC(Code::cast(code_table->get(i)), map);
} }
...@@ -635,7 +635,7 @@ void RedirectCallsitesInInstanceGC(Isolate* isolate, ...@@ -635,7 +635,7 @@ void RedirectCallsitesInInstanceGC(Isolate* isolate,
// Redirect all calls in exported functions. // Redirect all calls in exported functions.
FixedArray* weak_exported_functions = FixedArray* weak_exported_functions =
instance->compiled_module()->ptr_to_weak_exported_functions(); instance->compiled_module()->weak_exported_functions();
for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) { for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) {
WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i)); WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i));
if (weak_function->cleared()) continue; if (weak_function->cleared()) continue;
...@@ -657,7 +657,7 @@ void RedirectCallsitesInInstance(Isolate* isolate, WasmInstanceObject* instance, ...@@ -657,7 +657,7 @@ void RedirectCallsitesInInstance(Isolate* isolate, WasmInstanceObject* instance,
// Redirect all calls in exported functions. // Redirect all calls in exported functions.
FixedArray* weak_exported_functions = FixedArray* weak_exported_functions =
instance->compiled_module()->ptr_to_weak_exported_functions(); instance->compiled_module()->weak_exported_functions();
for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) { for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) {
WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i)); WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i));
if (weak_function->cleared()) continue; if (weak_function->cleared()) continue;
...@@ -731,7 +731,8 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -731,7 +731,8 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
wasm::WasmModule* module = instance->module(); wasm::WasmModule* module = instance->module();
CodeRelocationMap code_to_relocate; CodeRelocationMap code_to_relocate;
Handle<FixedArray> code_table = instance->compiled_module()->code_table(); Handle<FixedArray> code_table(instance->compiled_module()->code_table(),
isolate);
CodeRelocationMapGC code_to_relocate_gc(isolate->heap()); CodeRelocationMapGC code_to_relocate_gc(isolate->heap());
// We may modify js wrappers, as well as wasm functions. Hence the 2 // We may modify js wrappers, as well as wasm functions. Hence the 2
// modification scopes. // modification scopes.
...@@ -865,7 +866,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry( ...@@ -865,7 +866,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
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()->compiled_module()->native_context()); debug_info->wasm_instance()->compiled_module()->native_context());
new_entry->set_shared(*shared); new_entry->set_shared(*shared);
entries->set(index, *new_entry); entries->set(index, *new_entry);
} }
......
...@@ -1002,7 +1002,7 @@ class CodeMap { ...@@ -1002,7 +1002,7 @@ class CodeMap {
Code* GetImportedFunctionGC(uint32_t function_index) { Code* GetImportedFunctionGC(uint32_t function_index) {
DCHECK(has_instance()); DCHECK(has_instance());
DCHECK_GT(module_->num_imported_functions, function_index); DCHECK_GT(module_->num_imported_functions, function_index);
FixedArray* code_table = instance()->compiled_module()->ptr_to_code_table(); FixedArray* code_table = instance()->compiled_module()->code_table();
return Code::cast(code_table->get(static_cast<int>(function_index))); return Code::cast(code_table->get(static_cast<int>(function_index)));
} }
...@@ -2461,7 +2461,7 @@ class ThreadImpl { ...@@ -2461,7 +2461,7 @@ class ThreadImpl {
DCHECK(AllowHeapAllocation::IsAllowed()); DCHECK(AllowHeapAllocation::IsAllowed());
if (code->kind() == wasm::WasmCode::kFunction) { if (code->kind() == wasm::WasmCode::kFunction) {
DCHECK_EQ(*code->owner()->compiled_module()->owning_instance(), DCHECK_EQ(code->owner()->compiled_module()->owning_instance(),
codemap()->instance()); codemap()->instance());
return {ExternalCallResult::INTERNAL, codemap()->GetCode(code->index())}; return {ExternalCallResult::INTERNAL, codemap()->GetCode(code->index())};
} }
...@@ -2548,7 +2548,7 @@ class ThreadImpl { ...@@ -2548,7 +2548,7 @@ class ThreadImpl {
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
// Check signature. // Check signature.
FixedArray* sig_tables = compiled_module->ptr_to_signature_tables(); FixedArray* sig_tables = compiled_module->signature_tables();
if (table_index >= static_cast<uint32_t>(sig_tables->length())) { if (table_index >= static_cast<uint32_t>(sig_tables->length())) {
return {ExternalCallResult::INVALID_FUNC}; return {ExternalCallResult::INVALID_FUNC};
} }
...@@ -2568,7 +2568,7 @@ class ThreadImpl { ...@@ -2568,7 +2568,7 @@ class ThreadImpl {
} }
// Get code object. // Get code object.
FixedArray* fun_tables = compiled_module->ptr_to_function_tables(); FixedArray* fun_tables = compiled_module->function_tables();
DCHECK_EQ(sig_tables->length(), fun_tables->length()); DCHECK_EQ(sig_tables->length(), fun_tables->length());
Handle<FixedArray> fun_table(reinterpret_cast<FixedArray**>( Handle<FixedArray> fun_table(reinterpret_cast<FixedArray**>(
WasmCompiledModule::GetTableValue(fun_tables, table_index_as_int))); WasmCompiledModule::GetTableValue(fun_tables, table_index_as_int)));
......
...@@ -231,8 +231,8 @@ bool IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { ...@@ -231,8 +231,8 @@ bool IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) {
Handle<JSArray> GetImports(Isolate* isolate, Handle<JSArray> GetImports(Isolate* isolate,
Handle<WasmModuleObject> module_object) { Handle<WasmModuleObject> module_object) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
module_object->compiled_module()->shared(); module_object->compiled_module()->shared(), isolate);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<String> module_string = factory->InternalizeUtf8String("module"); Handle<String> module_string = factory->InternalizeUtf8String("module");
...@@ -301,8 +301,8 @@ Handle<JSArray> GetImports(Isolate* isolate, ...@@ -301,8 +301,8 @@ Handle<JSArray> GetImports(Isolate* isolate,
Handle<JSArray> GetExports(Isolate* isolate, Handle<JSArray> GetExports(Isolate* isolate,
Handle<WasmModuleObject> module_object) { Handle<WasmModuleObject> module_object) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
module_object->compiled_module()->shared(); module_object->compiled_module()->shared(), isolate);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<String> name_string = factory->InternalizeUtf8String("name"); Handle<String> name_string = factory->InternalizeUtf8String("name");
...@@ -365,8 +365,8 @@ Handle<JSArray> GetExports(Isolate* isolate, ...@@ -365,8 +365,8 @@ Handle<JSArray> GetExports(Isolate* isolate,
Handle<JSArray> GetCustomSections(Isolate* isolate, Handle<JSArray> GetCustomSections(Isolate* isolate,
Handle<WasmModuleObject> module_object, Handle<WasmModuleObject> module_object,
Handle<String> name, ErrorThrower* thrower) { Handle<String> name, ErrorThrower* thrower) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
module_object->compiled_module()->shared(); module_object->compiled_module()->shared(), isolate);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
std::vector<CustomSectionOffset> custom_sections; std::vector<CustomSectionOffset> custom_sections;
......
...@@ -82,22 +82,13 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -82,22 +82,13 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
#undef OPTIONAL_ACCESSORS #undef OPTIONAL_ACCESSORS
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK, SETTER_MODIFIER) \ #define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK, SETTER_MODIFIER) \
Handle<TYPE> WasmCompiledModule::NAME() const { \ TYPE* WasmCompiledModule::maybe_##NAME() const { \
return handle(ptr_to_##NAME()); \
} \
\
MaybeHandle<TYPE> WasmCompiledModule::maybe_##NAME() const { \
if (has_##NAME()) return NAME(); \
return MaybeHandle<TYPE>(); \
} \
\
TYPE* WasmCompiledModule::maybe_ptr_to_##NAME() const { \
Object* obj = get(ID); \ Object* obj = get(ID); \
if (!(TYPE_CHECK)) return nullptr; \ if (!(TYPE_CHECK)) return nullptr; \
return TYPE::cast(obj); \ return TYPE::cast(obj); \
} \ } \
\ \
TYPE* WasmCompiledModule::ptr_to_##NAME() const { \ TYPE* WasmCompiledModule::NAME() const { \
Object* obj = get(ID); \ Object* obj = get(ID); \
DCHECK(TYPE_CHECK); \ DCHECK(TYPE_CHECK); \
return TYPE::cast(obj); \ return TYPE::cast(obj); \
...@@ -110,10 +101,7 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -110,10 +101,7 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
\ \
void WasmCompiledModule::reset_##NAME() { set_undefined(ID); } \ void WasmCompiledModule::reset_##NAME() { set_undefined(ID); } \
\ \
void WasmCompiledModule::set_##NAME(Handle<TYPE> value) { \ void WasmCompiledModule::set_##NAME(TYPE* value) { set(ID, value); }
set_ptr_to_##NAME(*value); \
} \
void WasmCompiledModule::set_ptr_to_##NAME(TYPE* value) { set(ID, value); }
#define WCM_OBJECT(TYPE, NAME) \ #define WCM_OBJECT(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), public) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), public)
...@@ -137,8 +125,9 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -137,8 +125,9 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME, obj->IsWeakCell(), \ WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME, obj->IsWeakCell(), \
public) \ public) \
\ \
Handle<TYPE> WasmCompiledModule::NAME() const { \ TYPE* WasmCompiledModule::NAME() const { \
return handle(TYPE::cast(weak_##NAME()->value())); \ DCHECK(!weak_##NAME()->cleared()); \
return TYPE::cast(weak_##NAME()->value()); \
} }
#define DEFINITION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) #define DEFINITION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
...@@ -161,7 +150,7 @@ bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; } ...@@ -161,7 +150,7 @@ bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
void WasmCompiledModule::ReplaceCodeTableForTesting( void WasmCompiledModule::ReplaceCodeTableForTesting(
Handle<FixedArray> testing_table) { Handle<FixedArray> testing_table) {
set_code_table(testing_table); set_code_table(*testing_table);
} }
#include "src/objects/object-macros-undef.h" #include "src/objects/object-macros-undef.h"
......
...@@ -47,7 +47,9 @@ class CompiledModulesIterator ...@@ -47,7 +47,9 @@ class CompiledModulesIterator
Handle<WasmCompiledModule> start_module, bool at_end) Handle<WasmCompiledModule> start_module, bool at_end)
: isolate_(isolate), : isolate_(isolate),
start_module_(start_module), start_module_(start_module),
current_(at_end ? Handle<WasmCompiledModule>::null() : start_module) {} current_(
at_end ? Handle<WasmCompiledModule>::null()
: Handle<WasmCompiledModule>::New(*start_module, isolate)) {}
Handle<WasmCompiledModule> operator*() const { Handle<WasmCompiledModule> operator*() const {
DCHECK(!current_.is_null()); DCHECK(!current_.is_null());
...@@ -66,7 +68,7 @@ class CompiledModulesIterator ...@@ -66,7 +68,7 @@ class CompiledModulesIterator
DCHECK(!current_.is_null()); DCHECK(!current_.is_null());
if (!is_backwards_) { if (!is_backwards_) {
if (current_->has_next_instance()) { if (current_->has_next_instance()) {
current_ = current_->next_instance(); *current_.location() = current_->next_instance();
return; return;
} }
// No more modules in next-links, now try the previous-links. // No more modules in next-links, now try the previous-links.
...@@ -74,7 +76,7 @@ class CompiledModulesIterator ...@@ -74,7 +76,7 @@ class CompiledModulesIterator
current_ = start_module_; current_ = start_module_;
} }
if (current_->has_prev_instance()) { if (current_->has_prev_instance()) {
current_ = current_->prev_instance(); *current_.location() = current_->prev_instance();
return; return;
} }
current_ = Handle<WasmCompiledModule>::null(); current_ = Handle<WasmCompiledModule>::null();
...@@ -120,7 +122,7 @@ class CompiledModuleInstancesIterator ...@@ -120,7 +122,7 @@ class CompiledModuleInstancesIterator
bool NeedToAdvance() { bool NeedToAdvance() {
return !it.current_.is_null() && return !it.current_.is_null() &&
(!it.current_->has_weak_owning_instance() || (!it.current_->has_weak_owning_instance() ||
it.current_->ptr_to_weak_owning_instance()->cleared()); it.current_->weak_owning_instance()->cleared());
} }
CompiledModulesIterator it; CompiledModulesIterator it;
}; };
...@@ -172,7 +174,7 @@ Handle<WasmModuleObject> WasmModuleObject::New( ...@@ -172,7 +174,7 @@ Handle<WasmModuleObject> WasmModuleObject::New(
module_object->set_compiled_module(*compiled_module); module_object->set_compiled_module(*compiled_module);
Handle<WeakCell> link_to_module = Handle<WeakCell> link_to_module =
isolate->factory()->NewWeakCell(module_object); isolate->factory()->NewWeakCell(module_object);
compiled_module->set_weak_wasm_module(link_to_module); compiled_module->set_weak_wasm_module(*link_to_module);
return module_object; return module_object;
} }
...@@ -181,7 +183,7 @@ void WasmModuleObject::ValidateStateForTesting( ...@@ -181,7 +183,7 @@ void WasmModuleObject::ValidateStateForTesting(
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = module_obj->compiled_module(); WasmCompiledModule* compiled_module = module_obj->compiled_module();
CHECK(compiled_module->has_weak_wasm_module()); CHECK(compiled_module->has_weak_wasm_module());
CHECK_EQ(compiled_module->ptr_to_weak_wasm_module()->value(), *module_obj); CHECK_EQ(compiled_module->weak_wasm_module()->value(), *module_obj);
CHECK(!compiled_module->has_prev_instance()); CHECK(!compiled_module->has_prev_instance());
CHECK(!compiled_module->has_next_instance()); CHECK(!compiled_module->has_next_instance());
CHECK(!compiled_module->has_weak_owning_instance()); CHECK(!compiled_module->has_weak_owning_instance());
...@@ -293,23 +295,23 @@ void WasmTableObject::Grow(Isolate* isolate, uint32_t count) { ...@@ -293,23 +295,23 @@ void WasmTableObject::Grow(Isolate* isolate, uint32_t count) {
WasmInstanceObject::cast(dispatch_tables->get(i)); WasmInstanceObject::cast(dispatch_tables->get(i));
WasmCompiledModule* compiled_module = instance->compiled_module(); WasmCompiledModule* compiled_module = instance->compiled_module();
GlobalHandleAddress old_function_table_addr = GlobalHandleAddress old_function_table_addr =
WasmCompiledModule::GetTableValue( WasmCompiledModule::GetTableValue(compiled_module->function_tables(),
compiled_module->ptr_to_function_tables(), table_index); table_index);
GlobalHandleAddress old_signature_table_addr = GlobalHandleAddress old_signature_table_addr =
WasmCompiledModule::GetTableValue( WasmCompiledModule::GetTableValue(compiled_module->signature_tables(),
compiled_module->ptr_to_signature_tables(), table_index); table_index);
code_specialization.PatchTableSize(old_size, old_size + count); code_specialization.PatchTableSize(old_size, old_size + count);
code_specialization.RelocatePointer(old_function_table_addr, code_specialization.RelocatePointer(old_function_table_addr,
new_function_table_addr); new_function_table_addr);
code_specialization.RelocatePointer(old_signature_table_addr, code_specialization.RelocatePointer(old_signature_table_addr,
new_signature_table_addr); new_signature_table_addr);
code_specialization.ApplyToWholeInstance(instance); code_specialization.ApplyToWholeInstance(instance);
WasmCompiledModule::UpdateTableValue( WasmCompiledModule::UpdateTableValue(compiled_module->function_tables(),
compiled_module->ptr_to_function_tables(), table_index, table_index,
new_function_table_addr); new_function_table_addr);
WasmCompiledModule::UpdateTableValue( WasmCompiledModule::UpdateTableValue(compiled_module->signature_tables(),
compiled_module->ptr_to_signature_tables(), table_index, table_index,
new_signature_table_addr); new_signature_table_addr);
} }
} }
} }
...@@ -539,7 +541,7 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate, ...@@ -539,7 +541,7 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate,
} }
WasmModuleObject* WasmInstanceObject::module_object() { WasmModuleObject* WasmInstanceObject::module_object() {
return *compiled_module()->wasm_module(); return compiled_module()->wasm_module();
} }
WasmModule* WasmInstanceObject::module() { WasmModule* WasmInstanceObject::module() {
...@@ -613,7 +615,7 @@ WasmInstanceObject* WasmInstanceObject::GetOwningInstance( ...@@ -613,7 +615,7 @@ WasmInstanceObject* WasmInstanceObject::GetOwningInstance(
Object* weak_link = nullptr; Object* weak_link = nullptr;
DCHECK(code->kind() == wasm::WasmCode::kFunction || DCHECK(code->kind() == wasm::WasmCode::kFunction ||
code->kind() == wasm::WasmCode::kInterpreterStub); code->kind() == wasm::WasmCode::kInterpreterStub);
weak_link = code->owner()->compiled_module()->ptr_to_weak_owning_instance(); weak_link = code->owner()->compiled_module()->weak_owning_instance();
DCHECK(weak_link->IsWeakCell()); DCHECK(weak_link->IsWeakCell());
WeakCell* cell = WeakCell::cast(weak_link); WeakCell* cell = WeakCell::cast(weak_link);
if (cell->cleared()) return nullptr; if (cell->cleared()) return nullptr;
...@@ -639,21 +641,21 @@ void WasmInstanceObject::ValidateInstancesChainForTesting( ...@@ -639,21 +641,21 @@ void WasmInstanceObject::ValidateInstancesChainForTesting(
CHECK_GE(instance_count, 0); CHECK_GE(instance_count, 0);
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = module_obj->compiled_module(); WasmCompiledModule* compiled_module = module_obj->compiled_module();
CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), CHECK_EQ(JSObject::cast(compiled_module->weak_wasm_module()->value()),
*module_obj); *module_obj);
Object* prev = nullptr; Object* prev = nullptr;
int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0;
WasmCompiledModule* current_instance = compiled_module; WasmCompiledModule* current_instance = compiled_module;
while (current_instance->has_next_instance()) { while (current_instance->has_next_instance()) {
CHECK((prev == nullptr && !current_instance->has_prev_instance()) || CHECK((prev == nullptr && !current_instance->has_prev_instance()) ||
current_instance->ptr_to_prev_instance() == prev); current_instance->prev_instance() == prev);
CHECK_EQ(current_instance->ptr_to_weak_wasm_module()->value(), *module_obj); CHECK_EQ(current_instance->weak_wasm_module()->value(), *module_obj);
CHECK(current_instance->ptr_to_weak_owning_instance() CHECK(current_instance->weak_owning_instance()
->value() ->value()
->IsWasmInstanceObject()); ->IsWasmInstanceObject());
prev = current_instance; prev = current_instance;
current_instance = current_instance =
WasmCompiledModule::cast(current_instance->ptr_to_next_instance()); WasmCompiledModule::cast(current_instance->next_instance());
++found_instances; ++found_instances;
CHECK_LE(found_instances, instance_count); CHECK_LE(found_instances, instance_count);
} }
...@@ -665,7 +667,7 @@ void WasmInstanceObject::ValidateOrphanedInstanceForTesting( ...@@ -665,7 +667,7 @@ void WasmInstanceObject::ValidateOrphanedInstanceForTesting(
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = instance->compiled_module(); WasmCompiledModule* compiled_module = instance->compiled_module();
CHECK(compiled_module->has_weak_wasm_module()); CHECK(compiled_module->has_weak_wasm_module());
CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); CHECK(compiled_module->weak_wasm_module()->cleared());
} }
bool WasmExportedFunction::IsWasmExportedFunction(Object* object) { bool WasmExportedFunction::IsWasmExportedFunction(Object* object) {
...@@ -1253,13 +1255,13 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1253,13 +1255,13 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
// WasmCompiledModule::cast would fail since fields are not set yet. // WasmCompiledModule::cast would fail since fields are not set yet.
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
reinterpret_cast<WasmCompiledModule*>(*ret), isolate); reinterpret_cast<WasmCompiledModule*>(*ret), isolate);
compiled_module->set_native_context(isolate->native_context()); compiled_module->set_native_context(*isolate->native_context());
compiled_module->set_use_trap_handler(use_trap_handler); compiled_module->set_use_trap_handler(use_trap_handler);
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
compiled_module->InitId(); compiled_module->InitId();
compiled_module->set_native_context(isolate->native_context()); compiled_module->set_native_context(*isolate->native_context());
compiled_module->set_code_table(code_table); compiled_module->set_code_table(*code_table);
compiled_module->set_export_wrappers(export_wrappers); compiled_module->set_export_wrappers(*export_wrappers);
// TODO(mtrofin): we copy these because the order of finalization isn't // TODO(mtrofin): we copy these because the order of finalization isn't
// reliable, and we need these at Reset (which is called at // reliable, and we need these at Reset (which is called at
// finalization). If the order were reliable, and top-down, we could instead // finalization). If the order were reliable, and top-down, we could instead
...@@ -1282,14 +1284,14 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1282,14 +1284,14 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
// assumption that we compile and then instantiate. It needs rework if we // assumption that we compile and then instantiate. It needs rework if we
// do direct instantiation. The empty tables are used as a default when // do direct instantiation. The empty tables are used as a default when
// resetting the compiled module. // resetting the compiled module.
compiled_module->set_signature_tables(st); compiled_module->set_signature_tables(*st);
compiled_module->set_empty_signature_tables(st); compiled_module->set_empty_signature_tables(*st);
compiled_module->set_function_tables(ft); compiled_module->set_function_tables(*ft);
compiled_module->set_empty_function_tables(ft); compiled_module->set_empty_function_tables(*ft);
} }
} else { } else {
if (!export_wrappers.is_null()) { if (!export_wrappers.is_null()) {
compiled_module->set_export_wrappers(export_wrappers); compiled_module->set_export_wrappers(*export_wrappers);
} }
wasm::NativeModule* native_module = nullptr; wasm::NativeModule* native_module = nullptr;
{ {
...@@ -1298,7 +1300,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1298,7 +1300,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
native_module = native_module_ptr.release(); native_module = native_module_ptr.release();
Handle<Foreign> native_module_wrapper = Handle<Foreign> native_module_wrapper =
Managed<wasm::NativeModule>::From(isolate, native_module); Managed<wasm::NativeModule>::From(isolate, native_module);
compiled_module->set_native_module(native_module_wrapper); compiled_module->set_native_module(*native_module_wrapper);
Handle<WasmCompiledModule> weak_link = Handle<WasmCompiledModule> weak_link =
isolate->global_handles()->Create(*compiled_module); isolate->global_handles()->Create(*compiled_module);
GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(), GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(),
...@@ -1310,7 +1312,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1310,7 +1312,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
// This is here just because it's easier for APIs that need to work with // This is here just because it's easier for APIs that need to work with
// either code_table or native_module. Otherwise we need to check if // either code_table or native_module. Otherwise we need to check if
// has_code_table and pass undefined. // has_code_table and pass undefined.
compiled_module->set_code_table(code_table); compiled_module->set_code_table(*code_table);
native_module->function_tables() = function_tables; native_module->function_tables() = function_tables;
native_module->signature_tables() = signature_tables; native_module->signature_tables() = signature_tables;
...@@ -1320,10 +1322,10 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1320,10 +1322,10 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
int function_count = static_cast<int>(module->functions.size()); int function_count = static_cast<int>(module->functions.size());
Handle<FixedArray> handler_table = Handle<FixedArray> handler_table =
isolate->factory()->NewFixedArray(function_count, TENURED); isolate->factory()->NewFixedArray(function_count, TENURED);
compiled_module->set_handler_table(handler_table); compiled_module->set_handler_table(*handler_table);
Handle<FixedArray> source_positions = Handle<FixedArray> source_positions =
isolate->factory()->NewFixedArray(function_count, TENURED); isolate->factory()->NewFixedArray(function_count, TENURED);
compiled_module->set_source_positions(source_positions); compiled_module->set_source_positions(*source_positions);
} }
// TODO(mtrofin): copy the rest of the specialization parameters over. // TODO(mtrofin): copy the rest of the specialization parameters over.
// We're currently OK because we're only using defaults. // We're currently OK because we're only using defaults.
...@@ -1334,7 +1336,8 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1334,7 +1336,8 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
Isolate* isolate, Handle<WasmCompiledModule> module) { Isolate* isolate, Handle<WasmCompiledModule> module) {
Handle<FixedArray> code_copy; Handle<FixedArray> code_copy;
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
code_copy = isolate->factory()->CopyFixedArray(module->code_table()); code_copy = isolate->factory()->CopyFixedArray(
handle(module->code_table(), isolate));
} }
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
isolate->factory()->CopyFixedArray(module)); isolate->factory()->CopyFixedArray(module));
...@@ -1344,7 +1347,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1344,7 +1347,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
ret->reset_weak_exported_functions(); ret->reset_weak_exported_functions();
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
ret->InitId(); ret->InitId();
ret->set_code_table(code_copy); ret->set_code_table(*code_copy);
return ret; return ret;
} }
...@@ -1354,7 +1357,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1354,7 +1357,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
// which would shift the this pointer in set_native_module. // which would shift the this pointer in set_native_module.
Handle<Foreign> native_module_wrapper = Handle<Foreign> native_module_wrapper =
Managed<wasm::NativeModule>::From(isolate, native_module.release()); Managed<wasm::NativeModule>::From(isolate, native_module.release());
ret->set_native_module(native_module_wrapper); ret->set_native_module(*native_module_wrapper);
Handle<WasmCompiledModule> weak_link = Handle<WasmCompiledModule> weak_link =
isolate->global_handles()->Create(*ret); isolate->global_handles()->Create(*ret);
GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(), GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(),
...@@ -1366,7 +1369,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1366,7 +1369,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
if (module->has_lazy_compile_data()) { if (module->has_lazy_compile_data()) {
Handle<FixedArray> lazy_comp_data = isolate->factory()->NewFixedArray( Handle<FixedArray> lazy_comp_data = isolate->factory()->NewFixedArray(
module->lazy_compile_data()->length(), TENURED); module->lazy_compile_data()->length(), TENURED);
ret->set_lazy_compile_data(lazy_comp_data); ret->set_lazy_compile_data(*lazy_comp_data);
} }
return ret; return ret;
} }
...@@ -1394,7 +1397,7 @@ Address WasmCompiledModule::GetTableValue(FixedArray* table, int index) { ...@@ -1394,7 +1397,7 @@ Address WasmCompiledModule::GetTableValue(FixedArray* table, int index) {
wasm::NativeModule* WasmCompiledModule::GetNativeModule() const { wasm::NativeModule* WasmCompiledModule::GetNativeModule() const {
if (!has_native_module()) return nullptr; if (!has_native_module()) return nullptr;
return Managed<wasm::NativeModule>::cast(ptr_to_native_module())->get(); return Managed<wasm::NativeModule>::cast(native_module())->get();
} }
void WasmCompiledModule::ResetGCModel(Isolate* isolate, void WasmCompiledModule::ResetGCModel(Isolate* isolate,
...@@ -1402,7 +1405,7 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate, ...@@ -1402,7 +1405,7 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate,
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
TRACE("Resetting %d\n", compiled_module->instance_id()); TRACE("Resetting %d\n", compiled_module->instance_id());
Object* undefined = *isolate->factory()->undefined_value(); Object* undefined = *isolate->factory()->undefined_value();
Object* fct_obj = compiled_module->ptr_to_code_table(); Object* fct_obj = compiled_module->code_table();
if (fct_obj != nullptr && fct_obj != undefined) { if (fct_obj != nullptr && fct_obj != undefined) {
// Patch code to update memory references, global references, and function // Patch code to update memory references, global references, and function
// table references. // table references.
...@@ -1411,12 +1414,12 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate, ...@@ -1411,12 +1414,12 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate,
// Reset function tables. // Reset function tables.
if (compiled_module->has_function_tables()) { if (compiled_module->has_function_tables()) {
FixedArray* function_tables = compiled_module->ptr_to_function_tables(); FixedArray* function_tables = compiled_module->function_tables();
FixedArray* signature_tables = compiled_module->ptr_to_signature_tables(); FixedArray* signature_tables = compiled_module->signature_tables();
FixedArray* empty_function_tables = FixedArray* empty_function_tables =
compiled_module->ptr_to_empty_function_tables(); compiled_module->empty_function_tables();
FixedArray* empty_signature_tables = FixedArray* empty_signature_tables =
compiled_module->ptr_to_empty_signature_tables(); compiled_module->empty_signature_tables();
if (function_tables != empty_function_tables) { if (function_tables != empty_function_tables) {
DCHECK_EQ(function_tables->length(), empty_function_tables->length()); DCHECK_EQ(function_tables->length(), empty_function_tables->length());
for (int i = 0, e = function_tables->length(); i < e; ++i) { for (int i = 0, e = function_tables->length(); i < e; ++i) {
...@@ -1431,8 +1434,8 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate, ...@@ -1431,8 +1434,8 @@ void WasmCompiledModule::ResetGCModel(Isolate* isolate,
sig_addr, sig_addr,
WasmCompiledModule::GetTableValue(empty_signature_tables, i)); WasmCompiledModule::GetTableValue(empty_signature_tables, i));
} }
compiled_module->set_ptr_to_function_tables(empty_function_tables); compiled_module->set_function_tables(empty_function_tables);
compiled_module->set_ptr_to_signature_tables(empty_signature_tables); compiled_module->set_signature_tables(empty_signature_tables);
} }
} }
...@@ -1624,7 +1627,7 @@ void WasmCompiledModule::PrintInstancesChain() { ...@@ -1624,7 +1627,7 @@ void WasmCompiledModule::PrintInstancesChain() {
PrintF("->%d", current->instance_id()); PrintF("->%d", current->instance_id());
} }
if (!current->has_next_instance()) break; if (!current->has_next_instance()) break;
current = current->ptr_to_next_instance(); current = current->next_instance();
} }
PrintF("\n"); PrintF("\n");
#endif #endif
...@@ -1633,8 +1636,8 @@ void WasmCompiledModule::PrintInstancesChain() { ...@@ -1633,8 +1636,8 @@ void WasmCompiledModule::PrintInstancesChain() {
void WasmCompiledModule::InsertInChain(WasmModuleObject* module) { void WasmCompiledModule::InsertInChain(WasmModuleObject* module) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmCompiledModule* original = module->compiled_module(); WasmCompiledModule* original = module->compiled_module();
set_ptr_to_next_instance(original); set_next_instance(original);
original->set_ptr_to_prev_instance(this); original->set_prev_instance(this);
set_weak_wasm_module(original->weak_wasm_module()); set_weak_wasm_module(original->weak_wasm_module());
} }
...@@ -1655,7 +1658,7 @@ void WasmCompiledModule::RemoveFromChain() { ...@@ -1655,7 +1658,7 @@ void WasmCompiledModule::RemoveFromChain() {
void WasmCompiledModule::OnWasmModuleDecodingComplete( void WasmCompiledModule::OnWasmModuleDecodingComplete(
Handle<WasmSharedModuleData> shared) { Handle<WasmSharedModuleData> shared) {
set_shared(shared); set_shared(*shared);
} }
void WasmCompiledModule::ReinitializeAfterDeserialization( void WasmCompiledModule::ReinitializeAfterDeserialization(
...@@ -1679,11 +1682,17 @@ void WasmCompiledModule::ReinitializeAfterDeserialization( ...@@ -1679,11 +1682,17 @@ void WasmCompiledModule::ReinitializeAfterDeserialization(
// addresses. Produce new global handles for the empty tables, then reset, // addresses. Produce new global handles for the empty tables, then reset,
// which will relocate the code. We end up with a WasmCompiledModule as-if // which will relocate the code. We end up with a WasmCompiledModule as-if
// it were just compiled. // it were just compiled.
Handle<FixedArray> function_tables;
Handle<FixedArray> signature_tables;
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
DCHECK(compiled_module->has_function_tables()); DCHECK(compiled_module->has_function_tables());
DCHECK(compiled_module->has_signature_tables()); DCHECK(compiled_module->has_signature_tables());
DCHECK(compiled_module->has_empty_signature_tables()); DCHECK(compiled_module->has_empty_signature_tables());
DCHECK(compiled_module->has_empty_function_tables()); DCHECK(compiled_module->has_empty_function_tables());
function_tables =
handle(compiled_module->empty_function_tables(), isolate);
signature_tables =
handle(compiled_module->empty_signature_tables(), isolate);
} else { } else {
DCHECK_GT(native_module->function_tables().size(), 0); DCHECK_GT(native_module->function_tables().size(), 0);
DCHECK_GT(native_module->signature_tables().size(), 0); DCHECK_GT(native_module->signature_tables().size(), 0);
...@@ -1700,10 +1709,10 @@ void WasmCompiledModule::ReinitializeAfterDeserialization( ...@@ -1700,10 +1709,10 @@ void WasmCompiledModule::ReinitializeAfterDeserialization(
GlobalHandleAddress new_func_table = global_func_table_handle.address(); GlobalHandleAddress new_func_table = global_func_table_handle.address();
GlobalHandleAddress new_sig_table = global_sig_table_handle.address(); GlobalHandleAddress new_sig_table = global_sig_table_handle.address();
if (!FLAG_wasm_jit_to_native) { if (!FLAG_wasm_jit_to_native) {
SetTableValue(isolate, compiled_module->empty_function_tables(), SetTableValue(isolate, function_tables, static_cast<int>(i),
static_cast<int>(i), new_func_table); new_func_table);
SetTableValue(isolate, compiled_module->empty_signature_tables(), SetTableValue(isolate, signature_tables, static_cast<int>(i),
static_cast<int>(i), new_sig_table); new_sig_table);
} else { } else {
native_module->empty_function_tables()[i] = new_func_table; native_module->empty_function_tables()[i] = new_func_table;
native_module->empty_signature_tables()[i] = new_sig_table; native_module->empty_signature_tables()[i] = new_sig_table;
...@@ -1807,7 +1816,7 @@ bool WasmCompiledModule::SetBreakPoint( ...@@ -1807,7 +1816,7 @@ bool WasmCompiledModule::SetBreakPoint(
Handle<WasmCompiledModule> compiled_module, int* position, Handle<WasmCompiledModule> compiled_module, int* position,
Handle<Object> break_point_object) { Handle<Object> break_point_object) {
Isolate* isolate = compiled_module->GetIsolate(); Isolate* isolate = compiled_module->GetIsolate();
Handle<WasmSharedModuleData> shared = compiled_module->shared(); Handle<WasmSharedModuleData> shared(compiled_module->shared(), isolate);
// Find the function for this breakpoint. // Find the function for this breakpoint.
int func_index = shared->GetContainingFunction(*position); int func_index = shared->GetContainingFunction(*position);
......
...@@ -426,16 +426,13 @@ class WasmCompiledModule : public FixedArray { ...@@ -426,16 +426,13 @@ class WasmCompiledModule : public FixedArray {
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK, SETTER_MODIFIER) \ #define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK, SETTER_MODIFIER) \
public: \ public: \
inline Handle<TYPE> NAME() const; \ inline TYPE* maybe_##NAME() const; \
inline MaybeHandle<TYPE> maybe_##NAME() const; \ inline TYPE* NAME() const; \
inline TYPE* maybe_ptr_to_##NAME() const; \
inline TYPE* ptr_to_##NAME() const; \
inline bool has_##NAME() const; \ inline bool has_##NAME() const; \
inline void reset_##NAME(); \ inline void reset_##NAME(); \
\ \
SETTER_MODIFIER: \ SETTER_MODIFIER: \
inline void set_##NAME(Handle<TYPE> value); \ inline void set_##NAME(TYPE* value);
inline void set_ptr_to_##NAME(TYPE* value);
#define WCM_OBJECT(TYPE, NAME) \ #define WCM_OBJECT(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), public) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), public)
...@@ -458,7 +455,7 @@ class WasmCompiledModule : public FixedArray { ...@@ -458,7 +455,7 @@ class WasmCompiledModule : public FixedArray {
public) \ public) \
\ \
public: \ public: \
inline Handle<TYPE> NAME() const; inline TYPE* NAME() const;
// Add values here if they are required for creating new instances or // Add values here if they are required for creating new instances or
// for deserialization, and if they are serializable. // for deserialization, and if they are serializable.
......
...@@ -268,7 +268,7 @@ WASM_COMPILED_EXEC_TEST(WasmCollectPossibleBreakpoints) { ...@@ -268,7 +268,7 @@ WASM_COMPILED_EXEC_TEST(WasmCollectPossibleBreakpoints) {
BUILD(runner, WASM_NOP, WASM_I32_ADD(WASM_ZERO, WASM_ONE)); BUILD(runner, WASM_NOP, WASM_I32_ADD(WASM_ZERO, WASM_ONE));
WasmInstanceObject* instance = *runner.builder().instance_object(); WasmInstanceObject* instance = *runner.builder().instance_object();
WasmSharedModuleData* shared = instance->compiled_module()->ptr_to_shared(); WasmSharedModuleData* shared = instance->compiled_module()->shared();
std::vector<debug::Location> locations; std::vector<debug::Location> locations;
// Check all locations for function 0. // Check all locations for function 0.
......
...@@ -132,13 +132,14 @@ Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) { ...@@ -132,13 +132,14 @@ Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) {
// Add weak reference to exported functions. // Add weak reference to exported functions.
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
instance_object()->compiled_module(), isolate_); instance_object()->compiled_module(), isolate_);
Handle<FixedArray> old_arr = compiled_module->weak_exported_functions(); Handle<FixedArray> old_arr(compiled_module->weak_exported_functions(),
isolate_);
Handle<FixedArray> new_arr = Handle<FixedArray> new_arr =
isolate_->factory()->NewFixedArray(old_arr->length() + 1); isolate_->factory()->NewFixedArray(old_arr->length() + 1);
old_arr->CopyTo(0, *new_arr, 0, old_arr->length()); old_arr->CopyTo(0, *new_arr, 0, old_arr->length());
Handle<WeakCell> weak_fn = isolate_->factory()->NewWeakCell(ret); Handle<WeakCell> weak_fn = isolate_->factory()->NewWeakCell(ret);
new_arr->set(old_arr->length(), *weak_fn); new_arr->set(old_arr->length(), *weak_fn);
compiled_module->set_weak_exported_functions(new_arr); compiled_module->set_weak_exported_functions(*new_arr);
return ret; return ret;
} }
...@@ -193,8 +194,8 @@ void TestingModuleBuilder::PopulateIndirectFunctionTable() { ...@@ -193,8 +194,8 @@ void TestingModuleBuilder::PopulateIndirectFunctionTable() {
} }
uint32_t TestingModuleBuilder::AddBytes(Vector<const byte> bytes) { uint32_t TestingModuleBuilder::AddBytes(Vector<const byte> bytes) {
Handle<WasmSharedModuleData> shared = Handle<WasmSharedModuleData> shared(
instance_object_->compiled_module()->shared(); instance_object_->compiled_module()->shared(), isolate_);
Handle<SeqOneByteString> old_bytes(shared->module_bytes(), isolate_); Handle<SeqOneByteString> old_bytes(shared->module_bytes(), isolate_);
uint32_t old_size = static_cast<uint32_t>(old_bytes->length()); uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
// Avoid placing strings at offset 0, this might be interpreted as "not // Avoid placing strings at offset 0, this might be interpreted as "not
...@@ -251,13 +252,13 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() { ...@@ -251,13 +252,13 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
native_module_ = compiled_module->GetNativeModule(); native_module_ = compiled_module->GetNativeModule();
Handle<FixedArray> weak_exported = isolate_->factory()->NewFixedArray(0); Handle<FixedArray> weak_exported = isolate_->factory()->NewFixedArray(0);
compiled_module->set_weak_exported_functions(weak_exported); compiled_module->set_weak_exported_functions(*weak_exported);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
script->set_wasm_compiled_module(*compiled_module); script->set_wasm_compiled_module(*compiled_module);
auto instance = WasmInstanceObject::New(isolate_, compiled_module); auto instance = WasmInstanceObject::New(isolate_, compiled_module);
instance->wasm_context()->get()->globals_start = globals_data_; instance->wasm_context()->get()->globals_start = globals_data_;
Handle<WeakCell> weak_instance = isolate()->factory()->NewWeakCell(instance); Handle<WeakCell> weak_instance = isolate()->factory()->NewWeakCell(instance);
compiled_module->set_weak_owning_instance(weak_instance); compiled_module->set_weak_owning_instance(*weak_instance);
return instance; return instance;
} }
...@@ -490,7 +491,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -490,7 +491,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
builder_->SetFunctionCode(function_index(), code); builder_->SetFunctionCode(function_index(), code);
// Add to code table. // Add to code table.
Handle<FixedArray> code_table = compiled_module->code_table(); Handle<FixedArray> code_table(compiled_module->code_table(), isolate());
if (static_cast<int>(function_index()) >= code_table->length()) { if (static_cast<int>(function_index()) >= code_table->length()) {
Handle<FixedArray> new_arr = isolate()->factory()->NewFixedArray( Handle<FixedArray> new_arr = isolate()->factory()->NewFixedArray(
static_cast<int>(function_index()) + 1); static_cast<int>(function_index()) + 1);
......
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