Commit 9bed3d6f authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move weak list of instances from module to Script.

This moves the weak list of instances from {WasmModuleObject} to the
corresponding {Script} object. The list is used solely for breakpoints
which are intended to affect all instances belonging to a given script,
hence the new placement of the list is a preparation to fully support
per-script breakpoints.

R=clemensb@chromium.org
BUG=v8:6847,chromium:893069

Change-Id: I52315e0ba1e5e5021f55bf05d8cb0f01bf9f0fbb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847359
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64191}
parent 5ee115fe
......@@ -1593,7 +1593,6 @@ extern class WasmModuleObject extends JSObject {
native_module: Foreign;
export_wrappers: FixedArray;
script: Script;
weak_instance_list: WeakArrayList;
asm_js_offset_table: ByteArray | Undefined;
break_point_infos: FixedArray | Undefined;
}
......
......@@ -36,8 +36,6 @@ ACCESSORS_CHECKED(Script, eval_from_shared_or_wrapped_arguments, Object,
this->type() != TYPE_WASM)
SMI_ACCESSORS_CHECKED(Script, eval_from_position, kEvalFromPositionOffset,
this->type() != TYPE_WASM)
ACCESSORS(Script, shared_function_infos, WeakFixedArray,
kSharedFunctionInfosOffset)
SMI_ACCESSORS(Script, flags, kFlagsOffset)
ACCESSORS(Script, source_url, Object, kSourceUrlOffset)
ACCESSORS(Script, source_mapping_url, Object, kSourceMappingUrlOffset)
......@@ -47,6 +45,8 @@ ACCESSORS_CHECKED(Script, wasm_module_object, Object,
this->type() == TYPE_WASM)
ACCESSORS_CHECKED(Script, wasm_managed_native_module, Object,
kEvalFromPositionOffset, this->type() == TYPE_WASM)
ACCESSORS_CHECKED(Script, wasm_weak_instance_list, WeakArrayList,
kSharedFunctionInfosOffset, this->type() == TYPE_WASM)
bool Script::is_wrapped() const {
return eval_from_shared_or_wrapped_arguments().IsFixedArray();
......@@ -77,6 +77,20 @@ FixedArray Script::wrapped_arguments() const {
return FixedArray::cast(eval_from_shared_or_wrapped_arguments());
}
DEF_GETTER(Script, shared_function_infos, WeakFixedArray) {
return type() == TYPE_WASM
? ReadOnlyRoots(GetHeap()).empty_weak_fixed_array()
: TaggedField<WeakFixedArray, kSharedFunctionInfosOffset>::load(
*this);
}
void Script::set_shared_function_infos(WeakFixedArray value,
WriteBarrierMode mode) {
DCHECK_NE(TYPE_WASM, type());
TaggedField<WeakFixedArray, kSharedFunctionInfosOffset>::store(*this, value);
CONDITIONAL_WRITE_BARRIER(*this, kSharedFunctionInfosOffset, value, mode);
}
wasm::NativeModule* Script::wasm_native_module() const {
return Managed<wasm::NativeModule>::cast(wasm_managed_native_module()).raw();
}
......
......@@ -112,6 +112,11 @@ class Script : public Struct {
DECL_ACCESSORS(wasm_managed_native_module, Object)
inline wasm::NativeModule* wasm_native_module() const;
// [wasm_weak_instance_list]: the list of all {WasmInstanceObject} being
// affected by breakpoints that are managed via this script.
// This must only be called if the type of this script is TYPE_WASM.
DECL_ACCESSORS(wasm_weak_instance_list, WeakArrayList)
// [host_defined_options]: Options defined by the embedder.
DECL_ACCESSORS(host_defined_options, FixedArray)
......
......@@ -1259,7 +1259,8 @@ RUNTIME_FUNCTION(Runtime_WasmGetNumberOfInstances) {
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
int instance_count = 0;
WeakArrayList weak_instance_list = module_obj->weak_instance_list();
WeakArrayList weak_instance_list =
module_obj->script().wasm_weak_instance_list();
for (int i = 0; i < weak_instance_list.length(); ++i) {
if (weak_instance_list.Get(i)->IsWeak()) instance_count++;
}
......
......@@ -88,8 +88,6 @@ ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
kNativeModuleOffset)
ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList,
kWeakInstanceListOffset)
OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray,
kAsmJsOffsetTableOffset)
OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray,
......
......@@ -244,10 +244,10 @@ Handle<WasmModuleObject> WasmModuleObject::New(
if (script->type() == Script::TYPE_WASM) {
script->set_wasm_module_object(*module_object);
script->set_wasm_managed_native_module(*managed_native_module);
script->set_wasm_weak_instance_list(
ReadOnlyRoots(isolate).empty_weak_array_list());
}
module_object->set_script(*script);
module_object->set_weak_instance_list(
ReadOnlyRoots(isolate).empty_weak_array_list());
module_object->set_managed_native_module(*managed_native_module);
return module_object;
}
......@@ -273,10 +273,10 @@ bool WasmModuleObject::SetBreakPoint(Handle<WasmModuleObject> module_object,
// Insert new break point into break_positions of module object.
WasmModuleObject::AddBreakpointToInfo(module_object, *position, break_point);
// Iterate over all instances of this module and tell them to set this new
// breakpoint. We do this using the weak list of all instances.
Handle<WeakArrayList> weak_instance_list(module_object->weak_instance_list(),
isolate);
// Iterate over all instances and tell them to set this new breakpoint.
// We do this using the weak list of all instances from the script.
Handle<WeakArrayList> weak_instance_list(
module_object->script().wasm_weak_instance_list(), isolate);
for (int i = 0; i < weak_instance_list->length(); ++i) {
MaybeObject maybe_instance = weak_instance_list->Get(i);
if (maybe_instance->IsWeak()) {
......@@ -310,10 +310,10 @@ bool WasmModuleObject::ClearBreakPoint(Handle<WasmModuleObject> module_object,
return false;
}
// Iterate over all instances of this module and tell them to remove this
// breakpoint. We do this using the weak list of all instances.
Handle<WeakArrayList> weak_instance_list(module_object->weak_instance_list(),
isolate);
// Iterate over all instances and tell them to remove this breakpoint.
// We do this using the weak list of all instances from the script.
Handle<WeakArrayList> weak_instance_list(
module_object->script().wasm_weak_instance_list(), isolate);
for (int i = 0; i < weak_instance_list->length(); ++i) {
MaybeObject maybe_instance = weak_instance_list->Get(i);
if (maybe_instance->IsWeak()) {
......@@ -1687,13 +1687,16 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
instance->set_jump_table_start(
module_object->native_module()->jump_table_start());
// Insert the new instance into the modules weak list of instances.
// Insert the new instance into the scripts weak list of instances. This list
// is used for breakpoints affecting all instances belonging to the script.
// TODO(mstarzinger): Allow to reuse holes in the {WeakArrayList} below.
Handle<WeakArrayList> weak_instance_list(module_object->weak_instance_list(),
isolate);
if (module_object->script().type() == Script::TYPE_WASM) {
Handle<WeakArrayList> weak_instance_list(
module_object->script().wasm_weak_instance_list(), isolate);
weak_instance_list = WeakArrayList::AddToEnd(
isolate, weak_instance_list, MaybeObjectHandle::Weak(instance));
module_object->set_weak_instance_list(*weak_instance_list);
module_object->script().set_wasm_weak_instance_list(*weak_instance_list);
}
InitDataSegmentArrays(instance, module_object);
InitElemSegmentArrays(instance, module_object);
......
......@@ -126,7 +126,6 @@ class WasmModuleObject : public JSObject {
DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
DECL_ACCESSORS(export_wrappers, FixedArray)
DECL_ACCESSORS(script, Script)
DECL_ACCESSORS(weak_instance_list, WeakArrayList)
DECL_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray)
DECL_OPTIONAL_ACCESSORS(breakpoint_infos, FixedArray)
inline wasm::NativeModule* native_module() const;
......
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