|
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"
|
@@ -2544,6 +2545,61 @@ TEST(MultipleProfilers) {
|
2544 | 2545 | profiler2->StopProfiling("2");
|
2545 | 2546 | }
|
2546 | 2547 |
|
| 2548 | +int GetSourcePositionEntryCount(i::Isolate* isolate, const char* source) { |
| 2549 | + i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast( |
| 2550 | + v8::Utils::OpenHandle(*CompileRun(source))); |
| 2551 | + if (function->IsInterpreted()) return -1; |
| 2552 | + i::Handle<i::Code> code(function->code(), isolate); |
| 2553 | + i::SourcePositionTableIterator iterator( |
| 2554 | + ByteArray::cast(code->source_position_table())); |
| 2555 | + int count = 0; |
| 2556 | + while (!iterator.done()) { |
| 2557 | + count++; |
| 2558 | + iterator.Advance(); |
| 2559 | + } |
| 2560 | + return count; |
| 2561 | +} |
| 2562 | + |
| 2563 | +UNINITIALIZED_TEST(DetailedSourcePositionAPI) { |
| 2564 | + i::FLAG_detailed_line_info = false; |
| 2565 | + i::FLAG_allow_natives_syntax = true; |
| 2566 | + v8::Isolate::CreateParams create_params; |
| 2567 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 2568 | + v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 2569 | + |
| 2570 | + const char* source = |
| 2571 | + "function fib(i) {" |
| 2572 | + " if (i <= 1) return 1; " |
| 2573 | + " return fib(i - 1) +" |
| 2574 | + " fib(i - 2);" |
| 2575 | + "}" |
| 2576 | + "fib(5);" |
| 2577 | + "%OptimizeFunctionOnNextCall(fib);" |
| 2578 | + "fib(5);" |
| 2579 | + "fib"; |
| 2580 | + { |
| 2581 | + v8::Isolate::Scope isolate_scope(isolate); |
| 2582 | + v8::HandleScope handle_scope(isolate); |
| 2583 | + v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 2584 | + v8::Context::Scope context_scope(context); |
| 2585 | + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2586 | + |
| 2587 | + CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo()); |
| 2588 | + |
| 2589 | + int non_detailed_positions = GetSourcePositionEntryCount(i_isolate, source); |
| 2590 | + |
| 2591 | + v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); |
| 2592 | + CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo()); |
| 2593 | + |
| 2594 | + int detailed_positions = GetSourcePositionEntryCount(i_isolate, source); |
| 2595 | + |
| 2596 | + CHECK((non_detailed_positions == -1 && detailed_positions == -1) || |
| 2597 | + non_detailed_positions < detailed_positions); |
| 2598 | + } |
| 2599 | + |
| 2600 | + isolate->Dispose(); |
| 2601 | +} |
| 2602 | + |
2547 | 2603 | } // namespace test_cpu_profiler
|
2548 | 2604 | } // namespace internal
|
2549 | 2605 | } // namespace v8
|
0 commit comments