Revision: 4910
Author: [email protected]
Date: Mon Jun 21 16:31:30 2010
Log: [Isolates] StatsTable moved to Isolate.
Its static fields / methods were transformed to instance one.
Review URL: http://codereview.chromium.org/2817018
http://code.google.com/p/v8/source/detail?r=4910
Modified:
/branches/experimental/isolates/src/api.cc
/branches/experimental/isolates/src/compilation-cache.cc
/branches/experimental/isolates/src/compilation-cache.h
/branches/experimental/isolates/src/counters.cc
/branches/experimental/isolates/src/counters.h
/branches/experimental/isolates/src/isolate.cc
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/test/cctest/test-serialize.cc
=======================================
--- /branches/experimental/isolates/src/api.cc Mon Jun 21 10:40:11 2010
+++ /branches/experimental/isolates/src/api.cc Mon Jun 21 16:31:30 2010
@@ -3792,17 +3792,18 @@
void V8::SetCounterFunction(CounterLookupCallback callback) {
if (IsDeadCheck("v8::V8::SetCounterFunction()")) return;
- i::StatsTable::SetCounterFunction(callback);
+ i::Isolate::Current()->stats_table()->SetCounterFunction(callback);
}
void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) {
if (IsDeadCheck("v8::V8::SetCreateHistogramFunction()")) return;
- i::StatsTable::SetCreateHistogramFunction(callback);
+
i::Isolate::Current()->stats_table()->SetCreateHistogramFunction(callback);
}
void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback
callback) {
if (IsDeadCheck("v8::V8::SetAddHistogramSampleFunction()")) return;
- i::StatsTable::SetAddHistogramSampleFunction(callback);
+ i::Isolate::Current()->stats_table()->
+ SetAddHistogramSampleFunction(callback);
}
void V8::EnableSlidingStateWindow() {
=======================================
--- /branches/experimental/isolates/src/compilation-cache.cc Fri Jun 18
13:14:40 2010
+++ /branches/experimental/isolates/src/compilation-cache.cc Mon Jun 21
16:31:30 2010
@@ -121,6 +121,13 @@
void CompilationSubCache::Clear() {
MemsetPointer(tables_, HEAP->undefined_value(), generations_);
}
+
+
+CompilationCacheScript::CompilationCacheScript(int generations)
+ : CompilationSubCache(generations),
+ script_histogram_(NULL),
+ script_histogram_initialized_(false) {
+}
// We only re-use a cached function for some script source code if the
@@ -178,16 +185,19 @@
}
}
- // TODO(isolates): make it per isolate
- static void* script_histogram = StatsTable::CreateHistogram(
- "V8.ScriptCache",
- 0,
- kScriptGenerations,
- kScriptGenerations + 1);
-
- if (script_histogram != NULL) {
+ if (!script_histogram_initialized_) {
+ script_histogram_ = Isolate::Current()->stats_table()->CreateHistogram(
+ "V8.ScriptCache",
+ 0,
+ kScriptGenerations,
+ kScriptGenerations + 1);
+ script_histogram_initialized_ = true;
+ }
+
+ if (script_histogram_ != NULL) {
// The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache
miss.
- StatsTable::AddHistogramSample(script_histogram, generation);
+ Isolate::Current()->stats_table()->AddHistogramSample(
+ script_histogram_, generation);
}
// Once outside the manacles of the handle scope, we need to recheck
=======================================
--- /branches/experimental/isolates/src/compilation-cache.h Fri Jun 18
13:14:40 2010
+++ /branches/experimental/isolates/src/compilation-cache.h Mon Jun 21
16:31:30 2010
@@ -86,8 +86,7 @@
// Sub-cache for scripts.
class CompilationCacheScript : public CompilationSubCache {
public:
- explicit CompilationCacheScript(int generations)
- : CompilationSubCache(generations) { }
+ explicit CompilationCacheScript(int generations);
Handle<SharedFunctionInfo> Lookup(Handle<String> source,
Handle<Object> name,
@@ -105,6 +104,9 @@
int line_offset,
int column_offset);
+ void* script_histogram_;
+ bool script_histogram_initialized_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript);
};
=======================================
--- /branches/experimental/isolates/src/counters.cc Mon May 25 03:05:56 2009
+++ /branches/experimental/isolates/src/counters.cc Mon Jun 21 16:31:30 2010
@@ -28,14 +28,22 @@
#include "v8.h"
#include "counters.h"
+#include "isolate.h"
#include "platform.h"
namespace v8 {
namespace internal {
-CounterLookupCallback StatsTable::lookup_function_ = NULL;
-CreateHistogramCallback StatsTable::create_histogram_function_ = NULL;
-AddHistogramSampleCallback StatsTable::add_histogram_sample_function_ =
NULL;
+StatsTable::StatsTable()
+ : lookup_function_(NULL),
+ create_histogram_function_(NULL),
+ add_histogram_sample_function_(NULL) {}
+
+
+int* StatsCounter::FindLocationInStatsTable() const {
+ return Isolate::Current()->stats_table()->FindLocation(name_);
+}
+
// Start the timer.
void StatsCounterTimer::Start() {
@@ -71,8 +79,15 @@
// Compute the delta between start and stop, in milliseconds.
int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000;
- StatsTable::AddHistogramSample(histogram_, milliseconds);
+ Isolate::Current()->stats_table()->
+ AddHistogramSample(histogram_, milliseconds);
}
}
+
+
+void* HistogramTimer::CreateHistogram() const {
+ return Isolate::Current()->stats_table()->
+ CreateHistogram(name_, 0, 10000, 50);
+}
} } // namespace v8::internal
=======================================
--- /branches/experimental/isolates/src/counters.h Wed Mar 17 07:53:16 2010
+++ /branches/experimental/isolates/src/counters.h Mon Jun 21 16:31:30 2010
@@ -35,27 +35,27 @@
// counters for monitoring. Counters can be looked up and
// manipulated by name.
-class StatsTable : public AllStatic {
+class StatsTable {
public:
// Register an application-defined function where
// counters can be looked up.
- static void SetCounterFunction(CounterLookupCallback f) {
+ void SetCounterFunction(CounterLookupCallback f) {
lookup_function_ = f;
}
// Register an application-defined function to create
// a histogram for passing to the AddHistogramSample function
- static void SetCreateHistogramFunction(CreateHistogramCallback f) {
+ void SetCreateHistogramFunction(CreateHistogramCallback f) {
create_histogram_function_ = f;
}
// Register an application-defined function to add a sample
// to a histogram created with CreateHistogram function
- static void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
+ void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
add_histogram_sample_function_ = f;
}
- static bool HasCounterFunction() {
+ bool HasCounterFunction() const {
return lookup_function_ != NULL;
}
@@ -65,7 +65,7 @@
// may receive a different location to store it's counter.
// The return value must not be cached and re-used across
// threads, although a single thread is free to cache it.
- static int* FindLocation(const char* name) {
+ int* FindLocation(const char* name) {
if (!lookup_function_) return NULL;
return lookup_function_(name);
}
@@ -75,25 +75,31 @@
// function. min and max define the expected minimum and maximum
// sample values. buckets is the maximum number of buckets
// that the samples will be grouped into.
- static void* CreateHistogram(const char* name,
- int min,
- int max,
- size_t buckets) {
+ void* CreateHistogram(const char* name,
+ int min,
+ int max,
+ size_t buckets) {
if (!create_histogram_function_) return NULL;
return create_histogram_function_(name, min, max, buckets);
}
// Add a sample to a histogram created with the CreateHistogram
// function.
- static void AddHistogramSample(void* histogram, int sample) {
+ void AddHistogramSample(void* histogram, int sample) {
if (!add_histogram_sample_function_) return;
return add_histogram_sample_function_(histogram, sample);
}
private:
- static CounterLookupCallback lookup_function_;
- static CreateHistogramCallback create_histogram_function_;
- static AddHistogramSampleCallback add_histogram_sample_function_;
+ StatsTable();
+
+ CounterLookupCallback lookup_function_;
+ CreateHistogramCallback create_histogram_function_;
+ AddHistogramSampleCallback add_histogram_sample_function_;
+
+ friend class Isolate;
+
+ DISALLOW_COPY_AND_ASSIGN(StatsTable);
};
// StatsCounters are dynamically created values which can be tracked in
@@ -163,9 +169,12 @@
if (lookup_done_)
return ptr_;
lookup_done_ = true;
- ptr_ = StatsTable::FindLocation(name_);
+ ptr_ = FindLocationInStatsTable();
return ptr_;
}
+
+ private:
+ int* FindLocationInStatsTable() const;
};
// StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 };
@@ -213,10 +222,13 @@
void* GetHistogram() {
if (!lookup_done_) {
lookup_done_ = true;
- histogram_ = StatsTable::CreateHistogram(name_, 0, 10000, 50);
+ histogram_ = CreateHistogram();
}
return histogram_;
}
+
+ private:
+ void* CreateHistogram() const;
};
// Helper class for scoping a HistogramTimer.
=======================================
--- /branches/experimental/isolates/src/isolate.cc Mon Jun 21 15:48:21 2010
+++ /branches/experimental/isolates/src/isolate.cc Mon Jun 21 16:31:30 2010
@@ -230,6 +230,7 @@
cpu_features_(NULL),
code_range_(new CodeRange()),
break_access_(OS::CreateMutex()),
+ stats_table_(new StatsTable()),
stub_cache_(NULL),
transcendental_cache_(new TranscendentalCache()),
memory_allocator_(new MemoryAllocator()),
@@ -312,6 +313,9 @@
transcendental_cache_ = NULL;
delete stub_cache_;
stub_cache_ = NULL;
+ delete stats_table_;
+ stats_table_ = NULL;
+
delete cpu_features_;
cpu_features_ = NULL;
delete compilation_cache_;
=======================================
--- /branches/experimental/isolates/src/isolate.h Mon Jun 21 15:48:21 2010
+++ /branches/experimental/isolates/src/isolate.h Mon Jun 21 16:31:30 2010
@@ -458,6 +458,7 @@
CompilationCache* compilation_cache() { return compilation_cache_; }
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
+ StatsTable* stats_table() { return stats_table_; }
StubCache* stub_cache() { return stub_cache_; }
ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
@@ -561,6 +562,7 @@
Mutex* break_access_;
Heap heap_;
StackGuard stack_guard_;
+ StatsTable* stats_table_;
StubCache* stub_cache_;
ThreadLocalTop thread_local_top_;
TranscendentalCache* transcendental_cache_;
=======================================
--- /branches/experimental/isolates/test/cctest/test-serialize.cc Mon Jun
21 10:40:11 2010
+++ /branches/experimental/isolates/test/cctest/test-serialize.cc Mon Jun
21 16:31:30 2010
@@ -104,7 +104,7 @@
TEST(ExternalReferenceEncoder) {
- StatsTable::SetCounterFunction(counter_function);
+
i::Isolate::Current()->stats_table()->SetCounterFunction(counter_function);
HEAP->Setup(false);
ExternalReferenceEncoder encoder;
CHECK_EQ(make_code(BUILTIN, Builtins::ArrayCode),
@@ -141,7 +141,7 @@
TEST(ExternalReferenceDecoder) {
- StatsTable::SetCounterFunction(counter_function);
+
i::Isolate::Current()->stats_table()->SetCounterFunction(counter_function);
HEAP->Setup(false);
ExternalReferenceDecoder decoder;
CHECK_EQ(AddressOf(Builtins::ArrayCode),
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev