src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp

changeset 3294
bca17e38de00
parent 3115
c2bf0120ee5d
child 4037
da91efe96a93
     1.1 --- a/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp	Tue Nov 22 04:47:10 2011 -0500
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp	Tue Aug 09 10:16:01 2011 -0700
     1.3 @@ -152,15 +152,16 @@
     1.4  {
     1.5    ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
     1.6    uint parallel_gc_threads = heap->gc_task_manager()->workers();
     1.7 +  uint active_gc_threads = heap->gc_task_manager()->active_workers();
     1.8    RegionTaskQueueSet* qset = ParCompactionManager::region_array();
     1.9 -  ParallelTaskTerminator terminator(parallel_gc_threads, qset);
    1.10 +  ParallelTaskTerminator terminator(active_gc_threads, qset);
    1.11    GCTaskQueue* q = GCTaskQueue::create();
    1.12    for(uint i=0; i<parallel_gc_threads; i++) {
    1.13      q->enqueue(new RefProcTaskProxy(task, i));
    1.14    }
    1.15    if (task.marks_oops_alive()) {
    1.16      if (parallel_gc_threads>1) {
    1.17 -      for (uint j=0; j<parallel_gc_threads; j++) {
    1.18 +      for (uint j=0; j<active_gc_threads; j++) {
    1.19          q->enqueue(new StealMarkingTask(&terminator));
    1.20        }
    1.21      }
    1.22 @@ -216,7 +217,6 @@
    1.23  // StealRegionCompactionTask
    1.24  //
    1.25  
    1.26 -
    1.27  StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
    1.28    _terminator(t) {}
    1.29  
    1.30 @@ -229,6 +229,32 @@
    1.31    ParCompactionManager* cm =
    1.32      ParCompactionManager::gc_thread_compaction_manager(which);
    1.33  
    1.34 +
    1.35 +  // If not all threads are active, get a draining stack
    1.36 +  // from the list.  Else, just use this threads draining stack.
    1.37 +  uint which_stack_index;
    1.38 +  bool use_all_workers = manager->all_workers_active();
    1.39 +  if (use_all_workers) {
    1.40 +    which_stack_index = which;
    1.41 +    assert(manager->active_workers() == ParallelGCThreads,
    1.42 +           err_msg("all_workers_active has been incorrectly set: "
    1.43 +                   " active %d  ParallelGCThreads %d", manager->active_workers(),
    1.44 +                   ParallelGCThreads));
    1.45 +  } else {
    1.46 +    which_stack_index = ParCompactionManager::pop_recycled_stack_index();
    1.47 +  }
    1.48 +
    1.49 +  cm->set_region_stack_index(which_stack_index);
    1.50 +  cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
    1.51 +  if (TraceDynamicGCThreads) {
    1.52 +    gclog_or_tty->print_cr("StealRegionCompactionTask::do_it "
    1.53 +                           "region_stack_index %d region_stack = 0x%x "
    1.54 +                           " empty (%d) use all workers %d",
    1.55 +    which_stack_index, ParCompactionManager::region_list(which_stack_index),
    1.56 +    cm->region_stack()->is_empty(),
    1.57 +    use_all_workers);
    1.58 +  }
    1.59 +
    1.60    // Has to drain stacks first because there may be regions on
    1.61    // preloaded onto the stack and this thread may never have
    1.62    // done a draining task.  Are the draining tasks needed?
    1.63 @@ -285,6 +311,50 @@
    1.64    ParCompactionManager* cm =
    1.65      ParCompactionManager::gc_thread_compaction_manager(which);
    1.66  
    1.67 +  uint which_stack_index;
    1.68 +  bool use_all_workers = manager->all_workers_active();
    1.69 +  if (use_all_workers) {
    1.70 +    which_stack_index = which;
    1.71 +    assert(manager->active_workers() == ParallelGCThreads,
    1.72 +           err_msg("all_workers_active has been incorrectly set: "
    1.73 +                   " active %d  ParallelGCThreads %d", manager->active_workers(),
    1.74 +                   ParallelGCThreads));
    1.75 +  } else {
    1.76 +    which_stack_index = stack_index();
    1.77 +  }
    1.78 +
    1.79 +  cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
    1.80 +  if (TraceDynamicGCThreads) {
    1.81 +    gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d "
    1.82 +                           "which_stack_index = %d/empty(%d) "
    1.83 +                           "use all workers %d",
    1.84 +                           which, which_stack_index,
    1.85 +                           cm->region_stack()->is_empty(),
    1.86 +                           use_all_workers);
    1.87 +  }
    1.88 +
    1.89 +  cm->set_region_stack_index(which_stack_index);
    1.90 +
    1.91    // Process any regions already in the compaction managers stacks.
    1.92    cm->drain_region_stacks();
    1.93 +
    1.94 +  assert(cm->region_stack()->is_empty(), "Not empty");
    1.95 +
    1.96 +  if (!use_all_workers) {
    1.97 +    // Always give up the region stack.
    1.98 +    assert(cm->region_stack() ==
    1.99 +           ParCompactionManager::region_list(cm->region_stack_index()),
   1.100 +           "region_stack and region_stack_index are inconsistent");
   1.101 +    ParCompactionManager::push_recycled_stack_index(cm->region_stack_index());
   1.102 +
   1.103 +    if (TraceDynamicGCThreads) {
   1.104 +      void* old_region_stack = (void*) cm->region_stack();
   1.105 +      int old_region_stack_index = cm->region_stack_index();
   1.106 +      gclog_or_tty->print_cr("Pushing region stack 0x%x/%d",
   1.107 +        old_region_stack, old_region_stack_index);
   1.108 +    }
   1.109 +
   1.110 +    cm->set_region_stack(NULL);
   1.111 +    cm->set_region_stack_index((uint)max_uintx);
   1.112 +  }
   1.113  }

mercurial