Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: runtime/vm/thread.cc

Issue 1261923008: Begin migration of InterruptableThreadState into Thread. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Parentheses. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/thread.h ('k') | runtime/vm/thread_interrupter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/os_thread.h" 11 #include "vm/os_thread.h"
12 #include "vm/profiler.h" 12 #include "vm/profiler.h"
13 #include "vm/stub_code.h" 13 #include "vm/stub_code.h"
14 #include "vm/thread_interrupter.h" 14 #include "vm/thread_interrupter.h"
15 #include "vm/thread_registry.h" 15 #include "vm/thread_registry.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 // The single thread local key which stores all the thread local data 19 // The single thread local key which stores all the thread local data
20 // for a thread. 20 // for a thread.
21 // TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_?
22 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey; 21 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey;
23 22
24 23
25 static void DeleteThread(void* thread) { 24 static void DeleteThread(void* thread) {
26 delete reinterpret_cast<Thread*>(thread); 25 delete reinterpret_cast<Thread*>(thread);
27 } 26 }
28 27
29 28
30 Thread::~Thread() { 29 Thread::~Thread() {
31 // We should cleanly exit any isolate before destruction. 30 // We should cleanly exit any isolate before destruction.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 118 }
120 119
121 120
122 void Thread::EnterIsolate(Isolate* isolate) { 121 void Thread::EnterIsolate(Isolate* isolate) {
123 Thread* thread = Thread::Current(); 122 Thread* thread = Thread::Current();
124 ASSERT(thread != NULL); 123 ASSERT(thread != NULL);
125 ASSERT(thread->isolate() == NULL); 124 ASSERT(thread->isolate() == NULL);
126 ASSERT(isolate->mutator_thread() == NULL); 125 ASSERT(isolate->mutator_thread() == NULL);
127 thread->isolate_ = isolate; 126 thread->isolate_ = isolate;
128 isolate->set_mutator_thread(thread); 127 isolate->set_mutator_thread(thread);
129 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow 128 ASSERT(thread->thread_state() == NULL);
130 // helper threads concurrent with mutator.
131 ASSERT(isolate->thread_state() == NULL);
132 InterruptableThreadState* thread_state = 129 InterruptableThreadState* thread_state =
133 ThreadInterrupter::GetCurrentThreadState(); 130 ThreadInterrupter::GetCurrentThreadState();
134 #if defined(DEBUG) 131 #if defined(DEBUG)
132 thread->set_thread_state(NULL); // Exclude thread itself from the dupe check.
135 Isolate::CheckForDuplicateThreadState(thread_state); 133 Isolate::CheckForDuplicateThreadState(thread_state);
134 thread->set_thread_state(thread_state);
136 #endif 135 #endif
137 ASSERT(thread_state != NULL); 136 ASSERT(thread_state != NULL);
137 // TODO(koda): Migrate profiler interface to use Thread.
138 Profiler::BeginExecution(isolate); 138 Profiler::BeginExecution(isolate);
139 isolate->set_thread_state(thread_state);
140 isolate->set_vm_tag(VMTag::kVMTagId); 139 isolate->set_vm_tag(VMTag::kVMTagId);
141 ASSERT(thread->store_buffer_block_ == NULL); 140 ASSERT(thread->store_buffer_block_ == NULL);
142 thread->store_buffer_block_ = isolate->store_buffer()->PopBlock(); 141 thread->store_buffer_block_ = isolate->store_buffer()->PopBlock();
143 ASSERT(isolate->heap() != NULL); 142 ASSERT(isolate->heap() != NULL);
144 thread->heap_ = isolate->heap(); 143 thread->heap_ = isolate->heap();
145 thread->Schedule(isolate); 144 thread->Schedule(isolate);
146 } 145 }
147 146
148 147
149 void Thread::ExitIsolate() { 148 void Thread::ExitIsolate() {
150 Thread* thread = Thread::Current(); 149 Thread* thread = Thread::Current();
151 // 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.
152 if (thread == NULL || thread->isolate() == NULL) return; 151 if (thread == NULL || thread->isolate() == NULL) return;
153 Isolate* isolate = thread->isolate(); 152 Isolate* isolate = thread->isolate();
154 thread->Unschedule(); 153 thread->Unschedule();
155 StoreBufferBlock* block = thread->store_buffer_block_; 154 StoreBufferBlock* block = thread->store_buffer_block_;
156 thread->store_buffer_block_ = NULL; 155 thread->store_buffer_block_ = NULL;
157 isolate->store_buffer()->PushBlock(block); 156 isolate->store_buffer()->PushBlock(block);
158 if (isolate->is_runnable()) { 157 if (isolate->is_runnable()) {
159 isolate->set_vm_tag(VMTag::kIdleTagId); 158 isolate->set_vm_tag(VMTag::kIdleTagId);
160 } else { 159 } else {
161 isolate->set_vm_tag(VMTag::kLoadWaitTagId); 160 isolate->set_vm_tag(VMTag::kLoadWaitTagId);
162 } 161 }
163 isolate->set_thread_state(NULL);
164 Profiler::EndExecution(isolate); 162 Profiler::EndExecution(isolate);
163 thread->set_thread_state(NULL);
165 isolate->set_mutator_thread(NULL); 164 isolate->set_mutator_thread(NULL);
166 thread->isolate_ = NULL; 165 thread->isolate_ = NULL;
167 ASSERT(Isolate::Current() == NULL); 166 ASSERT(Isolate::Current() == NULL);
168 thread->heap_ = NULL; 167 thread->heap_ = NULL;
169 } 168 }
170 169
171 170
172 void Thread::EnterIsolateAsHelper(Isolate* isolate) { 171 void Thread::EnterIsolateAsHelper(Isolate* isolate) {
173 Thread* thread = Thread::Current(); 172 Thread* thread = Thread::Current();
174 ASSERT(thread != NULL); 173 ASSERT(thread != NULL);
175 ASSERT(thread->isolate() == NULL); 174 ASSERT(thread->isolate() == NULL);
176 thread->isolate_ = isolate; 175 thread->isolate_ = isolate;
177 ASSERT(isolate->heap() != NULL); 176 ASSERT(isolate->heap() != NULL);
178 thread->heap_ = isolate->heap(); 177 thread->heap_ = isolate->heap();
178 ASSERT(thread->thread_state() == NULL);
179 // Do not update isolate->mutator_thread, but perform sanity check: 179 // Do not update isolate->mutator_thread, but perform sanity check:
180 // this thread should not be both the main mutator and helper. 180 // this thread should not be both the main mutator and helper.
181 ASSERT(isolate->mutator_thread() != thread); 181 ASSERT(isolate->mutator_thread() != thread);
182 thread->Schedule(isolate); 182 thread->Schedule(isolate);
183 } 183 }
184 184
185 185
186 void Thread::ExitIsolateAsHelper() { 186 void Thread::ExitIsolateAsHelper() {
187 Thread* thread = Thread::Current(); 187 Thread* thread = Thread::Current();
188 // 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
189 // already been flushed manually. 189 // already been flushed manually.
190 ASSERT(thread->store_buffer_block_ == NULL); 190 ASSERT(thread->store_buffer_block_ == NULL);
191 Isolate* isolate = thread->isolate(); 191 Isolate* isolate = thread->isolate();
192 ASSERT(isolate != NULL); 192 ASSERT(isolate != NULL);
193 thread->Unschedule(); 193 thread->Unschedule();
194 thread->set_thread_state(NULL);
194 thread->isolate_ = NULL; 195 thread->isolate_ = NULL;
195 thread->heap_ = NULL; 196 thread->heap_ = NULL;
196 ASSERT(isolate->mutator_thread() != thread); 197 ASSERT(isolate->mutator_thread() != thread);
197 } 198 }
198 199
199 200
200 void Thread::PrepareForGC() { 201 void Thread::PrepareForGC() {
201 Thread* thread = Thread::Current(); 202 Thread* thread = Thread::Current();
202 StoreBuffer* sb = thread->isolate()->store_buffer(); 203 StoreBuffer* sb = thread->isolate()->store_buffer();
203 StoreBufferBlock* block = thread->store_buffer_block_; 204 StoreBufferBlock* block = thread->store_buffer_block_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ 259 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \
259 ASSERT((expr)->IsVMHeapObject()); \ 260 ASSERT((expr)->IsVMHeapObject()); \
260 if (object.raw() == expr) return Thread::member_name##offset(); 261 if (object.raw() == expr) return Thread::member_name##offset();
261 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) 262 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET)
262 #undef COMPUTE_OFFSET 263 #undef COMPUTE_OFFSET
263 UNREACHABLE(); 264 UNREACHABLE();
264 return -1; 265 return -1;
265 } 266 }
266 267
267 } // namespace dart 268 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.h ('k') | runtime/vm/thread_interrupter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698