OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
6 #define VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
7 | 7 |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/os_thread.h" | 9 #include "vm/os_thread.h" |
10 #include "vm/store_buffer.h" | 10 #include "vm/store_buffer.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ | 31 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ |
32 | 32 |
33 #define CACHED_ADDRESSES_LIST(V) \ | 33 #define CACHED_ADDRESSES_LIST(V) \ |
34 V(uword, update_store_buffer_entry_point_, \ | 34 V(uword, update_store_buffer_entry_point_, \ |
35 StubCode::UpdateStoreBuffer_entry()->EntryPoint(), 0) | 35 StubCode::UpdateStoreBuffer_entry()->EntryPoint(), 0) |
36 | 36 |
37 #define CACHED_CONSTANTS_LIST(V) \ | 37 #define CACHED_CONSTANTS_LIST(V) \ |
38 CACHED_VM_OBJECTS_LIST(V) \ | 38 CACHED_VM_OBJECTS_LIST(V) \ |
39 CACHED_ADDRESSES_LIST(V) | 39 CACHED_ADDRESSES_LIST(V) |
40 | 40 |
| 41 // TODO(koda): Merge thread.h and thread_registry.h. |
| 42 typedef int64_t SafepointId; |
| 43 static const SafepointId kNoSafepointId = -1; |
41 | 44 |
42 // A VM thread; may be executing Dart code or performing helper tasks like | 45 // A VM thread; may be executing Dart code or performing helper tasks like |
43 // garbage collection or compilation. The Thread structure associated with | 46 // garbage collection or compilation. The Thread structure associated with |
44 // a thread is allocated by EnsureInit before entering an isolate, and destroyed | 47 // a thread is allocated by EnsureInit before entering an isolate, and destroyed |
45 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp | 48 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
46 // must currently be called manually (issue 23474). | 49 // must currently be called manually (issue 23474). |
47 class Thread { | 50 class Thread { |
48 public: | 51 public: |
49 // The currently executing thread, or NULL if not yet initialized. | 52 // The currently executing thread, or NULL if not yet initialized. |
50 static Thread* Current() { | 53 static Thread* Current() { |
51 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); | 54 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); |
52 } | 55 } |
53 | 56 |
54 // Initializes the current thread as a VM thread, if not already done. | 57 // Initializes the current thread as a VM thread, if not already done. |
55 static void EnsureInit(); | 58 static void EnsureInit(); |
56 | 59 |
57 // Makes the current thread enter 'isolate'. | 60 // Makes the current thread enter 'isolate'. |
58 static void EnterIsolate(Isolate* isolate); | 61 static void EnterIsolate(Isolate* isolate); |
59 // Makes the current thread exit its isolate. | 62 // Makes the current thread exit its isolate. |
60 static void ExitIsolate(); | 63 static void ExitIsolate(); |
61 | 64 |
62 // A VM thread other than the main mutator thread can enter an isolate as a | 65 // A VM thread other than the main mutator thread can enter an isolate as a |
63 // "helper" to gain limited concurrent access to the isolate. One example is | 66 // "helper" to gain limited concurrent access to the isolate. One example is |
64 // SweeperTask (which uses the class table, which is copy-on-write). | 67 // SweeperTask (which uses the class table, which is copy-on-write). |
65 // TODO(koda): Properly synchronize heap access to expand allowed operations. | 68 // TODO(koda): Properly synchronize heap access to expand allowed operations. |
66 static void EnterIsolateAsHelper(Isolate* isolate); | 69 // |
| 70 // If 'pass_safepoint' is set to the current rendezvous (returned by |
| 71 // ThreadRegistry::SafepointThreads), the thread will be allowed free passage |
| 72 // into the isolate while this rendezvous is in progress. |
| 73 static void EnterIsolateAsHelper( |
| 74 Isolate* isolate, |
| 75 SafepointId pass_safepoint = kNoSafepointId); |
67 static void ExitIsolateAsHelper(); | 76 static void ExitIsolateAsHelper(); |
68 | 77 |
69 // Called when the current thread transitions from mutator to collector. | 78 // Called when the current thread transitions from mutator to collector. |
70 // Empties the store buffer block into the isolate. | 79 // Empties the store buffer block into the isolate. |
71 // TODO(koda): Always run GC in separate thread. | 80 // TODO(koda): Always run GC in separate thread. |
72 static void PrepareForGC(); | 81 static void PrepareForGC(); |
73 | 82 |
74 #if defined(TARGET_OS_WINDOWS) | 83 #if defined(TARGET_OS_WINDOWS) |
75 // Clears the state of the current thread and frees the allocation. | 84 // Clears the state of the current thread and frees the allocation. |
76 static void CleanUp(); | 85 static void CleanUp(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 state_.timeline_block = block; | 235 state_.timeline_block = block; |
227 } | 236 } |
228 | 237 |
229 private: | 238 private: |
230 static ThreadLocalKey thread_key_; | 239 static ThreadLocalKey thread_key_; |
231 | 240 |
232 Isolate* isolate_; | 241 Isolate* isolate_; |
233 Heap* heap_; | 242 Heap* heap_; |
234 State state_; | 243 State state_; |
235 StoreBufferBlock* store_buffer_block_; | 244 StoreBufferBlock* store_buffer_block_; |
| 245 SafepointId pass_safepoint_; |
236 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ | 246 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
237 type_name member_name; | 247 type_name member_name; |
238 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) | 248 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
239 #undef DECLARE_MEMBERS | 249 #undef DECLARE_MEMBERS |
240 | 250 |
241 explicit Thread(bool init_vm_constants = true); | 251 explicit Thread(bool init_vm_constants = true); |
242 | 252 |
243 void InitVMConstants(); | 253 void InitVMConstants(); |
244 | 254 |
245 void ClearState() { | 255 void ClearState() { |
(...skipping 16 matching lines...) Expand all Loading... |
262 friend class ApiZone; | 272 friend class ApiZone; |
263 friend class Isolate; | 273 friend class Isolate; |
264 friend class StackZone; | 274 friend class StackZone; |
265 friend class ThreadRegistry; | 275 friend class ThreadRegistry; |
266 DISALLOW_COPY_AND_ASSIGN(Thread); | 276 DISALLOW_COPY_AND_ASSIGN(Thread); |
267 }; | 277 }; |
268 | 278 |
269 } // namespace dart | 279 } // namespace dart |
270 | 280 |
271 #endif // VM_THREAD_H_ | 281 #endif // VM_THREAD_H_ |
OLD | NEW |