| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (current != NULL) { | 68 if (current != NULL) { |
| 69 delete current; | 69 delete current; |
| 70 } | 70 } |
| 71 SetCurrent(NULL); | 71 SetCurrent(NULL); |
| 72 } | 72 } |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 | 75 |
| 76 Thread::Thread(bool init_vm_constants) | 76 Thread::Thread(bool init_vm_constants) |
| 77 : isolate_(NULL), | 77 : isolate_(NULL), |
| 78 store_buffer_block_(NULL) { | 78 store_buffer_block_(NULL), |
| 79 pass_safepoint_(kNoSafepointId) { |
| 79 ClearState(); | 80 ClearState(); |
| 80 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ | 81 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ |
| 81 member_name = default_init_value; | 82 member_name = default_init_value; |
| 82 CACHED_CONSTANTS_LIST(DEFAULT_INIT) | 83 CACHED_CONSTANTS_LIST(DEFAULT_INIT) |
| 83 #undef DEFAULT_INIT | 84 #undef DEFAULT_INIT |
| 84 if (init_vm_constants) { | 85 if (init_vm_constants) { |
| 85 InitVMConstants(); | 86 InitVMConstants(); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } else { | 162 } else { |
| 162 isolate->set_vm_tag(VMTag::kLoadWaitTagId); | 163 isolate->set_vm_tag(VMTag::kLoadWaitTagId); |
| 163 } | 164 } |
| 164 isolate->ClearMutatorThread(); | 165 isolate->ClearMutatorThread(); |
| 165 thread->isolate_ = NULL; | 166 thread->isolate_ = NULL; |
| 166 ASSERT(Isolate::Current() == NULL); | 167 ASSERT(Isolate::Current() == NULL); |
| 167 thread->heap_ = NULL; | 168 thread->heap_ = NULL; |
| 168 } | 169 } |
| 169 | 170 |
| 170 | 171 |
| 171 void Thread::EnterIsolateAsHelper(Isolate* isolate) { | 172 void Thread::EnterIsolateAsHelper(Isolate* isolate, |
| 173 SafepointId pass_safepoint) { |
| 172 Thread* thread = Thread::Current(); | 174 Thread* thread = Thread::Current(); |
| 173 ASSERT(thread != NULL); | 175 ASSERT(thread != NULL); |
| 174 ASSERT(thread->isolate() == NULL); | 176 ASSERT(thread->isolate() == NULL); |
| 175 thread->isolate_ = isolate; | 177 thread->isolate_ = isolate; |
| 178 thread->pass_safepoint_ = pass_safepoint; |
| 176 ASSERT(isolate->heap() != NULL); | 179 ASSERT(isolate->heap() != NULL); |
| 177 thread->heap_ = isolate->heap(); | 180 thread->heap_ = isolate->heap(); |
| 178 ASSERT(thread->thread_state() == NULL); | 181 ASSERT(thread->thread_state() == NULL); |
| 179 // Do not update isolate->mutator_thread, but perform sanity check: | 182 // Do not update isolate->mutator_thread, but perform sanity check: |
| 180 // this thread should not be both the main mutator and helper. | 183 // this thread should not be both the main mutator and helper. |
| 181 ASSERT(!isolate->MutatorThreadIsCurrentThread()); | 184 ASSERT(!isolate->MutatorThreadIsCurrentThread()); |
| 182 thread->Schedule(isolate); | 185 thread->Schedule(isolate); |
| 183 } | 186 } |
| 184 | 187 |
| 185 | 188 |
| 186 void Thread::ExitIsolateAsHelper() { | 189 void Thread::ExitIsolateAsHelper() { |
| 187 Thread* thread = Thread::Current(); | 190 Thread* thread = Thread::Current(); |
| 188 // If the helper thread chose to use the store buffer, check that it has | 191 // If the helper thread chose to use the store buffer, check that it has |
| 189 // already been flushed manually. | 192 // already been flushed manually. |
| 190 ASSERT(thread->store_buffer_block_ == NULL); | 193 ASSERT(thread->store_buffer_block_ == NULL); |
| 191 Isolate* isolate = thread->isolate(); | 194 Isolate* isolate = thread->isolate(); |
| 192 ASSERT(isolate != NULL); | 195 ASSERT(isolate != NULL); |
| 193 thread->Unschedule(); | 196 thread->Unschedule(); |
| 194 thread->set_thread_state(NULL); | 197 thread->set_thread_state(NULL); |
| 198 thread->pass_safepoint_ = kNoSafepointId; |
| 195 thread->isolate_ = NULL; | 199 thread->isolate_ = NULL; |
| 196 thread->heap_ = NULL; | 200 thread->heap_ = NULL; |
| 197 ASSERT(!isolate->MutatorThreadIsCurrentThread()); | 201 ASSERT(!isolate->MutatorThreadIsCurrentThread()); |
| 198 } | 202 } |
| 199 | 203 |
| 200 | 204 |
| 201 void Thread::PrepareForGC() { | 205 void Thread::PrepareForGC() { |
| 202 Thread* thread = Thread::Current(); | 206 Thread* thread = Thread::Current(); |
| 203 StoreBuffer* sb = thread->isolate()->store_buffer(); | 207 StoreBuffer* sb = thread->isolate()->store_buffer(); |
| 204 StoreBufferBlock* block = thread->store_buffer_block_; | 208 StoreBufferBlock* block = thread->store_buffer_block_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ | 263 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ |
| 260 ASSERT((expr)->IsVMHeapObject()); \ | 264 ASSERT((expr)->IsVMHeapObject()); \ |
| 261 if (object.raw() == expr) return Thread::member_name##offset(); | 265 if (object.raw() == expr) return Thread::member_name##offset(); |
| 262 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) | 266 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) |
| 263 #undef COMPUTE_OFFSET | 267 #undef COMPUTE_OFFSET |
| 264 UNREACHABLE(); | 268 UNREACHABLE(); |
| 265 return -1; | 269 return -1; |
| 266 } | 270 } |
| 267 | 271 |
| 268 } // namespace dart | 272 } // namespace dart |
| OLD | NEW |