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" |
11 #include "src/base/bits.h" | 11 #include "src/base/bits.h" |
12 #include "src/deoptimizer.h" | 12 #include "src/deoptimizer.h" |
13 #include "src/frames-inl.h" | 13 #include "src/frames-inl.h" |
14 #include "src/full-codegen/full-codegen.h" | 14 #include "src/full-codegen/full-codegen.h" |
15 #include "src/register-configuration.h" | 15 #include "src/register-configuration.h" |
16 #include "src/safepoint-table.h" | 16 #include "src/safepoint-table.h" |
17 #include "src/string-stream.h" | 17 #include "src/string-stream.h" |
18 #include "src/vm-state-inl.h" | 18 #include "src/vm-state-inl.h" |
| 19 #include "src/wasm/wasm-module.h" |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 ReturnAddressLocationResolver | 24 ReturnAddressLocationResolver |
24 StackFrame::return_address_location_resolver_ = NULL; | 25 StackFrame::return_address_location_resolver_ = NULL; |
25 | 26 |
26 | 27 |
27 // Iterator that supports traversing the stack handlers of a | 28 // Iterator that supports traversing the stack handlers of a |
28 // particular frame. Needs to know the top of the handler chain. | 29 // particular frame. Needs to know the top of the handler chain. |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 state->fp = fp; | 611 state->fp = fp; |
611 state->pc_address = ResolveReturnAddressLocation( | 612 state->pc_address = ResolveReturnAddressLocation( |
612 reinterpret_cast<Address*>(sp - 1 * kPCOnStackSize)); | 613 reinterpret_cast<Address*>(sp - 1 * kPCOnStackSize)); |
613 // The constant pool recorded in the exit frame is not associated | 614 // 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 | 615 // with the pc in this state (the return address into a C entry |
615 // stub). ComputeCallerState will retrieve the constant pool | 616 // stub). ComputeCallerState will retrieve the constant pool |
616 // together with the associated caller pc. | 617 // together with the associated caller pc. |
617 state->constant_pool_address = NULL; | 618 state->constant_pool_address = NULL; |
618 } | 619 } |
619 | 620 |
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 { | 621 Address StandardFrame::GetExpressionAddress(int n) const { |
636 const int offset = StandardFrameConstants::kExpressionsOffset; | 622 const int offset = StandardFrameConstants::kExpressionsOffset; |
637 return fp() + offset - n * kPointerSize; | 623 return fp() + offset - n * kPointerSize; |
638 } | 624 } |
639 | 625 |
640 Address InterpretedFrame::GetExpressionAddress(int n) const { | 626 Address InterpretedFrame::GetExpressionAddress(int n) const { |
641 const int offset = InterpreterFrameConstants::kExpressionsOffset; | 627 const int offset = InterpreterFrameConstants::kExpressionsOffset; |
642 return fp() + offset - n * kPointerSize; | 628 return fp() + offset - n * kPointerSize; |
643 } | 629 } |
644 | 630 |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 | 1322 |
1337 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, | 1323 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, |
1338 int index) const { | 1324 int index) const { |
1339 accumulator->Add("wasm frame"); | 1325 accumulator->Add("wasm frame"); |
1340 } | 1326 } |
1341 | 1327 |
1342 Code* WasmFrame::unchecked_code() const { | 1328 Code* WasmFrame::unchecked_code() const { |
1343 return static_cast<Code*>(isolate()->FindCodeObject(pc())); | 1329 return static_cast<Code*>(isolate()->FindCodeObject(pc())); |
1344 } | 1330 } |
1345 | 1331 |
1346 JSFunction* WasmFrame::function() const { | |
1347 // TODO(clemensh): generate the right JSFunctions once per wasm function and | |
1348 // cache them | |
1349 Factory* factory = isolate()->factory(); | |
1350 Handle<JSFunction> fun = | |
1351 factory->NewFunction(factory->NewStringFromAsciiChecked("<WASM>")); | |
1352 return *fun; | |
1353 } | |
1354 | |
1355 void WasmFrame::Summarize(List<FrameSummary>* functions, | |
1356 FrameSummary::Mode mode) const { | |
1357 DCHECK(functions->length() == 0); | |
1358 Code* code = LookupCode(); | |
1359 int offset = static_cast<int>(pc() - code->instruction_start()); | |
1360 AbstractCode* abstract_code = AbstractCode::cast(code); | |
1361 Handle<JSFunction> fun(function(), isolate()); | |
1362 FrameSummary summary(receiver(), *fun, abstract_code, offset, false); | |
1363 functions->Add(summary); | |
1364 } | |
1365 | |
1366 void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); } | 1332 void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); } |
1367 | 1333 |
1368 Address WasmFrame::GetCallerStackPointer() const { | 1334 Address WasmFrame::GetCallerStackPointer() const { |
1369 return fp() + ExitFrameConstants::kCallerSPOffset; | 1335 return fp() + ExitFrameConstants::kCallerSPOffset; |
1370 } | 1336 } |
1371 | 1337 |
| 1338 Object* WasmFrame::wasm_obj() { |
| 1339 FixedArray* deopt_data = LookupCode()->deoptimization_data(); |
| 1340 DCHECK(deopt_data->length() == 2); |
| 1341 return deopt_data->get(0); |
| 1342 } |
| 1343 |
| 1344 uint32_t WasmFrame::function_index() { |
| 1345 FixedArray* deopt_data = LookupCode()->deoptimization_data(); |
| 1346 DCHECK(deopt_data->length() == 2); |
| 1347 Object* func_index_obj = deopt_data->get(1); |
| 1348 if (func_index_obj->IsUndefined()) return static_cast<uint32_t>(-1); |
| 1349 if (func_index_obj->IsSmi()) return Smi::cast(func_index_obj)->value(); |
| 1350 DCHECK(func_index_obj->IsHeapNumber()); |
| 1351 uint32_t val = static_cast<uint32_t>(-1); |
| 1352 func_index_obj->ToUint32(&val); |
| 1353 DCHECK(val != static_cast<uint32_t>(-1)); |
| 1354 return val; |
| 1355 } |
| 1356 |
| 1357 Object* WasmFrame::function_name() { |
| 1358 Object* wasm_object = wasm_obj(); |
| 1359 if (wasm_object->IsUndefined()) return wasm_object; |
| 1360 Handle<JSObject> wasm = handle(JSObject::cast(wasm_object)); |
| 1361 return *wasm::GetWasmFunctionName(wasm, function_index()); |
| 1362 } |
| 1363 |
1372 namespace { | 1364 namespace { |
1373 | 1365 |
1374 | 1366 |
1375 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, | 1367 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, |
1376 Code* code) { | 1368 Code* code) { |
1377 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { | 1369 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { |
1378 std::ostringstream os; | 1370 std::ostringstream os; |
1379 os << "--------- s o u r c e c o d e ---------\n" | 1371 os << "--------- s o u r c e c o d e ---------\n" |
1380 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) | 1372 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) |
1381 << "\n-----------------------------------------\n"; | 1373 << "\n-----------------------------------------\n"; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { | 1791 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { |
1800 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); | 1792 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); |
1801 list.Add(frame, zone); | 1793 list.Add(frame, zone); |
1802 } | 1794 } |
1803 return list.ToVector(); | 1795 return list.ToVector(); |
1804 } | 1796 } |
1805 | 1797 |
1806 | 1798 |
1807 } // namespace internal | 1799 } // namespace internal |
1808 } // namespace v8 | 1800 } // namespace v8 |
OLD | NEW |