Revision: 22141
Author:   [email protected]
Date:     Wed Jul  2 07:44:02 2014 UTC
Log:      Revert "Reland 22105 "Remove static initializer from isolate""

BUG=none
[email protected]
LOG=n

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

Modified:
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/src/isolate.h
 /branches/bleeding_edge/src/mksnapshot.cc
 /branches/bleeding_edge/test/cctest/cctest.cc
 /branches/bleeding_edge/tools/check-static-initializers.sh

=======================================
--- /branches/bleeding_edge/src/isolate.cc      Wed Jul  2 07:04:44 2014 UTC
+++ /branches/bleeding_edge/src/isolate.cc      Wed Jul  2 07:44:02 2014 UTC
@@ -46,7 +46,6 @@


 int ThreadId::GetCurrentThreadId() {
-  Isolate::EnsureInitialized();
   int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
   if (thread_id == 0) {
     thread_id = AllocateThreadId();
@@ -105,17 +104,24 @@
 #ifdef DEBUG
 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
 #endif  // DEBUG
-base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
+base::Mutex Isolate::process_wide_mutex_;
+// TODO(dcarney): Remove with default isolate.
+enum DefaultIsolateStatus {
+  kDefaultIsolateUninitialized,
+  kDefaultIsolateInitialized,
+  kDefaultIsolateCrashIfInitialized
+};
+static DefaultIsolateStatus default_isolate_status_
+    = kDefaultIsolateUninitialized;
 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
 base::Atomic32 Isolate::isolate_counter_ = 0;

 Isolate::PerIsolateThreadData*
     Isolate::FindOrAllocatePerThreadDataForThisThread() {
-  EnsureInitialized();
   ThreadId thread_id = ThreadId::Current();
   PerIsolateThreadData* per_thread = NULL;
   {
-    base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+    base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
     per_thread = thread_data_table_->Lookup(this, thread_id);
     if (per_thread == NULL) {
       per_thread = new PerIsolateThreadData(this, thread_id);
@@ -135,18 +141,25 @@

 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
     ThreadId thread_id) {
-  EnsureInitialized();
   PerIsolateThreadData* per_thread = NULL;
   {
-    base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+    base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
     per_thread = thread_data_table_->Lookup(this, thread_id);
   }
   return per_thread;
 }


-void Isolate::EnsureInitialized() {
-  base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+void Isolate::SetCrashIfDefaultIsolateInitialized() {
+  base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
+  CHECK(default_isolate_status_ != kDefaultIsolateInitialized);
+  default_isolate_status_ = kDefaultIsolateCrashIfInitialized;
+}
+
+
+void Isolate::EnsureDefaultIsolate() {
+  base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
+  CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
   if (thread_data_table_ == NULL) {
     isolate_key_ = base::Thread::CreateThreadLocalKey();
     thread_id_key_ = base::Thread::CreateThreadLocalKey();
@@ -159,6 +172,12 @@
   }
 }

+struct StaticInitializer {
+  StaticInitializer() {
+    Isolate::EnsureDefaultIsolate();
+  }
+} static_initializer;
+

 Address Isolate::get_address_from_id(Isolate::AddressId id) {
   return isolate_addresses_[id];
@@ -1508,7 +1527,7 @@

   Deinit();

-  { base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+  { base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
     thread_data_table_->RemoveAllThreads(this);
   }

@@ -1609,7 +1628,6 @@

 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
                                      PerIsolateThreadData* data) {
-  EnsureInitialized();
   base::Thread::SetThreadLocal(isolate_key_, isolate);
   base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
 }
=======================================
--- /branches/bleeding_edge/src/isolate.h       Wed Jul  2 07:04:44 2014 UTC
+++ /branches/bleeding_edge/src/isolate.h       Wed Jul  2 07:44:02 2014 UTC
@@ -448,14 +448,12 @@
// Returns the PerIsolateThreadData for the current thread (or NULL if one is
   // not currently set).
   static PerIsolateThreadData* CurrentPerIsolateThreadData() {
-    EnsureInitialized();
     return reinterpret_cast<PerIsolateThreadData*>(
         base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
   }

   // Returns the isolate inside which the current thread is running.
   INLINE(static Isolate* Current()) {
-    EnsureInitialized();
     Isolate* isolate = reinterpret_cast<Isolate*>(
         base::Thread::GetExistingThreadLocal(isolate_key_));
     ASSERT(isolate != NULL);
@@ -463,7 +461,6 @@
   }

   INLINE(static Isolate* UncheckedCurrent()) {
-    EnsureInitialized();
     return reinterpret_cast<Isolate*>(
         base::Thread::GetThreadLocal(isolate_key_));
   }
@@ -489,6 +486,13 @@

   static void GlobalTearDown();

+  static void SetCrashIfDefaultIsolateInitialized();
+  // Ensures that process-wide resources and the default isolate have been
+  // allocated. It is only necessary to call this method in rare cases, for
+ // example if you are using V8 from within the body of a static initializer.
+  // Safe to call multiple times.
+  static void EnsureDefaultIsolate();
+
   // Find the PerThread for this particular (isolate, thread) combination
   // If one does not yet exist, return null.
   PerIsolateThreadData* FindPerThreadDataForThisThread();
@@ -501,13 +505,11 @@
// Used internally for V8 threads that do not execute JavaScript but still
   // are part of the domain of an isolate (like the context switcher).
   static base::Thread::LocalStorageKey isolate_key() {
-    EnsureInitialized();
     return isolate_key_;
   }

   // Returns the key used to store process-wide thread IDs.
   static base::Thread::LocalStorageKey thread_id_key() {
-    EnsureInitialized();
     return thread_id_key_;
   }

@@ -1088,8 +1090,6 @@
   void CountUsage(v8::Isolate::UseCounterFeature feature);

  private:
-  static void EnsureInitialized();
-
   Isolate();

   friend struct GlobalState;
@@ -1149,7 +1149,7 @@
   };

   // This mutex protects highest_thread_id_ and thread_data_table_.
-  static base::LazyMutex process_wide_mutex_;
+  static base::Mutex process_wide_mutex_;

   static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
   static base::Thread::LocalStorageKey isolate_key_;
=======================================
--- /branches/bleeding_edge/src/mksnapshot.cc   Wed Jul  2 07:04:44 2014 UTC
+++ /branches/bleeding_edge/src/mksnapshot.cc   Wed Jul  2 07:44:02 2014 UTC
@@ -317,6 +317,7 @@

 int main(int argc, char** argv) {
   V8::InitializeICU();
+  i::Isolate::SetCrashIfDefaultIsolateInitialized();
   i::CpuFeatures::Probe(true);

   // By default, log code create information in the snapshot.
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.cc Wed Jul 2 07:04:44 2014 UTC +++ /branches/bleeding_edge/test/cctest/cctest.cc Wed Jul 2 07:44:02 2014 UTC
@@ -138,6 +138,7 @@

 int main(int argc, char* argv[]) {
   v8::V8::InitializeICU();
+  i::Isolate::SetCrashIfDefaultIsolateInitialized();

   v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);

=======================================
--- /branches/bleeding_edge/tools/check-static-initializers.sh Wed Jul 2 07:04:44 2014 UTC +++ /branches/bleeding_edge/tools/check-static-initializers.sh Wed Jul 2 07:44:02 2014 UTC
@@ -32,7 +32,8 @@
 # Allow:
 #  - _GLOBAL__I__ZN2v810LineEditor6first_E
 #  - _GLOBAL__I__ZN2v88internal32AtomicOps_Internalx86CPUFeaturesE
-expected_static_init_count=2
+#  - _GLOBAL__I__ZN2v88internal8ThreadId18highest_thread_id_E
+expected_static_init_count=3

 v8_root=$(readlink -f $(dirname $BASH_SOURCE)/../)

--
--
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