Commit b8490293 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[tracing] Properly trace stack guards and interrupts.

Add tracing support for the %StackGuard() and %Interrupt() runtime calls
and the individual actions performed in StackGuard::HandleInterrupts().
This includes:

 - "V8.GCHandleGCRequest" (in "disabled-by-default-v8.gc") when the
   GC_REQUEST bit is set.
 - "V8.WasmGrowSharedMemory" (in "disabled-by-default-v8.wasm") when
   the GROW_SHARED_MEMORY bit is set.
 - "V8.TerminateExecution" (in "v8.execute") when the
   TERMINATE_EXECUTION bit is set.
 - "V8.GCDeoptMarkedAllocationSites" (in "disabled-by-default-v8.gc")
   when the DEOPT_MARKED_ALLOCATION_SITES bit is set.
 - "V8.InstallOptimizedFunctions" (in "disabled-by-default-v8.compile")
   when the INSTALL_CODE bit is set.
 - "V8.InvokeApiInterruptCallbacks" (in "v8.execute") when the
   API_INTERRUPT bit is set.

Now we also emit a trace event "V8.MarkCandidatesForOptimization" (in
"disabled-by-default-v8.compile") in addition to the above from the
RuntimeProfiler when we mark candidates for optimization at the end
of each stack check.

An example of the "V8.InstallOptimizedFunctions" in action (in the
trace viewer) can be seen here:

  https://i.paste.pics/094a04af035eedc0690cd4079afa28f1.png

This supersedes the previously introduced --trace-interrupts CLI flag,
which is thus removed as part of this change.

Bug: v8:8598
Change-Id: I3c3375d00b07cbe700b6912097d7264031ace802
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1538116
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60428}
parent 8cbcae37
...@@ -12,15 +12,6 @@ ...@@ -12,15 +12,6 @@
#include "src/runtime-profiler.h" #include "src/runtime-profiler.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#define TRACE_INTERRUPT(...) \
do { \
if (FLAG_trace_interrupts) { \
if (any_interrupt_handled) PrintF(", "); \
PrintF(__VA_ARGS__); \
any_interrupt_handled = true; \
} \
} while (false)
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -625,56 +616,49 @@ void StackGuard::InitThread(const ExecutionAccess& lock) { ...@@ -625,56 +616,49 @@ void StackGuard::InitThread(const ExecutionAccess& lock) {
// --- C a l l s t o n a t i v e s --- // --- C a l l s t o n a t i v e s ---
Object StackGuard::HandleInterrupts() { Object StackGuard::HandleInterrupts() {
TRACE_EVENT0("v8.execute", "V8.HandleInterrupts");
if (FLAG_verify_predictable) { if (FLAG_verify_predictable) {
// Advance synthetic time by making a time request. // Advance synthetic time by making a time request.
isolate_->heap()->MonotonicallyIncreasingTimeInMs(); isolate_->heap()->MonotonicallyIncreasingTimeInMs();
} }
bool any_interrupt_handled = false;
if (FLAG_trace_interrupts) {
PrintF("[Handling interrupts: ");
}
if (CheckAndClearInterrupt(GC_REQUEST)) { if (CheckAndClearInterrupt(GC_REQUEST)) {
TRACE_INTERRUPT("GC_REQUEST"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), "V8.GCHandleGCRequest");
isolate_->heap()->HandleGCRequest(); isolate_->heap()->HandleGCRequest();
} }
if (CheckAndClearInterrupt(GROW_SHARED_MEMORY)) { if (CheckAndClearInterrupt(GROW_SHARED_MEMORY)) {
TRACE_INTERRUPT("GROW_SHARED_MEMORY"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"V8.WasmGrowSharedMemory");
isolate_->wasm_engine()->memory_tracker()->UpdateSharedMemoryInstances( isolate_->wasm_engine()->memory_tracker()->UpdateSharedMemoryInstances(
isolate_); isolate_);
} }
if (CheckAndClearInterrupt(TERMINATE_EXECUTION)) { if (CheckAndClearInterrupt(TERMINATE_EXECUTION)) {
TRACE_INTERRUPT("TERMINATE_EXECUTION"); TRACE_EVENT0("v8.execute", "V8.TerminateExecution");
return isolate_->TerminateExecution(); return isolate_->TerminateExecution();
} }
if (CheckAndClearInterrupt(DEOPT_MARKED_ALLOCATION_SITES)) { if (CheckAndClearInterrupt(DEOPT_MARKED_ALLOCATION_SITES)) {
TRACE_INTERRUPT("DEOPT_MARKED_ALLOCATION_SITES"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"),
"V8.GCDeoptMarkedAllocationSites");
isolate_->heap()->DeoptMarkedAllocationSites(); isolate_->heap()->DeoptMarkedAllocationSites();
} }
if (CheckAndClearInterrupt(INSTALL_CODE)) { if (CheckAndClearInterrupt(INSTALL_CODE)) {
TRACE_INTERRUPT("INSTALL_CODE"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.InstallOptimizedFunctions");
DCHECK(isolate_->concurrent_recompilation_enabled()); DCHECK(isolate_->concurrent_recompilation_enabled());
isolate_->optimizing_compile_dispatcher()->InstallOptimizedFunctions(); isolate_->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
} }
if (CheckAndClearInterrupt(API_INTERRUPT)) { if (CheckAndClearInterrupt(API_INTERRUPT)) {
TRACE_INTERRUPT("API_INTERRUPT"); TRACE_EVENT0("v8.execute", "V8.InvokeApiInterruptCallbacks");
// Callbacks must be invoked outside of ExecusionAccess lock. // Callbacks must be invoked outside of ExecusionAccess lock.
isolate_->InvokeApiInterruptCallbacks(); isolate_->InvokeApiInterruptCallbacks();
} }
if (FLAG_trace_interrupts) {
if (!any_interrupt_handled) {
PrintF("No interrupt flags set");
}
PrintF("]\n");
}
isolate_->counters()->stack_interrupts()->Increment(); isolate_->counters()->stack_interrupts()->Increment();
isolate_->counters()->runtime_profiler_ticks()->Increment(); isolate_->counters()->runtime_profiler_ticks()->Increment();
isolate_->runtime_profiler()->MarkCandidatesForOptimization(); isolate_->runtime_profiler()->MarkCandidatesForOptimization();
...@@ -684,5 +668,3 @@ Object StackGuard::HandleInterrupts() { ...@@ -684,5 +668,3 @@ Object StackGuard::HandleInterrupts() {
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
#undef TRACE_INTERRUPT
...@@ -952,7 +952,6 @@ DEFINE_BOOL(trace_opt_stats, false, "trace lazy optimization statistics") ...@@ -952,7 +952,6 @@ DEFINE_BOOL(trace_opt_stats, false, "trace lazy optimization statistics")
DEFINE_BOOL(trace_deopt, false, "trace optimize function deoptimization") DEFINE_BOOL(trace_deopt, false, "trace optimize function deoptimization")
DEFINE_BOOL(trace_file_names, false, DEFINE_BOOL(trace_file_names, false,
"include file names in trace-opt/trace-deopt output") "include file names in trace-opt/trace-deopt output")
DEFINE_BOOL(trace_interrupts, false, "trace interrupts when they are handled")
DEFINE_BOOL(always_opt, false, "always try to optimize functions") DEFINE_BOOL(always_opt, false, "always try to optimize functions")
DEFINE_BOOL(always_osr, false, "always try to OSR functions") DEFINE_BOOL(always_osr, false, "always try to OSR functions")
DEFINE_BOOL(prepare_always_opt, false, "prepare for turning on always opt") DEFINE_BOOL(prepare_always_opt, false, "prepare for turning on always opt")
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/frames-inl.h" #include "src/frames-inl.h"
#include "src/global-handles.h" #include "src/global-handles.h"
#include "src/interpreter/interpreter.h" #include "src/interpreter/interpreter.h"
#include "src/tracing/trace-event.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -222,6 +223,8 @@ void RuntimeProfiler::MarkCandidatesForOptimization() { ...@@ -222,6 +223,8 @@ void RuntimeProfiler::MarkCandidatesForOptimization() {
if (!isolate_->use_optimizer()) return; if (!isolate_->use_optimizer()) return;
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.MarkCandidatesForOptimization");
// Run through the JavaScript frames and collect them. If we already // Run through the JavaScript frames and collect them. If we already
// have a sample of the function, we mark it for optimizations // have a sample of the function, we mark it for optimizations
......
...@@ -260,6 +260,7 @@ RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) { ...@@ -260,6 +260,7 @@ RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
RUNTIME_FUNCTION(Runtime_StackGuard) { RUNTIME_FUNCTION(Runtime_StackGuard) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(0, args.length()); DCHECK_EQ(0, args.length());
TRACE_EVENT0("v8.execute", "V8.StackGuard");
// First check if this is a real stack overflow. // First check if this is a real stack overflow.
StackLimitCheck check(isolate); StackLimitCheck check(isolate);
...@@ -273,6 +274,7 @@ RUNTIME_FUNCTION(Runtime_StackGuard) { ...@@ -273,6 +274,7 @@ RUNTIME_FUNCTION(Runtime_StackGuard) {
RUNTIME_FUNCTION(Runtime_Interrupt) { RUNTIME_FUNCTION(Runtime_Interrupt) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(0, args.length()); DCHECK_EQ(0, args.length());
TRACE_EVENT0("v8.execute", "V8.Interrupt");
return isolate->stack_guard()->HandleInterrupts(); return isolate->stack_guard()->HandleInterrupts();
} }
......
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