[wasm] Move the NativeModule to the WasmModuleObject
The reference to the {NativeModule} (stored in a {Managed}) should live on the {WasmModuleObject}, not on the individual {WasmCompiledModule} objects. R=titzer@chromium.org Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: I21dfa088c9643d36d9fd5052a145e7e2af5e47f9 Reviewed-on: https://chromium-review.googlesource.com/1106380 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Ben Titzer <titzer@chromium.org> Cr-Commit-Position: refs/heads/master@{#53860}
This commit is contained in:
parent
e1ffbe2cb8
commit
f318f9835f
@ -7482,8 +7482,7 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule(
|
||||
WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
|
||||
i::Handle<i::WasmModuleObject> obj =
|
||||
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
|
||||
i::wasm::NativeModule* native_module =
|
||||
obj->compiled_module()->GetNativeModule();
|
||||
i::wasm::NativeModule* native_module = obj->native_module();
|
||||
size_t buffer_size =
|
||||
i::wasm::GetSerializedNativeModuleSize(obj->GetIsolate(), native_module);
|
||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
|
||||
|
@ -1758,7 +1758,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
|
||||
// a second lookup here could lead to inconsistency.
|
||||
int byte_offset =
|
||||
FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
|
||||
instance->compiled_module()->GetNativeModule()->code(func_index),
|
||||
instance->module_object()->native_module()->code(func_index),
|
||||
code_offset);
|
||||
|
||||
bool is_at_number_conversion =
|
||||
|
30
src/log.cc
30
src/log.cc
@ -1756,23 +1756,23 @@ static int EnumerateCompiledFunctions(Heap* heap,
|
||||
return compiled_funcs_count;
|
||||
}
|
||||
|
||||
static int EnumerateWasmModules(Heap* heap,
|
||||
Handle<WasmCompiledModule>* modules) {
|
||||
static int EnumerateWasmModuleObjects(
|
||||
Heap* heap, Handle<WasmModuleObject>* module_objects) {
|
||||
HeapIterator iterator(heap);
|
||||
DisallowHeapAllocation no_gc;
|
||||
int wasm_modules_count = 0;
|
||||
int module_objects_count = 0;
|
||||
|
||||
for (HeapObject* obj = iterator.next(); obj != nullptr;
|
||||
obj = iterator.next()) {
|
||||
if (obj->IsWasmCompiledModule()) {
|
||||
WasmCompiledModule* module = WasmCompiledModule::cast(obj);
|
||||
if (modules != nullptr) {
|
||||
modules[wasm_modules_count] = Handle<WasmCompiledModule>(module);
|
||||
if (obj->IsWasmModuleObject()) {
|
||||
WasmModuleObject* module = WasmModuleObject::cast(obj);
|
||||
if (module_objects != nullptr) {
|
||||
module_objects[module_objects_count] = handle(module, heap->isolate());
|
||||
}
|
||||
wasm_modules_count++;
|
||||
module_objects_count++;
|
||||
}
|
||||
}
|
||||
return wasm_modules_count;
|
||||
return module_objects_count;
|
||||
}
|
||||
|
||||
void Logger::LogCodeObject(Object* object) {
|
||||
@ -2091,11 +2091,13 @@ void ExistingCodeLogger::LogCompiledFunctions() {
|
||||
LogExistingFunction(sfis[i], code_objects[i]);
|
||||
}
|
||||
|
||||
const int compiled_wasm_modules_count = EnumerateWasmModules(heap, nullptr);
|
||||
ScopedVector<Handle<WasmCompiledModule>> modules(compiled_wasm_modules_count);
|
||||
EnumerateWasmModules(heap, modules.start());
|
||||
for (int i = 0; i < compiled_wasm_modules_count; ++i) {
|
||||
modules[i]->GetNativeModule()->LogWasmCodes(isolate_);
|
||||
const int wasm_module_objects_count =
|
||||
EnumerateWasmModuleObjects(heap, nullptr);
|
||||
std::unique_ptr<Handle<WasmModuleObject>[]> module_objects(
|
||||
new Handle<WasmModuleObject>[wasm_module_objects_count]);
|
||||
EnumerateWasmModuleObjects(heap, module_objects.get());
|
||||
for (int i = 0; i < wasm_module_objects_count; ++i) {
|
||||
module_objects[i]->native_module()->LogWasmCodes(isolate_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ void WasmStackFrame::FromFrameArray(Isolate* isolate, Handle<FrameArray> array,
|
||||
if (array->IsWasmInterpretedFrame(frame_ix)) {
|
||||
code_ = nullptr;
|
||||
} else {
|
||||
code_ = wasm_instance_->compiled_module()->GetNativeModule()->code(
|
||||
code_ = wasm_instance_->module_object()->native_module()->code(
|
||||
wasm_func_index_);
|
||||
}
|
||||
offset_ = array->Offset(frame_ix)->value();
|
||||
|
@ -1593,7 +1593,6 @@ void WasmCompiledModule::WasmCompiledModuleVerify() {
|
||||
VerifyObjectField(kNextInstanceOffset);
|
||||
VerifyObjectField(kPrevInstanceOffset);
|
||||
VerifyObjectField(kOwningInstanceOffset);
|
||||
VerifyObjectField(kNativeModuleOffset);
|
||||
}
|
||||
|
||||
void WasmDebugInfo::WasmDebugInfoVerify() {
|
||||
@ -1633,6 +1632,7 @@ void WasmExportedFunctionData::WasmExportedFunctionDataVerify() {
|
||||
|
||||
void WasmModuleObject::WasmModuleObjectVerify() {
|
||||
CHECK(IsWasmModuleObject());
|
||||
VerifyObjectField(kNativeModuleOffset);
|
||||
VerifyObjectField(kCompiledModuleOffset);
|
||||
VerifyObjectField(kExportWrappersOffset);
|
||||
VerifyObjectField(kManagedModuleOffset);
|
||||
|
@ -1768,6 +1768,12 @@ void WasmModuleObject::WasmModuleObjectPrint(std::ostream& os) { // NOLINT
|
||||
JSObjectPrintHeader(os, this, "WasmModuleObject");
|
||||
JSObjectPrintBody(os, this);
|
||||
os << "\n - module: " << module();
|
||||
os << "\n - native module: " << native_module();
|
||||
os << "\n - export wrappers: " << Brief(export_wrappers());
|
||||
os << "\n - module bytes: " << Brief(module_bytes());
|
||||
os << "\n - script: " << Brief(script());
|
||||
os << "\n - asm_js_offset_table: " << Brief(asm_js_offset_table());
|
||||
os << "\n - breakpoint_infos: " << Brief(breakpoint_infos());
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
|
@ -909,8 +909,7 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
|
||||
DCHECK_EQ(1, args.length());
|
||||
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
|
||||
|
||||
wasm::NativeModule* native_module =
|
||||
module_obj->compiled_module()->GetNativeModule();
|
||||
wasm::NativeModule* native_module = module_obj->native_module();
|
||||
size_t compiled_size =
|
||||
wasm::GetSerializedNativeModuleSize(isolate, native_module);
|
||||
void* array_data = isolate->array_buffer_allocator()->Allocate(compiled_size);
|
||||
@ -1053,7 +1052,7 @@ RUNTIME_FUNCTION(Runtime_IsLiftoffFunction) {
|
||||
Handle<WasmExportedFunction> exp_fun =
|
||||
Handle<WasmExportedFunction>::cast(function);
|
||||
wasm::NativeModule* native_module =
|
||||
exp_fun->instance()->compiled_module()->GetNativeModule();
|
||||
exp_fun->instance()->module_object()->native_module();
|
||||
uint32_t func_index = exp_fun->function_index();
|
||||
return isolate->heap()->ToBoolean(
|
||||
native_module->has_code(func_index) &&
|
||||
@ -1075,7 +1074,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) {
|
||||
DisallowHeapAllocation no_gc;
|
||||
CONVERT_ARG_CHECKED(WasmInstanceObject, instance, 0);
|
||||
|
||||
instance->compiled_module()->GetNativeModule()->set_lazy_compile_frozen(true);
|
||||
instance->module_object()->native_module()->set_lazy_compile_frozen(true);
|
||||
return isolate->heap()->undefined_value();
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ RUNTIME_FUNCTION(Runtime_WasmCompileLazy) {
|
||||
#endif
|
||||
|
||||
Address entrypoint = wasm::CompileLazy(
|
||||
isolate, instance->compiled_module()->GetNativeModule(), func_index);
|
||||
isolate, instance->module_object()->native_module(), func_index);
|
||||
return reinterpret_cast<Object*>(entrypoint);
|
||||
}
|
||||
|
||||
|
@ -887,8 +887,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) {
|
||||
String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length);
|
||||
}
|
||||
|
||||
wasm::NativeModule* native_module =
|
||||
object->compiled_module()->GetNativeModule();
|
||||
wasm::NativeModule* native_module = object->native_module();
|
||||
size_t module_size =
|
||||
wasm::GetSerializedNativeModuleSize(isolate_, native_module);
|
||||
CHECK_GE(std::numeric_limits<uint32_t>::max(), module_size);
|
||||
|
@ -31,11 +31,6 @@
|
||||
if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
#define TRACE_CHAIN(instance) \
|
||||
do { \
|
||||
instance->PrintInstancesChain(); \
|
||||
} while (false)
|
||||
|
||||
#define TRACE_COMPILE(...) \
|
||||
do { \
|
||||
if (FLAG_trace_wasm_compiler) PrintF(__VA_ARGS__); \
|
||||
@ -286,11 +281,8 @@ class InstanceBuilder {
|
||||
Counters* counters() const { return async_counters().get(); }
|
||||
|
||||
wasm::UseTrapHandler use_trap_handler() const {
|
||||
return module_object_->compiled_module()
|
||||
->GetNativeModule()
|
||||
->use_trap_handler()
|
||||
? kUseTrapHandler
|
||||
: kNoTrapHandler;
|
||||
return module_object_->native_module()->use_trap_handler() ? kUseTrapHandler
|
||||
: kNoTrapHandler;
|
||||
}
|
||||
|
||||
// Helper routines to print out errors with imports.
|
||||
@ -810,8 +802,7 @@ void ValidateSequentially(Isolate* isolate, const ModuleWireBytes& wire_bytes,
|
||||
void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower,
|
||||
Handle<WasmModuleObject> module_object,
|
||||
const WasmModule* wasm_module, ModuleEnv* env) {
|
||||
WasmCompiledModule* compiled_module = module_object->compiled_module();
|
||||
NativeModule* const native_module = compiled_module->GetNativeModule();
|
||||
NativeModule* const native_module = module_object->native_module();
|
||||
auto* byte_string = module_object->module_bytes();
|
||||
const ModuleWireBytes wire_bytes(
|
||||
byte_string->GetChars(), byte_string->GetChars() + byte_string->length());
|
||||
@ -1039,9 +1030,7 @@ MaybeHandle<WasmModuleObject> CompileToModuleObject(
|
||||
}
|
||||
|
||||
// Log the code within the generated module for profiling.
|
||||
NativeModule* native_module =
|
||||
module_object->compiled_module()->GetNativeModule();
|
||||
native_module->LogWasmCodes(isolate);
|
||||
module_object->native_module()->LogWasmCodes(isolate);
|
||||
|
||||
return module_object;
|
||||
}
|
||||
@ -1134,8 +1123,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
constexpr bool allow_trap_handler = false;
|
||||
ModuleEnv env = CreateDefaultModuleEnv(module_, allow_trap_handler);
|
||||
// Disable trap handlers on this native module.
|
||||
NativeModule* native_module =
|
||||
module_object_->compiled_module()->GetNativeModule();
|
||||
NativeModule* native_module = module_object_->native_module();
|
||||
native_module->DisableTrapHandler();
|
||||
|
||||
// Recompile all functions in this native module.
|
||||
@ -1151,7 +1139,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
//--------------------------------------------------------------------------
|
||||
// Reuse the compiled module (if no owner), otherwise clone.
|
||||
//--------------------------------------------------------------------------
|
||||
wasm::NativeModule* native_module = nullptr;
|
||||
wasm::NativeModule* native_module = module_object_->native_module();
|
||||
// Root the old instance, if any, in case later allocation causes GC,
|
||||
// to prevent the finalizer running for the old instance.
|
||||
MaybeHandle<WasmInstanceObject> old_instance;
|
||||
@ -1167,19 +1155,15 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
// We do that last. Since we are holding on to the old instance,
|
||||
// the owner + original state used for cloning and patching
|
||||
// won't be mutated by possible finalizer runs.
|
||||
TRACE("Cloning from %zu\n", original->GetNativeModule()->instance_id);
|
||||
TRACE("Cloning from %zu\n", native_module->instance_id);
|
||||
new_compiled_module = WasmCompiledModule::Clone(isolate_, original);
|
||||
RecordStats(module_object_->compiled_module()->GetNativeModule(),
|
||||
counters());
|
||||
RecordStats(module_object_->native_module(), counters());
|
||||
} else {
|
||||
// No instance owned the original compiled module.
|
||||
new_compiled_module = original;
|
||||
TRACE("Reusing existing instance %zu\n",
|
||||
new_compiled_module->GetNativeModule()->instance_id);
|
||||
TRACE("Reusing existing instance %zu\n", native_module->instance_id);
|
||||
}
|
||||
native_module = new_compiled_module->GetNativeModule();
|
||||
}
|
||||
DCHECK_NOT_NULL(native_module);
|
||||
wasm::NativeModuleModificationScope native_modification_scope(native_module);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -1390,8 +1374,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
|
||||
DCHECK(!isolate_->has_pending_exception());
|
||||
TRACE("Successfully built instance %zu\n",
|
||||
module_object_->compiled_module()->GetNativeModule()->instance_id);
|
||||
TRACE_CHAIN(module_object_->compiled_module());
|
||||
module_object_->native_module()->instance_id);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -1638,7 +1621,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
|
||||
|
||||
DCHECK_EQ(module_->import_table.size(), sanitized_imports_.size());
|
||||
int num_imports = static_cast<int>(module_->import_table.size());
|
||||
NativeModule* native_module = instance->compiled_module()->GetNativeModule();
|
||||
NativeModule* native_module = instance->module_object()->native_module();
|
||||
for (int index = 0; index < num_imports; ++index) {
|
||||
WasmImport& import = module_->import_table[index];
|
||||
|
||||
@ -2211,8 +2194,7 @@ void InstanceBuilder::InitializeTables(Handle<WasmInstanceObject> instance) {
|
||||
}
|
||||
|
||||
void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
|
||||
NativeModule* native_module =
|
||||
module_object_->compiled_module()->GetNativeModule();
|
||||
NativeModule* native_module = module_object_->native_module();
|
||||
int function_table_count = static_cast<int>(module_->function_tables.size());
|
||||
for (int index = 0; index < function_table_count; ++index) {
|
||||
TableInstance& table_instance = table_instances_[index];
|
||||
@ -2593,8 +2575,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
|
||||
WasmModuleObject::New(job_->isolate_, export_wrappers, job_->module_,
|
||||
env, Handle<SeqOneByteString>::cast(module_bytes),
|
||||
script, asm_js_offset_table);
|
||||
job_->native_module_ =
|
||||
job_->module_object_->compiled_module()->GetNativeModule();
|
||||
job_->native_module_ = job_->module_object_->native_module();
|
||||
|
||||
{
|
||||
DeferredHandleScope deferred(job_->isolate_);
|
||||
@ -3198,8 +3179,7 @@ void CompileJsToWasmWrappers(Isolate* isolate,
|
||||
JSToWasmWrapperCache js_to_wasm_cache;
|
||||
int wrapper_index = 0;
|
||||
Handle<FixedArray> export_wrappers(module_object->export_wrappers(), isolate);
|
||||
NativeModule* native_module =
|
||||
module_object->compiled_module()->GetNativeModule();
|
||||
NativeModule* native_module = module_object->native_module();
|
||||
wasm::UseTrapHandler use_trap_handler =
|
||||
native_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler;
|
||||
WasmModule* module = module_object->module();
|
||||
@ -3252,7 +3232,6 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
|
||||
} // namespace v8
|
||||
|
||||
#undef TRACE
|
||||
#undef TRACE_CHAIN
|
||||
#undef TRACE_COMPILE
|
||||
#undef TRACE_STREAMING
|
||||
#undef TRACE_LAZY
|
||||
|
@ -560,8 +560,8 @@ Handle<FixedArray> GetOrCreateInterpretedFunctions(
|
||||
if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj);
|
||||
|
||||
int num_functions = debug_info->wasm_instance()
|
||||
->compiled_module()
|
||||
->GetNativeModule()
|
||||
->module_object()
|
||||
->native_module()
|
||||
->num_functions();
|
||||
Handle<FixedArray> new_arr = isolate->factory()->NewFixedArray(num_functions);
|
||||
debug_info->set_interpreted_functions(*new_arr);
|
||||
@ -611,7 +611,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
|
||||
GetOrCreateInterpretedFunctions(isolate, debug_info);
|
||||
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
|
||||
wasm::NativeModule* native_module =
|
||||
instance->compiled_module()->GetNativeModule();
|
||||
instance->module_object()->native_module();
|
||||
wasm::WasmModule* module = instance->module();
|
||||
|
||||
// We may modify js wrappers, as well as wasm functions. Hence the 2
|
||||
|
@ -49,6 +49,8 @@ CAST_ACCESSOR(WasmTableObject)
|
||||
}
|
||||
|
||||
// WasmModuleObject
|
||||
ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
|
||||
kNativeModuleOffset)
|
||||
ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule,
|
||||
kCompiledModuleOffset)
|
||||
ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
|
||||
@ -63,9 +65,18 @@ OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray,
|
||||
wasm::WasmModule* WasmModuleObject::module() const {
|
||||
return managed_module()->raw();
|
||||
}
|
||||
wasm::NativeModule* WasmModuleObject::native_module() {
|
||||
return managed_native_module()->raw();
|
||||
}
|
||||
void WasmModuleObject::reset_breakpoint_infos() {
|
||||
WRITE_FIELD(this, kBreakPointInfosOffset, GetHeap()->undefined_value());
|
||||
}
|
||||
bool WasmModuleObject::is_asm_js() {
|
||||
bool asm_js = module()->origin == wasm::kAsmJsOrigin;
|
||||
DCHECK_EQ(asm_js, script()->IsUserJavaScript());
|
||||
DCHECK_EQ(asm_js, has_asm_js_offset_table());
|
||||
return asm_js;
|
||||
}
|
||||
|
||||
// WasmTableObject
|
||||
ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset)
|
||||
@ -237,7 +248,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
|
||||
WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
|
||||
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
|
||||
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
|
||||
WCM_OBJECT(Foreign, native_module, kNativeModuleOffset)
|
||||
ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset);
|
||||
ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset);
|
||||
|
||||
|
@ -273,21 +273,21 @@ enum DispatchTableElements : int {
|
||||
|
||||
Handle<WasmModuleObject> WasmModuleObject::New(
|
||||
Isolate* isolate, Handle<FixedArray> export_wrappers,
|
||||
std::shared_ptr<wasm::WasmModule> module, wasm::ModuleEnv& env,
|
||||
std::shared_ptr<wasm::WasmModule> shared_module, wasm::ModuleEnv& env,
|
||||
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
|
||||
Handle<ByteArray> asm_js_offset_table) {
|
||||
DCHECK_EQ(module.get(), env.module);
|
||||
WasmModule* module = shared_module.get();
|
||||
DCHECK_EQ(module, env.module);
|
||||
size_t module_size = EstimateWasmModuleSize(module);
|
||||
// The {managed_module} will take shared ownership of the {WasmModule} object,
|
||||
// and release it when the GC reclaim the managed.
|
||||
size_t module_size = EstimateWasmModuleSize(module.get());
|
||||
Handle<Managed<WasmModule>> managed_module =
|
||||
Managed<WasmModule>::FromSharedPtr(isolate, module_size,
|
||||
std::move(module));
|
||||
std::move(shared_module));
|
||||
|
||||
// Create the first {WasmCompiledModule} associated with this
|
||||
// {WasmModuleObject}.
|
||||
Handle<WasmCompiledModule> compiled_module =
|
||||
WasmCompiledModule::New(isolate, env);
|
||||
Handle<WasmCompiledModule> compiled_module = WasmCompiledModule::New(isolate);
|
||||
|
||||
// Now create the {WasmModuleObject}.
|
||||
Handle<JSFunction> module_cons(
|
||||
@ -309,9 +309,19 @@ Handle<WasmModuleObject> WasmModuleObject::New(
|
||||
if (!asm_js_offset_table.is_null()) {
|
||||
module_object->set_asm_js_offset_table(*asm_js_offset_table);
|
||||
}
|
||||
// TODO(clemensh): Move the reference to the native module to the module
|
||||
// object.
|
||||
compiled_module->GetNativeModule()->SetModuleObject(module_object);
|
||||
|
||||
// Create the {NativeModule}, and link it bidirectionally to the
|
||||
// {WasmModuleObject}.
|
||||
size_t memory_estimate =
|
||||
isolate->wasm_engine()->code_manager()->EstimateNativeModuleSize(module);
|
||||
auto native_module =
|
||||
isolate->wasm_engine()->code_manager()->NewNativeModule(isolate, env);
|
||||
native_module->SetModuleObject(module_object);
|
||||
native_module->SetRuntimeStubs(isolate);
|
||||
Handle<Managed<wasm::NativeModule>> managed_native_module =
|
||||
Managed<wasm::NativeModule>::FromUniquePtr(isolate, memory_estimate,
|
||||
std::move(native_module));
|
||||
module_object->set_managed_native_module(*managed_native_module);
|
||||
|
||||
return module_object;
|
||||
}
|
||||
@ -355,13 +365,6 @@ void WasmModuleObject::ValidateStateForTesting(
|
||||
CHECK(!compiled_module->has_instance());
|
||||
}
|
||||
|
||||
bool WasmModuleObject::is_asm_js() {
|
||||
bool asm_js = module()->origin == wasm::kAsmJsOrigin;
|
||||
DCHECK_EQ(asm_js, script()->IsUserJavaScript());
|
||||
DCHECK_EQ(asm_js, has_asm_js_offset_table());
|
||||
return asm_js;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
int GetBreakpointPos(Isolate* isolate, Object* break_point_info_or_undef) {
|
||||
@ -1390,12 +1393,8 @@ void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
|
||||
// If a link to shared memory instances exists, update the list of memory
|
||||
// instances before the instance is destroyed.
|
||||
WasmCompiledModule* compiled_module = instance->compiled_module();
|
||||
wasm::NativeModule* native_module = compiled_module->GetNativeModule();
|
||||
if (native_module) {
|
||||
TRACE("Finalizing %zu {\n", native_module->instance_id);
|
||||
} else {
|
||||
TRACE("Finalized already cleaned up compiled module\n");
|
||||
}
|
||||
TRACE("Finalizing %zu {\n",
|
||||
instance->module_object()->native_module()->instance_id);
|
||||
|
||||
// Since the order of finalizers is not guaranteed, it can be the case
|
||||
// that {instance->compiled_module()->module()}, which is a
|
||||
@ -1443,7 +1442,7 @@ void WasmInstanceObject::InstallFinalizer(Isolate* isolate,
|
||||
}
|
||||
|
||||
Address WasmInstanceObject::GetCallTarget(uint32_t func_index) {
|
||||
wasm::NativeModule* native_module = compiled_module()->GetNativeModule();
|
||||
wasm::NativeModule* native_module = module_object()->native_module();
|
||||
if (func_index < native_module->num_imported_functions()) {
|
||||
return imported_function_targets()[func_index];
|
||||
}
|
||||
@ -1506,26 +1505,10 @@ Address WasmExportedFunction::GetWasmCallTarget() {
|
||||
return instance()->GetCallTarget(function_index());
|
||||
}
|
||||
|
||||
Handle<WasmCompiledModule> WasmCompiledModule::New(Isolate* isolate,
|
||||
wasm::ModuleEnv& env) {
|
||||
Handle<WasmCompiledModule> WasmCompiledModule::New(Isolate* isolate) {
|
||||
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast(
|
||||
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
|
||||
compiled_module->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
|
||||
{
|
||||
size_t memory_estimate =
|
||||
isolate->wasm_engine()->code_manager()->EstimateNativeModuleSize(
|
||||
env.module);
|
||||
auto native_module =
|
||||
isolate->wasm_engine()->code_manager()->NewNativeModule(isolate, env);
|
||||
Handle<Foreign> native_module_wrapper =
|
||||
Managed<wasm::NativeModule>::FromUniquePtr(isolate, memory_estimate,
|
||||
std::move(native_module));
|
||||
compiled_module->set_native_module(*native_module_wrapper);
|
||||
}
|
||||
compiled_module->GetNativeModule()->SetRuntimeStubs(isolate);
|
||||
|
||||
// TODO(mtrofin): copy the rest of the specialization parameters over.
|
||||
// We're currently OK because we're only using defaults.
|
||||
return compiled_module;
|
||||
}
|
||||
|
||||
@ -1535,25 +1518,10 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
|
||||
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
|
||||
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
|
||||
ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
|
||||
ret->set_native_module(module->native_module());
|
||||
|
||||
// construct the wrapper in 2 steps, because its construction may trigger GC,
|
||||
// which would shift the this pointer in set_native_module.
|
||||
size_t native_module_size = 0;
|
||||
Handle<Foreign> native_module_wrapper =
|
||||
Managed<wasm::NativeModule>::FromSharedPtr(
|
||||
isolate, native_module_size,
|
||||
Managed<wasm::NativeModule>::cast(module->native_module())->get());
|
||||
ret->set_native_module(*native_module_wrapper);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
wasm::NativeModule* WasmCompiledModule::GetNativeModule() const {
|
||||
if (!has_native_module()) return nullptr;
|
||||
return Managed<wasm::NativeModule>::cast(native_module())->raw();
|
||||
}
|
||||
|
||||
void WasmCompiledModule::Reset(Isolate* isolate,
|
||||
WasmCompiledModule* compiled_module) {
|
||||
DisallowHeapAllocation no_gc;
|
||||
@ -1561,18 +1529,6 @@ void WasmCompiledModule::Reset(Isolate* isolate,
|
||||
compiled_module->reset_next_instance();
|
||||
}
|
||||
|
||||
void WasmCompiledModule::PrintInstancesChain() {
|
||||
#if DEBUG
|
||||
if (!FLAG_trace_wasm_instances) return;
|
||||
for (WasmCompiledModule* current = this; current != nullptr;) {
|
||||
PrintF("->%zu", current->GetNativeModule()->instance_id);
|
||||
if (!current->has_next_instance()) break;
|
||||
current = current->next_instance();
|
||||
}
|
||||
PrintF("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void WasmCompiledModule::InsertInChain(WasmModuleObject* module) {
|
||||
DisallowHeapAllocation no_gc;
|
||||
WasmCompiledModule* original = module->compiled_module();
|
||||
|
@ -105,7 +105,8 @@ class WasmModuleObject : public JSObject {
|
||||
public:
|
||||
DECL_CAST(WasmModuleObject)
|
||||
|
||||
// Shared compiled code between multiple WebAssembly.Module objects.
|
||||
DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
|
||||
inline wasm::NativeModule* native_module();
|
||||
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
|
||||
DECL_ACCESSORS(export_wrappers, FixedArray)
|
||||
DECL_ACCESSORS(managed_module, Managed<wasm::WasmModule>)
|
||||
@ -122,6 +123,7 @@ class WasmModuleObject : public JSObject {
|
||||
|
||||
// Layout description.
|
||||
#define WASM_MODULE_OBJECT_FIELDS(V) \
|
||||
V(kNativeModuleOffset, kPointerSize) \
|
||||
V(kCompiledModuleOffset, kPointerSize) \
|
||||
V(kExportWrappersOffset, kPointerSize) \
|
||||
V(kManagedModuleOffset, kPointerSize) \
|
||||
@ -156,7 +158,7 @@ class WasmModuleObject : public JSObject {
|
||||
Handle<WasmModuleObject> module);
|
||||
|
||||
// Check whether this module was generated from asm.js source.
|
||||
bool is_asm_js();
|
||||
inline bool is_asm_js();
|
||||
|
||||
static void AddBreakpoint(Handle<WasmModuleObject>, int position,
|
||||
Handle<BreakPoint> break_point);
|
||||
@ -536,7 +538,6 @@ class WasmCompiledModule : public Struct {
|
||||
V(kNextInstanceOffset, kPointerSize) \
|
||||
V(kPrevInstanceOffset, kPointerSize) \
|
||||
V(kOwningInstanceOffset, kPointerSize) \
|
||||
V(kNativeModuleOffset, kPointerSize) \
|
||||
V(kSize, 0)
|
||||
|
||||
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
|
||||
@ -570,11 +571,9 @@ class WasmCompiledModule : public Struct {
|
||||
WCM_CONST_OBJECT(WasmCompiledModule, next_instance)
|
||||
WCM_CONST_OBJECT(WasmCompiledModule, prev_instance)
|
||||
WCM_WEAK_LINK(WasmInstanceObject, owning_instance)
|
||||
WCM_OBJECT(Foreign, native_module)
|
||||
|
||||
public:
|
||||
static Handle<WasmCompiledModule> New(Isolate* isolate,
|
||||
wasm::ModuleEnv& env);
|
||||
static Handle<WasmCompiledModule> New(Isolate* isolate);
|
||||
|
||||
static Handle<WasmCompiledModule> Clone(Isolate* isolate,
|
||||
Handle<WasmCompiledModule> module);
|
||||
@ -582,15 +581,12 @@ class WasmCompiledModule : public Struct {
|
||||
|
||||
bool has_instance() const;
|
||||
|
||||
wasm::NativeModule* GetNativeModule() const;
|
||||
void InsertInChain(WasmModuleObject*);
|
||||
void RemoveFromChain();
|
||||
|
||||
DECL_ACCESSORS(raw_next_instance, Object);
|
||||
DECL_ACCESSORS(raw_prev_instance, Object);
|
||||
|
||||
void PrintInstancesChain();
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
|
||||
};
|
||||
|
@ -608,7 +608,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
|
||||
Handle<ByteArray>::null());
|
||||
Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
|
||||
isolate);
|
||||
NativeModule* native_module = compiled_module->GetNativeModule();
|
||||
NativeModule* native_module = module_object->native_module();
|
||||
|
||||
if (FLAG_wasm_lazy_compilation) {
|
||||
native_module->SetLazyBuiltin(BUILTIN_CODE(isolate, WasmCompileLazy));
|
||||
|
@ -3452,7 +3452,7 @@ TEST(Liftoff_prologue) {
|
||||
r.Build(&call[0], &call[0] + call.size());
|
||||
|
||||
NativeModule* native_module =
|
||||
r.builder().instance_object()->compiled_module()->GetNativeModule();
|
||||
r.builder().instance_object()->module_object()->native_module();
|
||||
|
||||
// This test only works if we managed to compile with Liftoff.
|
||||
if (native_module->code(add_compiler.function_index())->is_liftoff()) {
|
||||
|
@ -234,7 +234,7 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
|
||||
// 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
|
||||
// interpreter when we get a memory. We do have globals, though.
|
||||
native_module_ = compiled_module->GetNativeModule();
|
||||
native_module_ = module_object->native_module();
|
||||
native_module_->ReserveCodeTableForTesting(kMaxFunctions);
|
||||
|
||||
DCHECK(compiled_module->IsWasmCompiledModule());
|
||||
@ -413,9 +413,6 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
|
||||
interpreter_->SetFunctionCodeForTesting(function_, start, end);
|
||||
}
|
||||
|
||||
Handle<WasmCompiledModule> compiled_module(
|
||||
builder_->instance_object()->compiled_module(), isolate());
|
||||
NativeModule* native_module = compiled_module->GetNativeModule();
|
||||
Handle<SeqOneByteString> wire_bytes(
|
||||
builder_->instance_object()->module_object()->module_bytes(), isolate());
|
||||
|
||||
@ -437,6 +434,8 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
|
||||
builder_->execution_mode() == WasmExecutionMode::kExecuteLiftoff
|
||||
? WasmCompilationUnit::CompilationMode::kLiftoff
|
||||
: WasmCompilationUnit::CompilationMode::kTurbofan;
|
||||
NativeModule* native_module =
|
||||
builder_->instance_object()->module_object()->native_module();
|
||||
WasmCompilationUnit unit(isolate(), &module_env, native_module, func_body,
|
||||
func_name, function_->func_index, comp_mode,
|
||||
isolate()->counters(), builder_->lower_simd());
|
||||
|
Loading…
Reference in New Issue
Block a user