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

Side by Side Diff: src/isolate.h

Issue 583153002: Reland 24052 - Require V8 to be explicitly initialized before an Isolate is created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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/d8.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 // 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 }; 459 };
460 460
461 461
462 enum AddressId { 462 enum AddressId {
463 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, 463 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
464 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) 464 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
465 #undef DECLARE_ENUM 465 #undef DECLARE_ENUM
466 kIsolateAddressCount 466 kIsolateAddressCount
467 }; 467 };
468 468
469 static void InitializeOncePerProcess();
470
469 // Returns the PerIsolateThreadData for the current thread (or NULL if one is 471 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
470 // not currently set). 472 // not currently set).
471 static PerIsolateThreadData* CurrentPerIsolateThreadData() { 473 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
472 EnsureInitialized();
473 return reinterpret_cast<PerIsolateThreadData*>( 474 return reinterpret_cast<PerIsolateThreadData*>(
474 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); 475 base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
475 } 476 }
476 477
477 // Returns the isolate inside which the current thread is running. 478 // Returns the isolate inside which the current thread is running.
478 INLINE(static Isolate* Current()) { 479 INLINE(static Isolate* Current()) {
479 EnsureInitialized();
480 Isolate* isolate = reinterpret_cast<Isolate*>( 480 Isolate* isolate = reinterpret_cast<Isolate*>(
481 base::Thread::GetExistingThreadLocal(isolate_key_)); 481 base::Thread::GetExistingThreadLocal(isolate_key_));
482 DCHECK(isolate != NULL); 482 DCHECK(isolate != NULL);
483 return isolate; 483 return isolate;
484 } 484 }
485 485
486 INLINE(static Isolate* UncheckedCurrent()) { 486 INLINE(static Isolate* UncheckedCurrent()) {
487 EnsureInitialized();
488 return reinterpret_cast<Isolate*>( 487 return reinterpret_cast<Isolate*>(
489 base::Thread::GetThreadLocal(isolate_key_)); 488 base::Thread::GetThreadLocal(isolate_key_));
490 } 489 }
491 490
492 // Like UncheckedCurrent, but skips the check that |isolate_key_| was 491 // Like UncheckedCurrent, but skips the check that |isolate_key_| was
493 // initialized. Callers have to ensure that themselves. 492 // initialized. Callers have to ensure that themselves.
494 INLINE(static Isolate* UnsafeCurrent()) { 493 INLINE(static Isolate* UnsafeCurrent()) {
495 return reinterpret_cast<Isolate*>( 494 return reinterpret_cast<Isolate*>(
496 base::Thread::GetThreadLocal(isolate_key_)); 495 base::Thread::GetThreadLocal(isolate_key_));
497 } 496 }
(...skipping 24 matching lines...) Expand all
522 PerIsolateThreadData* FindPerThreadDataForThisThread(); 521 PerIsolateThreadData* FindPerThreadDataForThisThread();
523 522
524 // Find the PerThread for given (isolate, thread) combination 523 // Find the PerThread for given (isolate, thread) combination
525 // If one does not yet exist, return null. 524 // If one does not yet exist, return null.
526 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); 525 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
527 526
528 // Returns the key used to store the pointer to the current isolate. 527 // Returns the key used to store the pointer to the current isolate.
529 // Used internally for V8 threads that do not execute JavaScript but still 528 // Used internally for V8 threads that do not execute JavaScript but still
530 // are part of the domain of an isolate (like the context switcher). 529 // are part of the domain of an isolate (like the context switcher).
531 static base::Thread::LocalStorageKey isolate_key() { 530 static base::Thread::LocalStorageKey isolate_key() {
532 EnsureInitialized();
533 return isolate_key_; 531 return isolate_key_;
534 } 532 }
535 533
536 // Returns the key used to store process-wide thread IDs. 534 // Returns the key used to store process-wide thread IDs.
537 static base::Thread::LocalStorageKey thread_id_key() { 535 static base::Thread::LocalStorageKey thread_id_key() {
538 EnsureInitialized();
539 return thread_id_key_; 536 return thread_id_key_;
540 } 537 }
541 538
542 static base::Thread::LocalStorageKey per_isolate_thread_data_key(); 539 static base::Thread::LocalStorageKey per_isolate_thread_data_key();
543 540
544 // Mutex for serializing access to break control structures. 541 // Mutex for serializing access to break control structures.
545 base::RecursiveMutex* break_access() { return &break_access_; } 542 base::RecursiveMutex* break_access() { return &break_access_; }
546 543
547 Address get_address_from_id(AddressId id); 544 Address get_address_from_id(AddressId id);
548 545
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 void AddCallCompletedCallback(CallCompletedCallback callback); 1100 void AddCallCompletedCallback(CallCompletedCallback callback);
1104 void RemoveCallCompletedCallback(CallCompletedCallback callback); 1101 void RemoveCallCompletedCallback(CallCompletedCallback callback);
1105 void FireCallCompletedCallback(); 1102 void FireCallCompletedCallback();
1106 1103
1107 void EnqueueMicrotask(Handle<Object> microtask); 1104 void EnqueueMicrotask(Handle<Object> microtask);
1108 void RunMicrotasks(); 1105 void RunMicrotasks();
1109 1106
1110 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); 1107 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
1111 void CountUsage(v8::Isolate::UseCounterFeature feature); 1108 void CountUsage(v8::Isolate::UseCounterFeature feature);
1112 1109
1110 static Isolate* NewForTesting() { return new Isolate(); }
1111
1113 private: 1112 private:
1114 static void EnsureInitialized();
1115
1116 Isolate(); 1113 Isolate();
1117 1114
1118 friend struct GlobalState; 1115 friend struct GlobalState;
1119 friend struct InitializeGlobalState; 1116 friend struct InitializeGlobalState;
1120 1117
1121 enum State { 1118 enum State {
1122 UNINITIALIZED, // Some components may not have been allocated. 1119 UNINITIALIZED, // Some components may not have been allocated.
1123 INITIALIZED // All components are fully initialized. 1120 INITIALIZED // All components are fully initialized.
1124 }; 1121 };
1125 1122
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1161
1165 int entry_count; 1162 int entry_count;
1166 PerIsolateThreadData* previous_thread_data; 1163 PerIsolateThreadData* previous_thread_data;
1167 Isolate* previous_isolate; 1164 Isolate* previous_isolate;
1168 EntryStackItem* previous_item; 1165 EntryStackItem* previous_item;
1169 1166
1170 private: 1167 private:
1171 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); 1168 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1172 }; 1169 };
1173 1170
1174 // This mutex protects highest_thread_id_ and thread_data_table_. 1171 static base::LazyMutex thread_data_table_mutex_;
1175 static base::LazyMutex process_wide_mutex_;
1176 1172
1177 static base::Thread::LocalStorageKey per_isolate_thread_data_key_; 1173 static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
1178 static base::Thread::LocalStorageKey isolate_key_; 1174 static base::Thread::LocalStorageKey isolate_key_;
1179 static base::Thread::LocalStorageKey thread_id_key_; 1175 static base::Thread::LocalStorageKey thread_id_key_;
1180 static ThreadDataTable* thread_data_table_; 1176 static ThreadDataTable* thread_data_table_;
1181 1177
1182 // A global counter for all generated Isolates, might overflow. 1178 // A global counter for all generated Isolates, might overflow.
1183 static base::Atomic32 isolate_counter_; 1179 static base::Atomic32 isolate_counter_;
1184 1180
1185 void Deinit(); 1181 void Deinit();
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 } 1549 }
1554 1550
1555 EmbeddedVector<char, 128> filename_; 1551 EmbeddedVector<char, 128> filename_;
1556 FILE* file_; 1552 FILE* file_;
1557 int scope_depth_; 1553 int scope_depth_;
1558 }; 1554 };
1559 1555
1560 } } // namespace v8::internal 1556 } } // namespace v8::internal
1561 1557
1562 #endif // V8_ISOLATE_H_ 1558 #endif // V8_ISOLATE_H_
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698