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

Side by Side Diff: src/isolate.h

Issue 9836108: Rollback of r11015, r11014, r11011, r11010 in trunk branch. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Finish file upload 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, 423 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
424 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) 424 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
425 #undef C 425 #undef C
426 kIsolateAddressCount 426 kIsolateAddressCount
427 }; 427 };
428 428
429 // Returns the PerIsolateThreadData for the current thread (or NULL if one is 429 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
430 // not currently set). 430 // not currently set).
431 static PerIsolateThreadData* CurrentPerIsolateThreadData() { 431 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
432 return reinterpret_cast<PerIsolateThreadData*>( 432 return reinterpret_cast<PerIsolateThreadData*>(
433 Thread::GetThreadLocal(per_isolate_thread_data_key())); 433 Thread::GetThreadLocal(per_isolate_thread_data_key_));
434 } 434 }
435 435
436 // Returns the isolate inside which the current thread is running. 436 // Returns the isolate inside which the current thread is running.
437 INLINE(static Isolate* Current()) { 437 INLINE(static Isolate* Current()) {
438 const Thread::LocalStorageKey key = isolate_key();
439 Isolate* isolate = reinterpret_cast<Isolate*>( 438 Isolate* isolate = reinterpret_cast<Isolate*>(
440 Thread::GetExistingThreadLocal(key)); 439 Thread::GetExistingThreadLocal(isolate_key_));
441 if (!isolate) {
442 EnsureDefaultIsolate();
443 isolate = reinterpret_cast<Isolate*>(
444 Thread::GetExistingThreadLocal(key));
445 }
446 ASSERT(isolate != NULL); 440 ASSERT(isolate != NULL);
447 return isolate; 441 return isolate;
448 } 442 }
449 443
450 INLINE(static Isolate* UncheckedCurrent()) { 444 INLINE(static Isolate* UncheckedCurrent()) {
451 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key())); 445 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_));
452 } 446 }
453 447
454 // Usually called by Init(), but can be called early e.g. to allow 448 // Usually called by Init(), but can be called early e.g. to allow
455 // testing components that require logging but not the whole 449 // testing components that require logging but not the whole
456 // isolate. 450 // isolate.
457 // 451 //
458 // Safe to call more than once. 452 // Safe to call more than once.
459 void InitializeLoggingAndCounters(); 453 void InitializeLoggingAndCounters();
460 454
461 bool Init(Deserializer* des); 455 bool Init(Deserializer* des);
462 456
463 bool IsInitialized() { return state_ == INITIALIZED; } 457 bool IsInitialized() { return state_ == INITIALIZED; }
464 458
465 // True if at least one thread Enter'ed this isolate. 459 // True if at least one thread Enter'ed this isolate.
466 bool IsInUse() { return entry_stack_ != NULL; } 460 bool IsInUse() { return entry_stack_ != NULL; }
467 461
468 // Destroys the non-default isolates. 462 // Destroys the non-default isolates.
469 // Sets default isolate into "has_been_disposed" state rather then destroying, 463 // Sets default isolate into "has_been_disposed" state rather then destroying,
470 // for legacy API reasons. 464 // for legacy API reasons.
471 void TearDown(); 465 void TearDown();
472 466
473 bool IsDefaultIsolate() const; 467 bool IsDefaultIsolate() const { return this == default_isolate_; }
474 468
475 // Ensures that process-wide resources and the default isolate have been 469 // Ensures that process-wide resources and the default isolate have been
476 // allocated. It is only necessary to call this method in rare cases, for 470 // allocated. It is only necessary to call this method in rare cases, for
477 // example if you are using V8 from within the body of a static initializer. 471 // example if you are using V8 from within the body of a static initializer.
478 // Safe to call multiple times. 472 // Safe to call multiple times.
479 static void EnsureDefaultIsolate(); 473 static void EnsureDefaultIsolate();
480 474
481 // Find the PerThread for this particular (isolate, thread) combination 475 // Find the PerThread for this particular (isolate, thread) combination
482 // If one does not yet exist, return null. 476 // If one does not yet exist, return null.
483 PerIsolateThreadData* FindPerThreadDataForThisThread(); 477 PerIsolateThreadData* FindPerThreadDataForThisThread();
484 478
485 #ifdef ENABLE_DEBUGGER_SUPPORT 479 #ifdef ENABLE_DEBUGGER_SUPPORT
486 // Get the debugger from the default isolate. Preinitializes the 480 // Get the debugger from the default isolate. Preinitializes the
487 // default isolate if needed. 481 // default isolate if needed.
488 static Debugger* GetDefaultIsolateDebugger(); 482 static Debugger* GetDefaultIsolateDebugger();
489 #endif 483 #endif
490 484
491 // Get the stack guard from the default isolate. Preinitializes the 485 // Get the stack guard from the default isolate. Preinitializes the
492 // default isolate if needed. 486 // default isolate if needed.
493 static StackGuard* GetDefaultIsolateStackGuard(); 487 static StackGuard* GetDefaultIsolateStackGuard();
494 488
495 // Returns the key used to store the pointer to the current isolate. 489 // Returns the key used to store the pointer to the current isolate.
496 // Used internally for V8 threads that do not execute JavaScript but still 490 // Used internally for V8 threads that do not execute JavaScript but still
497 // are part of the domain of an isolate (like the context switcher). 491 // are part of the domain of an isolate (like the context switcher).
498 static Thread::LocalStorageKey isolate_key(); 492 static Thread::LocalStorageKey isolate_key() {
493 return isolate_key_;
494 }
499 495
500 // Returns the key used to store process-wide thread IDs. 496 // Returns the key used to store process-wide thread IDs.
501 static Thread::LocalStorageKey thread_id_key(); 497 static Thread::LocalStorageKey thread_id_key() {
502 498 return thread_id_key_;
503 static Thread::LocalStorageKey per_isolate_thread_data_key(); 499 }
504 500
505 // If a client attempts to create a Locker without specifying an isolate, 501 // If a client attempts to create a Locker without specifying an isolate,
506 // we assume that the client is using legacy behavior. Set up the current 502 // we assume that the client is using legacy behavior. Set up the current
507 // thread to be inside the implicit isolate (or fail a check if we have 503 // thread to be inside the implicit isolate (or fail a check if we have
508 // switched to non-legacy behavior). 504 // switched to non-legacy behavior).
509 static void EnterDefaultIsolate(); 505 static void EnterDefaultIsolate();
510 506
511 // Mutex for serializing access to break control structures. 507 // Mutex for serializing access to break control structures.
512 Mutex* break_access() { return break_access_; } 508 Mutex* break_access() { return break_access_; }
513 509
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 void set_date_cache(DateCache* date_cache) { 1026 void set_date_cache(DateCache* date_cache) {
1031 if (date_cache != date_cache_) { 1027 if (date_cache != date_cache_) {
1032 delete date_cache_; 1028 delete date_cache_;
1033 } 1029 }
1034 date_cache_ = date_cache; 1030 date_cache_ = date_cache;
1035 } 1031 }
1036 1032
1037 private: 1033 private:
1038 Isolate(); 1034 Isolate();
1039 1035
1040 friend struct GlobalState;
1041 friend struct InitializeGlobalState;
1042
1043 // The per-process lock should be acquired before the ThreadDataTable is 1036 // The per-process lock should be acquired before the ThreadDataTable is
1044 // modified. 1037 // modified.
1045 class ThreadDataTable { 1038 class ThreadDataTable {
1046 public: 1039 public:
1047 ThreadDataTable(); 1040 ThreadDataTable();
1048 ~ThreadDataTable(); 1041 ~ThreadDataTable();
1049 1042
1050 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id); 1043 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id);
1051 void Insert(PerIsolateThreadData* data); 1044 void Insert(PerIsolateThreadData* data);
1052 void Remove(Isolate* isolate, ThreadId thread_id); 1045 void Remove(Isolate* isolate, ThreadId thread_id);
(...skipping 22 matching lines...) Expand all
1075 1068
1076 int entry_count; 1069 int entry_count;
1077 PerIsolateThreadData* previous_thread_data; 1070 PerIsolateThreadData* previous_thread_data;
1078 Isolate* previous_isolate; 1071 Isolate* previous_isolate;
1079 EntryStackItem* previous_item; 1072 EntryStackItem* previous_item;
1080 1073
1081 private: 1074 private:
1082 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); 1075 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1083 }; 1076 };
1084 1077
1078 // This mutex protects highest_thread_id_, thread_data_table_ and
1079 // default_isolate_.
1080 static Mutex* process_wide_mutex_;
1081
1082 static Thread::LocalStorageKey per_isolate_thread_data_key_;
1083 static Thread::LocalStorageKey isolate_key_;
1084 static Thread::LocalStorageKey thread_id_key_;
1085 static Isolate* default_isolate_;
1086 static ThreadDataTable* thread_data_table_;
1087
1085 void Deinit(); 1088 void Deinit();
1086 1089
1087 static void SetIsolateThreadLocals(Isolate* isolate, 1090 static void SetIsolateThreadLocals(Isolate* isolate,
1088 PerIsolateThreadData* data); 1091 PerIsolateThreadData* data);
1089 1092
1090 enum State { 1093 enum State {
1091 UNINITIALIZED, // Some components may not have been allocated. 1094 UNINITIALIZED, // Some components may not have been allocated.
1092 INITIALIZED // All components are fully initialized. 1095 INITIALIZED // All components are fully initialized.
1093 }; 1096 };
1094 1097
1095 State state_; 1098 State state_;
1096 EntryStackItem* entry_stack_; 1099 EntryStackItem* entry_stack_;
1097 1100
1098 // Allocate and insert PerIsolateThreadData into the ThreadDataTable 1101 // Allocate and insert PerIsolateThreadData into the ThreadDataTable
1099 // (regardless of whether such data already exists). 1102 // (regardless of whether such data already exists).
1100 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id); 1103 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id);
1101 1104
1102 // Find the PerThread for this particular (isolate, thread) combination. 1105 // Find the PerThread for this particular (isolate, thread) combination.
1103 // If one does not yet exist, allocate a new one. 1106 // If one does not yet exist, allocate a new one.
1104 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); 1107 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread();
1105 1108
1106 // PreInits and returns a default isolate. Needed when a new thread tries 1109 // PreInits and returns a default isolate. Needed when a new thread tries
1107 // to create a Locker for the first time (the lock itself is in the isolate). 1110 // to create a Locker for the first time (the lock itself is in the isolate).
1108 static Isolate* GetDefaultIsolateForLocking(); 1111 static Isolate* GetDefaultIsolateForLocking();
1109 1112
1110 // Initializes the current thread to run this Isolate. 1113 // Initializes the current thread to run this Isolate.
1111 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate 1114 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1112 // at the same time, this should be prevented using external locking. 1115 // at the same time, this should be prevented using external locking.
1113 void Enter(); 1116 void Enter();
1114 1117
1115 // Exits the current thread. The previosuly entered Isolate is restored 1118 // Exits the current thread. The previosuly entered Isolate is restored
1116 // for the thread. 1119 // for the thread.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 1401
1399 // Mark the global context with out of memory. 1402 // Mark the global context with out of memory.
1400 inline void Context::mark_out_of_memory() { 1403 inline void Context::mark_out_of_memory() {
1401 global_context()->set_out_of_memory(HEAP->true_value()); 1404 global_context()->set_out_of_memory(HEAP->true_value());
1402 } 1405 }
1403 1406
1404 1407
1405 } } // namespace v8::internal 1408 } } // namespace v8::internal
1406 1409
1407 #endif // V8_ISOLATE_H_ 1410 #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