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

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

Issue 2126413002: Allow for recursive invocation of SafepointOperationScopes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address self review comments. Created 4 years, 5 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
« runtime/vm/safepoint.h ('K') | « runtime/vm/safepoint.cc ('k') | no next file » | 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) 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/safepoint.h" 10 #include "vm/safepoint.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 String& label = String::Handle(String::New("foo")); 398 String& label = String::Handle(String::New("foo"));
399 UserTag& tag = UserTag::Handle(UserTag::New(label)); 399 UserTag& tag = UserTag::Handle(UserTag::New(label));
400 isolate->set_current_tag(tag); 400 isolate->set_current_tag(tag);
401 MonitorLocker ml(&monitor); 401 MonitorLocker ml(&monitor);
402 while (exited != SafepointTestTask::kTaskCount) { 402 while (exited != SafepointTestTask::kTaskCount) {
403 ml.WaitWithSafepointCheck(thread); 403 ml.WaitWithSafepointCheck(thread);
404 } 404 }
405 } 405 }
406 406
407 407
408 // Test case for recursive safepoint operations.
409 VM_TEST_CASE(RecursiveSafepointTest1) {
410 intptr_t count = 0;
411 {
412 SafepointOperationScope safepoint_scope(thread);
413 count += 1;
414 {
415 SafepointOperationScope safepoint_scope(thread);
416 count += 1;
417 {
418 SafepointOperationScope safepoint_scope(thread);
419 count += 1;
420 }
421 }
422 }
423 EXPECT(count == 3);
424 }
425
426
408 VM_TEST_CASE(ThreadIterator_Count) { 427 VM_TEST_CASE(ThreadIterator_Count) {
409 intptr_t thread_count_0 = 0; 428 intptr_t thread_count_0 = 0;
410 intptr_t thread_count_1 = 0; 429 intptr_t thread_count_1 = 0;
411 430
412 { 431 {
413 OSThreadIterator ti; 432 OSThreadIterator ti;
414 while (ti.HasNext()) { 433 while (ti.HasNext()) {
415 OSThread* thread = ti.Next(); 434 OSThread* thread = ti.Next();
416 EXPECT(thread != NULL); 435 EXPECT(thread != NULL);
417 thread_count_0++; 436 thread_count_0++;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 String& label = String::Handle(String::New("foo")); 537 String& label = String::Handle(String::New("foo"));
519 UserTag& tag = UserTag::Handle(UserTag::New(label)); 538 UserTag& tag = UserTag::Handle(UserTag::New(label));
520 isolate->set_current_tag(tag); 539 isolate->set_current_tag(tag);
521 MonitorLocker ml(&monitor); 540 MonitorLocker ml(&monitor);
522 while (exited != SafepointTestTask::kTaskCount) { 541 while (exited != SafepointTestTask::kTaskCount) {
523 ml.WaitWithSafepointCheck(thread); 542 ml.WaitWithSafepointCheck(thread);
524 } 543 }
525 } 544 }
526 545
527 546
547 // Test recursive safepoint operation scopes with other threads trying
548 // to also start a safepoint operation scope.
549 VM_TEST_CASE(RecursiveSafepointTest2) {
550 Isolate* isolate = thread->isolate();
551 Monitor monitor;
552 intptr_t expected_count = 0;
553 intptr_t total_done = 0;
554 intptr_t exited = 0;
555 for (int i = 0; i < SafepointTestTask::kTaskCount; i++) {
556 Dart::thread_pool()->Run(new SafepointTestTask(
557 isolate, &monitor, &expected_count, &total_done, &exited));
558 }
559 bool all_helpers = false;
560 do {
561 SafepointOperationScope safepoint_scope(thread);
562 {
563 SafepointOperationScope safepoint_scope(thread);
564 MonitorLocker ml(&monitor);
565 if (expected_count == SafepointTestTask::kTaskCount) {
566 all_helpers = true;
567 }
568 }
569 } while (!all_helpers);
570 String& label = String::Handle(String::New("foo"));
571 UserTag& tag = UserTag::Handle(UserTag::New(label));
572 isolate->set_current_tag(tag);
573 bool all_exited = false;
574 do {
575 SafepointOperationScope safepoint_scope(thread);
576 {
577 SafepointOperationScope safepoint_scope(thread);
578 MonitorLocker ml(&monitor);
579 if (exited == SafepointTestTask::kTaskCount) {
580 all_exited = true;
581 }
582 }
583 } while (!all_exited);
584 }
585
586
528 class AllocAndGCTask : public ThreadPool::Task { 587 class AllocAndGCTask : public ThreadPool::Task {
529 public: 588 public:
530 AllocAndGCTask(Isolate* isolate, 589 AllocAndGCTask(Isolate* isolate,
531 Monitor* done_monitor, 590 Monitor* done_monitor,
532 bool* done) 591 bool* done)
533 : isolate_(isolate), 592 : isolate_(isolate),
534 done_monitor_(done_monitor), 593 done_monitor_(done_monitor),
535 done_(done) { 594 done_(done) {
536 } 595 }
537 596
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 TransitionVMToBlocked transition(thread); 632 TransitionVMToBlocked transition(thread);
574 MonitorLocker ml(&done_monitor); 633 MonitorLocker ml(&done_monitor);
575 if (done) { 634 if (done) {
576 break; 635 break;
577 } 636 }
578 } 637 }
579 } 638 }
580 } 639 }
581 640
582 } // namespace dart 641 } // namespace dart
OLDNEW
« runtime/vm/safepoint.h ('K') | « runtime/vm/safepoint.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698