OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 | 1967 |
1968 bool wasm::IsWasmInstance(Object* object) { | 1968 bool wasm::IsWasmInstance(Object* object) { |
1969 return WasmInstanceObject::IsWasmInstanceObject(object); | 1969 return WasmInstanceObject::IsWasmInstanceObject(object); |
1970 } | 1970 } |
1971 | 1971 |
1972 bool wasm::WasmIsAsmJs(Object* instance, Isolate* isolate) { | 1972 bool wasm::WasmIsAsmJs(Object* instance, Isolate* isolate) { |
1973 if (instance->IsUndefined(isolate)) return false; | 1973 if (instance->IsUndefined(isolate)) return false; |
1974 DCHECK(IsWasmInstance(instance)); | 1974 DCHECK(IsWasmInstance(instance)); |
1975 WasmCompiledModule* compiled_module = | 1975 WasmCompiledModule* compiled_module = |
1976 WasmInstanceObject::cast(instance)->get_compiled_module(); | 1976 WasmInstanceObject::cast(instance)->get_compiled_module(); |
1977 DCHECK_EQ(compiled_module->has_asm_js_offset_tables(), | 1977 DCHECK_EQ(compiled_module->has_asm_js_offset_table(), |
1978 compiled_module->script()->type() == Script::TYPE_NORMAL); | 1978 compiled_module->script()->type() == Script::TYPE_NORMAL); |
1979 return compiled_module->has_asm_js_offset_tables(); | 1979 return compiled_module->has_asm_js_offset_table(); |
1980 } | 1980 } |
1981 | 1981 |
1982 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { | 1982 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
1983 WasmCompiledModule* compiled_module = | 1983 WasmCompiledModule* compiled_module = |
1984 WasmInstanceObject::cast(*instance)->get_compiled_module(); | 1984 WasmInstanceObject::cast(*instance)->get_compiled_module(); |
1985 DCHECK(compiled_module->has_script()); | 1985 DCHECK(compiled_module->has_script()); |
1986 return compiled_module->script(); | 1986 return compiled_module->script(); |
1987 } | 1987 } |
1988 | 1988 |
1989 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> | 1989 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> |
1990 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, | 1990 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, |
1991 int func_index) { | 1991 int func_index) { |
1992 if (func_index < 0 || | 1992 if (func_index < 0 || |
1993 static_cast<uint32_t>(func_index) >= | 1993 static_cast<uint32_t>(func_index) >= |
1994 compiled_module->module()->functions.size()) | 1994 compiled_module->module()->functions.size()) |
1995 return {}; | 1995 return {}; |
1996 | 1996 |
1997 std::ostringstream disassembly_os; | 1997 std::ostringstream disassembly_os; |
1998 std::vector<std::tuple<uint32_t, int, int>> offset_table; | 1998 std::vector<std::tuple<uint32_t, int, int>> offset_table; |
1999 | 1999 |
2000 PrintWasmText(compiled_module->module(), static_cast<uint32_t>(func_index), | 2000 PrintWasmText(compiled_module->module(), static_cast<uint32_t>(func_index), |
2001 disassembly_os, &offset_table); | 2001 disassembly_os, &offset_table); |
2002 | 2002 |
2003 return {disassembly_os.str(), std::move(offset_table)}; | 2003 return {disassembly_os.str(), std::move(offset_table)}; |
2004 } | 2004 } |
2005 | 2005 |
2006 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, | |
2007 int byte_offset) { | |
2008 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), | |
2009 func_index, byte_offset); | |
2010 } | |
2011 | |
2012 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) { | 2006 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) { |
2013 auto instance = Handle<WasmInstanceObject>::cast(object); | 2007 auto instance = Handle<WasmInstanceObject>::cast(object); |
2014 if (instance->has_debug_info()) { | 2008 if (instance->has_debug_info()) { |
2015 Handle<WasmDebugInfo> info(instance->get_debug_info(), | 2009 Handle<WasmDebugInfo> info(instance->get_debug_info(), |
2016 instance->GetIsolate()); | 2010 instance->GetIsolate()); |
2017 return info; | 2011 return info; |
2018 } | 2012 } |
2019 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance); | 2013 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance); |
2020 instance->set_debug_info(*new_info); | 2014 instance->set_debug_info(*new_info); |
2021 return new_info; | 2015 return new_info; |
2022 } | 2016 } |
2023 | 2017 |
2024 int wasm::GetNumberOfFunctions(Handle<JSObject> object) { | |
2025 return static_cast<int>( | |
2026 Handle<WasmInstanceObject>::cast(object)->module()->functions.size()); | |
2027 } | |
2028 | |
2029 // TODO(clemensh): origin can be inferred from asm_js_script; remove it. | 2018 // TODO(clemensh): origin can be inferred from asm_js_script; remove it. |
2030 MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes( | 2019 MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes( |
2031 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 2020 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
2032 ModuleOrigin origin, Handle<Script> asm_js_script, | 2021 ModuleOrigin origin, Handle<Script> asm_js_script, |
2033 const byte* asm_js_offset_tables_start, | 2022 const byte* asm_js_offset_tables_start, |
2034 const byte* asm_js_offset_tables_end) { | 2023 const byte* asm_js_offset_tables_end) { |
2035 MaybeHandle<WasmModuleObject> nothing; | 2024 MaybeHandle<WasmModuleObject> nothing; |
2036 ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin); | 2025 ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin); |
2037 if (result.failed()) { | 2026 if (result.failed()) { |
2038 if (result.val) delete result.val; | 2027 if (result.val) delete result.val; |
(...skipping 10 matching lines...) Expand all Loading... |
2049 MaybeHandle<WasmCompiledModule> maybe_compiled_module = | 2038 MaybeHandle<WasmCompiledModule> maybe_compiled_module = |
2050 result.val->CompileFunctions(isolate, module_wrapper, thrower); | 2039 result.val->CompileFunctions(isolate, module_wrapper, thrower); |
2051 | 2040 |
2052 if (maybe_compiled_module.is_null()) return nothing; | 2041 if (maybe_compiled_module.is_null()) return nothing; |
2053 | 2042 |
2054 Handle<WasmCompiledModule> compiled_module = | 2043 Handle<WasmCompiledModule> compiled_module = |
2055 maybe_compiled_module.ToHandleChecked(); | 2044 maybe_compiled_module.ToHandleChecked(); |
2056 | 2045 |
2057 DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null()); | 2046 DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null()); |
2058 DCHECK(!compiled_module->has_script()); | 2047 DCHECK(!compiled_module->has_script()); |
2059 DCHECK(!compiled_module->has_asm_js_offset_tables()); | 2048 DCHECK(!compiled_module->has_asm_js_offset_table()); |
2060 if (origin == kAsmJsOrigin) { | 2049 if (origin == kAsmJsOrigin) { |
2061 // Set script for the asm.js source, and the offset table mapping wasm byte | 2050 // Set script for the asm.js source, and the offset table mapping wasm byte |
2062 // offsets to source positions. | 2051 // offsets to source positions. |
2063 compiled_module->set_script(asm_js_script); | 2052 compiled_module->set_script(asm_js_script); |
2064 size_t offset_tables_len = | 2053 size_t offset_table_len = |
2065 asm_js_offset_tables_end - asm_js_offset_tables_start; | 2054 asm_js_offset_tables_end - asm_js_offset_tables_start; |
2066 DCHECK_GE(static_cast<size_t>(kMaxInt), offset_tables_len); | 2055 DCHECK_GE(static_cast<size_t>(kMaxInt), offset_table_len); |
2067 Handle<ByteArray> offset_tables = | 2056 Handle<ByteArray> offset_table = |
2068 isolate->factory()->NewByteArray(static_cast<int>(offset_tables_len)); | 2057 isolate->factory()->NewByteArray(static_cast<int>(offset_table_len)); |
2069 memcpy(offset_tables->GetDataStartAddress(), asm_js_offset_tables_start, | 2058 memcpy(offset_table->GetDataStartAddress(), asm_js_offset_tables_start, |
2070 offset_tables_len); | 2059 offset_table_len); |
2071 compiled_module->set_asm_js_offset_tables(offset_tables); | 2060 compiled_module->set_asm_js_offset_table(offset_table); |
2072 } else { | 2061 } else { |
2073 // Create a new Script object representing this wasm module, store it in the | 2062 // Create a new Script object representing this wasm module, store it in the |
2074 // compiled wasm module, and register it at the debugger. | 2063 // compiled wasm module, and register it at the debugger. |
2075 Handle<Script> script = | 2064 Handle<Script> script = |
2076 isolate->factory()->NewScript(isolate->factory()->empty_string()); | 2065 isolate->factory()->NewScript(isolate->factory()->empty_string()); |
2077 script->set_type(Script::TYPE_WASM); | 2066 script->set_type(Script::TYPE_WASM); |
2078 | 2067 |
2079 DCHECK_GE(kMaxInt, end - start); | 2068 DCHECK_GE(kMaxInt, end - start); |
2080 int hash = StringHasher::HashSequentialString( | 2069 int hash = StringHasher::HashSequentialString( |
2081 reinterpret_cast<const char*>(start), static_cast<int>(end - start), | 2070 reinterpret_cast<const char*>(start), static_cast<int>(end - start), |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2361 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
2373 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2362 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
2374 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2363 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
2375 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2364 WasmFunction& function = compiled_module->module()->functions[func_index]; |
2376 Isolate* isolate = compiled_module->GetIsolate(); | 2365 Isolate* isolate = compiled_module->GetIsolate(); |
2377 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2366 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
2378 isolate, compiled_module, function.name_offset, function.name_length); | 2367 isolate, compiled_module, function.name_offset, function.name_length); |
2379 if (!string.is_null()) return string.ToHandleChecked(); | 2368 if (!string.is_null()) return string.ToHandleChecked(); |
2380 return {}; | 2369 return {}; |
2381 } | 2370 } |
OLD | NEW |