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;
......
This diff is collapsed.
...@@ -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"
......
This diff is collapsed.
...@@ -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