Commit 541abb1c authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move {shared} field to {WasmModuleObject}.

This makes the fact that {WasmSharedModuleData} is shared across
instances explicit by hanging this {shared} reference off the module
object instead of the instance-specific {WasmCompiledModule} object.

R=titzer@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I99bf3d855d6283bdc48373f0f8e2df1990905d3f
Reviewed-on: https://chromium-review.googlesource.com/1051909
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53163}
parent 1825cccf
...@@ -7416,9 +7416,7 @@ MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target, ...@@ -7416,9 +7416,7 @@ MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
Local<String> WasmCompiledModule::GetWasmWireBytes() { Local<String> WasmCompiledModule::GetWasmWireBytes() {
i::Handle<i::WasmModuleObject> obj = i::Handle<i::WasmModuleObject> obj =
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this)); i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
i::Handle<i::WasmCompiledModule> compiled_part = i::Handle<i::String> wire_bytes(obj->shared()->module_bytes());
i::handle(obj->compiled_module());
i::Handle<i::String> wire_bytes(compiled_part->shared()->module_bytes());
return Local<String>::Cast(Utils::ToLocal(wire_bytes)); return Local<String>::Cast(Utils::ToLocal(wire_bytes));
} }
......
...@@ -1317,18 +1317,18 @@ WASM_SUMMARY_DISPATCH(int, byte_offset) ...@@ -1317,18 +1317,18 @@ WASM_SUMMARY_DISPATCH(int, byte_offset)
int FrameSummary::WasmFrameSummary::SourcePosition() const { int FrameSummary::WasmFrameSummary::SourcePosition() const {
Handle<WasmSharedModuleData> shared( Handle<WasmSharedModuleData> shared(
wasm_instance()->compiled_module()->shared(), isolate()); wasm_instance()->module_object()->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());
} }
Handle<Script> FrameSummary::WasmFrameSummary::script() const { Handle<Script> FrameSummary::WasmFrameSummary::script() const {
return handle(wasm_instance()->compiled_module()->shared()->script()); return handle(wasm_instance()->module_object()->shared()->script());
} }
Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const { Handle<String> FrameSummary::WasmFrameSummary::FunctionName() const {
Handle<WasmSharedModuleData> shared( Handle<WasmSharedModuleData> shared(
wasm_instance()->compiled_module()->shared(), isolate()); wasm_instance()->module_object()->shared(), isolate());
return WasmSharedModuleData::GetFunctionName(isolate(), shared, return WasmSharedModuleData::GetFunctionName(isolate(), shared,
function_index()); function_index());
} }
...@@ -1803,7 +1803,7 @@ WasmInstanceObject* WasmCompiledFrame::wasm_instance() const { ...@@ -1803,7 +1803,7 @@ WasmInstanceObject* WasmCompiledFrame::wasm_instance() const {
} }
WasmSharedModuleData* WasmCompiledFrame::shared() const { WasmSharedModuleData* WasmCompiledFrame::shared() const {
return wasm_instance()->compiled_module()->shared(); return wasm_instance()->module_object()->shared();
} }
WasmCompiledModule* WasmCompiledFrame::compiled_module() const { WasmCompiledModule* WasmCompiledFrame::compiled_module() const {
...@@ -1899,7 +1899,7 @@ WasmDebugInfo* WasmInterpreterEntryFrame::debug_info() const { ...@@ -1899,7 +1899,7 @@ WasmDebugInfo* WasmInterpreterEntryFrame::debug_info() const {
} }
WasmSharedModuleData* WasmInterpreterEntryFrame::shared() const { WasmSharedModuleData* WasmInterpreterEntryFrame::shared() const {
return wasm_instance()->compiled_module()->shared(); return wasm_instance()->module_object()->shared();
} }
WasmCompiledModule* WasmInterpreterEntryFrame::compiled_module() const { WasmCompiledModule* WasmInterpreterEntryFrame::compiled_module() const {
......
...@@ -470,7 +470,7 @@ class FrameArrayBuilder { ...@@ -470,7 +470,7 @@ class FrameArrayBuilder {
} }
Handle<WasmInstanceObject> instance = summary.wasm_instance(); Handle<WasmInstanceObject> instance = summary.wasm_instance();
int flags = 0; int flags = 0;
if (instance->compiled_module()->shared()->is_asm_js()) { if (instance->module_object()->shared()->is_asm_js()) {
flags |= FrameArray::kIsAsmJsWasmFrame; flags |= FrameArray::kIsAsmJsWasmFrame;
if (WasmCompiledFrame::cast(frame)->at_to_number_conversion()) { if (WasmCompiledFrame::cast(frame)->at_to_number_conversion()) {
flags |= FrameArray::kAsmJsAtNumberConversion; flags |= FrameArray::kAsmJsAtNumberConversion;
...@@ -489,7 +489,7 @@ class FrameArrayBuilder { ...@@ -489,7 +489,7 @@ class FrameArrayBuilder {
const auto& summary = summ.AsWasmInterpreted(); const auto& summary = summ.AsWasmInterpreted();
Handle<WasmInstanceObject> instance = summary.wasm_instance(); Handle<WasmInstanceObject> instance = summary.wasm_instance();
int flags = FrameArray::kIsWasmInterpretedFrame; int flags = FrameArray::kIsWasmInterpretedFrame;
DCHECK(!instance->compiled_module()->shared()->is_asm_js()); DCHECK(!instance->module_object()->shared()->is_asm_js());
elements_ = FrameArray::AppendWasmFrame(elements_, instance, elements_ = FrameArray::AppendWasmFrame(elements_, instance,
summary.function_index(), {}, summary.function_index(), {},
summary.byte_offset(), flags); summary.byte_offset(), flags);
...@@ -807,7 +807,7 @@ class CaptureStackTraceHelper { ...@@ -807,7 +807,7 @@ class CaptureStackTraceHelper {
Handle<StackFrameInfo> info = factory()->NewStackFrameInfo(); Handle<StackFrameInfo> info = factory()->NewStackFrameInfo();
Handle<WasmSharedModuleData> shared( Handle<WasmSharedModuleData> shared(
summ.wasm_instance()->compiled_module()->shared(), isolate_); summ.wasm_instance()->module_object()->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);
...@@ -1738,8 +1738,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1738,8 +1738,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
const int frame_count = elements->FrameCount(); const int frame_count = elements->FrameCount();
for (int i = 0; i < frame_count; i++) { for (int i = 0; i < frame_count; i++) {
if (elements->IsWasmFrame(i) || elements->IsAsmJsWasmFrame(i)) { if (elements->IsWasmFrame(i) || elements->IsAsmJsWasmFrame(i)) {
Handle<WasmCompiledModule> compiled_module( Handle<WasmInstanceObject> instance(elements->WasmInstance(i));
elements->WasmInstance(i)->compiled_module());
uint32_t func_index = uint32_t func_index =
static_cast<uint32_t>(elements->WasmFunctionIndex(i)->value()); static_cast<uint32_t>(elements->WasmFunctionIndex(i)->value());
int code_offset = elements->Offset(i)->value(); int code_offset = elements->Offset(i)->value();
...@@ -1748,16 +1747,16 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1748,16 +1747,16 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
// a second lookup here could lead to inconsistency. // a second lookup here could lead to inconsistency.
int byte_offset = int byte_offset =
FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition( FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
compiled_module->GetNativeModule()->code(func_index), instance->compiled_module()->GetNativeModule()->code(func_index),
code_offset); code_offset);
bool is_at_number_conversion = bool is_at_number_conversion =
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(
handle(compiled_module->shared(), this), func_index, byte_offset, handle(instance->module_object()->shared(), this), func_index,
is_at_number_conversion); byte_offset, is_at_number_conversion);
Handle<Script> script(compiled_module->shared()->script()); Handle<Script> script(instance->module_object()->shared()->script());
*target = MessageLocation(script, pos, pos + 1); *target = MessageLocation(script, pos, pos + 1);
return true; return true;
......
...@@ -664,8 +664,8 @@ Handle<Object> WasmStackFrame::GetFunction() const { ...@@ -664,8 +664,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_->module_object()->shared(),
wasm_instance_->compiled_module()->shared(), isolate_); isolate_);
if (!WasmSharedModuleData::GetFunctionNameOrNull(isolate_, shared, if (!WasmSharedModuleData::GetFunctionNameOrNull(isolate_, shared,
wasm_func_index_) wasm_func_index_)
.ToHandle(&name)) { .ToHandle(&name)) {
...@@ -677,8 +677,8 @@ Handle<Object> WasmStackFrame::GetFunctionName() { ...@@ -677,8 +677,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_->module_object()->shared(),
wasm_instance_->compiled_module()->shared(), isolate_); 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 =
...@@ -726,8 +726,7 @@ Handle<Object> WasmStackFrame::Null() const { ...@@ -726,8 +726,7 @@ Handle<Object> WasmStackFrame::Null() const {
bool WasmStackFrame::HasScript() const { return true; } bool WasmStackFrame::HasScript() const { return true; }
Handle<Script> WasmStackFrame::GetScript() const { Handle<Script> WasmStackFrame::GetScript() const {
return handle(wasm_instance_->compiled_module()->shared()->script(), return handle(wasm_instance_->module_object()->shared()->script(), isolate_);
isolate_);
} }
AsmJsWasmStackFrame::AsmJsWasmStackFrame() {} AsmJsWasmStackFrame::AsmJsWasmStackFrame() {}
...@@ -751,14 +750,14 @@ Handle<Object> AsmJsWasmStackFrame::GetFunction() const { ...@@ -751,14 +750,14 @@ Handle<Object> AsmJsWasmStackFrame::GetFunction() const {
} }
Handle<Object> AsmJsWasmStackFrame::GetFileName() { Handle<Object> AsmJsWasmStackFrame::GetFileName() {
Handle<Script> script(wasm_instance_->compiled_module()->shared()->script(), Handle<Script> script(wasm_instance_->module_object()->shared()->script(),
isolate_); isolate_);
DCHECK(script->IsUserJavaScript()); DCHECK(script->IsUserJavaScript());
return handle(script->name(), isolate_); return handle(script->name(), isolate_);
} }
Handle<Object> AsmJsWasmStackFrame::GetScriptNameOrSourceUrl() { Handle<Object> AsmJsWasmStackFrame::GetScriptNameOrSourceUrl() {
Handle<Script> script(wasm_instance_->compiled_module()->shared()->script(), Handle<Script> script(wasm_instance_->module_object()->shared()->script(),
isolate_); isolate_);
DCHECK_EQ(Script::TYPE_NORMAL, script->type()); DCHECK_EQ(Script::TYPE_NORMAL, script->type());
return ScriptNameOrSourceUrl(script, isolate_); return ScriptNameOrSourceUrl(script, isolate_);
...@@ -769,8 +768,8 @@ int AsmJsWasmStackFrame::GetPosition() const { ...@@ -769,8 +768,8 @@ int AsmJsWasmStackFrame::GetPosition() const {
int byte_offset = int byte_offset =
FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code_, FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code_,
offset_); offset_);
Handle<WasmSharedModuleData> shared( Handle<WasmSharedModuleData> shared(wasm_instance_->module_object()->shared(),
wasm_instance_->compiled_module()->shared(), isolate_); 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),
...@@ -779,7 +778,7 @@ int AsmJsWasmStackFrame::GetPosition() const { ...@@ -779,7 +778,7 @@ int AsmJsWasmStackFrame::GetPosition() const {
int AsmJsWasmStackFrame::GetLineNumber() { int AsmJsWasmStackFrame::GetLineNumber() {
DCHECK_LE(0, GetPosition()); DCHECK_LE(0, GetPosition());
Handle<Script> script(wasm_instance_->compiled_module()->shared()->script(), Handle<Script> script(wasm_instance_->module_object()->shared()->script(),
isolate_); isolate_);
DCHECK(script->IsUserJavaScript()); DCHECK(script->IsUserJavaScript());
return Script::GetLineNumber(script, GetPosition()) + 1; return Script::GetLineNumber(script, GetPosition()) + 1;
...@@ -787,7 +786,7 @@ int AsmJsWasmStackFrame::GetLineNumber() { ...@@ -787,7 +786,7 @@ int AsmJsWasmStackFrame::GetLineNumber() {
int AsmJsWasmStackFrame::GetColumnNumber() { int AsmJsWasmStackFrame::GetColumnNumber() {
DCHECK_LE(0, GetPosition()); DCHECK_LE(0, GetPosition());
Handle<Script> script(wasm_instance_->compiled_module()->shared()->script(), Handle<Script> script(wasm_instance_->module_object()->shared()->script(),
isolate_); isolate_);
DCHECK(script->IsUserJavaScript()); DCHECK(script->IsUserJavaScript());
return Script::GetColumnNumber(script, GetPosition()) + 1; return Script::GetColumnNumber(script, GetPosition()) + 1;
......
...@@ -1546,7 +1546,6 @@ void Tuple3::Tuple3Verify() { ...@@ -1546,7 +1546,6 @@ void Tuple3::Tuple3Verify() {
void WasmCompiledModule::WasmCompiledModuleVerify() { void WasmCompiledModule::WasmCompiledModuleVerify() {
CHECK(IsWasmCompiledModule()); CHECK(IsWasmCompiledModule());
VerifyObjectField(kSharedOffset);
VerifyObjectField(kNextInstanceOffset); VerifyObjectField(kNextInstanceOffset);
VerifyObjectField(kPrevInstanceOffset); VerifyObjectField(kPrevInstanceOffset);
VerifyObjectField(kOwningInstanceOffset); VerifyObjectField(kOwningInstanceOffset);
......
...@@ -1644,7 +1644,6 @@ void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT ...@@ -1644,7 +1644,6 @@ void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT
void WasmCompiledModule::WasmCompiledModulePrint(std::ostream& os) { // NOLINT void WasmCompiledModule::WasmCompiledModulePrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmCompiledModule"); HeapObject::PrintHeader(os, "WasmCompiledModule");
os << "\n - shared: " << Brief(shared());
os << "\n"; os << "\n";
} }
......
...@@ -872,12 +872,11 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) { ...@@ -872,12 +872,11 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) {
} }
} }
Handle<WasmCompiledModule> compiled_part(object->compiled_module(), isolate_);
WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes; WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes;
WriteTag(SerializationTag::kWasmModule); WriteTag(SerializationTag::kWasmModule);
WriteRawBytes(&encoding_tag, sizeof(encoding_tag)); WriteRawBytes(&encoding_tag, sizeof(encoding_tag));
Handle<String> wire_bytes(compiled_part->shared()->module_bytes(), isolate_); Handle<String> wire_bytes(object->shared()->module_bytes(), isolate_);
int wire_bytes_length = wire_bytes->length(); int wire_bytes_length = wire_bytes->length();
WriteVarint<uint32_t>(wire_bytes_length); WriteVarint<uint32_t>(wire_bytes_length);
uint8_t* destination; uint8_t* destination;
...@@ -885,6 +884,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) { ...@@ -885,6 +884,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) {
String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length); String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length);
} }
Handle<WasmCompiledModule> compiled_part(object->compiled_module(), isolate_);
size_t module_size = size_t module_size =
wasm::GetSerializedNativeModuleSize(isolate_, compiled_part); wasm::GetSerializedNativeModuleSize(isolate_, compiled_part);
CHECK_GE(std::numeric_limits<uint32_t>::max(), module_size); CHECK_GE(std::numeric_limits<uint32_t>::max(), module_size);
......
This diff is collapsed.
...@@ -72,7 +72,7 @@ bool CodeSpecialization::ApplyToWholeModule( ...@@ -72,7 +72,7 @@ bool CodeSpecialization::ApplyToWholeModule(
NativeModule* native_module, Handle<WasmModuleObject> module_object, NativeModule* native_module, Handle<WasmModuleObject> module_object,
ICacheFlushMode icache_flush_mode) { ICacheFlushMode icache_flush_mode) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmSharedModuleData* shared = module_object->compiled_module()->shared(); WasmSharedModuleData* shared = module_object->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;
FixedArray* export_wrappers = module_object->export_wrappers(); FixedArray* export_wrappers = module_object->export_wrappers();
......
...@@ -71,7 +71,7 @@ MaybeHandle<String> GetLocalName(Isolate* isolate, ...@@ -71,7 +71,7 @@ MaybeHandle<String> GetLocalName(Isolate* isolate,
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(), isolate); debug_info->wasm_instance()->module_object()->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);
} }
...@@ -132,10 +132,8 @@ class InterpreterHandle { ...@@ -132,10 +132,8 @@ class InterpreterHandle {
static Vector<const byte> GetBytes(WasmDebugInfo* debug_info) { static Vector<const byte> GetBytes(WasmDebugInfo* debug_info) {
// Return raw pointer into heap. The WasmInterpreter will make its own copy // Return raw pointer into heap. The WasmInterpreter will make its own copy
// of this data anyway, and there is no heap allocation in-between. // of this data anyway, and there is no heap allocation in-between.
SeqOneByteString* bytes_str = debug_info->wasm_instance() SeqOneByteString* bytes_str =
->compiled_module() debug_info->wasm_instance()->module_object()->shared()->module_bytes();
->shared()
->module_bytes();
return {bytes_str->GetChars(), static_cast<size_t>(bytes_str->length())}; return {bytes_str->GetChars(), static_cast<size_t>(bytes_str->length())};
} }
...@@ -144,7 +142,7 @@ class InterpreterHandle { ...@@ -144,7 +142,7 @@ class InterpreterHandle {
InterpreterHandle(Isolate* isolate, WasmDebugInfo* debug_info) InterpreterHandle(Isolate* isolate, WasmDebugInfo* debug_info)
: isolate_(isolate), : isolate_(isolate),
module_( module_(
debug_info->wasm_instance()->compiled_module()->shared()->module()), debug_info->wasm_instance()->module_object()->shared()->module()),
interpreter_(isolate, module_, GetBytes(debug_info), interpreter_(isolate, module_, GetBytes(debug_info),
handle(debug_info->wasm_instance())) {} handle(debug_info->wasm_instance())) {}
...@@ -309,7 +307,7 @@ class InterpreterHandle { ...@@ -309,7 +307,7 @@ 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(), isolate_); GetInstanceObject()->module_object()->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)
...@@ -557,7 +555,7 @@ wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) { ...@@ -557,7 +555,7 @@ wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) {
int GetNumFunctions(WasmInstanceObject* instance) { int GetNumFunctions(WasmInstanceObject* instance) {
size_t num_functions = size_t num_functions =
instance->compiled_module()->shared()->module()->functions.size(); instance->module_object()->shared()->module()->functions.size();
DCHECK_GE(kMaxInt, num_functions); DCHECK_GE(kMaxInt, num_functions);
return static_cast<int>(num_functions); return static_cast<int>(num_functions);
} }
......
...@@ -127,8 +127,7 @@ bool IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { ...@@ -127,8 +127,7 @@ 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->shared(), isolate);
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");
...@@ -197,8 +196,7 @@ Handle<JSArray> GetImports(Isolate* isolate, ...@@ -197,8 +196,7 @@ 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->shared(), isolate);
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");
...@@ -261,8 +259,7 @@ Handle<JSArray> GetExports(Isolate* isolate, ...@@ -261,8 +259,7 @@ 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->shared(), isolate);
module_object->compiled_module()->shared(), isolate);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
std::vector<CustomSectionOffset> custom_sections; std::vector<CustomSectionOffset> custom_sections;
......
...@@ -51,10 +51,7 @@ CAST_ACCESSOR(WasmTableObject) ...@@ -51,10 +51,7 @@ CAST_ACCESSOR(WasmTableObject)
ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule, ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset) kCompiledModuleOffset)
ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset) ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS(WasmModuleObject, shared, WasmSharedModuleData, kSharedOffset)
WasmSharedModuleData* WasmModuleObject::shared() const {
return compiled_module()->shared();
}
// WasmTableObject // WasmTableObject
ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset) ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset)
...@@ -232,7 +229,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -232,7 +229,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
} }
// WasmCompiledModule // WasmCompiledModule
WCM_OBJECT(WasmSharedModuleData, shared, kSharedOffset)
WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset) WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset) WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset) WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
......
...@@ -262,16 +262,17 @@ enum DispatchTableElements : int { ...@@ -262,16 +262,17 @@ enum DispatchTableElements : int {
Handle<WasmModuleObject> WasmModuleObject::New( Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module, Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers) { Handle<FixedArray> export_wrappers, Handle<WasmSharedModuleData> shared) {
Handle<JSFunction> module_cons( Handle<JSFunction> module_cons(
isolate->native_context()->wasm_module_constructor()); isolate->native_context()->wasm_module_constructor());
auto module_object = Handle<WasmModuleObject>::cast( auto module_object = Handle<WasmModuleObject>::cast(
isolate->factory()->NewJSObject(module_cons)); isolate->factory()->NewJSObject(module_cons));
module_object->set_compiled_module(*compiled_module); module_object->set_compiled_module(*compiled_module);
module_object->set_export_wrappers(*export_wrappers); module_object->set_export_wrappers(*export_wrappers);
if (compiled_module->shared()->script()->type() == Script::TYPE_WASM) { if (shared->script()->type() == Script::TYPE_WASM) {
compiled_module->shared()->script()->set_wasm_module_object(*module_object); shared->script()->set_wasm_module_object(*module_object);
} }
module_object->set_shared(*shared);
compiled_module->LogWasmCodes(isolate); compiled_module->LogWasmCodes(isolate);
return module_object; return module_object;
...@@ -758,7 +759,7 @@ void WasmInstanceObject::SetRawMemory(byte* mem_start, uint32_t mem_size) { ...@@ -758,7 +759,7 @@ void WasmInstanceObject::SetRawMemory(byte* mem_start, uint32_t mem_size) {
} }
WasmModule* WasmInstanceObject::module() { WasmModule* WasmInstanceObject::module() {
return compiled_module()->shared()->module(); return module_object()->shared()->module();
} }
Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo( Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo(
...@@ -782,9 +783,9 @@ Handle<WasmInstanceObject> WasmInstanceObject::New( ...@@ -782,9 +783,9 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
// Initialize the imported function arrays. // Initialize the imported function arrays.
auto num_imported_functions = auto num_imported_functions =
compiled_module->shared()->module()->num_imported_functions; module_object->shared()->module()->num_imported_functions;
auto num_imported_mutable_globals = auto num_imported_mutable_globals =
compiled_module->shared()->module()->num_imported_mutable_globals; module_object->shared()->module()->num_imported_mutable_globals;
auto native_allocations = Managed<WasmInstanceNativeAllocations>::Allocate( auto native_allocations = Managed<WasmInstanceNativeAllocations>::Allocate(
isolate, instance, num_imported_functions, num_imported_mutable_globals); isolate, instance, num_imported_functions, num_imported_mutable_globals);
instance->set_managed_native_allocations(*native_allocations); instance->set_managed_native_allocations(*native_allocations);
...@@ -1373,7 +1374,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1373,7 +1374,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
Handle<FixedArray> code_copy; Handle<FixedArray> code_copy;
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED)); isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
ret->set_shared(module->shared());
ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell()); ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
ret->set_native_module(module->native_module()); ret->set_native_module(module->native_module());
...@@ -1554,13 +1554,10 @@ void WasmCompiledModule::LogWasmCodes(Isolate* isolate) { ...@@ -1554,13 +1554,10 @@ void WasmCompiledModule::LogWasmCodes(Isolate* isolate) {
wasm::NativeModule* native_module = GetNativeModule(); wasm::NativeModule* native_module = GetNativeModule();
if (native_module == nullptr) return; if (native_module == nullptr) return;
const uint32_t number_of_codes = native_module->function_count(); const uint32_t number_of_codes = native_module->function_count();
if (has_shared()) { for (uint32_t i = 0; i < number_of_codes; i++) {
Handle<WasmSharedModuleData> shared_handle(shared(), isolate); wasm::WasmCode* code = native_module->code(i);
for (uint32_t i = 0; i < number_of_codes; i++) { if (code == nullptr) continue;
wasm::WasmCode* code = native_module->code(i); code->LogCode(isolate);
if (code == nullptr) continue;
code->LogCode(isolate);
}
} }
} }
......
...@@ -108,16 +108,13 @@ class WasmModuleObject : public JSObject { ...@@ -108,16 +108,13 @@ class WasmModuleObject : public JSObject {
// Shared compiled code between multiple WebAssembly.Module objects. // Shared compiled code between multiple WebAssembly.Module objects.
DECL_ACCESSORS(compiled_module, WasmCompiledModule) DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(export_wrappers, FixedArray) DECL_ACCESSORS(export_wrappers, FixedArray)
DECL_ACCESSORS(shared, WasmSharedModuleData)
// TODO(mstarzinger): Currently this getter uses an indirection via the
// {WasmCompiledModule}, but we will soon move the reference to the shared
// data directly into this {WasmModuleObject}, making this a normal accessor.
inline WasmSharedModuleData* shared() const;
// Layout description. // Layout description.
#define WASM_MODULE_OBJECT_FIELDS(V) \ #define WASM_MODULE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \ V(kCompiledModuleOffset, kPointerSize) \
V(kExportWrappersOffset, kPointerSize) \ V(kExportWrappersOffset, kPointerSize) \
V(kSharedOffset, kPointerSize) \
V(kSize, 0) V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
...@@ -126,7 +123,7 @@ class WasmModuleObject : public JSObject { ...@@ -126,7 +123,7 @@ class WasmModuleObject : public JSObject {
static Handle<WasmModuleObject> New( static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module, Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Handle<FixedArray> export_wrappers); Handle<FixedArray> export_wrappers, Handle<WasmSharedModuleData> shared);
// Set a breakpoint on the given byte position inside the given module. // Set a breakpoint on the given byte position inside the given module.
// This will affect all live and future instances of the module. // This will affect all live and future instances of the module.
...@@ -537,7 +534,6 @@ class WasmCompiledModule : public Struct { ...@@ -537,7 +534,6 @@ class WasmCompiledModule : public Struct {
// Layout description. // Layout description.
#define WASM_COMPILED_MODULE_FIELDS(V) \ #define WASM_COMPILED_MODULE_FIELDS(V) \
V(kSharedOffset, kPointerSize) \
V(kNextInstanceOffset, kPointerSize) \ V(kNextInstanceOffset, kPointerSize) \
V(kPrevInstanceOffset, kPointerSize) \ V(kPrevInstanceOffset, kPointerSize) \
V(kOwningInstanceOffset, kPointerSize) \ V(kOwningInstanceOffset, kPointerSize) \
...@@ -572,7 +568,6 @@ class WasmCompiledModule : public Struct { ...@@ -572,7 +568,6 @@ class WasmCompiledModule : public Struct {
// for deserialization, and if they are serializable. // for deserialization, and if they are serializable.
// By default, instance values go to WasmInstanceObject, however, if // By default, instance values go to WasmInstanceObject, however, if
// we embed the generated code with a value, then we track that value here. // we embed the generated code with a value, then we track that value here.
WCM_OBJECT(WasmSharedModuleData, shared)
WCM_CONST_OBJECT(WasmCompiledModule, next_instance) WCM_CONST_OBJECT(WasmCompiledModule, next_instance)
WCM_CONST_OBJECT(WasmCompiledModule, prev_instance) WCM_CONST_OBJECT(WasmCompiledModule, prev_instance)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance) WCM_WEAK_LINK(WasmInstanceObject, owning_instance)
......
...@@ -665,7 +665,6 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -665,7 +665,6 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
wasm::RuntimeExceptionSupport::kRuntimeExceptionSupport); wasm::RuntimeExceptionSupport::kRuntimeExceptionSupport);
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate, shared->module(), env); WasmCompiledModule::New(isolate, shared->module(), env);
compiled_module->set_shared(*shared);
compiled_module->GetNativeModule()->SetSharedModuleData(shared); compiled_module->GetNativeModule()->SetSharedModuleData(shared);
NativeModuleDeserializer deserializer(isolate, NativeModuleDeserializer deserializer(isolate,
compiled_module->GetNativeModule()); compiled_module->GetNativeModule());
...@@ -674,7 +673,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -674,7 +673,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
if (!deserializer.Read(&reader)) return {}; if (!deserializer.Read(&reader)) return {};
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate, compiled_module, export_wrappers); WasmModuleObject::New(isolate, compiled_module, export_wrappers, shared);
// TODO(6792): Wrappers below might be cloned using {Factory::CopyCode}. This // TODO(6792): Wrappers below might be cloned using {Factory::CopyCode}. This
// requires unlocking the code space here. This should eventually be moved // requires unlocking the code space here. This should eventually be moved
......
...@@ -277,12 +277,10 @@ class WasmSerializationTest { ...@@ -277,12 +277,10 @@ class WasmSerializationTest {
v8::Utils::OpenHandle(*deserialized_module)); v8::Utils::OpenHandle(*deserialized_module));
{ {
DisallowHeapAllocation assume_no_gc; DisallowHeapAllocation assume_no_gc;
Handle<WasmCompiledModule> compiled_part(module_object->compiled_module(),
current_isolate());
CHECK_EQ( CHECK_EQ(
memcmp( memcmp(
reinterpret_cast<const uint8_t*>( reinterpret_cast<const uint8_t*>(
compiled_part->shared()->module_bytes()->GetCharsAddress()), module_object->shared()->module_bytes()->GetCharsAddress()),
wire_bytes().first, wire_bytes().second), wire_bytes().first, wire_bytes().second),
0); 0);
} }
...@@ -345,8 +343,9 @@ class WasmSerializationTest { ...@@ -345,8 +343,9 @@ class WasmSerializationTest {
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
module_object->compiled_module()); module_object->compiled_module());
Handle<FixedArray> export_wrappers(module_object->export_wrappers()); Handle<FixedArray> export_wrappers(module_object->export_wrappers());
Handle<WasmSharedModuleData> shared(module_object->shared());
Handle<JSObject> module_obj = WasmModuleObject::New( Handle<JSObject> module_obj = WasmModuleObject::New(
serialization_isolate, compiled_module, export_wrappers); serialization_isolate, compiled_module, export_wrappers, shared);
v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj); v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj);
CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); CHECK(v8_module_obj->IsWebAssemblyCompiledModule());
...@@ -1181,9 +1180,7 @@ TEST(AtomicOpDisassembly) { ...@@ -1181,9 +1180,7 @@ TEST(AtomicOpDisassembly) {
isolate->wasm_engine()->SyncCompile( isolate->wasm_engine()->SyncCompile(
isolate, &thrower, ModuleWireBytes(buffer.begin(), buffer.end())); isolate, &thrower, ModuleWireBytes(buffer.begin(), buffer.end()));
Handle<WasmCompiledModule> compiled_module( module_object.ToHandleChecked()->shared()->DisassembleFunction(0);
module_object.ToHandleChecked()->compiled_module(), isolate);
compiled_module->shared()->DisassembleFunction(0);
} }
Cleanup(); Cleanup();
} }
......
...@@ -249,7 +249,7 @@ WASM_COMPILED_EXEC_TEST(WasmCollectPossibleBreakpoints) { ...@@ -249,7 +249,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()->shared(); WasmSharedModuleData* shared = instance->module_object()->shared();
std::vector<debug::Location> locations; std::vector<debug::Location> locations;
// Check all locations for function 0. // Check all locations for function 0.
......
...@@ -173,7 +173,7 @@ void TestingModuleBuilder::PopulateIndirectFunctionTable() { ...@@ -173,7 +173,7 @@ 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(), isolate_); instance_object_->module_object()->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
...@@ -222,10 +222,9 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() { ...@@ -222,10 +222,9 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
ModuleEnv env = CreateModuleEnv(); ModuleEnv env = CreateModuleEnv();
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate_, test_module_ptr_, env); WasmCompiledModule::New(isolate_, test_module_ptr_, env);
compiled_module->set_shared(*shared_module_data);
compiled_module->GetNativeModule()->SetSharedModuleData(shared_module_data); compiled_module->GetNativeModule()->SetSharedModuleData(shared_module_data);
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject> module_object = WasmModuleObject::New(
WasmModuleObject::New(isolate_, compiled_module, export_wrappers); isolate_, compiled_module, export_wrappers, shared_module_data);
// This method is called when we initialize TestEnvironment. We don't // This method is called when we initialize TestEnvironment. We don't
// have a memory yet, so we won't create it here. We'll update the // have a memory yet, so we won't create it here. We'll update the
// interpreter when we get a memory. We do have globals, though. // interpreter when we get a memory. We do have globals, though.
...@@ -421,8 +420,9 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -421,8 +420,9 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
builder_->instance_object()->compiled_module(), isolate()); builder_->instance_object()->compiled_module(), isolate());
NativeModule* native_module = compiled_module->GetNativeModule(); NativeModule* native_module = compiled_module->GetNativeModule();
Handle<SeqOneByteString> wire_bytes(compiled_module->shared()->module_bytes(), Handle<SeqOneByteString> wire_bytes(
isolate()); builder_->instance_object()->module_object()->shared()->module_bytes(),
isolate());
ModuleEnv module_env = builder_->CreateModuleEnv(); ModuleEnv module_env = builder_->CreateModuleEnv();
ErrorThrower thrower(isolate(), "WasmFunctionCompiler::Build"); ErrorThrower thrower(isolate(), "WasmFunctionCompiler::Build");
......
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