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

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

Issue 1260283007: Fix race and limit access to mutator_thread_. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove debug print. 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/isolate.cc ('k') | runtime/vm/thread_registry.cc » ('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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ASSERT(reg->Contains(this)); 116 ASSERT(reg->Contains(this));
117 reg->SaveStateFrom(this, state_); 117 reg->SaveStateFrom(this, state_);
118 ClearState(); 118 ClearState();
119 } 119 }
120 120
121 121
122 void Thread::EnterIsolate(Isolate* isolate) { 122 void Thread::EnterIsolate(Isolate* isolate) {
123 Thread* thread = Thread::Current(); 123 Thread* thread = Thread::Current();
124 ASSERT(thread != NULL); 124 ASSERT(thread != NULL);
125 ASSERT(thread->isolate() == NULL); 125 ASSERT(thread->isolate() == NULL);
126 ASSERT(isolate->mutator_thread() == NULL); 126 ASSERT(!isolate->HasMutatorThread());
127 thread->isolate_ = isolate; 127 thread->isolate_ = isolate;
128 isolate->set_mutator_thread(thread); 128 isolate->MakeCurrentThreadMutator(thread);
129 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow 129 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow
130 // helper threads concurrent with mutator. 130 // helper threads concurrent with mutator.
131 ASSERT(isolate->thread_state() == NULL); 131 ASSERT(isolate->thread_state() == NULL);
132 InterruptableThreadState* thread_state = 132 InterruptableThreadState* thread_state =
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);
(...skipping 16 matching lines...) Expand all
155 StoreBufferBlock* block = thread->store_buffer_block_; 155 StoreBufferBlock* block = thread->store_buffer_block_;
156 thread->store_buffer_block_ = NULL; 156 thread->store_buffer_block_ = NULL;
157 isolate->store_buffer()->PushBlock(block); 157 isolate->store_buffer()->PushBlock(block);
158 if (isolate->is_runnable()) { 158 if (isolate->is_runnable()) {
159 isolate->set_vm_tag(VMTag::kIdleTagId); 159 isolate->set_vm_tag(VMTag::kIdleTagId);
160 } else { 160 } else {
161 isolate->set_vm_tag(VMTag::kLoadWaitTagId); 161 isolate->set_vm_tag(VMTag::kLoadWaitTagId);
162 } 162 }
163 isolate->set_thread_state(NULL); 163 isolate->set_thread_state(NULL);
164 Profiler::EndExecution(isolate); 164 Profiler::EndExecution(isolate);
165 isolate->set_mutator_thread(NULL); 165 isolate->ClearMutatorThread();
166 thread->isolate_ = NULL; 166 thread->isolate_ = NULL;
167 ASSERT(Isolate::Current() == NULL); 167 ASSERT(Isolate::Current() == NULL);
168 thread->heap_ = NULL; 168 thread->heap_ = NULL;
169 } 169 }
170 170
171 171
172 void Thread::EnterIsolateAsHelper(Isolate* isolate) { 172 void Thread::EnterIsolateAsHelper(Isolate* isolate) {
173 Thread* thread = Thread::Current(); 173 Thread* thread = Thread::Current();
174 ASSERT(thread != NULL); 174 ASSERT(thread != NULL);
175 ASSERT(thread->isolate() == NULL); 175 ASSERT(thread->isolate() == NULL);
176 thread->isolate_ = isolate; 176 thread->isolate_ = isolate;
177 ASSERT(isolate->heap() != NULL); 177 ASSERT(isolate->heap() != NULL);
178 thread->heap_ = isolate->heap(); 178 thread->heap_ = isolate->heap();
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->MutatorThreadIsCurrentThread());
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->isolate_ = NULL; 194 thread->isolate_ = NULL;
195 thread->heap_ = NULL; 195 thread->heap_ = NULL;
196 ASSERT(isolate->mutator_thread() != thread); 196 ASSERT(!isolate->MutatorThreadIsCurrentThread());
197 } 197 }
198 198
199 199
200 void Thread::PrepareForGC() { 200 void Thread::PrepareForGC() {
201 Thread* thread = Thread::Current(); 201 Thread* thread = Thread::Current();
202 StoreBuffer* sb = thread->isolate()->store_buffer(); 202 StoreBuffer* sb = thread->isolate()->store_buffer();
203 StoreBufferBlock* block = thread->store_buffer_block_; 203 StoreBufferBlock* block = thread->store_buffer_block_;
204 thread->store_buffer_block_ = NULL; 204 thread->store_buffer_block_ = NULL;
205 const bool kCheckThreshold = false; // Prevent scheduling another GC. 205 const bool kCheckThreshold = false; // Prevent scheduling another GC.
206 sb->PushBlock(block, kCheckThreshold); 206 sb->PushBlock(block, kCheckThreshold);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ 258 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \
259 ASSERT((expr)->IsVMHeapObject()); \ 259 ASSERT((expr)->IsVMHeapObject()); \
260 if (object.raw() == expr) return Thread::member_name##offset(); 260 if (object.raw() == expr) return Thread::member_name##offset();
261 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) 261 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET)
262 #undef COMPUTE_OFFSET 262 #undef COMPUTE_OFFSET
263 UNREACHABLE(); 263 UNREACHABLE();
264 return -1; 264 return -1;
265 } 265 }
266 266
267 } // namespace dart 267 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/thread_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698