Commit 48a96d17 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Handlify WasmDebugInfo where needed

All function which potentially do heap allocations now take a Handle
on a WasmDebugInfo. This unfortunately requires to make some function
static, since otherwise the "this" pointer would not be handlified.

R=ahaas@chromium.org, titzer@chromium.org
BUG=chromium:613110

Review-Url: https://codereview.chromium.org/2074933005
Cr-Commit-Position: refs/heads/master@{#37099}
parent bfdaff31
...@@ -23,7 +23,7 @@ enum { ...@@ -23,7 +23,7 @@ enum {
kWasmDebugInfoNumEntries kWasmDebugInfoNumEntries
}; };
ByteArray *GetOrCreateFunctionOffsetTable(WasmDebugInfo *debug_info) { ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) {
Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets); Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets);
Isolate *isolate = debug_info->GetIsolate(); Isolate *isolate = debug_info->GetIsolate();
if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table); if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table);
...@@ -53,7 +53,7 @@ ByteArray *GetOrCreateFunctionOffsetTable(WasmDebugInfo *debug_info) { ...@@ -53,7 +53,7 @@ ByteArray *GetOrCreateFunctionOffsetTable(WasmDebugInfo *debug_info) {
return arr; return arr;
} }
std::pair<int, int> GetFunctionOffsetAndLength(WasmDebugInfo *debug_info, std::pair<int, int> GetFunctionOffsetAndLength(Handle<WasmDebugInfo> debug_info,
int func_index) { int func_index) {
ByteArray *arr = GetOrCreateFunctionOffsetTable(debug_info); ByteArray *arr = GetOrCreateFunctionOffsetTable(debug_info);
DCHECK(func_index >= 0 && func_index < arr->length() / kIntSize / 2); DCHECK(func_index >= 0 && func_index < arr->length() / kIntSize / 2);
...@@ -65,9 +65,8 @@ std::pair<int, int> GetFunctionOffsetAndLength(WasmDebugInfo *debug_info, ...@@ -65,9 +65,8 @@ std::pair<int, int> GetFunctionOffsetAndLength(WasmDebugInfo *debug_info,
return {offset, length}; return {offset, length};
} }
Vector<const uint8_t> GetFunctionBytes(WasmDebugInfo *debug_info, Vector<const uint8_t> GetFunctionBytes(Handle<WasmDebugInfo> debug_info,
int func_index) { int func_index) {
DCHECK(!AllowHeapAllocation::IsAllowed());
SeqOneByteString *module_bytes = SeqOneByteString *module_bytes =
wasm::GetWasmBytes(debug_info->wasm_object()); wasm::GetWasmBytes(debug_info->wasm_object());
std::pair<int, int> offset_and_length = std::pair<int, int> offset_and_length =
...@@ -123,12 +122,13 @@ bool WasmDebugInfo::SetBreakPoint(int byte_offset) { ...@@ -123,12 +122,13 @@ bool WasmDebugInfo::SetBreakPoint(int byte_offset) {
return false; return false;
} }
Handle<String> WasmDebugInfo::DisassembleFunction(int func_index) { Handle<String> WasmDebugInfo::DisassembleFunction(
Handle<WasmDebugInfo> debug_info, int func_index) {
std::ostringstream disassembly_os; std::ostringstream disassembly_os;
{ {
Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index);
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
Vector<const uint8_t> bytes_vec = GetFunctionBytes(this, func_index);
base::AccountingAllocator allocator; base::AccountingAllocator allocator;
bool ok = PrintAst( bool ok = PrintAst(
...@@ -141,14 +141,14 @@ Handle<String> WasmDebugInfo::DisassembleFunction(int func_index) { ...@@ -141,14 +141,14 @@ Handle<String> WasmDebugInfo::DisassembleFunction(int func_index) {
// Unfortunately, we have to copy the string here. // Unfortunately, we have to copy the string here.
std::string code_str = disassembly_os.str(); std::string code_str = disassembly_os.str();
CHECK_LE(code_str.length(), static_cast<size_t>(kMaxInt)); CHECK_LE(code_str.length(), static_cast<size_t>(kMaxInt));
return GetIsolate() Factory *factory = debug_info->GetIsolate()->factory();
->factory() Vector<const char> code_vec(code_str.data(),
->NewStringFromAscii(Vector<const char>( static_cast<int>(code_str.length()));
code_str.data(), static_cast<int>(code_str.length()))) return factory->NewStringFromAscii(code_vec).ToHandleChecked();
.ToHandleChecked();
} }
Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(int func_index) { Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(
Handle<WasmDebugInfo> debug_info, int func_index) {
class NullBuf : public std::streambuf {}; class NullBuf : public std::streambuf {};
NullBuf null_buf; NullBuf null_buf;
std::ostream null_stream(&null_buf); std::ostream null_stream(&null_buf);
...@@ -156,8 +156,8 @@ Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(int func_index) { ...@@ -156,8 +156,8 @@ Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(int func_index) {
std::vector<std::tuple<uint32_t, int, int>> offset_table_vec; std::vector<std::tuple<uint32_t, int, int>> offset_table_vec;
{ {
Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index);
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
Vector<const uint8_t> bytes_vec = GetFunctionBytes(this, func_index);
v8::base::AccountingAllocator allocator; v8::base::AccountingAllocator allocator;
bool ok = PrintAst( bool ok = PrintAst(
...@@ -169,8 +169,9 @@ Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(int func_index) { ...@@ -169,8 +169,9 @@ Handle<FixedArray> WasmDebugInfo::GetFunctionOffsetTable(int func_index) {
size_t arr_size = 3 * offset_table_vec.size(); size_t arr_size = 3 * offset_table_vec.size();
CHECK_LE(arr_size, static_cast<size_t>(kMaxInt)); CHECK_LE(arr_size, static_cast<size_t>(kMaxInt));
Handle<FixedArray> offset_table = GetIsolate()->factory()->NewFixedArray( Factory *factory = debug_info->GetIsolate()->factory();
static_cast<int>(arr_size), TENURED); Handle<FixedArray> offset_table =
factory->NewFixedArray(static_cast<int>(arr_size), TENURED);
int idx = 0; int idx = 0;
for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { for (std::tuple<uint32_t, int, int> elem : offset_table_vec) {
......
...@@ -24,12 +24,14 @@ class WasmDebugInfo : public FixedArray { ...@@ -24,12 +24,14 @@ class WasmDebugInfo : public FixedArray {
bool SetBreakPoint(int byte_offset); bool SetBreakPoint(int byte_offset);
// Disassemble the specified function from this module. // Disassemble the specified function from this module.
Handle<String> DisassembleFunction(int func_index); static Handle<String> DisassembleFunction(Handle<WasmDebugInfo> debug_info,
int func_index);
// Get the offset table for the specified function. // Get the offset table for the specified function.
// Returns an array with three entries per instruction: byte offset, line and // Returns an array with three entries per instruction: byte offset, line and
// column. // column.
Handle<FixedArray> GetFunctionOffsetTable(int func_index); static Handle<FixedArray> GetFunctionOffsetTable(
Handle<WasmDebugInfo> debug_info, int func_index);
}; };
} // namespace wasm } // namespace wasm
......
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