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