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 #include "vm/thread.h" | 5 #include "vm/thread.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/os_thread.h" | 8 #include "vm/os_thread.h" |
9 #include "vm/profiler.h" | 9 #include "vm/profiler.h" |
10 #include "vm/thread_interrupter.h" | 10 #include "vm/thread_interrupter.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 ASSERT(isolate->thread_state() == NULL); | 65 ASSERT(isolate->thread_state() == NULL); |
66 InterruptableThreadState* thread_state = | 66 InterruptableThreadState* thread_state = |
67 ThreadInterrupter::GetCurrentThreadState(); | 67 ThreadInterrupter::GetCurrentThreadState(); |
68 #if defined(DEBUG) | 68 #if defined(DEBUG) |
69 Isolate::CheckForDuplicateThreadState(thread_state); | 69 Isolate::CheckForDuplicateThreadState(thread_state); |
70 #endif | 70 #endif |
71 ASSERT(thread_state != NULL); | 71 ASSERT(thread_state != NULL); |
72 Profiler::BeginExecution(isolate); | 72 Profiler::BeginExecution(isolate); |
73 isolate->set_thread_state(thread_state); | 73 isolate->set_thread_state(thread_state); |
74 isolate->set_vm_tag(VMTag::kVMTagId); | 74 isolate->set_vm_tag(VMTag::kVMTagId); |
75 ASSERT(thread->store_buffer_block_ == NULL); | |
76 thread->store_buffer_block_ = isolate->store_buffer()->PopPartialOrEmpty(); | |
Ivan Posva
2015/06/08 13:05:21
Looking at this use here I am revising my suggesti
koda
2015/06/09 13:10:30
Done.
| |
75 } | 77 } |
76 | 78 |
77 | 79 |
78 void Thread::ExitIsolate() { | 80 void Thread::ExitIsolate() { |
79 Thread* thread = Thread::Current(); | 81 Thread* thread = Thread::Current(); |
80 // TODO(koda): Audit callers; they should know whether they're in an isolate. | 82 // TODO(koda): Audit callers; they should know whether they're in an isolate. |
81 if (thread == NULL || thread->isolate() == NULL) return; | 83 if (thread == NULL || thread->isolate() == NULL) return; |
82 Isolate* isolate = thread->isolate(); | 84 Isolate* isolate = thread->isolate(); |
85 isolate->store_buffer()->Push(thread->store_buffer_block_); | |
86 thread->store_buffer_block_ = NULL; | |
83 if (isolate->is_runnable()) { | 87 if (isolate->is_runnable()) { |
84 isolate->set_vm_tag(VMTag::kIdleTagId); | 88 isolate->set_vm_tag(VMTag::kIdleTagId); |
85 } else { | 89 } else { |
86 isolate->set_vm_tag(VMTag::kLoadWaitTagId); | 90 isolate->set_vm_tag(VMTag::kLoadWaitTagId); |
87 } | 91 } |
88 isolate->set_thread_state(NULL); | 92 isolate->set_thread_state(NULL); |
89 Profiler::EndExecution(isolate); | 93 Profiler::EndExecution(isolate); |
90 isolate->set_mutator_thread(NULL); | 94 isolate->set_mutator_thread(NULL); |
91 thread->isolate_ = NULL; | 95 thread->isolate_ = NULL; |
92 ASSERT(Isolate::Current() == NULL); | 96 ASSERT(Isolate::Current() == NULL); |
93 } | 97 } |
94 | 98 |
95 | 99 |
96 void Thread::EnterIsolateAsHelper(Isolate* isolate) { | 100 void Thread::EnterIsolateAsHelper(Isolate* isolate) { |
97 Thread* thread = Thread::Current(); | 101 Thread* thread = Thread::Current(); |
98 ASSERT(thread != NULL); | 102 ASSERT(thread != NULL); |
99 ASSERT(thread->isolate() == NULL); | 103 ASSERT(thread->isolate() == NULL); |
100 thread->isolate_ = isolate; | 104 thread->isolate_ = isolate; |
101 // Do not update isolate->mutator_thread, but perform sanity check: | 105 // Do not update isolate->mutator_thread, but perform sanity check: |
102 // this thread should not be both the main mutator and helper. | 106 // this thread should not be both the main mutator and helper. |
103 ASSERT(isolate->mutator_thread() != thread); | 107 ASSERT(isolate->mutator_thread() != thread); |
104 } | 108 } |
105 | 109 |
106 | 110 |
107 void Thread::ExitIsolateAsHelper() { | 111 void Thread::ExitIsolateAsHelper() { |
108 Thread* thread = Thread::Current(); | 112 Thread* thread = Thread::Current(); |
113 // If the helper thread chose to use the store buffer, check that it has | |
114 // already been flushed manually. | |
115 ASSERT(thread->store_buffer_block_ == NULL); | |
109 Isolate* isolate = thread->isolate(); | 116 Isolate* isolate = thread->isolate(); |
110 ASSERT(isolate != NULL); | 117 ASSERT(isolate != NULL); |
111 thread->isolate_ = NULL; | 118 thread->isolate_ = NULL; |
112 ASSERT(isolate->mutator_thread() != thread); | 119 ASSERT(isolate->mutator_thread() != thread); |
113 } | 120 } |
114 | 121 |
115 | 122 |
123 void Thread::PrepareForGC() { | |
124 Thread* thread = Thread::Current(); | |
125 StoreBuffer* sb = thread->isolate()->store_buffer(); | |
126 sb->Push(thread->store_buffer_block_, false); | |
Ivan Posva
2015/06/08 13:05:21
Please explain in a comment why you are passing fa
koda
2015/06/09 13:10:30
Done.
| |
127 thread->store_buffer_block_ = sb->PopEmpty(); | |
128 } | |
129 | |
130 | |
131 void Thread::StoreBufferBlockProcess(bool check_threshold) { | |
132 StoreBuffer* sb = isolate()->store_buffer(); | |
133 sb->Push(store_buffer_block_, check_threshold); | |
Ivan Posva
2015/06/08 13:05:21
The fact that we still have a reference to the Sto
koda
2015/06/09 13:10:30
Done.
| |
134 store_buffer_block_ = sb->PopPartialOrEmpty(); | |
135 } | |
136 | |
137 | |
138 void Thread::StoreBufferAddObject(RawObject* obj) { | |
139 store_buffer_block_->Add(obj); | |
140 if (store_buffer_block_->IsFull()) { | |
141 StoreBufferBlockProcess(true); | |
142 } | |
143 } | |
144 | |
145 | |
146 void Thread::StoreBufferAddObjectGC(RawObject* obj) { | |
147 store_buffer_block_->Add(obj); | |
148 if (store_buffer_block_->IsFull()) { | |
149 StoreBufferBlockProcess(false); | |
150 } | |
151 } | |
152 | |
153 | |
116 CHA* Thread::cha() const { | 154 CHA* Thread::cha() const { |
117 ASSERT(isolate_ != NULL); | 155 ASSERT(isolate_ != NULL); |
118 return isolate_->cha_; | 156 return isolate_->cha_; |
119 } | 157 } |
120 | 158 |
121 | 159 |
122 void Thread::set_cha(CHA* value) { | 160 void Thread::set_cha(CHA* value) { |
123 ASSERT(isolate_ != NULL); | 161 ASSERT(isolate_ != NULL); |
124 isolate_->cha_ = value; | 162 isolate_->cha_ = value; |
125 } | 163 } |
126 | 164 |
127 } // namespace dart | 165 } // namespace dart |
OLD | NEW |