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/base_isolate.h" | 8 #include "vm/base_isolate.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 class CHA; | 14 class CHA; |
15 class Isolate; | 15 class Isolate; |
16 | 16 |
17 // A VM thread; may be executing Dart code or performing helper tasks like | 17 // A VM thread; may be executing Dart code or performing helper tasks like |
18 // garbage collection or compilation. The Thread structure associated with | 18 // garbage collection or compilation. The Thread structure associated with |
19 // a thread is allocated when the thread enters an isolate, and destroyed | 19 // a thread is allocated when the thread enters an isolate, and destroyed |
20 // upon exiting an isolate or an explicit call to CleanUp. | 20 // upon an explicit call to CleanUp. |
| 21 // |
| 22 // NOTE: When the underlying OS thread is started by the embedder, i.e., not |
| 23 // part of a ThreadPool managed by the VM, we currently leak the Thread |
| 24 // structure after its last isolate exit. We could add an explicit cleanup API, |
| 25 // or, on platforms that support it, register a cleanup callback. |
21 class Thread { | 26 class Thread { |
22 public: | 27 public: |
23 // The currently executing thread, or NULL if not yet initialized. | 28 // The currently executing thread, or NULL if not yet initialized. |
24 static Thread* Current() { | 29 static Thread* Current() { |
25 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); | 30 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); |
26 } | 31 } |
27 | 32 |
28 // Makes the current thread enter 'isolate'. Also calls EnsureInit. | 33 // Makes the current thread enter 'isolate'. Also calls EnsureInit. |
29 static void EnterIsolate(Isolate* isolate); | 34 static void EnterIsolate(Isolate* isolate); |
30 // Makes the current thread exit its isolate. Also calls CleanUp. | 35 // Makes the current thread exit its isolate. |
31 static void ExitIsolate(); | 36 static void ExitIsolate(); |
32 | 37 |
| 38 // A VM thread other than the main mutator thread can enter an isolate as a |
| 39 // "helper" to gain limited concurrent access to the isolate. One example is |
| 40 // SweeperTask (which uses the class table, which is copy-on-write). |
| 41 // TODO(koda): Properly synchronize heap access to expand allowed operations. |
| 42 static void EnterIsolateAsHelper(Isolate* isolate); |
| 43 static void ExitIsolateAsHelper(); |
| 44 |
33 // Initializes the current thread as a VM thread, if not already done. | 45 // Initializes the current thread as a VM thread, if not already done. |
34 static void EnsureInit(); | 46 static void EnsureInit(); |
35 // Clears the state of the current thread. | 47 // Clears the state of the current thread. |
36 static void CleanUp(); | 48 static void CleanUp(); |
37 | 49 |
38 // Called at VM startup. | 50 // Called at VM startup. |
39 static void InitOnce(); | 51 static void InitOnce(); |
40 | 52 |
41 // The topmost zone used for allocation in this thread. | 53 // The topmost zone used for allocation in this thread. |
42 Zone* zone() { | 54 Zone* zone() { |
(...skipping 17 matching lines...) Expand all Loading... |
60 : isolate_(NULL) {} | 72 : isolate_(NULL) {} |
61 | 73 |
62 static void SetCurrent(Thread* current); | 74 static void SetCurrent(Thread* current); |
63 | 75 |
64 DISALLOW_COPY_AND_ASSIGN(Thread); | 76 DISALLOW_COPY_AND_ASSIGN(Thread); |
65 }; | 77 }; |
66 | 78 |
67 } // namespace dart | 79 } // namespace dart |
68 | 80 |
69 #endif // VM_THREAD_H_ | 81 #endif // VM_THREAD_H_ |
OLD | NEW |