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/growable_array.h" | 7 #include "vm/growable_array.h" |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 146 |
147 | 147 |
148 void Thread::ExitIsolate() { | 148 void Thread::ExitIsolate() { |
149 Thread* thread = Thread::Current(); | 149 Thread* thread = Thread::Current(); |
150 // TODO(koda): Audit callers; they should know whether they're in an isolate. | 150 // TODO(koda): Audit callers; they should know whether they're in an isolate. |
151 if (thread == NULL || thread->isolate() == NULL) return; | 151 if (thread == NULL || thread->isolate() == NULL) return; |
152 Isolate* isolate = thread->isolate(); | 152 Isolate* isolate = thread->isolate(); |
153 Profiler::EndExecution(isolate); | 153 Profiler::EndExecution(isolate); |
154 thread->set_thread_state(NULL); | 154 thread->set_thread_state(NULL); |
155 thread->Unschedule(); | 155 thread->Unschedule(); |
156 StoreBufferBlock* block = thread->store_buffer_block_; | 156 // TODO(koda): Move store_buffer_block_ into State. |
157 thread->store_buffer_block_ = NULL; | 157 thread->StoreBufferFlush(); |
158 isolate->store_buffer()->PushBlock(block); | |
159 if (isolate->is_runnable()) { | 158 if (isolate->is_runnable()) { |
160 isolate->set_vm_tag(VMTag::kIdleTagId); | 159 isolate->set_vm_tag(VMTag::kIdleTagId); |
161 } else { | 160 } else { |
162 isolate->set_vm_tag(VMTag::kLoadWaitTagId); | 161 isolate->set_vm_tag(VMTag::kLoadWaitTagId); |
163 } | 162 } |
164 isolate->ClearMutatorThread(); | 163 isolate->ClearMutatorThread(); |
165 thread->isolate_ = NULL; | 164 thread->isolate_ = NULL; |
166 ASSERT(Isolate::Current() == NULL); | 165 ASSERT(Isolate::Current() == NULL); |
167 thread->heap_ = NULL; | 166 thread->heap_ = NULL; |
168 } | 167 } |
169 | 168 |
170 | 169 |
171 void Thread::EnterIsolateAsHelper(Isolate* isolate) { | 170 void Thread::EnterIsolateAsHelper(Isolate* isolate) { |
172 Thread* thread = Thread::Current(); | 171 Thread* thread = Thread::Current(); |
173 ASSERT(thread != NULL); | 172 ASSERT(thread != NULL); |
174 ASSERT(thread->isolate() == NULL); | 173 ASSERT(thread->isolate() == NULL); |
175 thread->isolate_ = isolate; | 174 thread->isolate_ = isolate; |
175 ASSERT(thread->store_buffer_block_ == NULL); | |
176 thread->store_buffer_block_ = isolate->store_buffer()->PopNonFullBlock(); | |
176 ASSERT(isolate->heap() != NULL); | 177 ASSERT(isolate->heap() != NULL); |
177 thread->heap_ = isolate->heap(); | 178 thread->heap_ = isolate->heap(); |
178 ASSERT(thread->thread_state() == NULL); | 179 ASSERT(thread->thread_state() == NULL); |
179 // Do not update isolate->mutator_thread, but perform sanity check: | 180 // Do not update isolate->mutator_thread, but perform sanity check: |
180 // this thread should not be both the main mutator and helper. | 181 // this thread should not be both the main mutator and helper. |
181 ASSERT(!isolate->MutatorThreadIsCurrentThread()); | 182 ASSERT(!isolate->MutatorThreadIsCurrentThread()); |
182 thread->Schedule(isolate); | 183 thread->Schedule(isolate); |
183 } | 184 } |
184 | 185 |
185 | 186 |
186 void Thread::ExitIsolateAsHelper() { | 187 void Thread::ExitIsolateAsHelper() { |
187 Thread* thread = Thread::Current(); | 188 Thread* thread = Thread::Current(); |
188 // If the helper thread chose to use the store buffer, check that it has | |
189 // already been flushed manually. | |
190 ASSERT(thread->store_buffer_block_ == NULL); | |
191 Isolate* isolate = thread->isolate(); | 189 Isolate* isolate = thread->isolate(); |
192 ASSERT(isolate != NULL); | 190 ASSERT(isolate != NULL); |
193 thread->Unschedule(); | 191 thread->Unschedule(); |
192 // TODO(koda): Move store_buffer_block_ into State. | |
193 thread->StoreBufferFlush(); | |
194 thread->set_thread_state(NULL); | 194 thread->set_thread_state(NULL); |
195 thread->isolate_ = NULL; | 195 thread->isolate_ = NULL; |
196 thread->heap_ = NULL; | 196 thread->heap_ = NULL; |
197 ASSERT(!isolate->MutatorThreadIsCurrentThread()); | 197 ASSERT(!isolate->MutatorThreadIsCurrentThread()); |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 void Thread::PrepareForGC() { | 201 void Thread::PrepareForGC() { |
202 Thread* thread = Thread::Current(); | 202 Thread* thread = Thread::Current(); |
203 StoreBuffer* sb = thread->isolate()->store_buffer(); | |
204 StoreBufferBlock* block = thread->store_buffer_block_; | |
205 thread->store_buffer_block_ = NULL; | |
206 const bool kCheckThreshold = false; // Prevent scheduling another GC. | 203 const bool kCheckThreshold = false; // Prevent scheduling another GC. |
Ivan Posva
2015/08/14 22:15:29
Name is reverse from its meaning. Should be kDoNot
koda
2015/08/17 15:51:07
Done.
| |
207 sb->PushBlock(block, kCheckThreshold); | 204 thread->StoreBufferFlush(kCheckThreshold); |
208 thread->store_buffer_block_ = sb->PopEmptyBlock(); | 205 thread->store_buffer_block_ = |
206 thread->isolate()->store_buffer()->PopEmptyBlock(); | |
209 } | 207 } |
210 | 208 |
211 | 209 |
212 void Thread::StoreBufferBlockProcess(bool check_threshold) { | 210 void Thread::StoreBufferBlockProcess(bool check_threshold) { |
213 StoreBuffer* sb = isolate()->store_buffer(); | 211 StoreBufferFlush(check_threshold); |
214 StoreBufferBlock* block = store_buffer_block_; | 212 store_buffer_block_ = isolate()->store_buffer()->PopNonFullBlock(); |
215 store_buffer_block_ = NULL; | |
216 sb->PushBlock(block, check_threshold); | |
217 store_buffer_block_ = sb->PopNonFullBlock(); | |
218 } | 213 } |
219 | 214 |
220 | 215 |
221 void Thread::StoreBufferAddObject(RawObject* obj) { | 216 void Thread::StoreBufferAddObject(RawObject* obj) { |
222 store_buffer_block_->Push(obj); | 217 store_buffer_block_->Push(obj); |
223 if (store_buffer_block_->IsFull()) { | 218 if (store_buffer_block_->IsFull()) { |
224 StoreBufferBlockProcess(true); | 219 StoreBufferBlockProcess(true); |
225 } | 220 } |
226 } | 221 } |
227 | 222 |
228 | 223 |
229 void Thread::StoreBufferAddObjectGC(RawObject* obj) { | 224 void Thread::StoreBufferAddObjectGC(RawObject* obj) { |
230 store_buffer_block_->Push(obj); | 225 store_buffer_block_->Push(obj); |
231 if (store_buffer_block_->IsFull()) { | 226 if (store_buffer_block_->IsFull()) { |
232 StoreBufferBlockProcess(false); | 227 StoreBufferBlockProcess(false); |
233 } | 228 } |
234 } | 229 } |
235 | 230 |
236 | 231 |
232 void Thread::StoreBufferFlush(bool check_threshold) { | |
Ivan Posva
2015/08/14 22:15:29
Unused parameter "check_threshold".
How about Sto
koda
2015/08/17 15:51:07
Done.
| |
233 StoreBufferBlock* block = store_buffer_block_; | |
234 store_buffer_block_ = NULL; | |
235 isolate_->store_buffer()->PushBlock(block); | |
236 } | |
237 | |
238 | |
237 CHA* Thread::cha() const { | 239 CHA* Thread::cha() const { |
238 ASSERT(isolate_ != NULL); | 240 ASSERT(isolate_ != NULL); |
239 return isolate_->cha_; | 241 return isolate_->cha_; |
240 } | 242 } |
241 | 243 |
242 | 244 |
243 void Thread::set_cha(CHA* value) { | 245 void Thread::set_cha(CHA* value) { |
244 ASSERT(isolate_ != NULL); | 246 ASSERT(isolate_ != NULL); |
245 isolate_->cha_ = value; | 247 isolate_->cha_ = value; |
246 } | 248 } |
(...skipping 12 matching lines...) Expand all Loading... | |
259 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ | 261 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ |
260 ASSERT((expr)->IsVMHeapObject()); \ | 262 ASSERT((expr)->IsVMHeapObject()); \ |
261 if (object.raw() == expr) return Thread::member_name##offset(); | 263 if (object.raw() == expr) return Thread::member_name##offset(); |
262 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) | 264 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) |
263 #undef COMPUTE_OFFSET | 265 #undef COMPUTE_OFFSET |
264 UNREACHABLE(); | 266 UNREACHABLE(); |
265 return -1; | 267 return -1; |
266 } | 268 } |
267 | 269 |
268 } // namespace dart | 270 } // namespace dart |
OLD | NEW |