Commit 16a84f94 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove {WasmDebugInfo::interpreted_functions}.

R=clemensh@chromium.org

Change-Id: I76f9f5dd8c4faef3e33dde96c7bb7f81448d8e79
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1585848Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61074}
parent ac497d1c
...@@ -713,7 +713,6 @@ extern class WasmExportedFunctionData extends Struct { ...@@ -713,7 +713,6 @@ extern class WasmExportedFunctionData extends Struct {
extern class WasmDebugInfo extends Struct { extern class WasmDebugInfo extends Struct {
instance: WasmInstanceObject; instance: WasmInstanceObject;
interpreter_handle: Foreign | Undefined; interpreter_handle: Foreign | Undefined;
interpreted_functions: FixedArray;
locals_names: FixedArray; locals_names: FixedArray;
c_wasm_entries: FixedArray; c_wasm_entries: FixedArray;
c_wasm_entry_map: Foreign; // Managed<wasm::SignatureMap> c_wasm_entry_map: Foreign; // Managed<wasm::SignatureMap>
......
...@@ -1912,8 +1912,6 @@ void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) { ...@@ -1912,8 +1912,6 @@ void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) {
VerifyObjectField(isolate, kInterpreterHandleOffset); VerifyObjectField(isolate, kInterpreterHandleOffset);
CHECK(interpreter_handle()->IsUndefined(isolate) || CHECK(interpreter_handle()->IsUndefined(isolate) ||
interpreter_handle()->IsForeign()); interpreter_handle()->IsForeign());
VerifyObjectField(isolate, kInterpretedFunctionsOffset);
CHECK(interpreted_functions()->IsFixedArray());
VerifyObjectField(isolate, kLocalsNamesOffset); VerifyObjectField(isolate, kLocalsNamesOffset);
VerifyObjectField(isolate, kCWasmEntriesOffset); VerifyObjectField(isolate, kCWasmEntriesOffset);
VerifyObjectField(isolate, kCWasmEntryMapOffset); VerifyObjectField(isolate, kCWasmEntryMapOffset);
......
...@@ -1401,6 +1401,11 @@ std::vector<WasmCode*> NativeModule::AddCompiledCode( ...@@ -1401,6 +1401,11 @@ std::vector<WasmCode*> NativeModule::AddCompiledCode(
return code_vector; return code_vector;
} }
bool NativeModule::IsRedirectedToInterpreter(uint32_t func_index) {
base::MutexGuard lock(&allocation_mutex_);
return has_interpreter_redirection(func_index);
}
void NativeModule::FreeCode(Vector<WasmCode* const> codes) { void NativeModule::FreeCode(Vector<WasmCode* const> codes) {
// For now, we neither free the {WasmCode} objects, nor do we free any code. // For now, we neither free the {WasmCode} objects, nor do we free any code.
// We just zap the code to ensure it's not executed any more. // We just zap the code to ensure it's not executed any more.
......
...@@ -405,6 +405,10 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -405,6 +405,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* AddCompiledCode(WasmCompilationResult); WasmCode* AddCompiledCode(WasmCompilationResult);
std::vector<WasmCode*> AddCompiledCode(Vector<WasmCompilationResult>); std::vector<WasmCode*> AddCompiledCode(Vector<WasmCompilationResult>);
// Allows to check whether a function has been redirected to the interpreter
// by publishing an entry stub with the {Kind::kInterpreterEntry} code kind.
bool IsRedirectedToInterpreter(uint32_t func_index);
// Free a set of functions of this module. Uncommits whole pages if possible. // Free a set of functions of this module. Uncommits whole pages if possible.
// The given vector must be ordered by the instruction start address, and all // The given vector must be ordered by the instruction start address, and all
// {WasmCode} objects must not be used any more. // {WasmCode} objects must not be used any more.
...@@ -440,7 +444,7 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -440,7 +444,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* CreateEmptyJumpTable(uint32_t jump_table_size); WasmCode* CreateEmptyJumpTable(uint32_t jump_table_size);
// Hold the {mutex_} when calling this method. // Hold the {allocation_mutex_} when calling this method.
bool has_interpreter_redirection(uint32_t func_index) { bool has_interpreter_redirection(uint32_t func_index) {
DCHECK_LT(func_index, num_functions()); DCHECK_LT(func_index, num_functions());
DCHECK_LE(module_->num_imported_functions, func_index); DCHECK_LE(module_->num_imported_functions, func_index);
...@@ -450,7 +454,7 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -450,7 +454,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
return byte & (1 << (bitset_idx % kBitsPerByte)); return byte & (1 << (bitset_idx % kBitsPerByte));
} }
// Hold the {mutex_} when calling this method. // Hold the {allocation_mutex_} when calling this method.
void SetInterpreterRedirection(uint32_t func_index) { void SetInterpreterRedirection(uint32_t func_index) {
DCHECK_LT(func_index, num_functions()); DCHECK_LT(func_index, num_functions());
DCHECK_LE(module_->num_imported_functions, func_index); DCHECK_LE(module_->num_imported_functions, func_index);
......
...@@ -473,21 +473,6 @@ wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo debug_info) { ...@@ -473,21 +473,6 @@ wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo debug_info) {
return Managed<wasm::InterpreterHandle>::cast(handle_obj)->raw(); return Managed<wasm::InterpreterHandle>::cast(handle_obj)->raw();
} }
Handle<FixedArray> GetOrCreateInterpretedFunctions(
Isolate* isolate, Handle<WasmDebugInfo> debug_info) {
Handle<FixedArray> arr(debug_info->interpreted_functions(), isolate);
int num_functions = debug_info->wasm_instance()
->module_object()
->native_module()
->num_functions();
if (arr->length() == 0 && num_functions > 0) {
arr = isolate->factory()->NewFixedArray(num_functions);
debug_info->set_interpreted_functions(*arr);
}
DCHECK_EQ(num_functions, arr->length());
return arr;
}
} // namespace } // namespace
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
...@@ -496,7 +481,6 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { ...@@ -496,7 +481,6 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast( Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(
factory->NewStruct(WASM_DEBUG_INFO_TYPE, AllocationType::kOld)); factory->NewStruct(WASM_DEBUG_INFO_TYPE, AllocationType::kOld));
debug_info->set_wasm_instance(*instance); debug_info->set_wasm_instance(*instance);
debug_info->set_interpreted_functions(*factory->empty_fixed_array());
instance->set_debug_info(*debug_info); instance->set_debug_info(*debug_info);
return debug_info; return debug_info;
} }
...@@ -530,8 +514,6 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -530,8 +514,6 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
Isolate* isolate = debug_info->GetIsolate(); Isolate* isolate = debug_info->GetIsolate();
// Ensure that the interpreter is instantiated. // Ensure that the interpreter is instantiated.
GetOrCreateInterpreterHandle(isolate, debug_info); GetOrCreateInterpreterHandle(isolate, debug_info);
Handle<FixedArray> interpreted_functions =
GetOrCreateInterpretedFunctions(isolate, debug_info);
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate); Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
wasm::NativeModule* native_module = wasm::NativeModule* native_module =
instance->module_object()->native_module(); instance->module_object()->native_module();
...@@ -544,7 +526,9 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -544,7 +526,9 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
for (int func_index : func_indexes) { for (int func_index : func_indexes) {
DCHECK_LE(0, func_index); DCHECK_LE(0, func_index);
DCHECK_GT(module->functions.size(), func_index); DCHECK_GT(module->functions.size(), func_index);
if (!interpreted_functions->get(func_index)->IsUndefined(isolate)) continue; // Note that this is just a best effort check. Multiple threads can still
// race at redirecting the same function to the interpreter, which is OK.
if (native_module->IsRedirectedToInterpreter(func_index)) continue;
wasm::WasmCodeRefScope code_ref_scope; wasm::WasmCodeRefScope code_ref_scope;
wasm::WasmCompilationResult result = compiler::CompileWasmInterpreterEntry( wasm::WasmCompilationResult result = compiler::CompileWasmInterpreterEntry(
...@@ -555,12 +539,8 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -555,12 +539,8 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
result.tagged_parameter_slots, std::move(result.protected_instructions), result.tagged_parameter_slots, std::move(result.protected_instructions),
std::move(result.source_positions), wasm::WasmCode::kInterpreterEntry, std::move(result.source_positions), wasm::WasmCode::kInterpreterEntry,
wasm::ExecutionTier::kInterpreter); wasm::ExecutionTier::kInterpreter);
Address instruction_start = wasm_code->instruction_start();
native_module->PublishCode(std::move(wasm_code)); native_module->PublishCode(std::move(wasm_code));
DCHECK(native_module->IsRedirectedToInterpreter(func_index));
Handle<Foreign> foreign_holder =
isolate->factory()->NewForeign(instruction_start, AllocationType::kOld);
interpreted_functions->set(func_index, *foreign_holder);
} }
} }
......
...@@ -311,8 +311,6 @@ SMI_ACCESSORS(WasmExportedFunctionData, function_index, kFunctionIndexOffset) ...@@ -311,8 +311,6 @@ SMI_ACCESSORS(WasmExportedFunctionData, function_index, kFunctionIndexOffset)
// WasmDebugInfo // WasmDebugInfo
ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset) ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset)
ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset) ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset)
ACCESSORS(WasmDebugInfo, interpreted_functions, FixedArray,
kInterpretedFunctionsOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset) OPTIONAL_ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entries, FixedArray, OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entries, FixedArray,
kCWasmEntriesOffset) kCWasmEntriesOffset)
......
...@@ -680,7 +680,6 @@ class WasmDebugInfo : public Struct { ...@@ -680,7 +680,6 @@ class WasmDebugInfo : public Struct {
NEVER_READ_ONLY_SPACE NEVER_READ_ONLY_SPACE
DECL_ACCESSORS(wasm_instance, WasmInstanceObject) DECL_ACCESSORS(wasm_instance, WasmInstanceObject)
DECL_ACCESSORS(interpreter_handle, Object) // Foreign or undefined DECL_ACCESSORS(interpreter_handle, Object) // Foreign or undefined
DECL_ACCESSORS(interpreted_functions, FixedArray)
DECL_OPTIONAL_ACCESSORS(locals_names, FixedArray) DECL_OPTIONAL_ACCESSORS(locals_names, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entries, FixedArray) DECL_OPTIONAL_ACCESSORS(c_wasm_entries, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>) DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>)
......
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