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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 | 1321 |
1336 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, | 1322 void WasmFrame::Print(StringStream* accumulator, PrintMode mode, |
1337 int index) const { | 1323 int index) const { |
1338 accumulator->Add("wasm frame"); | 1324 accumulator->Add("wasm frame"); |
1339 } | 1325 } |
1340 | 1326 |
1341 Code* WasmFrame::unchecked_code() const { | 1327 Code* WasmFrame::unchecked_code() const { |
1342 return static_cast<Code*>(isolate()->FindCodeObject(pc())); | 1328 return static_cast<Code*>(isolate()->FindCodeObject(pc())); |
1343 } | 1329 } |
1344 | 1330 |
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); } | 1331 void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); } |
1366 | 1332 |
1367 Address WasmFrame::GetCallerStackPointer() const { | 1333 Address WasmFrame::GetCallerStackPointer() const { |
1368 return fp() + ExitFrameConstants::kCallerSPOffset; | 1334 return fp() + ExitFrameConstants::kCallerSPOffset; |
1369 } | 1335 } |
1370 | 1336 |
1337 Object* WasmFrame::wasm_obj(Handle<Code> code) { | |
1338 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); | |
Yang
2016/05/03 18:59:07
I assume this is a performance optimization. Is th
Clemens Hammacher
2016/05/04 09:06:20
Yes it's a performance optimization, and no, it's
| |
1339 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); | |
1340 FixedArray* deopt_data = code->deoptimization_data(); | |
1341 DCHECK(deopt_data->length() == 2); | |
1342 return deopt_data->get(0); | |
1343 } | |
1344 | |
1345 uint32_t WasmFrame::function_index(Handle<Code> code) { | |
1346 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); | |
1347 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); | |
1348 FixedArray* deopt_data = code->deoptimization_data(); | |
1349 DCHECK(deopt_data->length() == 2); | |
1350 Object* func_index_obj = deopt_data->get(1); | |
1351 if (func_index_obj->IsUndefined()) return static_cast<uint32_t>(-1); | |
1352 if (func_index_obj->IsSmi()) return Smi::cast(func_index_obj)->value(); | |
1353 DCHECK(func_index_obj->IsHeapNumber()); | |
1354 uint32_t val = static_cast<uint32_t>(-1); | |
1355 func_index_obj->ToUint32(&val); | |
1356 DCHECK(val != static_cast<uint32_t>(-1)); | |
1357 return val; | |
1358 } | |
1359 | |
1360 Object* WasmFrame::function_name(Handle<Code> code) { | |
Yang
2016/05/03 18:59:07
Isn't this always going to return a String?
Clemens Hammacher
2016/05/04 09:06:20
No, it returns undefined if the the wasm module do
Yang
2016/05/04 12:04:27
No I think this is fine. MaybeHandle would only wo
| |
1361 DCHECK_IMPLIES(!code.is_null(), *code == LookupCode()); | |
1362 if (code.is_null()) code = Handle<Code>(LookupCode(), isolate()); | |
1363 Object* wasm_obj_or_string = wasm_obj(); | |
1364 if (wasm_obj_or_string->IsString()) return wasm_obj_or_string; | |
1365 DCHECK(wasm_obj_or_string->IsJSObject()); | |
1366 Handle<JSObject> wasm = handle(JSObject::cast(wasm_obj())); | |
1367 return *wasm::GetWasmFunctionName(wasm, function_index(code)); | |
1368 } | |
1369 | |
1371 namespace { | 1370 namespace { |
1372 | 1371 |
1373 | 1372 |
1374 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, | 1373 void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared, |
1375 Code* code) { | 1374 Code* code) { |
1376 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { | 1375 if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { |
1377 std::ostringstream os; | 1376 std::ostringstream os; |
1378 os << "--------- s o u r c e c o d e ---------\n" | 1377 os << "--------- s o u r c e c o d e ---------\n" |
1379 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) | 1378 << SourceCodeOf(shared, FLAG_max_stack_trace_source_length) |
1380 << "\n-----------------------------------------\n"; | 1379 << "\n-----------------------------------------\n"; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1798 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { | 1797 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { |
1799 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); | 1798 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); |
1800 list.Add(frame, zone); | 1799 list.Add(frame, zone); |
1801 } | 1800 } |
1802 return list.ToVector(); | 1801 return list.ToVector(); |
1803 } | 1802 } |
1804 | 1803 |
1805 | 1804 |
1806 } // namespace internal | 1805 } // namespace internal |
1807 } // namespace v8 | 1806 } // namespace v8 |
OLD | NEW |