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

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

Issue 1276753003: Correct thread state update order (fixes Windows crashes). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Mac, Android. 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 | « no previous file | runtime/vm/thread_interrupter_android.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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 120
121 void Thread::EnterIsolate(Isolate* isolate) { 121 void Thread::EnterIsolate(Isolate* isolate) {
122 Thread* thread = Thread::Current(); 122 Thread* thread = Thread::Current();
123 ASSERT(thread != NULL); 123 ASSERT(thread != NULL);
124 ASSERT(thread->isolate() == NULL); 124 ASSERT(thread->isolate() == NULL);
125 ASSERT(!isolate->HasMutatorThread()); 125 ASSERT(!isolate->HasMutatorThread());
126 thread->isolate_ = isolate; 126 thread->isolate_ = isolate;
127 isolate->MakeCurrentThreadMutator(thread); 127 isolate->MakeCurrentThreadMutator(thread);
128 isolate->set_vm_tag(VMTag::kVMTagId);
129 ASSERT(thread->store_buffer_block_ == NULL);
130 thread->store_buffer_block_ = isolate->store_buffer()->PopNonFullBlock();
131 ASSERT(isolate->heap() != NULL);
132 thread->heap_ = isolate->heap();
133 thread->Schedule(isolate);
128 ASSERT(thread->thread_state() == NULL); 134 ASSERT(thread->thread_state() == NULL);
129 InterruptableThreadState* thread_state = 135 InterruptableThreadState* thread_state =
130 ThreadInterrupter::GetCurrentThreadState(); 136 ThreadInterrupter::GetCurrentThreadState();
131 #if defined(DEBUG) 137 #if defined(DEBUG)
132 thread->set_thread_state(NULL); // Exclude thread itself from the dupe check. 138 thread->set_thread_state(NULL); // Exclude thread itself from the dupe check.
133 Isolate::CheckForDuplicateThreadState(thread_state); 139 Isolate::CheckForDuplicateThreadState(thread_state);
134 thread->set_thread_state(thread_state); 140 thread->set_thread_state(thread_state);
135 #endif 141 #endif
136 ASSERT(thread_state != NULL); 142 ASSERT(thread_state != NULL);
137 // TODO(koda): Migrate profiler interface to use Thread. 143 // TODO(koda): Migrate profiler interface to use Thread.
138 Profiler::BeginExecution(isolate); 144 Profiler::BeginExecution(isolate);
139 isolate->set_vm_tag(VMTag::kVMTagId);
140 ASSERT(thread->store_buffer_block_ == NULL);
141 thread->store_buffer_block_ = isolate->store_buffer()->PopNonFullBlock();
142 ASSERT(isolate->heap() != NULL);
143 thread->heap_ = isolate->heap();
144 thread->Schedule(isolate);
145 } 145 }
146 146
147 147
148 void Thread::ExitIsolate() { 148 void Thread::ExitIsolate() {
149 Thread* thread = Thread::Current(); 149 Thread* thread = Thread::Current();
150 // 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.
151 if (thread == NULL || thread->isolate() == NULL) return; 151 if (thread == NULL || thread->isolate() == NULL) return;
152 Isolate* isolate = thread->isolate(); 152 Isolate* isolate = thread->isolate();
153 Profiler::EndExecution(isolate);
154 thread->set_thread_state(NULL);
153 thread->Unschedule(); 155 thread->Unschedule();
154 StoreBufferBlock* block = thread->store_buffer_block_; 156 StoreBufferBlock* block = thread->store_buffer_block_;
155 thread->store_buffer_block_ = NULL; 157 thread->store_buffer_block_ = NULL;
156 isolate->store_buffer()->PushBlock(block); 158 isolate->store_buffer()->PushBlock(block);
157 if (isolate->is_runnable()) { 159 if (isolate->is_runnable()) {
158 isolate->set_vm_tag(VMTag::kIdleTagId); 160 isolate->set_vm_tag(VMTag::kIdleTagId);
159 } else { 161 } else {
160 isolate->set_vm_tag(VMTag::kLoadWaitTagId); 162 isolate->set_vm_tag(VMTag::kLoadWaitTagId);
161 } 163 }
162 Profiler::EndExecution(isolate);
163 thread->set_thread_state(NULL);
164 isolate->ClearMutatorThread(); 164 isolate->ClearMutatorThread();
165 thread->isolate_ = NULL; 165 thread->isolate_ = NULL;
166 ASSERT(Isolate::Current() == NULL); 166 ASSERT(Isolate::Current() == NULL);
167 thread->heap_ = NULL; 167 thread->heap_ = NULL;
168 } 168 }
169 169
170 170
171 void Thread::EnterIsolateAsHelper(Isolate* isolate) { 171 void Thread::EnterIsolateAsHelper(Isolate* isolate) {
172 Thread* thread = Thread::Current(); 172 Thread* thread = Thread::Current();
173 ASSERT(thread != NULL); 173 ASSERT(thread != NULL);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \ 259 #define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \
260 ASSERT((expr)->IsVMHeapObject()); \ 260 ASSERT((expr)->IsVMHeapObject()); \
261 if (object.raw() == expr) return Thread::member_name##offset(); 261 if (object.raw() == expr) return Thread::member_name##offset();
262 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET) 262 CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET)
263 #undef COMPUTE_OFFSET 263 #undef COMPUTE_OFFSET
264 UNREACHABLE(); 264 UNREACHABLE();
265 return -1; 265 return -1;
266 } 266 }
267 267
268 } // namespace dart 268 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/thread_interrupter_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698