OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "src/frames.h" | 5 #include "src/frames.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopeinfo.h" | 10 #include "src/ast/scopeinfo.h" |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 state->fp = fp; | 610 state->fp = fp; |
611 state->pc_address = ResolveReturnAddressLocation( | 611 state->pc_address = ResolveReturnAddressLocation( |
612 reinterpret_cast<Address*>(sp - 1 * kPCOnStackSize)); | 612 reinterpret_cast<Address*>(sp - 1 * kPCOnStackSize)); |
613 // The constant pool recorded in the exit frame is not associated | 613 // The constant pool recorded in the exit frame is not associated |
614 // with the pc in this state (the return address into a C entry | 614 // with the pc in this state (the return address into a C entry |
615 // stub). ComputeCallerState will retrieve the constant pool | 615 // stub). ComputeCallerState will retrieve the constant pool |
616 // together with the associated caller pc. | 616 // together with the associated caller pc. |
617 state->constant_pool_address = NULL; | 617 state->constant_pool_address = NULL; |
618 } | 618 } |
619 | 619 |
620 void StandardFrame::Summarize(List<FrameSummary>* functions, | |
621 FrameSummary::Mode mode) const { | |
622 DCHECK(functions->length() == 0); | |
623 // default implementation: no summary added | |
624 } | |
625 | |
626 JSFunction* StandardFrame::function() const { | |
627 // this default implementation is overridden by JS and WASM frames | |
628 return nullptr; | |
629 } | |
630 | |
631 Object* StandardFrame::receiver() const { | |
632 return isolate()->heap()->undefined_value(); | |
633 } | |
634 | |
635 Address StandardFrame::GetExpressionAddress(int n) const { | 620 Address StandardFrame::GetExpressionAddress(int n) const { |
636 const int offset = StandardFrameConstants::kExpressionsOffset; | 621 const int offset = StandardFrameConstants::kExpressionsOffset; |
637 return fp() + offset - n * kPointerSize; | 622 return fp() + offset - n * kPointerSize; |
638 } | 623 } |
639 | 624 |
640 Address InterpretedFrame::GetExpressionAddress(int n) const { | 625 Address InterpretedFrame::GetExpressionAddress(int n) const { |
641 const int offset = InterpreterFrameConstants::kExpressionsOffset; | 626 const int offset = InterpreterFrameConstants::kExpressionsOffset; |
642 return fp() + offset - n * kPointerSize; | 627 return fp() + offset - n * kPointerSize; |
643 } | 628 } |
644 | 629 |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 | 1320 |
1336 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, | 1321 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, |
1337 int index) const { | 1322 int index) const { |
1338 accumulator->Add("wasm frame"); | 1323 accumulator->Add("wasm frame"); |
1339 } | 1324 } |
1340 | 1325 |
1341 Code* WasmFrame::unchecked_code() const { | 1326 Code* WasmFrame::unchecked_code() const { |
1342 return static_cast<Code*>(isolate()->FindCodeObject(pc())); | 1327 return static_cast<Code*>(isolate()->FindCodeObject(pc())); |
1343 } | 1328 } |
1344 | 1329 |
1345 JSFunction* WasmFrame::function() const { | |
1346 // TODO(clemensh): generate the right JSFunctions once per wasm function and | |
1347 // cache them | |
1348 Factory* factory = isolate()->factory(); | |
1349 Handle<JSFunction> fun = | |
1350 factory->NewFunction(factory->NewStringFromAsciiChecked("<WASM>")); | |
1351 return *fun; | |
1352 } | |
1353 | |
1354 void WasmFrame::Summarize(List<FrameSummary>* functions, | |
1355 FrameSummary::Mode mode) const { | |
1356 DCHECK(functions->length() == 0); | |
1357 Code* code = LookupCode(); | |
1358 int offset = static_cast<int>(pc() - code->instruction_start()); | |
1359 AbstractCode* abstract_code = AbstractCode::cast(code); | |
1360 Handle<JSFunction> fun(function(), isolate()); | |
1361 FrameSummary summary(receiver(), *fun, abstract_code, offset, false); | |
1362 functions->Add(summary); | |
1363 } | |
1364 | |
1365 void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); } | 1330 void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); } |
1366 | 1331 |
1367 Address WasmFrame::GetCallerStackPointer() const { | 1332 Address WasmFrame::GetCallerStackPointer() const { |
1368 return fp() + ExitFrameConstants::kCallerSPOffset; | 1333 return fp() + ExitFrameConstants::kCallerSPOffset; |
1369 } | 1334 } |
1370 | 1335 |
| 1336 Object* WasmFrame::wasm_obj(Handle<Code> code) { |
| 1337 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); |
| 1338 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); |
| 1339 Handle<FixedArray> deopt_data(code->deoptimization_data(), isolate()); |
| 1340 DCHECK(deopt_data->length() == 2); |
| 1341 return deopt_data->get(0); |
| 1342 } |
| 1343 |
| 1344 uint32_t WasmFrame::function_index(Handle<Code> code) { |
| 1345 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); |
| 1346 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); |
| 1347 Handle<FixedArray> deopt_data(code->deoptimization_data(), isolate()); |
| 1348 DCHECK(deopt_data->length() == 2); |
| 1349 Object* func_index_obj = deopt_data->get(1); |
| 1350 if (func_index_obj->IsUndefined()) return static_cast<uint32_t>(-1); |
| 1351 if (func_index_obj->IsSmi()) return Smi::cast(func_index_obj)->value(); |
| 1352 DCHECK(func_index_obj->IsHeapNumber()); |
| 1353 uint32_t val = static_cast<uint32_t>(-1); |
| 1354 func_index_obj->ToUint32(&val); |
| 1355 DCHECK(val != static_cast<uint32_t>(-1)); |
| 1356 return val; |
| 1357 } |
| 1358 |
| 1359 Object* WasmFrame::function_name(Handle<Code> code) { |
| 1360 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); |
| 1361 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); |
| 1362 Object* wasm_obj_or_string = wasm_obj(); |
| 1363 if (wasm_obj_or_string->IsString()) return wasm_obj_or_string; |
| 1364 DCHECK(wasm_obj_or_string->IsJSObject()); |
| 1365 Handle<JSObject> wasm = handle(JSObject::cast(wasm_obj())); |
| 1366 MaybeHandle<Object> fun_names_prop = JSObject::GetDataProperty( |
| 1367 wasm, isolate()->factory()->InternalizeUtf8String( |
| 1368 Vector<const char>("function_names"))); |
| 1369 Handle<FixedArray> func_names = |
| 1370 Handle<FixedArray>::cast(fun_names_prop.ToHandleChecked()); |
| 1371 uint32_t func_index = function_index(); |
| 1372 DCHECK(func_index < static_cast<uint32_t>(func_names->length())); |
| 1373 return func_names->get(func_index); |
| 1374 } |
| 1375 |
1371 namespace { | 1376 namespace { |
1372 | 1377 |
1373 | 1378 |
1374 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, | 1379 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, |
1375 Code* code) { | 1380 Code* code) { |
1376 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { | 1381 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { |
1377 std::ostringstream os; | 1382 std::ostringstream os; |
1378 os << "--------- s o u r c e c o d e ---------\n" | 1383 os << "--------- s o u r c e c o d e ---------\n" |
1379 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) | 1384 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) |
1380 << "\n-----------------------------------------\n"; | 1385 << "\n-----------------------------------------\n"; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { | 1803 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { |
1799 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); | 1804 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); |
1800 list.Add(frame, zone); | 1805 list.Add(frame, zone); |
1801 } | 1806 } |
1802 return list.ToVector(); | 1807 return list.ToVector(); |
1803 } | 1808 } |
1804 | 1809 |
1805 | 1810 |
1806 } // namespace internal | 1811 } // namespace internal |
1807 } // namespace v8 | 1812 } // namespace v8 |
OLD | NEW |