Commit 4a4ca6d5 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Move {GetGlobalScopeObject} out of the interpreter

This method should be reused for compiled frames, hence this CL moves
it to the top-level in wasm-debug.cc, and makes it externally available
via wasm-debug.h.

R=mstarzinger@chromium.org

Bug: v8:9676
Change-Id: If2fbcad1d0911efe4c2169e8a5bd85b598ac335f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1876060Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64538}
parent 22fd9555
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/execution/frames-inl.h" #include "src/execution/frames-inl.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/objects/js-generator-inl.h" #include "src/objects/js-generator-inl.h"
#include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
namespace v8 { namespace v8 {
...@@ -158,9 +159,11 @@ v8::Local<v8::Object> DebugWasmScopeIterator::GetObject() { ...@@ -158,9 +159,11 @@ v8::Local<v8::Object> DebugWasmScopeIterator::GetObject() {
Handle<WasmDebugInfo> debug_info( Handle<WasmDebugInfo> debug_info(
WasmInterpreterEntryFrame::cast(frame_)->debug_info(), isolate_); WasmInterpreterEntryFrame::cast(frame_)->debug_info(), isolate_);
switch (type_) { switch (type_) {
case debug::ScopeIterator::ScopeTypeGlobal: case debug::ScopeIterator::ScopeTypeGlobal: {
return Utils::ToLocal(WasmDebugInfo::GetGlobalScopeObject( Handle<WasmInstanceObject> instance(debug_info->wasm_instance(),
debug_info, frame_->fp(), inlined_frame_index_)); isolate_);
return Utils::ToLocal(wasm::GetGlobalScopeObject(instance));
}
case debug::ScopeIterator::ScopeTypeLocal: case debug::ScopeIterator::ScopeTypeLocal:
return Utils::ToLocal(WasmDebugInfo::GetLocalScopeObject( return Utils::ToLocal(WasmDebugInfo::GetLocalScopeObject(
debug_info, frame_->fp(), inlined_frame_index_)); debug_info, frame_->fp(), inlined_frame_index_));
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/wasm/wasm-debug.h"
#include <unordered_map> #include <unordered_map>
#include "src/base/optional.h" #include "src/base/optional.h"
...@@ -361,50 +363,6 @@ class InterpreterHandle { ...@@ -361,50 +363,6 @@ class InterpreterHandle {
return interpreter()->GetThread(0)->NumInterpretedCalls(); return interpreter()->GetThread(0)->NumInterpretedCalls();
} }
Handle<JSObject> GetGlobalScopeObject(InterpretedFrame* frame,
Handle<WasmDebugInfo> debug_info) {
Isolate* isolate = isolate_;
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
Handle<JSObject> global_scope_object =
isolate_->factory()->NewJSObjectWithNullProto();
if (instance->has_memory_object()) {
Handle<String> name =
isolate_->factory()->InternalizeString(StaticCharVector("memory"));
Handle<JSArrayBuffer> memory_buffer(
instance->memory_object().array_buffer(), isolate_);
Handle<JSTypedArray> uint8_array = isolate_->factory()->NewJSTypedArray(
kExternalUint8Array, memory_buffer, 0, memory_buffer->byte_length());
JSObject::SetOwnPropertyIgnoreAttributes(global_scope_object, name,
uint8_array, NONE)
.Assert();
}
auto& globals = module()->globals;
if (!globals.empty()) {
Handle<JSObject> globals_obj =
isolate_->factory()->NewJSObjectWithNullProto();
Handle<String> globals_name =
isolate_->factory()->InternalizeString(StaticCharVector("globals"));
JSObject::SetOwnPropertyIgnoreAttributes(global_scope_object,
globals_name, globals_obj, NONE)
.Assert();
for (uint32_t i = 0; i < globals.size(); ++i) {
const char* label = "global#%d";
Handle<String> name = PrintFToOneByteString<true>(isolate_, label, i);
WasmValue value =
WasmInstanceObject::GetGlobalValue(instance, globals[i]);
Handle<Object> value_obj = WasmValueToValueObject(isolate_, value);
JSObject::SetOwnPropertyIgnoreAttributes(globals_obj, name, value_obj,
NONE)
.Assert();
}
}
return global_scope_object;
}
Handle<JSObject> GetLocalScopeObject(InterpretedFrame* frame, Handle<JSObject> GetLocalScopeObject(InterpretedFrame* frame,
Handle<WasmDebugInfo> debug_info) { Handle<WasmDebugInfo> debug_info) {
Isolate* isolate = isolate_; Isolate* isolate = isolate_;
...@@ -468,6 +426,48 @@ class InterpreterHandle { ...@@ -468,6 +426,48 @@ class InterpreterHandle {
} // namespace } // namespace
Handle<JSObject> GetGlobalScopeObject(Handle<WasmInstanceObject> instance) {
Isolate* isolate = instance->GetIsolate();
Handle<JSObject> global_scope_object =
isolate->factory()->NewJSObjectWithNullProto();
if (instance->has_memory_object()) {
Handle<String> name =
isolate->factory()->InternalizeString(StaticCharVector("memory"));
Handle<JSArrayBuffer> memory_buffer(
instance->memory_object().array_buffer(), isolate);
Handle<JSTypedArray> uint8_array = isolate->factory()->NewJSTypedArray(
kExternalUint8Array, memory_buffer, 0, memory_buffer->byte_length());
JSObject::SetOwnPropertyIgnoreAttributes(global_scope_object, name,
uint8_array, NONE)
.Assert();
}
auto& globals = instance->module()->globals;
if (globals.size() > 0) {
Handle<JSObject> globals_obj =
isolate->factory()->NewJSObjectWithNullProto();
Handle<String> globals_name =
isolate->factory()->InternalizeString(StaticCharVector("globals"));
JSObject::SetOwnPropertyIgnoreAttributes(global_scope_object, globals_name,
globals_obj, NONE)
.Assert();
for (size_t i = 0; i < globals.size(); ++i) {
const char* label = "global#%d";
Handle<String> name = PrintFToOneByteString<true>(isolate, label, i);
WasmValue value =
WasmInstanceObject::GetGlobalValue(instance, globals[i]);
Handle<Object> value_obj = WasmValueToValueObject(isolate, value);
JSObject::SetOwnPropertyIgnoreAttributes(globals_obj, name, value_obj,
NONE)
.Assert();
}
}
return global_scope_object;
}
} // namespace wasm } // namespace wasm
namespace { namespace {
...@@ -620,14 +620,6 @@ uint64_t WasmDebugInfo::NumInterpretedCalls() { ...@@ -620,14 +620,6 @@ uint64_t WasmDebugInfo::NumInterpretedCalls() {
return handle ? handle->NumInterpretedCalls() : 0; return handle ? handle->NumInterpretedCalls() : 0;
} }
// static
Handle<JSObject> WasmDebugInfo::GetGlobalScopeObject(
Handle<WasmDebugInfo> debug_info, Address frame_pointer, int frame_index) {
auto* interp_handle = GetInterpreterHandle(*debug_info);
auto frame = interp_handle->GetInterpretedFrame(frame_pointer, frame_index);
return interp_handle->GetGlobalScopeObject(frame.get(), debug_info);
}
// static // static
Handle<JSObject> WasmDebugInfo::GetLocalScopeObject( Handle<JSObject> WasmDebugInfo::GetLocalScopeObject(
Handle<WasmDebugInfo> debug_info, Address frame_pointer, int frame_index) { Handle<WasmDebugInfo> debug_info, Address frame_pointer, int frame_index) {
......
// Copyright 2019 the V8 project authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_WASM_DEBUG_H_
#define V8_WASM_WASM_DEBUG_H_
namespace v8 {
namespace internal {
template <typename T>
class Handle;
class JSObject;
class WasmInstanceObject;
namespace wasm {
// Get the global scope for a given instance. This will contain the wasm memory
// (if the instance has a memory) and the values of all globals.
Handle<JSObject> GetGlobalScopeObject(Handle<WasmInstanceObject>);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_WASM_DEBUG_H_
...@@ -871,16 +871,8 @@ class WasmDebugInfo : public Struct { ...@@ -871,16 +871,8 @@ class WasmDebugInfo : public Struct {
// Returns the number of calls / function frames executed in the interpreter. // Returns the number of calls / function frames executed in the interpreter.
V8_EXPORT_PRIVATE uint64_t NumInterpretedCalls(); V8_EXPORT_PRIVATE uint64_t NumInterpretedCalls();
// Get scope details for a specific interpreted frame. // Get local scope details for a specific interpreted frame. It contains
// Both of these methods return a JSArrays (for the global scope and local // information about parameters, locals, and stack values.
// scope respectively) of size {ScopeIterator::kScopeDetailsSize} and layout
// as described in debug-scopes.h.
// - The global scope contains information about globals and the memory.
// - The local scope contains information about parameters, locals, and
// stack values.
static Handle<JSObject> GetGlobalScopeObject(Handle<WasmDebugInfo>,
Address frame_pointer,
int frame_index);
static Handle<JSObject> GetLocalScopeObject(Handle<WasmDebugInfo>, static Handle<JSObject> GetLocalScopeObject(Handle<WasmDebugInfo>,
Address frame_pointer, Address frame_pointer,
int frame_index); int frame_index);
......
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