Revision: 22223
Author:   [email protected]
Date:     Mon Jul  7 07:19:46 2014 UTC
Log:      Remove a bunch of Isolate::UncheckedCurrent calls

The callbacks are per isolate, so we shouldn't get the isolate implicitly
from TLS. Also, we shouldn't allow calls to these methods prior to
initializing the respective isolate (and silently ignore them).

Esp. add a per-isolate API to set the stats counter callbacks and
make it possible to set the stats counter callback after the isolate
was touched.

Embedders should use e.g. isolate->SetCounterFunction(callback) instead
of v8::V8::SetCounterFunction(callback).

BUG=none
[email protected]
LOG=y

Review URL: https://codereview.chromium.org/365153002
http://code.google.com/p/v8/source/detail?r=22223

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/counters.cc
 /branches/bleeding_edge/src/counters.h
 /branches/bleeding_edge/src/d8.cc
 /branches/bleeding_edge/src/d8.h
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Thu Jul  3 10:04:57 2014 UTC
+++ /branches/bleeding_edge/include/v8.h        Mon Jul  7 07:19:46 2014 UTC
@@ -4430,6 +4430,21 @@
    */
   void SetUseCounterCallback(UseCounterCallback callback);

+  /**
+   * Enables the host application to provide a mechanism for recording
+   * statistics counters.
+   */
+  void SetCounterFunction(CounterLookupCallback);
+
+  /**
+   * 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.
+   */
+  void SetCreateHistogramFunction(CreateHistogramCallback);
+  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
+
  private:
   template<class K, class V, class Traits> friend class PersistentValueMap;

@@ -4744,6 +4759,8 @@
   /**
    * Enables the host application to provide a mechanism for recording
    * statistics counters.
+   *
+   * Deprecated, use Isolate::SetCounterFunction instead.
    */
   static void SetCounterFunction(CounterLookupCallback);

@@ -4752,8 +4769,13 @@
    * histograms. The CreateHistogram function returns a
    * histogram which will later be passed to the AddHistogramSample
    * function.
+   *
+   * Deprecated, use Isolate::SetCreateHistogramFunction instead.
+   * Isolate::SetAddHistogramSampleFunction instead.
    */
   static void SetCreateHistogramFunction(CreateHistogramCallback);
+
+  /** Deprecated, use Isolate::SetAddHistogramSampleFunction instead. */
   static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);

   /** Callback function for reporting failed access checks.*/
=======================================
--- /branches/bleeding_edge/src/api.cc  Thu Jul  3 10:04:57 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Mon Jul  7 07:19:46 2014 UTC
@@ -370,14 +370,14 @@


 void V8::SetFatalErrorHandler(FatalErrorCallback that) {
-  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+  i::Isolate* isolate = i::Isolate::Current();
   isolate->set_exception_behavior(that);
 }


 void V8::SetAllowCodeGenerationFromStringsCallback(
     AllowCodeGenerationFromStringsCallback callback) {
-  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+  i::Isolate* isolate = i::Isolate::Current();
   isolate->set_allow_code_gen_callback(callback);
 }

@@ -6602,7 +6602,7 @@


 Isolate* Isolate::GetCurrent() {
-  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+  i::Isolate* isolate = i::Isolate::Current();
   return reinterpret_cast<Isolate*>(isolate);
 }

@@ -6766,6 +6766,30 @@
 void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
   reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
 }
+
+
+void Isolate::SetCounterFunction(CounterLookupCallback callback) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+  isolate->stats_table()->SetCounterFunction(callback);
+  isolate->InitializeLoggingAndCounters();
+  isolate->counters()->ResetCounters();
+}
+
+
+void Isolate::SetCreateHistogramFunction(CreateHistogramCallback callback) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+  isolate->stats_table()->SetCreateHistogramFunction(callback);
+  isolate->InitializeLoggingAndCounters();
+  isolate->counters()->ResetHistograms();
+}
+
+
+void Isolate::SetAddHistogramSampleFunction(
+    AddHistogramSampleCallback callback) {
+  reinterpret_cast<i::Isolate*>(this)
+      ->stats_table()
+      ->SetAddHistogramSampleFunction(callback);
+}


 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
=======================================
--- /branches/bleeding_edge/src/counters.cc     Mon Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/src/counters.cc     Mon Jul  7 07:19:46 2014 UTC
@@ -107,6 +107,38 @@
     CODE_AGE_LIST_COMPLETE(SC)
 #undef SC
 }
+
+
+void Counters::ResetCounters() {
+#define SC(name, caption) name##_.Reset();
+  STATS_COUNTER_LIST_1(SC)
+  STATS_COUNTER_LIST_2(SC)
+#undef SC
+
+#define SC(name)              \
+  count_of_##name##_.Reset(); \
+  size_of_##name##_.Reset();
+  INSTANCE_TYPE_LIST(SC)
+#undef SC
+
+#define SC(name)                        \
+  count_of_CODE_TYPE_##name##_.Reset(); \
+  size_of_CODE_TYPE_##name##_.Reset();
+  CODE_KIND_LIST(SC)
+#undef SC
+
+#define SC(name)                          \
+  count_of_FIXED_ARRAY_##name##_.Reset(); \
+  size_of_FIXED_ARRAY_##name##_.Reset();
+  FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
+#undef SC
+
+#define SC(name)                       \
+  count_of_CODE_AGE_##name##_.Reset(); \
+  size_of_CODE_AGE_##name##_.Reset();
+  CODE_AGE_LIST_COMPLETE(SC)
+#undef SC
+}


 void Counters::ResetHistograms() {
=======================================
--- /branches/bleeding_edge/src/counters.h      Mon Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/src/counters.h      Mon Jul  7 07:19:46 2014 UTC
@@ -142,6 +142,9 @@
     ASSERT(loc != NULL);
     return loc;
   }
+
+  // Reset the cached internal pointer.
+  void Reset() { lookup_done_ = false; }

  protected:
   // Returns the cached address of this counter location.
@@ -629,6 +632,7 @@
     stats_counter_count
   };

+  void ResetCounters();
   void ResetHistograms();

  private:
=======================================
--- /branches/bleeding_edge/src/d8.cc   Thu Jul  3 07:57:29 2014 UTC
+++ /branches/bleeding_edge/src/d8.cc   Mon Jul  7 07:19:46 2014 UTC
@@ -677,7 +677,7 @@
 }


-void Shell::MapCounters(const char* name) {
+void Shell::MapCounters(v8::Isolate* isolate, const char* name) {
   counters_file_ = base::OS::MemoryMappedFile::create(
       name, sizeof(CounterCollection), &local_counters_);
   void* memory = (counters_file_ == NULL) ?
@@ -687,9 +687,9 @@
     Exit(1);
   }
   counters_ = static_cast<CounterCollection*>(memory);
-  V8::SetCounterFunction(LookupCounter);
-  V8::SetCreateHistogramFunction(CreateHistogram);
-  V8::SetAddHistogramSampleFunction(AddHistogramSample);
+  isolate->SetCounterFunction(LookupCounter);
+  isolate->SetCreateHistogramFunction(CreateHistogram);
+  isolate->SetAddHistogramSampleFunction(AddHistogramSample);
 }


@@ -897,7 +897,7 @@
   Shell::counter_map_ = new CounterMap();
   // Set up counters
   if (i::StrLength(i::FLAG_map_counters) != 0)
-    MapCounters(i::FLAG_map_counters);
+    MapCounters(isolate, i::FLAG_map_counters);
   if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) {
     V8::SetCounterFunction(LookupCounter);
     V8::SetCreateHistogramFunction(CreateHistogram);
=======================================
--- /branches/bleeding_edge/src/d8.h    Mon Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/src/d8.h    Mon Jul  7 07:19:46 2014 UTC
@@ -269,7 +269,7 @@
                                int max,
                                size_t buckets);
   static void AddHistogramSample(void* histogram, int sample);
-  static void MapCounters(const char* name);
+  static void MapCounters(v8::Isolate* isolate, const char* name);

   static Local<Object> DebugMessageDetails(Isolate* isolate,
                                            Handle<String> message);
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Thu Jul  3 19:18:26 2014 UTC
+++ /branches/bleeding_edge/src/isolate.cc      Mon Jul  7 07:19:46 2014 UTC
@@ -2046,16 +2046,6 @@
       return;
     }
   }
-
- // Threads can have default isolate set into TLS as Current but not yet have
-  // PerIsolateThreadData for it, as it requires more advanced phase of the
- // initialization. For example, a thread might be the one that system used for - // static initializers - in this case the default isolate is set in TLS but - // the thread did not yet Enter the isolate. If PerisolateThreadData is not
-  // there, use the isolate set in TLS.
-  if (current_isolate == NULL) {
-    current_isolate = Isolate::UncheckedCurrent();
-  }

   PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread();
   ASSERT(data != NULL);
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Thu Jul 3 10:04:57 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Mon Jul 7 07:19:46 2014 UTC
@@ -19495,15 +19495,15 @@
         break;

       case SetCounterFunction:
-        v8::V8::SetCounterFunction(NULL);
+        CcTest::isolate()->SetCounterFunction(NULL);
         break;

       case SetCreateHistogramFunction:
-        v8::V8::SetCreateHistogramFunction(NULL);
+        CcTest::isolate()->SetCreateHistogramFunction(NULL);
         break;

       case SetAddHistogramSampleFunction:
-        v8::V8::SetAddHistogramSampleFunction(NULL);
+        CcTest::isolate()->SetAddHistogramSampleFunction(NULL);
         break;
     }
     isolate->Exit();
@@ -20886,6 +20886,7 @@
 }


+#ifdef DEBUG
 static int probes_counter = 0;
 static int misses_counter = 0;
 static int updates_counter = 0;
@@ -20915,11 +20916,10 @@
     "  fooify(a);"
     "  fooify(b);"
     "}";
+#endif


 static void StubCacheHelper(bool primary) {
-  V8::SetCounterFunction(LookupCounter);
-  USE(kMegamorphicTestProgram);
 #ifdef DEBUG
   i::FLAG_native_code_counters = true;
   if (primary) {
@@ -20929,6 +20929,7 @@
   }
   i::FLAG_crankshaft = false;
   LocalContext env;
+  env->GetIsolate()->SetCounterFunction(LookupCounter);
   v8::HandleScope scope(env->GetIsolate());
   int initial_probes = probes_counter;
   int initial_misses = misses_counter;
@@ -20958,6 +20959,7 @@
 }


+#ifdef DEBUG
 static int cow_arrays_created_runtime = 0;


@@ -20967,13 +20969,14 @@
   }
   return NULL;
 }
+#endif


 TEST(CheckCOWArraysCreatedRuntimeCounter) {
-  V8::SetCounterFunction(LookupCounterCOWArrays);
 #ifdef DEBUG
   i::FLAG_native_code_counters = true;
   LocalContext env;
+  env->GetIsolate()->SetCounterFunction(LookupCounterCOWArrays);
   v8::HandleScope scope(env->GetIsolate());
   int initial_cow_arrays = cow_arrays_created_runtime;
   CompileRun("var o = [1, 2, 3];");

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to