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

Side by Side Diff: src/isolate.h

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Florian's comments. Created 8 years, 9 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 | « src/ia32/code-stubs-ia32.cc ('k') | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, 422 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
423 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) 423 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
424 #undef C 424 #undef C
425 kIsolateAddressCount 425 kIsolateAddressCount
426 }; 426 };
427 427
428 // Returns the PerIsolateThreadData for the current thread (or NULL if one is 428 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
429 // not currently set). 429 // not currently set).
430 static PerIsolateThreadData* CurrentPerIsolateThreadData() { 430 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
431 return reinterpret_cast<PerIsolateThreadData*>( 431 return reinterpret_cast<PerIsolateThreadData*>(
432 Thread::GetThreadLocal(per_isolate_thread_data_key_)); 432 Thread::GetThreadLocal(per_isolate_thread_data_key()));
433 } 433 }
434 434
435 // Returns the isolate inside which the current thread is running. 435 // Returns the isolate inside which the current thread is running.
436 INLINE(static Isolate* Current()) { 436 INLINE(static Isolate* Current()) {
437 const Thread::LocalStorageKey key = isolate_key();
437 Isolate* isolate = reinterpret_cast<Isolate*>( 438 Isolate* isolate = reinterpret_cast<Isolate*>(
438 Thread::GetExistingThreadLocal(isolate_key_)); 439 Thread::GetExistingThreadLocal(key));
440 if (!isolate) {
441 EnsureDefaultIsolate();
442 isolate = reinterpret_cast<Isolate*>(
443 Thread::GetExistingThreadLocal(key));
444 }
439 ASSERT(isolate != NULL); 445 ASSERT(isolate != NULL);
440 return isolate; 446 return isolate;
441 } 447 }
442 448
443 INLINE(static Isolate* UncheckedCurrent()) { 449 INLINE(static Isolate* UncheckedCurrent()) {
444 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_)); 450 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key()));
445 } 451 }
446 452
447 // Usually called by Init(), but can be called early e.g. to allow 453 // Usually called by Init(), but can be called early e.g. to allow
448 // testing components that require logging but not the whole 454 // testing components that require logging but not the whole
449 // isolate. 455 // isolate.
450 // 456 //
451 // Safe to call more than once. 457 // Safe to call more than once.
452 void InitializeLoggingAndCounters(); 458 void InitializeLoggingAndCounters();
453 459
454 bool Init(Deserializer* des); 460 bool Init(Deserializer* des);
455 461
456 bool IsInitialized() { return state_ == INITIALIZED; } 462 bool IsInitialized() { return state_ == INITIALIZED; }
457 463
458 // True if at least one thread Enter'ed this isolate. 464 // True if at least one thread Enter'ed this isolate.
459 bool IsInUse() { return entry_stack_ != NULL; } 465 bool IsInUse() { return entry_stack_ != NULL; }
460 466
461 // Destroys the non-default isolates. 467 // Destroys the non-default isolates.
462 // Sets default isolate into "has_been_disposed" state rather then destroying, 468 // Sets default isolate into "has_been_disposed" state rather then destroying,
463 // for legacy API reasons. 469 // for legacy API reasons.
464 void TearDown(); 470 void TearDown();
465 471
466 bool IsDefaultIsolate() const { return this == default_isolate_; } 472 bool IsDefaultIsolate() const;
467 473
468 // Ensures that process-wide resources and the default isolate have been 474 // Ensures that process-wide resources and the default isolate have been
469 // allocated. It is only necessary to call this method in rare cases, for 475 // allocated. It is only necessary to call this method in rare cases, for
470 // example if you are using V8 from within the body of a static initializer. 476 // example if you are using V8 from within the body of a static initializer.
471 // Safe to call multiple times. 477 // Safe to call multiple times.
472 static void EnsureDefaultIsolate(); 478 static void EnsureDefaultIsolate();
473 479
474 // Find the PerThread for this particular (isolate, thread) combination 480 // Find the PerThread for this particular (isolate, thread) combination
475 // If one does not yet exist, return null. 481 // If one does not yet exist, return null.
476 PerIsolateThreadData* FindPerThreadDataForThisThread(); 482 PerIsolateThreadData* FindPerThreadDataForThisThread();
477 483
478 #ifdef ENABLE_DEBUGGER_SUPPORT 484 #ifdef ENABLE_DEBUGGER_SUPPORT
479 // Get the debugger from the default isolate. Preinitializes the 485 // Get the debugger from the default isolate. Preinitializes the
480 // default isolate if needed. 486 // default isolate if needed.
481 static Debugger* GetDefaultIsolateDebugger(); 487 static Debugger* GetDefaultIsolateDebugger();
482 #endif 488 #endif
483 489
484 // Get the stack guard from the default isolate. Preinitializes the 490 // Get the stack guard from the default isolate. Preinitializes the
485 // default isolate if needed. 491 // default isolate if needed.
486 static StackGuard* GetDefaultIsolateStackGuard(); 492 static StackGuard* GetDefaultIsolateStackGuard();
487 493
488 // Returns the key used to store the pointer to the current isolate. 494 // Returns the key used to store the pointer to the current isolate.
489 // Used internally for V8 threads that do not execute JavaScript but still 495 // Used internally for V8 threads that do not execute JavaScript but still
490 // are part of the domain of an isolate (like the context switcher). 496 // are part of the domain of an isolate (like the context switcher).
491 static Thread::LocalStorageKey isolate_key() { 497 static Thread::LocalStorageKey isolate_key();
492 return isolate_key_;
493 }
494 498
495 // Returns the key used to store process-wide thread IDs. 499 // Returns the key used to store process-wide thread IDs.
496 static Thread::LocalStorageKey thread_id_key() { 500 static Thread::LocalStorageKey thread_id_key();
497 return thread_id_key_; 501
498 } 502 static Thread::LocalStorageKey per_isolate_thread_data_key();
499 503
500 // If a client attempts to create a Locker without specifying an isolate, 504 // If a client attempts to create a Locker without specifying an isolate,
501 // we assume that the client is using legacy behavior. Set up the current 505 // we assume that the client is using legacy behavior. Set up the current
502 // thread to be inside the implicit isolate (or fail a check if we have 506 // thread to be inside the implicit isolate (or fail a check if we have
503 // switched to non-legacy behavior). 507 // switched to non-legacy behavior).
504 static void EnterDefaultIsolate(); 508 static void EnterDefaultIsolate();
505 509
506 // Mutex for serializing access to break control structures. 510 // Mutex for serializing access to break control structures.
507 Mutex* break_access() { return break_access_; } 511 Mutex* break_access() { return break_access_; }
508 512
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 context_exit_happened_ = context_exit_happened; 1017 context_exit_happened_ = context_exit_happened;
1014 } 1018 }
1015 1019
1016 double time_millis_since_init() { 1020 double time_millis_since_init() {
1017 return OS::TimeCurrentMillis() - time_millis_at_init_; 1021 return OS::TimeCurrentMillis() - time_millis_at_init_;
1018 } 1022 }
1019 1023
1020 private: 1024 private:
1021 Isolate(); 1025 Isolate();
1022 1026
1027 friend struct GlobalState;
1028 friend struct InitializeGlobalState;
1029
1023 // The per-process lock should be acquired before the ThreadDataTable is 1030 // The per-process lock should be acquired before the ThreadDataTable is
1024 // modified. 1031 // modified.
1025 class ThreadDataTable { 1032 class ThreadDataTable {
1026 public: 1033 public:
1027 ThreadDataTable(); 1034 ThreadDataTable();
1028 ~ThreadDataTable(); 1035 ~ThreadDataTable();
1029 1036
1030 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id); 1037 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id);
1031 void Insert(PerIsolateThreadData* data); 1038 void Insert(PerIsolateThreadData* data);
1032 void Remove(Isolate* isolate, ThreadId thread_id); 1039 void Remove(Isolate* isolate, ThreadId thread_id);
(...skipping 22 matching lines...) Expand all
1055 1062
1056 int entry_count; 1063 int entry_count;
1057 PerIsolateThreadData* previous_thread_data; 1064 PerIsolateThreadData* previous_thread_data;
1058 Isolate* previous_isolate; 1065 Isolate* previous_isolate;
1059 EntryStackItem* previous_item; 1066 EntryStackItem* previous_item;
1060 1067
1061 private: 1068 private:
1062 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); 1069 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1063 }; 1070 };
1064 1071
1065 // This mutex protects highest_thread_id_, thread_data_table_ and
1066 // default_isolate_.
1067 static Mutex* process_wide_mutex_;
1068
1069 static Thread::LocalStorageKey per_isolate_thread_data_key_;
1070 static Thread::LocalStorageKey isolate_key_;
1071 static Thread::LocalStorageKey thread_id_key_;
1072 static Isolate* default_isolate_;
1073 static ThreadDataTable* thread_data_table_;
1074
1075 void Deinit(); 1072 void Deinit();
1076 1073
1077 static void SetIsolateThreadLocals(Isolate* isolate, 1074 static void SetIsolateThreadLocals(Isolate* isolate,
1078 PerIsolateThreadData* data); 1075 PerIsolateThreadData* data);
1079 1076
1080 enum State { 1077 enum State {
1081 UNINITIALIZED, // Some components may not have been allocated. 1078 UNINITIALIZED, // Some components may not have been allocated.
1082 INITIALIZED // All components are fully initialized. 1079 INITIALIZED // All components are fully initialized.
1083 }; 1080 };
1084 1081
1085 State state_; 1082 State state_;
1086 EntryStackItem* entry_stack_; 1083 EntryStackItem* entry_stack_;
1087 1084
1088 // Allocate and insert PerIsolateThreadData into the ThreadDataTable 1085 // Allocate and insert PerIsolateThreadData into the ThreadDataTable
1089 // (regardless of whether such data already exists). 1086 // (regardless of whether such data already exists).
1090 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id); 1087 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id);
1091 1088
1092 // Find the PerThread for this particular (isolate, thread) combination. 1089 // Find the PerThread for this particular (isolate, thread) combination.
1093 // If one does not yet exist, allocate a new one. 1090 // If one does not yet exist, allocate a new one.
1094 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); 1091 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread();
1095 1092
1096 // PreInits and returns a default isolate. Needed when a new thread tries 1093 // PreInits and returns a default isolate. Needed when a new thread tries
1097 // to create a Locker for the first time (the lock itself is in the isolate). 1094 // to create a Locker for the first time (the lock itself is in the isolate).
1098 static Isolate* GetDefaultIsolateForLocking(); 1095 static Isolate* GetDefaultIsolateForLocking();
1099 1096
1100 // Initializes the current thread to run this Isolate. 1097 // Initializes the current thread to run this Isolate.
1101 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate 1098 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1102 // at the same time, this should be prevented using external locking. 1099 // at the same time, this should be prevented using external locking.
1103 void Enter(); 1100 void Enter();
1104 1101
1105 // Exits the current thread. The previosuly entered Isolate is restored 1102 // Exits the current thread. The previosuly entered Isolate is restored
1106 // for the thread. 1103 // for the thread.
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1382
1386 // Mark the global context with out of memory. 1383 // Mark the global context with out of memory.
1387 inline void Context::mark_out_of_memory() { 1384 inline void Context::mark_out_of_memory() {
1388 global_context()->set_out_of_memory(HEAP->true_value()); 1385 global_context()->set_out_of_memory(HEAP->true_value());
1389 } 1386 }
1390 1387
1391 1388
1392 } } // namespace v8::internal 1389 } } // namespace v8::internal
1393 1390
1394 #endif // V8_ISOLATE_H_ 1391 #endif // V8_ISOLATE_H_
OLDNEW
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698