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 #include "vm/store_buffer.h" |
11 | 12 |
12 namespace dart { | 13 namespace dart { |
13 | 14 |
14 class CHA; | 15 class CHA; |
15 class Isolate; | 16 class Isolate; |
16 | 17 |
17 // A VM thread; may be executing Dart code or performing helper tasks like | 18 // A VM thread; may be executing Dart code or performing helper tasks like |
18 // garbage collection or compilation. The Thread structure associated with | 19 // garbage collection or compilation. The Thread structure associated with |
19 // a thread is allocated by EnsureInit before entering an isolate, and destroyed | 20 // a thread is allocated by EnsureInit before entering an isolate, and destroyed |
20 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp | 21 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
(...skipping 13 matching lines...) Expand all Loading... |
34 // Makes the current thread exit its isolate. | 35 // Makes the current thread exit its isolate. |
35 static void ExitIsolate(); | 36 static void ExitIsolate(); |
36 | 37 |
37 // A VM thread other than the main mutator thread can enter an isolate as a | 38 // A VM thread other than the main mutator thread can enter an isolate as a |
38 // "helper" to gain limited concurrent access to the isolate. One example is | 39 // "helper" to gain limited concurrent access to the isolate. One example is |
39 // SweeperTask (which uses the class table, which is copy-on-write). | 40 // SweeperTask (which uses the class table, which is copy-on-write). |
40 // TODO(koda): Properly synchronize heap access to expand allowed operations. | 41 // TODO(koda): Properly synchronize heap access to expand allowed operations. |
41 static void EnterIsolateAsHelper(Isolate* isolate); | 42 static void EnterIsolateAsHelper(Isolate* isolate); |
42 static void ExitIsolateAsHelper(); | 43 static void ExitIsolateAsHelper(); |
43 | 44 |
| 45 // Called when the current thread transitions from mutator to collector. |
| 46 // Empties the store buffer block into the isolate. |
| 47 // TODO(koda): Always run GC in separate thread. |
| 48 static void PrepareForGC(); |
| 49 |
44 #if defined(TARGET_OS_WINDOWS) | 50 #if defined(TARGET_OS_WINDOWS) |
45 // Clears the state of the current thread and frees the allocation. | 51 // Clears the state of the current thread and frees the allocation. |
46 static void CleanUp(); | 52 static void CleanUp(); |
47 #endif | 53 #endif |
48 | 54 |
49 // Called at VM startup. | 55 // Called at VM startup. |
50 static void InitOnce(); | 56 static void InitOnce(); |
51 | 57 |
52 // The topmost zone used for allocation in this thread. | 58 // The topmost zone used for allocation in this thread. |
53 Zone* zone() { | 59 Zone* zone() { |
54 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); | 60 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); |
55 } | 61 } |
56 | 62 |
57 // The isolate that this thread is operating on, or NULL if none. | 63 // The isolate that this thread is operating on, or NULL if none. |
58 Isolate* isolate() const { return isolate_; } | 64 Isolate* isolate() const { return isolate_; } |
59 static intptr_t isolate_offset() { | 65 static intptr_t isolate_offset() { |
60 return OFFSET_OF(Thread, isolate_); | 66 return OFFSET_OF(Thread, isolate_); |
61 } | 67 } |
62 | 68 |
63 // The (topmost) CHA for the compilation in the isolate of this thread. | 69 // The (topmost) CHA for the compilation in the isolate of this thread. |
64 // TODO(23153): Move this out of Isolate/Thread. | 70 // TODO(23153): Move this out of Isolate/Thread. |
65 CHA* cha() const; | 71 CHA* cha() const; |
66 void set_cha(CHA* value); | 72 void set_cha(CHA* value); |
67 | 73 |
| 74 void StoreBufferAddObject(RawObject* obj); |
| 75 void StoreBufferAddObjectGC(RawObject* obj); |
| 76 #if defined(TESTING) |
| 77 bool StoreBufferContains(RawObject* obj) const { |
| 78 return store_buffer_block_->Contains(obj); |
| 79 } |
| 80 #endif |
| 81 void StoreBufferBlockProcess(bool check_threshold); |
| 82 static intptr_t store_buffer_block_offset() { |
| 83 return OFFSET_OF(Thread, store_buffer_block_); |
| 84 } |
| 85 |
68 private: | 86 private: |
69 static ThreadLocalKey thread_key_; | 87 static ThreadLocalKey thread_key_; |
70 | 88 |
71 Isolate* isolate_; | 89 Isolate* isolate_; |
| 90 StoreBufferBlock* store_buffer_block_; |
72 | 91 |
73 Thread() | 92 Thread() |
74 : isolate_(NULL) {} | 93 : isolate_(NULL), store_buffer_block_(NULL) {} |
75 | 94 |
76 static void SetCurrent(Thread* current); | 95 static void SetCurrent(Thread* current); |
77 | 96 |
78 DISALLOW_COPY_AND_ASSIGN(Thread); | 97 DISALLOW_COPY_AND_ASSIGN(Thread); |
79 }; | 98 }; |
80 | 99 |
81 } // namespace dart | 100 } // namespace dart |
82 | 101 |
83 #endif // VM_THREAD_H_ | 102 #endif // VM_THREAD_H_ |
OLD | NEW |