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

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

Issue 1289153002: Add test of full GC on helper thread (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add comments, use Acquire method. 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.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/thread_pool.h" 10 #include "vm/thread_pool.h"
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 isolate->set_current_tag(tag); 441 isolate->set_current_tag(tag);
442 while (true) { 442 while (true) {
443 isolate->thread_registry()->CheckSafepoint(); 443 isolate->thread_registry()->CheckSafepoint();
444 MutexLocker ml(&mutex); 444 MutexLocker ml(&mutex);
445 if (exited == SafepointTestTask::kTaskCount) { 445 if (exited == SafepointTestTask::kTaskCount) {
446 break; 446 break;
447 } 447 }
448 } 448 }
449 } 449 }
450 450
451
452 class AllocAndGCTask : public ThreadPool::Task {
453 public:
454 AllocAndGCTask(Isolate* isolate,
455 Monitor* done_monitor,
456 bool* done)
457 : isolate_(isolate),
458 done_monitor_(done_monitor),
459 done_(done) {
460 }
461
462 virtual void Run() {
463 Thread::EnterIsolateAsHelper(isolate_);
464 {
465 Thread* thread = Thread::Current();
466 StackZone stack_zone(thread);
467 Zone* zone = stack_zone.GetZone();
468 HANDLESCOPE(thread);
469 String& old_str = String::Handle(zone, String::New("old", Heap::kOld));
470 isolate_->heap()->CollectAllGarbage();
471 EXPECT(old_str.Equals("old"));
472 }
473 Thread::ExitIsolateAsHelper();
474 // Tell main thread that we are ready.
475 {
476 MonitorLocker ml(done_monitor_);
477 ASSERT(!*done_);
478 *done_ = true;
479 ml.Notify();
480 }
481 }
482
483 private:
484 Isolate* isolate_;
485 Monitor* done_monitor_;
486 bool* done_;
487 };
488
489
490 TEST_CASE(HelperAllocAndGC) {
491 Monitor done_monitor;
492 bool done = false;
493 Isolate* isolate = Thread::Current()->isolate();
494 // Flush store buffers, etc.
495 // TODO(koda): Currently, the GC only does this for the current thread, (i.e,
496 // the helper, in this test), but it should be done for all *threads*
497 // while reaching a safepoint.
498 Thread::PrepareForGC();
499 Dart::thread_pool()->Run(new AllocAndGCTask(isolate, &done_monitor, &done));
500 {
501 // Manually wait.
502 // TODO(koda): Replace with execution of Dart and/or VM code when GC
503 // actually safepoints everything.
504 MonitorLocker ml(&done_monitor);
505 while (!done) {
506 ml.Wait();
507 }
508 }
509 }
510
451 } // namespace dart 511 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698