Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/isolate.h" | 6 #include "vm/isolate.h" |
| 7 #include "vm/lockers.h" | 7 #include "vm/lockers.h" |
| 8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 #include "vm/profiler.h" | 9 #include "vm/profiler.h" |
| 10 #include "vm/thread_pool.h" | 10 #include "vm/thread_pool.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 264 |
| 265 virtual void Run() { | 265 virtual void Run() { |
| 266 Thread::EnterIsolateAsHelper(isolate_); | 266 Thread::EnterIsolateAsHelper(isolate_); |
| 267 { | 267 { |
| 268 MutexLocker ml(mutex_); | 268 MutexLocker ml(mutex_); |
| 269 ++*expected_count_; | 269 ++*expected_count_; |
| 270 } | 270 } |
| 271 for (int i = 0; ; ++i) { | 271 for (int i = 0; ; ++i) { |
| 272 Thread* thread = Thread::Current(); | 272 Thread* thread = Thread::Current(); |
| 273 StackZone stack_zone(thread); | 273 StackZone stack_zone(thread); |
| 274 Zone* zone = thread->zone(); | 274 Zone* zone = thread->zone(); |
| 275 HANDLESCOPE(thread); | 275 HANDLESCOPE(thread); |
| 276 const intptr_t kUniqueSmi = 928327281; | 276 const intptr_t kUniqueSmi = 928327281; |
| 277 Smi& smi = Smi::Handle(zone, Smi::New(kUniqueSmi)); | 277 Smi& smi = Smi::Handle(zone, Smi::New(kUniqueSmi)); |
| 278 if ((i % 100) != 0) { | 278 if ((i % 100) != 0) { |
| 279 // Usually, we just cooperate. | 279 // Usually, we just cooperate. |
| 280 isolate_->thread_registry()->CheckSafepoint(); | 280 isolate_->thread_registry()->CheckSafepoint(); |
| 281 } else { | 281 } else { |
| 282 // But occasionally, organize a rendezvous. | 282 // But occasionally, organize a rendezvous. |
| 283 isolate_->thread_registry()->SafepointThreads(); | 283 isolate_->thread_registry()->SafepointThreads(); |
| 284 ObjectCounter counter(isolate_, &smi); | 284 ObjectCounter counter(isolate_, &smi); |
| 285 isolate_->thread_registry()->VisitObjectPointers(&counter); | 285 isolate_->thread_registry()->VisitObjectPointers(&counter); |
| 286 { | |
| 287 MutexLocker ml(mutex_); | |
| 288 EXPECT_EQ(*expected_count_, counter.count()); | |
| 289 } | |
| 290 UserTag& tag = UserTag::Handle(zone, isolate_->current_tag()); | |
| 291 if (tag.raw() != isolate_->default_tag()) { | |
| 292 String& label = String::Handle(zone, tag.label()); | |
| 293 EXPECT(label.Equals("foo")); | |
| 294 // if this is the first time. | |
| 295 MutexLocker ml(mutex_); | |
| 296 if (*expected_count_ == kTaskCount && !local_done_) { | |
| 297 // Success for the first time! Remember that we are done, and | |
| 298 // update the total count. | |
| 299 local_done_ = true; | |
| 300 ++*total_done_; | |
| 301 } | |
| 302 } | |
| 303 isolate_->thread_registry()->ResumeAllThreads(); | |
| 304 } | |
| 305 // Check whether everyone is done. | |
| 306 { | 286 { |
| 307 MutexLocker ml(mutex_); | 287 MutexLocker ml(mutex_); |
| 308 if (*total_done_ == kTaskCount) { | 288 EXPECT_EQ(*expected_count_, counter.count()); |
| 309 break; | 289 } |
| 290 UserTag& tag = UserTag::Handle(zone, isolate_->current_tag()); | |
| 291 if (tag.raw() != isolate_->default_tag()) { | |
| 292 String& label = String::Handle(zone, tag.label()); | |
| 293 EXPECT(label.Equals("foo")); | |
|
Ivan Posva
2015/08/03 16:07:46
Isn't this a potential source for flaky failures d
koda
2015/08/03 16:15:47
Compilation changes the VM tag, not the user tag.
| |
| 294 MutexLocker ml(mutex_); | |
| 295 if (*expected_count_ == kTaskCount && !local_done_) { | |
| 296 // Success for the first time! Remember that we are done, and | |
| 297 // update the total count. | |
| 298 local_done_ = true; | |
| 299 ++*total_done_; | |
| 310 } | 300 } |
| 311 } | 301 } |
| 302 isolate_->thread_registry()->ResumeAllThreads(); | |
|
Ivan Posva
2015/08/03 16:07:46
Is there a surviving All here?
koda
2015/08/03 16:15:47
Yes. I can rename it in a future CL.
| |
| 303 } | |
| 304 // Check whether everyone is done. | |
| 305 { | |
| 306 MutexLocker ml(mutex_); | |
| 307 if (*total_done_ == kTaskCount) { | |
| 308 // Another task might be at SafepointThreads when resuming. Ensure its | |
| 309 // expectation reflects reality, since we pop our handles here. | |
| 310 --*expected_count_; | |
| 311 break; | |
| 312 } | |
| 313 } | |
| 312 } | 314 } |
| 313 Thread::ExitIsolateAsHelper(); | 315 Thread::ExitIsolateAsHelper(); |
| 314 { | 316 { |
| 315 MutexLocker ml(mutex_); | 317 MutexLocker ml(mutex_); |
| 316 ++*exited_; | 318 ++*exited_; |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 private: | 322 private: |
| 321 Isolate* isolate_; | 323 Isolate* isolate_; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 while (true) { | 442 while (true) { |
| 441 isolate->thread_registry()->CheckSafepoint(); | 443 isolate->thread_registry()->CheckSafepoint(); |
| 442 MutexLocker ml(&mutex); | 444 MutexLocker ml(&mutex); |
| 443 if (exited == SafepointTestTask::kTaskCount) { | 445 if (exited == SafepointTestTask::kTaskCount) { |
| 444 break; | 446 break; |
| 445 } | 447 } |
| 446 } | 448 } |
| 447 } | 449 } |
| 448 | 450 |
| 449 } // namespace dart | 451 } // namespace dart |
| OLD | NEW |