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

Mon, 20 Sep 2010 14:38:38 -0700

author
jmasa
date
Mon, 20 Sep 2010 14:38:38 -0700
changeset 2188
8b10f48633dc
parent 1907
c18cbe5936b8
child 2191
894b1d7c7e01
permissions
-rw-r--r--

6984287: Regularize how GC parallel workers are specified.
Summary: Associate number of GC workers with the workgang as opposed to the task.
Reviewed-by: johnc, ysr

     1 /*
     2  * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 # include "incls/_precompiled.incl"
    26 # include "incls/_pcTasks.cpp.incl"
    28 //
    29 // ThreadRootsMarkingTask
    30 //
    32 void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
    33   assert(Universe::heap()->is_gc_active(), "called outside gc");
    35   ResourceMark rm;
    37   NOT_PRODUCT(TraceTime tm("ThreadRootsMarkingTask",
    38     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
    39   ParCompactionManager* cm =
    40     ParCompactionManager::gc_thread_compaction_manager(which);
    41   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
    42   CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
    44   if (_java_thread != NULL)
    45     _java_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
    47   if (_vm_thread != NULL)
    48     _vm_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
    50   // Do the real work
    51   cm->follow_marking_stacks();
    52 }
    55 void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) {
    56   assert(Universe::heap()->is_gc_active(), "called outside gc");
    58   NOT_PRODUCT(TraceTime tm("MarkFromRootsTask",
    59     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
    60   ParCompactionManager* cm =
    61     ParCompactionManager::gc_thread_compaction_manager(which);
    62   assert(cm->stacks_have_been_allocated(),
    63          "Stack space has not been allocated");
    64   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
    66   switch (_root_type) {
    67     case universe:
    68       Universe::oops_do(&mark_and_push_closure);
    69       break;
    71     case reference_processing:
    72       ReferenceProcessor::oops_do(&mark_and_push_closure);
    73       break;
    75     case jni_handles:
    76       JNIHandles::oops_do(&mark_and_push_closure);
    77       break;
    79     case threads:
    80     {
    81       ResourceMark rm;
    82       CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
    83       Threads::oops_do(&mark_and_push_closure, &each_active_code_blob);
    84     }
    85     break;
    87     case object_synchronizer:
    88       ObjectSynchronizer::oops_do(&mark_and_push_closure);
    89       break;
    91     case flat_profiler:
    92       FlatProfiler::oops_do(&mark_and_push_closure);
    93       break;
    95     case management:
    96       Management::oops_do(&mark_and_push_closure);
    97       break;
    99     case jvmti:
   100       JvmtiExport::oops_do(&mark_and_push_closure);
   101       break;
   103     case system_dictionary:
   104       SystemDictionary::always_strong_oops_do(&mark_and_push_closure);
   105       break;
   107     case vm_symbols:
   108       vmSymbols::oops_do(&mark_and_push_closure);
   109       break;
   111     case code_cache:
   112       // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
   113       //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
   114       break;
   116     default:
   117       fatal("Unknown root type");
   118   }
   120   // Do the real work
   121   cm->follow_marking_stacks();
   122   // cm->deallocate_stacks();
   123 }
   126 //
   127 // RefProcTaskProxy
   128 //
   130 void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
   131 {
   132   assert(Universe::heap()->is_gc_active(), "called outside gc");
   134   NOT_PRODUCT(TraceTime tm("RefProcTask",
   135     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
   136   ParCompactionManager* cm =
   137     ParCompactionManager::gc_thread_compaction_manager(which);
   138   assert(cm->stacks_have_been_allocated(),
   139          "Stack space has not been allocated");
   140   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   141   PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
   142   _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(),
   143                 mark_and_push_closure, follow_stack_closure);
   144 }
   146 //
   147 // RefProcTaskExecutor
   148 //
   150 void RefProcTaskExecutor::execute(ProcessTask& task)
   151 {
   152   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
   153   uint parallel_gc_threads = heap->gc_task_manager()->workers();
   154   RegionTaskQueueSet* qset = ParCompactionManager::region_array();
   155   ParallelTaskTerminator terminator(parallel_gc_threads, qset);
   156   GCTaskQueue* q = GCTaskQueue::create();
   157   for(uint i=0; i<parallel_gc_threads; i++) {
   158     q->enqueue(new RefProcTaskProxy(task, i));
   159   }
   160   if (task.marks_oops_alive()) {
   161     if (parallel_gc_threads>1) {
   162       for (uint j=0; j<parallel_gc_threads; j++) {
   163         q->enqueue(new StealMarkingTask(&terminator));
   164       }
   165     }
   166   }
   167   PSParallelCompact::gc_task_manager()->execute_and_wait(q);
   168 }
   170 void RefProcTaskExecutor::execute(EnqueueTask& task)
   171 {
   172   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
   173   uint parallel_gc_threads = heap->gc_task_manager()->workers();
   174   GCTaskQueue* q = GCTaskQueue::create();
   175   for(uint i=0; i<parallel_gc_threads; i++) {
   176     q->enqueue(new RefEnqueueTaskProxy(task, i));
   177   }
   178   PSParallelCompact::gc_task_manager()->execute_and_wait(q);
   179 }
   181 //
   182 // StealMarkingTask
   183 //
   185 StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) :
   186   _terminator(t) {}
   188 void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
   189   assert(Universe::heap()->is_gc_active(), "called outside gc");
   191   NOT_PRODUCT(TraceTime tm("StealMarkingTask",
   192     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
   194   ParCompactionManager* cm =
   195     ParCompactionManager::gc_thread_compaction_manager(which);
   196   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   198   oop obj = NULL;
   199   ObjArrayTask task;
   200   int random_seed = 17;
   201   do {
   202     while (ParCompactionManager::steal_objarray(which, &random_seed, task)) {
   203       objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
   204       k->oop_follow_contents(cm, task.obj(), task.index());
   205       cm->follow_marking_stacks();
   206     }
   207     while (ParCompactionManager::steal(which, &random_seed, obj)) {
   208       obj->follow_contents(cm);
   209       cm->follow_marking_stacks();
   210     }
   211   } while (!terminator()->offer_termination());
   212 }
   214 //
   215 // StealRegionCompactionTask
   216 //
   219 StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
   220   _terminator(t) {}
   222 void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
   223   assert(Universe::heap()->is_gc_active(), "called outside gc");
   225   NOT_PRODUCT(TraceTime tm("StealRegionCompactionTask",
   226     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
   228   ParCompactionManager* cm =
   229     ParCompactionManager::gc_thread_compaction_manager(which);
   231   // Has to drain stacks first because there may be regions on
   232   // preloaded onto the stack and this thread may never have
   233   // done a draining task.  Are the draining tasks needed?
   235   cm->drain_region_stacks();
   237   size_t region_index = 0;
   238   int random_seed = 17;
   240   // If we're the termination task, try 10 rounds of stealing before
   241   // setting the termination flag
   243   while(true) {
   244     if (ParCompactionManager::steal(which, &random_seed, region_index)) {
   245       PSParallelCompact::fill_and_update_region(cm, region_index);
   246       cm->drain_region_stacks();
   247     } else {
   248       if (terminator()->offer_termination()) {
   249         break;
   250       }
   251       // Go around again.
   252     }
   253   }
   254   return;
   255 }
   257 UpdateDensePrefixTask::UpdateDensePrefixTask(
   258                                    PSParallelCompact::SpaceId space_id,
   259                                    size_t region_index_start,
   260                                    size_t region_index_end) :
   261   _space_id(space_id), _region_index_start(region_index_start),
   262   _region_index_end(region_index_end) {}
   264 void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) {
   266   NOT_PRODUCT(TraceTime tm("UpdateDensePrefixTask",
   267     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
   269   ParCompactionManager* cm =
   270     ParCompactionManager::gc_thread_compaction_manager(which);
   272   PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
   273                                                          _space_id,
   274                                                          _region_index_start,
   275                                                          _region_index_end);
   276 }
   278 void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
   279   assert(Universe::heap()->is_gc_active(), "called outside gc");
   281   NOT_PRODUCT(TraceTime tm("DrainStacksCompactionTask",
   282     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
   284   ParCompactionManager* cm =
   285     ParCompactionManager::gc_thread_compaction_manager(which);
   287   // Process any regions already in the compaction managers stacks.
   288   cm->drain_region_stacks();
   289 }

mercurial