Chromium Code Reviews| 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/object.h" | |
| 8 #include "vm/os_thread.h" | 9 #include "vm/os_thread.h" |
| 9 #include "vm/profiler.h" | 10 #include "vm/profiler.h" |
| 11 #include "vm/stub_code.h" | |
| 10 #include "vm/thread_interrupter.h" | 12 #include "vm/thread_interrupter.h" |
| 11 | 13 |
| 12 | 14 |
| 13 namespace dart { | 15 namespace dart { |
| 14 | 16 |
| 15 // The single thread local key which stores all the thread local data | 17 // The single thread local key which stores all the thread local data |
| 16 // for a thread. | 18 // for a thread. |
| 17 // TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_? | 19 // TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_? |
| 18 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey; | 20 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey; |
| 19 | 21 |
| 20 | 22 |
| 21 static void DeleteThread(void* thread) { | 23 static void DeleteThread(void* thread) { |
| 22 delete reinterpret_cast<Thread*>(thread); | 24 delete reinterpret_cast<Thread*>(thread); |
| 23 } | 25 } |
| 24 | 26 |
| 25 | 27 |
| 26 void Thread::InitOnce() { | 28 void Thread::InitOnceBeforeIsolate() { |
| 27 ASSERT(thread_key_ == OSThread::kUnsetThreadLocalKey); | 29 ASSERT(thread_key_ == OSThread::kUnsetThreadLocalKey); |
| 28 thread_key_ = OSThread::CreateThreadLocal(DeleteThread); | 30 thread_key_ = OSThread::CreateThreadLocal(DeleteThread); |
| 29 ASSERT(thread_key_ != OSThread::kUnsetThreadLocalKey); | 31 ASSERT(thread_key_ != OSThread::kUnsetThreadLocalKey); |
| 32 ASSERT(Thread::Current() == NULL); | |
| 33 // Postpone initialization of VM constants for this first thread. | |
| 34 SetCurrent(new Thread(false)); | |
| 30 } | 35 } |
| 31 | 36 |
| 32 | 37 |
| 38 void Thread::InitOnceAfterObjectAndStubCode() { | |
| 39 Thread* thread = Thread::Current(); | |
| 40 ASSERT(thread != NULL); | |
| 41 ASSERT(thread->isolate() == Dart::vm_isolate()); | |
| 42 thread->InitVMConstants(); | |
| 43 } | |
| 44 | |
| 45 | |
| 33 void Thread::SetCurrent(Thread* current) { | 46 void Thread::SetCurrent(Thread* current) { |
| 34 OSThread::SetThreadLocal(thread_key_, reinterpret_cast<uword>(current)); | 47 OSThread::SetThreadLocal(thread_key_, reinterpret_cast<uword>(current)); |
| 35 } | 48 } |
| 36 | 49 |
| 37 | 50 |
| 38 void Thread::EnsureInit() { | 51 void Thread::EnsureInit() { |
| 39 if (Thread::Current() == NULL) { | 52 if (Thread::Current() == NULL) { |
| 40 SetCurrent(new Thread()); | 53 SetCurrent(new Thread()); |
| 41 } | 54 } |
| 42 } | 55 } |
| 43 | 56 |
| 44 | 57 |
| 45 #if defined(TARGET_OS_WINDOWS) | 58 #if defined(TARGET_OS_WINDOWS) |
| 46 void Thread::CleanUp() { | 59 void Thread::CleanUp() { |
| 47 Thread* current = Current(); | 60 Thread* current = Current(); |
| 48 if (current != NULL) { | 61 if (current != NULL) { |
| 49 delete current; | 62 delete current; |
| 50 } | 63 } |
| 51 SetCurrent(NULL); | 64 SetCurrent(NULL); |
| 52 } | 65 } |
| 53 #endif | 66 #endif |
| 54 | 67 |
| 55 | 68 |
| 69 Thread::Thread(bool init_vm_constants) | |
| 70 : isolate_(NULL), | |
| 71 store_buffer_block_(NULL) { | |
| 72 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ | |
| 73 member_name = default_init_value; | |
|
koda
2015/07/08 13:13:10
Too much indentation.
Florian Schneider
2015/07/08 13:31:35
Done.
| |
| 74 CACHED_CONSTANTS_LIST(DEFAULT_INIT) | |
| 75 #undef DEFAULT_INIT | |
| 76 if (init_vm_constants) { | |
| 77 InitVMConstants(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 | |
| 82 void Thread::InitVMConstants() { | |
| 83 #define INIT_VALUE(type_name, member_name, init_expr, default_init_value) \ | |
| 84 ASSERT(member_name == default_init_value); \ | |
| 85 member_name = init_expr; | |
|
koda
2015/07/08 13:13:10
For the objects, we should probably ASSERT they ar
Florian Schneider
2015/07/08 13:31:35
Done.
Asserting using IsVMHeapObject does not wor
koda
2015/07/08 13:45:55
Ah. This should go away soon, but for now you can
koda
2015/07/08 13:54:26
... although at second thought, that might actuall
| |
| 86 CACHED_CONSTANTS_LIST(INIT_VALUE) | |
| 87 #undef INIT_VALUE | |
| 88 } | |
| 89 | |
| 90 | |
| 56 void Thread::EnterIsolate(Isolate* isolate) { | 91 void Thread::EnterIsolate(Isolate* isolate) { |
| 57 Thread* thread = Thread::Current(); | 92 Thread* thread = Thread::Current(); |
| 58 ASSERT(thread != NULL); | 93 ASSERT(thread != NULL); |
| 59 ASSERT(thread->isolate() == NULL); | 94 ASSERT(thread->isolate() == NULL); |
| 60 ASSERT(isolate->mutator_thread() == NULL); | 95 ASSERT(isolate->mutator_thread() == NULL); |
| 61 thread->isolate_ = isolate; | 96 thread->isolate_ = isolate; |
| 62 isolate->set_mutator_thread(thread); | 97 isolate->set_mutator_thread(thread); |
| 63 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow | 98 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow |
| 64 // helper threads concurrent with mutator. | 99 // helper threads concurrent with mutator. |
| 65 ASSERT(isolate->thread_state() == NULL); | 100 ASSERT(isolate->thread_state() == NULL); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 ASSERT(isolate_ != NULL); | 196 ASSERT(isolate_ != NULL); |
| 162 return isolate_->cha_; | 197 return isolate_->cha_; |
| 163 } | 198 } |
| 164 | 199 |
| 165 | 200 |
| 166 void Thread::set_cha(CHA* value) { | 201 void Thread::set_cha(CHA* value) { |
| 167 ASSERT(isolate_ != NULL); | 202 ASSERT(isolate_ != NULL); |
| 168 isolate_->cha_ = value; | 203 isolate_->cha_ = value; |
| 169 } | 204 } |
| 170 | 205 |
| 206 | |
| 207 bool Thread::CanLoadFromThread(const Object& object) { | |
| 208 #define CHECK_OBJECT(type_name, member_name, expr, default_init_value) \ | |
| 209 if (object.raw() == expr) return true; | |
| 210 CACHED_VM_OBJECTS_LIST(CHECK_OBJECT) | |
| 211 #undef CHECK_OBJECT | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 | |
| 216 intptr_t Thread::OffsetFromThread(const Object& object) { | |
| 217 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ | |
| 218 if (object.raw() == expr) return Thread::member_name##offset(); | |
| 219 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) | |
| 220 #undef COMPUTE_OFFSET | |
| 221 UNREACHABLE(); | |
| 222 return -1; | |
| 223 } | |
| 224 | |
| 171 } // namespace dart | 225 } // namespace dart |
| OLD | NEW |