| 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/profiler/profile-generator.h" | 5 #include "src/profiler/profile-generator.h" |
| 6 | 6 |
| 7 #include "src/ast/scopeinfo.h" | 7 #include "src/ast/scopeinfo.h" |
| 8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
| 11 #include "src/global-handles.h" | 11 #include "src/global-handles.h" |
| 12 #include "src/profiler/cpu-profiler.h" | 12 #include "src/profiler/cpu-profiler.h" |
| 13 #include "src/profiler/profile-generator-inl.h" | 13 #include "src/profiler/profile-generator-inl.h" |
| 14 #include "src/profiler/tick-sample.h" | |
| 15 #include "src/unicode.h" | 14 #include "src/unicode.h" |
| 16 | 15 |
| 17 namespace v8 { | 16 namespace v8 { |
| 18 namespace internal { | 17 namespace internal { |
| 19 | 18 |
| 20 | 19 |
| 21 JITLineInfoTable::JITLineInfoTable() {} | 20 JITLineInfoTable::JITLineInfoTable() {} |
| 22 | 21 |
| 23 | 22 |
| 24 JITLineInfoTable::~JITLineInfoTable() {} | 23 JITLineInfoTable::~JITLineInfoTable() {} |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // for a JS function. Then, the detected source line is passed to | 570 // for a JS function. Then, the detected source line is passed to |
| 572 // ProfileNode to increase the tick count for this source line. | 571 // ProfileNode to increase the tick count for this source line. |
| 573 int src_line = v8::CpuProfileNode::kNoLineNumberInfo; | 572 int src_line = v8::CpuProfileNode::kNoLineNumberInfo; |
| 574 bool src_line_not_found = true; | 573 bool src_line_not_found = true; |
| 575 | 574 |
| 576 if (sample.pc != nullptr) { | 575 if (sample.pc != nullptr) { |
| 577 if (sample.has_external_callback && sample.state == EXTERNAL) { | 576 if (sample.has_external_callback && sample.state == EXTERNAL) { |
| 578 // Don't use PC when in external callback code, as it can point | 577 // Don't use PC when in external callback code, as it can point |
| 579 // inside callback's code, and we will erroneously report | 578 // inside callback's code, and we will erroneously report |
| 580 // that a callback calls itself. | 579 // that a callback calls itself. |
| 581 entries.push_back(code_map_.FindEntry(sample.external_callback_entry)); | 580 entries.push_back(code_map_.FindEntry( |
| 581 reinterpret_cast<Address>(sample.external_callback_entry))); |
| 582 } else { | 582 } else { |
| 583 CodeEntry* pc_entry = code_map_.FindEntry(sample.pc); | 583 CodeEntry* pc_entry = |
| 584 code_map_.FindEntry(reinterpret_cast<Address>(sample.pc)); |
| 584 // If there is no pc_entry we're likely in native code. | 585 // If there is no pc_entry we're likely in native code. |
| 585 // Find out, if top of stack was pointing inside a JS function | 586 // Find out, if top of stack was pointing inside a JS function |
| 586 // meaning that we have encountered a frameless invocation. | 587 // meaning that we have encountered a frameless invocation. |
| 587 if (!pc_entry && !sample.has_external_callback) { | 588 if (!pc_entry && !sample.has_external_callback) { |
| 588 pc_entry = code_map_.FindEntry(sample.tos); | 589 pc_entry = code_map_.FindEntry(reinterpret_cast<Address>(sample.tos)); |
| 589 } | 590 } |
| 590 // If pc is in the function code before it set up stack frame or after the | 591 // If pc is in the function code before it set up stack frame or after the |
| 591 // frame was destroyed SafeStackFrameIterator incorrectly thinks that | 592 // frame was destroyed SafeStackFrameIterator incorrectly thinks that |
| 592 // ebp contains return address of the current function and skips caller's | 593 // ebp contains return address of the current function and skips caller's |
| 593 // frame. Check for this case and just skip such samples. | 594 // frame. Check for this case and just skip such samples. |
| 594 if (pc_entry) { | 595 if (pc_entry) { |
| 595 int pc_offset = | 596 int pc_offset = static_cast<int>(reinterpret_cast<Address>(sample.pc) - |
| 596 static_cast<int>(sample.pc - pc_entry->instruction_start()); | 597 pc_entry->instruction_start()); |
| 597 src_line = pc_entry->GetSourceLine(pc_offset); | 598 src_line = pc_entry->GetSourceLine(pc_offset); |
| 598 if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) { | 599 if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) { |
| 599 src_line = pc_entry->line_number(); | 600 src_line = pc_entry->line_number(); |
| 600 } | 601 } |
| 601 src_line_not_found = false; | 602 src_line_not_found = false; |
| 602 entries.push_back(pc_entry); | 603 entries.push_back(pc_entry); |
| 603 | 604 |
| 604 if (pc_entry->builtin_id() == Builtins::kFunctionPrototypeApply || | 605 if (pc_entry->builtin_id() == Builtins::kFunctionPrototypeApply || |
| 605 pc_entry->builtin_id() == Builtins::kFunctionPrototypeCall) { | 606 pc_entry->builtin_id() == Builtins::kFunctionPrototypeCall) { |
| 606 // When current function is either the Function.prototype.apply or the | 607 // When current function is either the Function.prototype.apply or the |
| 607 // Function.prototype.call builtin the top frame is either frame of | 608 // Function.prototype.call builtin the top frame is either frame of |
| 608 // the calling JS function or internal frame. | 609 // the calling JS function or internal frame. |
| 609 // In the latter case we know the caller for sure but in the | 610 // In the latter case we know the caller for sure but in the |
| 610 // former case we don't so we simply replace the frame with | 611 // former case we don't so we simply replace the frame with |
| 611 // 'unresolved' entry. | 612 // 'unresolved' entry. |
| 612 if (!sample.has_external_callback) { | 613 if (!sample.has_external_callback) { |
| 613 entries.push_back(CodeEntry::unresolved_entry()); | 614 entries.push_back(CodeEntry::unresolved_entry()); |
| 614 } | 615 } |
| 615 } | 616 } |
| 616 } | 617 } |
| 617 } | 618 } |
| 618 | 619 |
| 619 for (const Address *stack_pos = sample.stack, | 620 for (unsigned i = 0; i < sample.frames_count; ++i) { |
| 620 *stack_end = stack_pos + sample.frames_count; | 621 Address stack_pos = reinterpret_cast<Address>(sample.stack[i]); |
| 621 stack_pos != stack_end; ++stack_pos) { | 622 CodeEntry* entry = code_map_.FindEntry(stack_pos); |
| 622 CodeEntry* entry = code_map_.FindEntry(*stack_pos); | |
| 623 | 623 |
| 624 if (entry) { | 624 if (entry) { |
| 625 // Find out if the entry has an inlining stack associated. | 625 // Find out if the entry has an inlining stack associated. |
| 626 int pc_offset = | 626 int pc_offset = |
| 627 static_cast<int>(*stack_pos - entry->instruction_start()); | 627 static_cast<int>(stack_pos - entry->instruction_start()); |
| 628 const std::vector<CodeEntry*>* inline_stack = | 628 const std::vector<CodeEntry*>* inline_stack = |
| 629 entry->GetInlineStack(pc_offset); | 629 entry->GetInlineStack(pc_offset); |
| 630 if (inline_stack) { | 630 if (inline_stack) { |
| 631 entries.insert(entries.end(), inline_stack->rbegin(), | 631 entries.insert(entries.end(), inline_stack->rbegin(), |
| 632 inline_stack->rend()); | 632 inline_stack->rend()); |
| 633 } | 633 } |
| 634 // Skip unresolved frames (e.g. internal frame) and get source line of | 634 // Skip unresolved frames (e.g. internal frame) and get source line of |
| 635 // the first JS caller. | 635 // the first JS caller. |
| 636 if (src_line_not_found) { | 636 if (src_line_not_found) { |
| 637 src_line = entry->GetSourceLine(pc_offset); | 637 src_line = entry->GetSourceLine(pc_offset); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 case EXTERNAL: | 677 case EXTERNAL: |
| 678 return CodeEntry::program_entry(); | 678 return CodeEntry::program_entry(); |
| 679 case IDLE: | 679 case IDLE: |
| 680 return CodeEntry::idle_entry(); | 680 return CodeEntry::idle_entry(); |
| 681 default: return NULL; | 681 default: return NULL; |
| 682 } | 682 } |
| 683 } | 683 } |
| 684 | 684 |
| 685 } // namespace internal | 685 } // namespace internal |
| 686 } // namespace v8 | 686 } // namespace v8 |
| OLD | NEW |