Commit ba84c63f authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[compiler] Fix test with lazy source positions

Fixes cctest/test-cpu-profiler/DetailedSourcePositionAPI by ensuring
that source positions are available when starting an optimize job when
NeedsDetailedOptimizedCodeLineInfo is set. Also collects source
positions when inlining functions and adds a new test for this.

Bug: v8:8510
Change-Id: I9d84e37f3c8b638db080f6ec4b6633cdd7e3ee2f
Reviewed-on: https://chromium-review.googlesource.com/c/1472634Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59685}
parent 63c4be59
...@@ -449,6 +449,10 @@ Reduction JSInliner::ReduceJSCall(Node* node) { ...@@ -449,6 +449,10 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
return NoChange(); return NoChange();
} }
if (info_->is_source_positions_enabled()) {
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate(), shared_info);
}
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// After this point, we've made a decision to inline this function. // After this point, we've made a decision to inline this function.
// We shall not bailout from inlining if we got here. // We shall not bailout from inlining if we got here.
......
...@@ -930,6 +930,11 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl( ...@@ -930,6 +930,11 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
compilation_info()->MarkAsFunctionContextSpecializing(); compilation_info()->MarkAsFunctionContextSpecializing();
} }
if (compilation_info()->is_source_positions_enabled()) {
SharedFunctionInfo::EnsureSourcePositionsAvailable(
isolate, compilation_info()->shared_info());
}
data_.set_start_source_position( data_.set_start_source_position(
compilation_info()->shared_info()->StartPosition()); compilation_info()->shared_info()->StartPosition());
......
...@@ -2823,19 +2823,27 @@ TEST(FastStopProfiling) { ...@@ -2823,19 +2823,27 @@ TEST(FastStopProfiling) {
CHECK_LT(duration, kWaitThreshold.InMillisecondsF()); CHECK_LT(duration, kWaitThreshold.InMillisecondsF());
} }
int GetSourcePositionEntryCount(i::Isolate* isolate, const char* source) { enum class EntryCountMode { kAll, kOnlyInlined };
// Count the number of unique source positions.
int GetSourcePositionEntryCount(i::Isolate* isolate, const char* source,
EntryCountMode mode = EntryCountMode::kAll) {
std::unordered_set<int64_t> raw_position_set;
i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast( i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast(
v8::Utils::OpenHandle(*CompileRun(source))); v8::Utils::OpenHandle(*CompileRun(source)));
if (function->IsInterpreted()) return -1; if (function->IsInterpreted()) return -1;
i::Handle<i::Code> code(function->code(), isolate); i::Handle<i::Code> code(function->code(), isolate);
i::SourcePositionTableIterator iterator( i::SourcePositionTableIterator iterator(
ByteArray::cast(code->source_position_table())); ByteArray::cast(code->source_position_table()));
int count = 0;
while (!iterator.done()) { while (!iterator.done()) {
count++; if (mode == EntryCountMode::kAll ||
iterator.source_position().isInlined()) {
raw_position_set.insert(iterator.source_position().raw());
}
iterator.Advance(); iterator.Advance();
} }
return count; return static_cast<int>(raw_position_set.size());
} }
UNINITIALIZED_TEST(DetailedSourcePositionAPI) { UNINITIALIZED_TEST(DetailedSourcePositionAPI) {
...@@ -2878,6 +2886,67 @@ UNINITIALIZED_TEST(DetailedSourcePositionAPI) { ...@@ -2878,6 +2886,67 @@ UNINITIALIZED_TEST(DetailedSourcePositionAPI) {
isolate->Dispose(); isolate->Dispose();
} }
UNINITIALIZED_TEST(DetailedSourcePositionAPI_Inlining) {
i::FLAG_detailed_line_info = false;
i::FLAG_stress_inline = true;
i::FLAG_always_opt = false;
i::FLAG_allow_natives_syntax = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
const char* source = R"(
function foo(x) {
return bar(x) + 1;
}
function bar(x) {
var y = 1;
for (var i = 0; i < x; ++i) {
y = y * x;
}
return x;
}
foo(5);
%OptimizeFunctionOnNextCall(foo);
foo(5);
foo;
)";
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo());
int non_detailed_positions =
GetSourcePositionEntryCount(i_isolate, source, EntryCountMode::kAll);
int non_detailed_inlined_positions = GetSourcePositionEntryCount(
i_isolate, source, EntryCountMode::kOnlyInlined);
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo());
int detailed_positions =
GetSourcePositionEntryCount(i_isolate, source, EntryCountMode::kAll);
int detailed_inlined_positions = GetSourcePositionEntryCount(
i_isolate, source, EntryCountMode::kOnlyInlined);
if (non_detailed_positions == -1) {
CHECK_EQ(non_detailed_positions, detailed_positions);
} else {
CHECK_LT(non_detailed_positions, detailed_positions);
CHECK_LT(non_detailed_inlined_positions, detailed_inlined_positions);
}
}
isolate->Dispose();
}
} // namespace test_cpu_profiler } // namespace test_cpu_profiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment