Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2404253002: [wasm] Provide better stack traces for asm.js code (Closed)
Patch Set: Rebase & fix paths for windows Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 case kStartSectionCode: 778 case kStartSectionCode:
779 return "Start"; 779 return "Start";
780 case kCodeSectionCode: 780 case kCodeSectionCode:
781 return "Code"; 781 return "Code";
782 case kElementSectionCode: 782 case kElementSectionCode:
783 return "Element"; 783 return "Element";
784 case kDataSectionCode: 784 case kDataSectionCode:
785 return "Data"; 785 return "Data";
786 case kNameSectionCode: 786 case kNameSectionCode:
787 return "Name"; 787 return "Name";
788 case kAsmOffsetsSectionCode:
789 return "AsmOffsets";
788 default: 790 default:
789 return "<unknown>"; 791 return "<unknown>";
790 } 792 }
791 } 793 }
792 794
793 std::ostream& operator<<(std::ostream& os, const WasmModule& module) { 795 std::ostream& operator<<(std::ostream& os, const WasmModule& module) {
794 os << "WASM module with "; 796 os << "WASM module with ";
795 os << (module.min_mem_pages * module.kPageSize) << " min mem"; 797 os << (module.min_mem_pages * module.kPageSize) << " min mem";
796 os << (module.max_mem_pages * module.kPageSize) << " max mem"; 798 os << (module.max_mem_pages * module.kPageSize) << " max mem";
797 os << module.functions.size() << " functions"; 799 os << module.functions.size() << " functions";
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) || 1997 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) ||
1996 !WasmCompiledModule::IsWasmCompiledModule( 1998 !WasmCompiledModule::IsWasmCompiledModule(
1997 obj->GetInternalField(kWasmCompiledModule))) { 1999 obj->GetInternalField(kWasmCompiledModule))) {
1998 return false; 2000 return false;
1999 } 2001 }
2000 2002
2001 // All checks passed. 2003 // All checks passed.
2002 return true; 2004 return true;
2003 } 2005 }
2004 2006
2007 bool WasmIsAsm(Object* wasm, Isolate* isolate) {
2008 if (wasm->IsUndefined(isolate)) return false;
2009 DCHECK(IsWasmObject(wasm));
2010 Object* compiled_module =
2011 JSObject::cast(wasm)->GetInternalField(kWasmCompiledModule);
2012 return WasmCompiledModule::cast(compiled_module)->has_asm_js_script();
2013 }
2014
2015 Handle<Script> GetAsmWasmScript(Handle<JSObject> wasm) {
2016 DCHECK(IsWasmObject(*wasm));
2017 Object* compiled_module =
2018 JSObject::cast(*wasm)->GetInternalField(kWasmCompiledModule);
2019 return WasmCompiledModule::cast(compiled_module)->asm_js_script();
2020 }
2021
2022 int GetAsmWasmSourcePosition(Handle<JSObject> wasm, int func_index,
2023 int byte_offset) {
2024 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(wasm), func_index,
2025 byte_offset);
2026 }
2027
2005 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm) { 2028 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm) {
2006 DCHECK(IsWasmObject(*wasm)); 2029 DCHECK(IsWasmObject(*wasm));
2007 Object* compiled_module = wasm->GetInternalField(kWasmCompiledModule); 2030 Object* compiled_module = wasm->GetInternalField(kWasmCompiledModule);
2008 return WasmCompiledModule::cast(compiled_module)->module_bytes(); 2031 return WasmCompiledModule::cast(compiled_module)->module_bytes();
2009 } 2032 }
2010 2033
2011 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm) { 2034 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm) {
2012 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), 2035 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo),
2013 wasm->GetIsolate()); 2036 wasm->GetIsolate());
2014 if (!info->IsUndefined(wasm->GetIsolate())) 2037 if (!info->IsUndefined(wasm->GetIsolate()))
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 module_obj->SetInternalField(0, *compiled_module); 2135 module_obj->SetInternalField(0, *compiled_module);
2113 if (origin == ModuleOrigin::kWasmOrigin) { 2136 if (origin == ModuleOrigin::kWasmOrigin) {
2114 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); 2137 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym());
2115 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); 2138 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
2116 } 2139 }
2117 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj); 2140 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj);
2118 compiled_module->set_weak_module_object(link_to_module); 2141 compiled_module->set_weak_module_object(link_to_module);
2119 return module_obj; 2142 return module_obj;
2120 } 2143 }
2121 2144
2122 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, 2145 // TODO(clemensh): origin can be inferred from asm_js_script; remove it.
2123 const byte* start, 2146 MaybeHandle<JSObject> CreateModuleObjectFromBytes(
2124 const byte* end, 2147 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower,
2125 ErrorThrower* thrower, 2148 ModuleOrigin origin, Handle<Script> asm_js_script) {
2126 ModuleOrigin origin) {
2127 MaybeHandle<JSObject> nothing; 2149 MaybeHandle<JSObject> nothing;
2128 Zone zone(isolate->allocator()); 2150 Zone zone(isolate->allocator());
2129 ModuleResult result = 2151 ModuleResult result =
2130 DecodeWasmModule(isolate, &zone, start, end, false, origin); 2152 DecodeWasmModule(isolate, &zone, start, end, false, origin);
2131 std::unique_ptr<const WasmModule> decoded_module(result.val); 2153 std::unique_ptr<const WasmModule> decoded_module(result.val);
2132 if (result.failed()) { 2154 if (result.failed()) {
2133 thrower->Failed("Wasm decoding failed", result); 2155 thrower->Failed("Wasm decoding failed", result);
2134 return nothing; 2156 return nothing;
2135 } 2157 }
2136 MaybeHandle<WasmCompiledModule> compiled_module = 2158 MaybeHandle<WasmCompiledModule> maybe_compiled_module =
2137 decoded_module->CompileFunctions(isolate, thrower); 2159 decoded_module->CompileFunctions(isolate, thrower);
2138 if (compiled_module.is_null()) return nothing; 2160 if (maybe_compiled_module.is_null()) return nothing;
2161 Handle<WasmCompiledModule> compiled_module =
2162 maybe_compiled_module.ToHandleChecked();
2139 2163
2140 return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(), 2164 DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null());
2141 origin); 2165 DCHECK(!compiled_module->has_asm_js_script());
2166 if (origin == kAsmJsOrigin) {
2167 compiled_module->set_asm_js_script(asm_js_script);
2168 }
2169
2170 return CreateCompiledModuleObject(isolate, compiled_module, origin);
2142 } 2171 }
2143 2172
2144 bool ValidateModuleBytes(Isolate* isolate, const byte* start, const byte* end, 2173 bool ValidateModuleBytes(Isolate* isolate, const byte* start, const byte* end,
2145 ErrorThrower* thrower, ModuleOrigin origin) { 2174 ErrorThrower* thrower, ModuleOrigin origin) {
2146 Zone zone(isolate->allocator()); 2175 Zone zone(isolate->allocator());
2147 ModuleResult result = 2176 ModuleResult result =
2148 DecodeWasmModule(isolate, &zone, start, end, false, origin); 2177 DecodeWasmModule(isolate, &zone, start, end, false, origin);
2149 if (result.ok()) { 2178 if (result.ok()) {
2150 DCHECK_NOT_NULL(result.val); 2179 DCHECK_NOT_NULL(result.val);
2151 delete result.val; 2180 delete result.val;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 WasmCompiledModule* compiled_module = 2307 WasmCompiledModule* compiled_module =
2279 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); 2308 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule));
2280 CHECK(compiled_module->has_weak_module_object()); 2309 CHECK(compiled_module->has_weak_module_object());
2281 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); 2310 CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
2282 } 2311 }
2283 2312
2284 } // namespace testing 2313 } // namespace testing
2285 } // namespace wasm 2314 } // namespace wasm
2286 } // namespace internal 2315 } // namespace internal
2287 } // namespace v8 2316 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698