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}
This commit is contained in:
parent
fe3544b370
commit
0e024449b8
23
include/v8.h
23
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;
|
||||
};
|
||||
|
||||
|
||||
|
12
src/api.cc
12
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);
|
||||
|
13
src/d8.cc
13
src/d8.cc
@ -963,15 +963,9 @@ Handle<ObjectTemplate> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user