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 by EnsureInit before entering an isolate, and destroyed |
20 // upon an explicit call to CleanUp. | 20 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
21 // | 21 // must currently be called manually (issue 23474). |
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. | |
26 class Thread { | 22 class Thread { |
27 public: | 23 public: |
28 // The currently executing thread, or NULL if not yet initialized. | 24 // The currently executing thread, or NULL if not yet initialized. |
29 static Thread* Current() { | 25 static Thread* Current() { |
30 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); | 26 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); |
31 } | 27 } |
32 | 28 |
33 // Makes the current thread enter 'isolate'. Also calls EnsureInit. | 29 // Initializes the current thread as a VM thread, if not already done. |
| 30 static void EnsureInit(); |
| 31 |
| 32 // Makes the current thread enter 'isolate'. |
34 static void EnterIsolate(Isolate* isolate); | 33 static void EnterIsolate(Isolate* isolate); |
35 // Makes the current thread exit its isolate. | 34 // Makes the current thread exit its isolate. |
36 static void ExitIsolate(); | 35 static void ExitIsolate(); |
37 | 36 |
38 // A VM thread other than the main mutator thread can enter an isolate as a | 37 // 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 | 38 // "helper" to gain limited concurrent access to the isolate. One example is |
40 // SweeperTask (which uses the class table, which is copy-on-write). | 39 // SweeperTask (which uses the class table, which is copy-on-write). |
41 // TODO(koda): Properly synchronize heap access to expand allowed operations. | 40 // TODO(koda): Properly synchronize heap access to expand allowed operations. |
42 static void EnterIsolateAsHelper(Isolate* isolate); | 41 static void EnterIsolateAsHelper(Isolate* isolate); |
43 static void ExitIsolateAsHelper(); | 42 static void ExitIsolateAsHelper(); |
44 | 43 |
45 // Initializes the current thread as a VM thread, if not already done. | 44 #if defined(TARGET_OS_WINDOWS) |
46 static void EnsureInit(); | 45 // Clears the state of the current thread and frees the allocation. |
47 // Clears the state of the current thread. | |
48 static void CleanUp(); | 46 static void CleanUp(); |
| 47 #endif |
49 | 48 |
50 // Called at VM startup. | 49 // Called at VM startup. |
51 static void InitOnce(); | 50 static void InitOnce(); |
52 | 51 |
53 // The topmost zone used for allocation in this thread. | 52 // The topmost zone used for allocation in this thread. |
54 Zone* zone() { | 53 Zone* zone() { |
55 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); | 54 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); |
56 } | 55 } |
57 | 56 |
58 // The isolate that this thread is operating on, or NULL if none. | 57 // The isolate that this thread is operating on, or NULL if none. |
(...skipping 13 matching lines...) Expand all Loading... |
72 : isolate_(NULL) {} | 71 : isolate_(NULL) {} |
73 | 72 |
74 static void SetCurrent(Thread* current); | 73 static void SetCurrent(Thread* current); |
75 | 74 |
76 DISALLOW_COPY_AND_ASSIGN(Thread); | 75 DISALLOW_COPY_AND_ASSIGN(Thread); |
77 }; | 76 }; |
78 | 77 |
79 } // namespace dart | 78 } // namespace dart |
80 | 79 |
81 #endif // VM_THREAD_H_ | 80 #endif // VM_THREAD_H_ |
OLD | NEW |