From 0e024449b8322f99534c1901ac6acc6611ddcb1d Mon Sep 17 00:00:00 2001 From: vegorov Date: Wed, 18 Mar 2015 03:14:51 -0700 Subject: [PATCH] Make counter and histogram related callbacks part of the Isolate::CreateParams. Some native counters (e.g. KeyedLoadGenericSlow) are referenced from stubs that are generated very early in the Isolate lifecycle before v8::Isolate::New returns. Thus counter lookup callback also needs to be installed early prior to v8::internal::Isolate::Init call. Otherwise assembler will just assume that the counter is not enabled and produce no code from IncrementCounter - because address of the counter is not yet available. Histogram related callbacks are moved for consistency to make them able to collect samples which occur at isolate initialization time. BUG= Review URL: https://codereview.chromium.org/1010233002 Cr-Commit-Position: refs/heads/master@{#27262} --- include/v8.h | 23 ++++++++++++++++++++++- src/api.cc | 12 ++++++++++++ src/d8.cc | 13 +++++++------ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/v8.h b/include/v8.h index 3cee396d6d..c07034c45d 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4902,7 +4902,12 @@ class V8_EXPORT Isolate { */ struct CreateParams { CreateParams() - : entry_hook(NULL), code_event_handler(NULL), snapshot_blob(NULL) {} + : entry_hook(NULL), + code_event_handler(NULL), + snapshot_blob(NULL), + counter_lookup_callback(NULL), + create_histogram_callback(NULL), + add_histogram_sample_callback(NULL) {} /** * The optional entry_hook allows the host application to provide the @@ -4928,6 +4933,22 @@ class V8_EXPORT Isolate { * Explicitly specify a startup snapshot blob. The embedder owns the blob. */ StartupData* snapshot_blob; + + + /** + * Enables the host application to provide a mechanism for recording + * statistics counters. + */ + CounterLookupCallback counter_lookup_callback; + + /** + * Enables the host application to provide a mechanism for recording + * histograms. The CreateHistogram function returns a + * histogram which will later be passed to the AddHistogramSample + * function. + */ + CreateHistogramCallback create_histogram_callback; + AddHistogramSampleCallback add_histogram_sample_callback; }; diff --git a/src/api.cc b/src/api.cc index 8a6164ff26..a34aa870e8 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6799,6 +6799,18 @@ Isolate* Isolate::New(const Isolate::CreateParams& params) { isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, params.code_event_handler); } + if (params.counter_lookup_callback) { + v8_isolate->SetCounterFunction(params.counter_lookup_callback); + } + + if (params.create_histogram_callback) { + v8_isolate->SetCreateHistogramFunction(params.create_histogram_callback); + } + + if (params.add_histogram_sample_callback) { + v8_isolate->SetAddHistogramSampleFunction( + params.add_histogram_sample_callback); + } SetResourceConstraints(isolate, params.constraints); // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. Isolate::Scope isolate_scope(v8_isolate); diff --git a/src/d8.cc b/src/d8.cc index 7fa6f8c42e..f28ff39ef3 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -963,15 +963,9 @@ Handle Shell::CreateGlobalTemplate(Isolate* isolate) { void Shell::Initialize(Isolate* isolate) { #ifndef V8_SHARED - Shell::counter_map_ = new CounterMap(); // Set up counters if (i::StrLength(i::FLAG_map_counters) != 0) MapCounters(isolate, i::FLAG_map_counters); - if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { - isolate->SetCounterFunction(LookupCounter); - isolate->SetCreateHistogramFunction(CreateHistogram); - isolate->SetAddHistogramSampleFunction(AddHistogramSample); - } #endif // !V8_SHARED } @@ -1639,6 +1633,13 @@ int Shell::Main(int argc, char* argv[]) { base::SysInfo::AmountOfPhysicalMemory(), base::SysInfo::AmountOfVirtualMemory(), base::SysInfo::NumberOfProcessors()); + + Shell::counter_map_ = new CounterMap(); + if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { + create_params.counter_lookup_callback = LookupCounter; + create_params.create_histogram_callback = CreateHistogram; + create_params.add_histogram_sample_callback = AddHistogramSample; + } #endif Isolate* isolate = Isolate::New(create_params); DumbLineEditor dumb_line_editor(isolate);