Commit e09d77a2 authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

Trigger full source position collection when needed

Optimizing compilation can no longer collect source positions on demand
since it may now run concurrently without serialization.

Instead, we now collect full source positions when any component that
needs them is enabled (profiler, debugger).

Bug: v8:7790,v8:12030
Change-Id: I6a2a82eb2b0d3e92121e101b4d9bf330c1f6c065
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3067226Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76114}
parent 05797b09
......@@ -9637,7 +9637,7 @@ CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)
->set_detailed_source_positions_for_profiling(true);
->SetDetailedSourcePositionsForProfiling(true);
}
uintptr_t CodeEvent::GetCodeStartAddress() {
......
......@@ -522,9 +522,24 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
// always hold true.
CHECK(shared_info->is_compiled());
if (!broker()->is_concurrent_inlining() && info_->source_positions()) {
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate(),
shared_info->object());
if (info_->source_positions()) {
if (broker()->is_concurrent_inlining()) {
if (!shared_info->object()->AreSourcePositionsAvailable(
broker()->local_isolate_or_isolate())) {
// This case is expected to be very rare, since we generate source
// positions for all functions when debugging or profiling are turned
// on (see Isolate::NeedsDetailedOptimizedCodeLineInfo). Source
// positions should only be missing here if there is a race between 1)
// enabling/disabling the debugger/profiler, and 2) this compile job.
// In that case, we simply don't inline.
TRACE("Not inlining " << *shared_info << " into " << outer_shared_info
<< " because source positions are missing.");
return NoChange();
}
} else {
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate(),
shared_info->object());
}
}
// Determine the target's feedback vector and its context.
......
......@@ -2299,6 +2299,7 @@ void Debug::UpdateState() {
// Note that the debug context could have already been loaded to
// bootstrap test cases.
isolate_->compilation_cache()->DisableScriptAndEval();
isolate_->CollectSourcePositionsForAllBytecodeArrays();
is_active = true;
feature_tracker()->Track(DebugFeatureTracker::kActive);
} else {
......
......@@ -3000,6 +3000,7 @@ Isolate::Isolate(std::unique_ptr<i::IsolateAllocator> isolate_allocator,
#endif
rail_mode_(PERFORMANCE_ANIMATION),
code_event_dispatcher_(new CodeEventDispatcher()),
detailed_source_positions_for_profiling_(FLAG_detailed_line_info),
persistent_handles_list_(new PersistentHandlesList()),
jitless_(FLAG_jitless),
#if V8_SFI_HAS_UNIQUE_ID
......@@ -3852,6 +3853,8 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms);
}
initialized_ = true;
return true;
}
......@@ -4012,10 +4015,14 @@ bool Isolate::NeedsDetailedOptimizedCodeLineInfo() const {
}
bool Isolate::NeedsSourcePositionsForProfiling() const {
return FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph ||
FLAG_turbo_profiling || FLAG_perf_prof || is_profiling() ||
debug_->is_active() || logger_->is_logging() || FLAG_log_maps ||
FLAG_log_ic;
return
// Static conditions.
FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph ||
FLAG_turbo_profiling || FLAG_perf_prof || FLAG_log_maps || FLAG_log_ic ||
// Dynamic conditions; changing any of these conditions triggers source
// position collection for the entire heap
// (CollectSourcePositionsForAllBytecodeArrays).
is_profiling() || debug_->is_active() || logger_->is_logging();
}
void Isolate::SetFeedbackVectorsForProfilingTools(Object value) {
......@@ -4809,6 +4816,8 @@ void Isolate::SetIdle(bool is_idle) {
}
void Isolate::CollectSourcePositionsForAllBytecodeArrays() {
if (!initialized_) return;
HandleScope scope(this);
std::vector<Handle<SharedFunctionInfo>> sfis;
{
......
......@@ -470,7 +470,6 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
V(v8_inspector::V8Inspector*, inspector, nullptr) \
V(bool, next_v8_call_is_safe_for_termination, false) \
V(bool, only_terminate_in_safe_scope, false) \
V(bool, detailed_source_positions_for_profiling, FLAG_detailed_line_info) \
V(int, embedder_wrapper_type_index, -1) \
V(int, embedder_wrapper_object_index, -1) \
V(compiler::NodeObserver*, node_observer, nullptr) \
......@@ -1006,6 +1005,17 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
#undef GLOBAL_ACCESSOR
void SetDetailedSourcePositionsForProfiling(bool value) {
if (value) {
CollectSourcePositionsForAllBytecodeArrays();
}
detailed_source_positions_for_profiling_ = value;
}
bool detailed_source_positions_for_profiling() const {
return detailed_source_positions_for_profiling_;
}
#define GLOBAL_ARRAY_ACCESSOR(type, name, length) \
inline type* name() { \
DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
......@@ -1216,7 +1226,10 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
return is_profiling_.load(std::memory_order_relaxed);
}
void set_is_profiling(bool enabled) {
void SetIsProfiling(bool enabled) {
if (enabled) {
CollectSourcePositionsForAllBytecodeArrays();
}
is_profiling_.store(enabled, std::memory_order_relaxed);
}
......@@ -2110,6 +2123,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
#undef ISOLATE_FIELD_OFFSET
#endif
bool detailed_source_positions_for_profiling_;
OptimizingCompileDispatcher* optimizing_compile_dispatcher_ = nullptr;
std::unique_ptr<PersistentHandlesList> persistent_handles_list_;
......@@ -2119,6 +2134,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool force_slow_path_ = false;
bool initialized_ = false;
bool jitless_ = false;
int next_optimization_id_ = 0;
......
......@@ -2117,6 +2117,9 @@ FILE* Logger::TearDownAndGetLogFile() {
void Logger::UpdateIsLogging(bool value) {
base::MutexGuard guard(log_->mutex());
if (value) {
isolate_->CollectSourcePositionsForAllBytecodeArrays();
}
// Relaxed atomic to avoid locking the mutex for the most common case: when
// logging is disabled.
is_logging_.store(value, std::memory_order_relaxed);
......
......@@ -74,7 +74,7 @@ ProfilingScope::ProfilingScope(Isolate* isolate, ProfilerListener* listener)
size_t profiler_count = isolate_->num_cpu_profilers();
profiler_count++;
isolate_->set_num_cpu_profilers(profiler_count);
isolate_->set_is_profiling(true);
isolate_->SetIsProfiling(true);
#if V8_ENABLE_WEBASSEMBLY
wasm::GetWasmEngine()->EnableCodeLogging(isolate_);
#endif // V8_ENABLE_WEBASSEMBLY
......@@ -99,7 +99,7 @@ ProfilingScope::~ProfilingScope() {
DCHECK_GT(profiler_count, 0);
profiler_count--;
isolate_->set_num_cpu_profilers(profiler_count);
if (profiler_count == 0) isolate_->set_is_profiling(false);
if (profiler_count == 0) isolate_->SetIsProfiling(false);
}
ProfilerEventsProcessor::ProfilerEventsProcessor(
......
......@@ -1626,7 +1626,7 @@ TEST(CodeSerializerWithProfiler) {
CHECK(!orig->GetBytecodeArray(isolate).HasSourcePositionTable());
isolate->set_is_profiling(true);
isolate->SetIsProfiling(true);
// This does not assert that no compilation can happen as source position
// collection could trigger it.
......
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