| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 ThreadInterrupter::GetCurrentThreadState(); | 133 ThreadInterrupter::GetCurrentThreadState(); |
| 134 #if defined(DEBUG) | 134 #if defined(DEBUG) |
| 135 Isolate::CheckForDuplicateThreadState(thread_state); | 135 Isolate::CheckForDuplicateThreadState(thread_state); |
| 136 #endif | 136 #endif |
| 137 ASSERT(thread_state != NULL); | 137 ASSERT(thread_state != NULL); |
| 138 Profiler::BeginExecution(isolate); | 138 Profiler::BeginExecution(isolate); |
| 139 isolate->set_thread_state(thread_state); | 139 isolate->set_thread_state(thread_state); |
| 140 isolate->set_vm_tag(VMTag::kVMTagId); | 140 isolate->set_vm_tag(VMTag::kVMTagId); |
| 141 ASSERT(thread->store_buffer_block_ == NULL); | 141 ASSERT(thread->store_buffer_block_ == NULL); |
| 142 thread->store_buffer_block_ = isolate->store_buffer()->PopBlock(); | 142 thread->store_buffer_block_ = isolate->store_buffer()->PopBlock(); |
| 143 ASSERT(isolate->heap() != NULL); |
| 144 thread->heap_ = isolate->heap(); |
| 143 thread->Schedule(isolate); | 145 thread->Schedule(isolate); |
| 144 } | 146 } |
| 145 | 147 |
| 146 | 148 |
| 147 void Thread::ExitIsolate() { | 149 void Thread::ExitIsolate() { |
| 148 Thread* thread = Thread::Current(); | 150 Thread* thread = Thread::Current(); |
| 149 // TODO(koda): Audit callers; they should know whether they're in an isolate. | 151 // TODO(koda): Audit callers; they should know whether they're in an isolate. |
| 150 if (thread == NULL || thread->isolate() == NULL) return; | 152 if (thread == NULL || thread->isolate() == NULL) return; |
| 151 Isolate* isolate = thread->isolate(); | 153 Isolate* isolate = thread->isolate(); |
| 152 thread->Unschedule(); | 154 thread->Unschedule(); |
| 153 StoreBufferBlock* block = thread->store_buffer_block_; | 155 StoreBufferBlock* block = thread->store_buffer_block_; |
| 154 thread->store_buffer_block_ = NULL; | 156 thread->store_buffer_block_ = NULL; |
| 155 isolate->store_buffer()->PushBlock(block); | 157 isolate->store_buffer()->PushBlock(block); |
| 156 if (isolate->is_runnable()) { | 158 if (isolate->is_runnable()) { |
| 157 isolate->set_vm_tag(VMTag::kIdleTagId); | 159 isolate->set_vm_tag(VMTag::kIdleTagId); |
| 158 } else { | 160 } else { |
| 159 isolate->set_vm_tag(VMTag::kLoadWaitTagId); | 161 isolate->set_vm_tag(VMTag::kLoadWaitTagId); |
| 160 } | 162 } |
| 161 isolate->set_thread_state(NULL); | 163 isolate->set_thread_state(NULL); |
| 162 Profiler::EndExecution(isolate); | 164 Profiler::EndExecution(isolate); |
| 163 isolate->set_mutator_thread(NULL); | 165 isolate->set_mutator_thread(NULL); |
| 164 thread->isolate_ = NULL; | 166 thread->isolate_ = NULL; |
| 165 ASSERT(Isolate::Current() == NULL); | 167 ASSERT(Isolate::Current() == NULL); |
| 168 thread->heap_ = NULL; |
| 166 } | 169 } |
| 167 | 170 |
| 168 | 171 |
| 169 void Thread::EnterIsolateAsHelper(Isolate* isolate) { | 172 void Thread::EnterIsolateAsHelper(Isolate* isolate) { |
| 170 Thread* thread = Thread::Current(); | 173 Thread* thread = Thread::Current(); |
| 171 ASSERT(thread != NULL); | 174 ASSERT(thread != NULL); |
| 172 ASSERT(thread->isolate() == NULL); | 175 ASSERT(thread->isolate() == NULL); |
| 173 thread->isolate_ = isolate; | 176 thread->isolate_ = isolate; |
| 177 ASSERT(isolate->heap() != NULL); |
| 178 thread->heap_ = isolate->heap(); |
| 174 // Do not update isolate->mutator_thread, but perform sanity check: | 179 // Do not update isolate->mutator_thread, but perform sanity check: |
| 175 // this thread should not be both the main mutator and helper. | 180 // this thread should not be both the main mutator and helper. |
| 176 ASSERT(isolate->mutator_thread() != thread); | 181 ASSERT(isolate->mutator_thread() != thread); |
| 177 thread->Schedule(isolate); | 182 thread->Schedule(isolate); |
| 178 } | 183 } |
| 179 | 184 |
| 180 | 185 |
| 181 void Thread::ExitIsolateAsHelper() { | 186 void Thread::ExitIsolateAsHelper() { |
| 182 Thread* thread = Thread::Current(); | 187 Thread* thread = Thread::Current(); |
| 183 // If the helper thread chose to use the store buffer, check that it has | 188 // If the helper thread chose to use the store buffer, check that it has |
| 184 // already been flushed manually. | 189 // already been flushed manually. |
| 185 ASSERT(thread->store_buffer_block_ == NULL); | 190 ASSERT(thread->store_buffer_block_ == NULL); |
| 186 Isolate* isolate = thread->isolate(); | 191 Isolate* isolate = thread->isolate(); |
| 187 ASSERT(isolate != NULL); | 192 ASSERT(isolate != NULL); |
| 188 thread->Unschedule(); | 193 thread->Unschedule(); |
| 189 thread->isolate_ = NULL; | 194 thread->isolate_ = NULL; |
| 195 thread->heap_ = NULL; |
| 190 ASSERT(isolate->mutator_thread() != thread); | 196 ASSERT(isolate->mutator_thread() != thread); |
| 191 } | 197 } |
| 192 | 198 |
| 193 | 199 |
| 194 void Thread::PrepareForGC() { | 200 void Thread::PrepareForGC() { |
| 195 Thread* thread = Thread::Current(); | 201 Thread* thread = Thread::Current(); |
| 196 StoreBuffer* sb = thread->isolate()->store_buffer(); | 202 StoreBuffer* sb = thread->isolate()->store_buffer(); |
| 197 StoreBufferBlock* block = thread->store_buffer_block_; | 203 StoreBufferBlock* block = thread->store_buffer_block_; |
| 198 thread->store_buffer_block_ = NULL; | 204 thread->store_buffer_block_ = NULL; |
| 199 const bool kCheckThreshold = false; // Prevent scheduling another GC. | 205 const bool kCheckThreshold = false; // Prevent scheduling another GC. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ | 258 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ |
| 253 ASSERT((expr)->IsVMHeapObject()); \ | 259 ASSERT((expr)->IsVMHeapObject()); \ |
| 254 if (object.raw() == expr) return Thread::member_name##offset(); | 260 if (object.raw() == expr) return Thread::member_name##offset(); |
| 255 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) | 261 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) |
| 256 #undef COMPUTE_OFFSET | 262 #undef COMPUTE_OFFSET |
| 257 UNREACHABLE(); | 263 UNREACHABLE(); |
| 258 return -1; | 264 return -1; |
| 259 } | 265 } |
| 260 | 266 |
| 261 } // namespace dart | 267 } // namespace dart |
| OLD | NEW |