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

Side by Side Diff: src/isolate.h

Issue 367583003: Reland 22105 "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 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 }
467 470
468 // Usually called by Init(), but can be called early e.g. to allow 471 // Usually called by Init(), but can be called early e.g. to allow
469 // testing components that require logging but not the whole 472 // testing components that require logging but not the whole
470 // isolate. 473 // isolate.
471 // 474 //
472 // Safe to call more than once. 475 // Safe to call more than once.
473 void InitializeLoggingAndCounters(); 476 void InitializeLoggingAndCounters();
474 477
475 bool Init(Deserializer* des); 478 bool Init(Deserializer* des);
476 479
477 bool IsInitialized() { return state_ == INITIALIZED; } 480 bool IsInitialized() { return state_ == INITIALIZED; }
478 481
479 // True if at least one thread Enter'ed this isolate. 482 // True if at least one thread Enter'ed this isolate.
480 bool IsInUse() { return entry_stack_ != NULL; } 483 bool IsInUse() { return entry_stack_ != NULL; }
481 484
482 // Destroys the non-default isolates. 485 // Destroys the non-default isolates.
483 // Sets default isolate into "has_been_disposed" state rather then destroying, 486 // Sets default isolate into "has_been_disposed" state rather then destroying,
484 // for legacy API reasons. 487 // for legacy API reasons.
485 void TearDown(); 488 void TearDown();
486 489
487 static void GlobalTearDown(); 490 static void GlobalTearDown();
488 491
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 492 // Find the PerThread for this particular (isolate, thread) combination
497 // If one does not yet exist, return null. 493 // If one does not yet exist, return null.
498 PerIsolateThreadData* FindPerThreadDataForThisThread(); 494 PerIsolateThreadData* FindPerThreadDataForThisThread();
499 495
500 // Find the PerThread for given (isolate, thread) combination 496 // Find the PerThread for given (isolate, thread) combination
501 // If one does not yet exist, return null. 497 // If one does not yet exist, return null.
502 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); 498 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
503 499
504 // Returns the key used to store the pointer to the current isolate. 500 // 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 501 // 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). 502 // are part of the domain of an isolate (like the context switcher).
507 static base::Thread::LocalStorageKey isolate_key() { 503 static base::Thread::LocalStorageKey isolate_key() {
504 EnsureInitialized();
508 return isolate_key_; 505 return isolate_key_;
509 } 506 }
510 507
511 // Returns the key used to store process-wide thread IDs. 508 // Returns the key used to store process-wide thread IDs.
512 static base::Thread::LocalStorageKey thread_id_key() { 509 static base::Thread::LocalStorageKey thread_id_key() {
510 EnsureInitialized();
513 return thread_id_key_; 511 return thread_id_key_;
514 } 512 }
515 513
516 static base::Thread::LocalStorageKey per_isolate_thread_data_key(); 514 static base::Thread::LocalStorageKey per_isolate_thread_data_key();
517 515
518 // Mutex for serializing access to break control structures. 516 // Mutex for serializing access to break control structures.
519 base::RecursiveMutex* break_access() { return &break_access_; } 517 base::RecursiveMutex* break_access() { return &break_access_; }
520 518
521 Address get_address_from_id(AddressId id); 519 Address get_address_from_id(AddressId id);
522 520
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 void RemoveCallCompletedCallback(CallCompletedCallback callback); 1081 void RemoveCallCompletedCallback(CallCompletedCallback callback);
1084 void FireCallCompletedCallback(); 1082 void FireCallCompletedCallback();
1085 1083
1086 void EnqueueMicrotask(Handle<Object> microtask); 1084 void EnqueueMicrotask(Handle<Object> microtask);
1087 void RunMicrotasks(); 1085 void RunMicrotasks();
1088 1086
1089 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); 1087 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
1090 void CountUsage(v8::Isolate::UseCounterFeature feature); 1088 void CountUsage(v8::Isolate::UseCounterFeature feature);
1091 1089
1092 private: 1090 private:
1091 static void EnsureInitialized();
1092
1093 Isolate(); 1093 Isolate();
1094 1094
1095 friend struct GlobalState; 1095 friend struct GlobalState;
1096 friend struct InitializeGlobalState; 1096 friend struct InitializeGlobalState;
1097 1097
1098 enum State { 1098 enum State {
1099 UNINITIALIZED, // Some components may not have been allocated. 1099 UNINITIALIZED, // Some components may not have been allocated.
1100 INITIALIZED // All components are fully initialized. 1100 INITIALIZED // All components are fully initialized.
1101 }; 1101 };
1102 1102
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 int entry_count; 1142 int entry_count;
1143 PerIsolateThreadData* previous_thread_data; 1143 PerIsolateThreadData* previous_thread_data;
1144 Isolate* previous_isolate; 1144 Isolate* previous_isolate;
1145 EntryStackItem* previous_item; 1145 EntryStackItem* previous_item;
1146 1146
1147 private: 1147 private:
1148 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); 1148 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1149 }; 1149 };
1150 1150
1151 // This mutex protects highest_thread_id_ and thread_data_table_. 1151 // This mutex protects highest_thread_id_ and thread_data_table_.
1152 static base::Mutex process_wide_mutex_; 1152 static base::LazyMutex process_wide_mutex_;
1153 1153
1154 static base::Thread::LocalStorageKey per_isolate_thread_data_key_; 1154 static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
1155 static base::Thread::LocalStorageKey isolate_key_; 1155 static base::Thread::LocalStorageKey isolate_key_;
1156 static base::Thread::LocalStorageKey thread_id_key_; 1156 static base::Thread::LocalStorageKey thread_id_key_;
1157 static ThreadDataTable* thread_data_table_; 1157 static ThreadDataTable* thread_data_table_;
1158 1158
1159 // A global counter for all generated Isolates, might overflow. 1159 // A global counter for all generated Isolates, might overflow.
1160 static base::Atomic32 isolate_counter_; 1160 static base::Atomic32 isolate_counter_;
1161 1161
1162 void Deinit(); 1162 void Deinit();
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 } 1508 }
1509 1509
1510 EmbeddedVector<char, 128> filename_; 1510 EmbeddedVector<char, 128> filename_;
1511 FILE* file_; 1511 FILE* file_;
1512 int scope_depth_; 1512 int scope_depth_;
1513 }; 1513 };
1514 1514
1515 } } // namespace v8::internal 1515 } } // namespace v8::internal
1516 1516
1517 #endif // V8_ISOLATE_H_ 1517 #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