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

Side by Side Diff: src/isolate.h

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