|
40 | 40 | #include "src/objects-inl.h" |
41 | 41 | #include "src/profiler/cpu-profiler-inl.h" |
42 | 42 | #include "src/profiler/profiler-listener.h" |
| 43 | +#include "src/source-position-table.h" |
43 | 44 | #include "src/utils.h" |
44 | 45 | #include "test/cctest/cctest.h" |
45 | 46 | #include "test/cctest/profiler-extension.h" |
@@ -2599,6 +2600,61 @@ TEST(MultipleIsolates) { |
2599 | 2600 | thread2.Join(); |
2600 | 2601 | } |
2601 | 2602 |
|
| 2603 | +int GetSourcePositionEntryCount(i::Isolate* isolate, const char* source) { |
| 2604 | + i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast( |
| 2605 | + v8::Utils::OpenHandle(*CompileRun(source))); |
| 2606 | + if (function->IsInterpreted()) return -1; |
| 2607 | + i::Handle<i::Code> code(function->code(), isolate); |
| 2608 | + i::SourcePositionTableIterator iterator( |
| 2609 | + ByteArray::cast(code->source_position_table())); |
| 2610 | + int count = 0; |
| 2611 | + while (!iterator.done()) { |
| 2612 | + count++; |
| 2613 | + iterator.Advance(); |
| 2614 | + } |
| 2615 | + return count; |
| 2616 | +} |
| 2617 | + |
| 2618 | +UNINITIALIZED_TEST(DetailedSourcePositionAPI) { |
| 2619 | + i::FLAG_detailed_line_info = false; |
| 2620 | + i::FLAG_allow_natives_syntax = true; |
| 2621 | + v8::Isolate::CreateParams create_params; |
| 2622 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 2623 | + v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 2624 | + |
| 2625 | + const char* source = |
| 2626 | + "function fib(i) {" |
| 2627 | + " if (i <= 1) return 1; " |
| 2628 | + " return fib(i - 1) +" |
| 2629 | + " fib(i - 2);" |
| 2630 | + "}" |
| 2631 | + "fib(5);" |
| 2632 | + "%OptimizeFunctionOnNextCall(fib);" |
| 2633 | + "fib(5);" |
| 2634 | + "fib"; |
| 2635 | + { |
| 2636 | + v8::Isolate::Scope isolate_scope(isolate); |
| 2637 | + v8::HandleScope handle_scope(isolate); |
| 2638 | + v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 2639 | + v8::Context::Scope context_scope(context); |
| 2640 | + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2641 | + |
| 2642 | + CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo()); |
| 2643 | + |
| 2644 | + int non_detailed_positions = GetSourcePositionEntryCount(i_isolate, source); |
| 2645 | + |
| 2646 | + v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); |
| 2647 | + CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo()); |
| 2648 | + |
| 2649 | + int detailed_positions = GetSourcePositionEntryCount(i_isolate, source); |
| 2650 | + |
| 2651 | + CHECK((non_detailed_positions == -1 && detailed_positions == -1) || |
| 2652 | + non_detailed_positions < detailed_positions); |
| 2653 | + } |
| 2654 | + |
| 2655 | + isolate->Dispose(); |
| 2656 | +} |
| 2657 | + |
2602 | 2658 | } // namespace test_cpu_profiler |
2603 | 2659 | } // namespace internal |
2604 | 2660 | } // namespace v8 |
0 commit comments