Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: src/isolate.h

Issue 366123002: Revert "Reland^2 r22105 "Remove static initializer from isolate"" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ISOLATE_H_ 5 #ifndef V8_ISOLATE_H_
6 #define V8_ISOLATE_H_ 6 #define V8_ISOLATE_H_
7 7
8 #include "include/v8-debug.h" 8 #include "include/v8-debug.h"
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 enum AddressId { 440 enum AddressId {
441 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, 441 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
442 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) 442 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
443 #undef DECLARE_ENUM 443 #undef DECLARE_ENUM
444 kIsolateAddressCount 444 kIsolateAddressCount
445 }; 445 };
446 446
447 // Returns the PerIsolateThreadData for the current thread (or NULL if one is 447 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
448 // not currently set). 448 // not currently set).
449 static PerIsolateThreadData* CurrentPerIsolateThreadData() { 449 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
450 EnsureInitialized();
451 return reinterpret_cast<PerIsolateThreadData*>( 450 return reinterpret_cast<PerIsolateThreadData*>(
452 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); 451 base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
453 } 452 }
454 453
455 // Returns the isolate inside which the current thread is running. 454 // Returns the isolate inside which the current thread is running.
456 INLINE(static Isolate* Current()) { 455 INLINE(static Isolate* Current()) {
457 EnsureInitialized();
458 Isolate* isolate = reinterpret_cast<Isolate*>( 456 Isolate* isolate = reinterpret_cast<Isolate*>(
459 base::Thread::GetExistingThreadLocal(isolate_key_)); 457 base::Thread::GetExistingThreadLocal(isolate_key_));
460 ASSERT(isolate != NULL); 458 ASSERT(isolate != NULL);
461 return isolate; 459 return isolate;
462 } 460 }
463 461
464 INLINE(static Isolate* UncheckedCurrent()) { 462 INLINE(static Isolate* UncheckedCurrent()) {
465 EnsureInitialized();
466 return reinterpret_cast<Isolate*>( 463 return reinterpret_cast<Isolate*>(
467 base::Thread::GetThreadLocal(isolate_key_)); 464 base::Thread::GetThreadLocal(isolate_key_));
468 } 465 }
469
470 // Like UncheckCurrent, but returns NULL if called reentrantly during
471 // initialization.
472 INLINE(static Isolate* UncheckedReentrantCurrent()) {
473 if (!process_wide_mutex_.Pointer()->TryLock()) return NULL;
474 process_wide_mutex_.Pointer()->Unlock();
475 EnsureInitialized();
476 return reinterpret_cast<Isolate*>(
477 base::Thread::GetThreadLocal(isolate_key_));
478 }
479 466
480 // Usually called by Init(), but can be called early e.g. to allow 467 // Usually called by Init(), but can be called early e.g. to allow
481 // testing components that require logging but not the whole 468 // testing components that require logging but not the whole
482 // isolate. 469 // isolate.
483 // 470 //
484 // Safe to call more than once. 471 // Safe to call more than once.
485 void InitializeLoggingAndCounters(); 472 void InitializeLoggingAndCounters();
486 473
487 bool Init(Deserializer* des); 474 bool Init(Deserializer* des);
488 475
489 bool IsInitialized() { return state_ == INITIALIZED; } 476 bool IsInitialized() { return state_ == INITIALIZED; }
490 477
491 // True if at least one thread Enter'ed this isolate. 478 // True if at least one thread Enter'ed this isolate.
492 bool IsInUse() { return entry_stack_ != NULL; } 479 bool IsInUse() { return entry_stack_ != NULL; }
493 480
494 // Destroys the non-default isolates. 481 // Destroys the non-default isolates.
495 // Sets default isolate into "has_been_disposed" state rather then destroying, 482 // Sets default isolate into "has_been_disposed" state rather then destroying,
496 // for legacy API reasons. 483 // for legacy API reasons.
497 void TearDown(); 484 void TearDown();
498 485
499 static void GlobalTearDown(); 486 static void GlobalTearDown();
500 487
488 static void SetCrashIfDefaultIsolateInitialized();
489 // Ensures that process-wide resources and the default isolate have been
490 // allocated. It is only necessary to call this method in rare cases, for
491 // example if you are using V8 from within the body of a static initializer.
492 // Safe to call multiple times.
493 static void EnsureDefaultIsolate();
494
501 // Find the PerThread for this particular (isolate, thread) combination 495 // Find the PerThread for this particular (isolate, thread) combination
502 // If one does not yet exist, return null. 496 // If one does not yet exist, return null.
503 PerIsolateThreadData* FindPerThreadDataForThisThread(); 497 PerIsolateThreadData* FindPerThreadDataForThisThread();
504 498
505 // Find the PerThread for given (isolate, thread) combination 499 // Find the PerThread for given (isolate, thread) combination
506 // If one does not yet exist, return null. 500 // If one does not yet exist, return null.
507 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); 501 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
508 502
509 // Returns the key used to store the pointer to the current isolate. 503 // Returns the key used to store the pointer to the current isolate.
510 // Used internally for V8 threads that do not execute JavaScript but still 504 // Used internally for V8 threads that do not execute JavaScript but still
511 // are part of the domain of an isolate (like the context switcher). 505 // are part of the domain of an isolate (like the context switcher).
512 static base::Thread::LocalStorageKey isolate_key() { 506 static base::Thread::LocalStorageKey isolate_key() {
513 EnsureInitialized();
514 return isolate_key_; 507 return isolate_key_;
515 } 508 }
516 509
517 // Returns the key used to store process-wide thread IDs. 510 // Returns the key used to store process-wide thread IDs.
518 static base::Thread::LocalStorageKey thread_id_key() { 511 static base::Thread::LocalStorageKey thread_id_key() {
519 EnsureInitialized();
520 return thread_id_key_; 512 return thread_id_key_;
521 } 513 }
522 514
523 static base::Thread::LocalStorageKey per_isolate_thread_data_key(); 515 static base::Thread::LocalStorageKey per_isolate_thread_data_key();
524 516
525 // Mutex for serializing access to break control structures. 517 // Mutex for serializing access to break control structures.
526 base::RecursiveMutex* break_access() { return &break_access_; } 518 base::RecursiveMutex* break_access() { return &break_access_; }
527 519
528 Address get_address_from_id(AddressId id); 520 Address get_address_from_id(AddressId id);
529 521
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 void RemoveCallCompletedCallback(CallCompletedCallback callback); 1082 void RemoveCallCompletedCallback(CallCompletedCallback callback);
1091 void FireCallCompletedCallback(); 1083 void FireCallCompletedCallback();
1092 1084
1093 void EnqueueMicrotask(Handle<Object> microtask); 1085 void EnqueueMicrotask(Handle<Object> microtask);
1094 void RunMicrotasks(); 1086 void RunMicrotasks();
1095 1087
1096 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); 1088 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
1097 void CountUsage(v8::Isolate::UseCounterFeature feature); 1089 void CountUsage(v8::Isolate::UseCounterFeature feature);
1098 1090
1099 private: 1091 private:
1100 static void EnsureInitialized();
1101
1102 Isolate(); 1092 Isolate();
1103 1093
1104 friend struct GlobalState; 1094 friend struct GlobalState;
1105 friend struct InitializeGlobalState; 1095 friend struct InitializeGlobalState;
1106 1096
1107 enum State { 1097 enum State {
1108 UNINITIALIZED, // Some components may not have been allocated. 1098 UNINITIALIZED, // Some components may not have been allocated.
1109 INITIALIZED // All components are fully initialized. 1099 INITIALIZED // All components are fully initialized.
1110 }; 1100 };
1111 1101
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 int entry_count; 1141 int entry_count;
1152 PerIsolateThreadData* previous_thread_data; 1142 PerIsolateThreadData* previous_thread_data;
1153 Isolate* previous_isolate; 1143 Isolate* previous_isolate;
1154 EntryStackItem* previous_item; 1144 EntryStackItem* previous_item;
1155 1145
1156 private: 1146 private:
1157 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); 1147 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1158 }; 1148 };
1159 1149
1160 // This mutex protects highest_thread_id_ and thread_data_table_. 1150 // This mutex protects highest_thread_id_ and thread_data_table_.
1161 static base::LazyMutex process_wide_mutex_; 1151 static base::Mutex process_wide_mutex_;
1162 1152
1163 static base::Thread::LocalStorageKey per_isolate_thread_data_key_; 1153 static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
1164 static base::Thread::LocalStorageKey isolate_key_; 1154 static base::Thread::LocalStorageKey isolate_key_;
1165 static base::Thread::LocalStorageKey thread_id_key_; 1155 static base::Thread::LocalStorageKey thread_id_key_;
1166 static ThreadDataTable* thread_data_table_; 1156 static ThreadDataTable* thread_data_table_;
1167 1157
1168 // A global counter for all generated Isolates, might overflow. 1158 // A global counter for all generated Isolates, might overflow.
1169 static base::Atomic32 isolate_counter_; 1159 static base::Atomic32 isolate_counter_;
1170 1160
1171 void Deinit(); 1161 void Deinit();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 } 1514 }
1525 1515
1526 EmbeddedVector<char, 128> filename_; 1516 EmbeddedVector<char, 128> filename_;
1527 FILE* file_; 1517 FILE* file_;
1528 int scope_depth_; 1518 int scope_depth_;
1529 }; 1519 };
1530 1520
1531 } } // namespace v8::internal 1521 } } // namespace v8::internal
1532 1522
1533 #endif // V8_ISOLATE_H_ 1523 #endif // V8_ISOLATE_H_
OLDNEW
« no previous file with comments | « no previous file | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698