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

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc_implementation/parallelScavenge/pcTasks.hpp"
  29 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"


  30 #include "gc_interface/collectedHeap.hpp"
  31 #include "memory/universe.hpp"
  32 #include "oops/objArrayKlass.inline.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "oops/oop.pcgc.inline.hpp"
  35 #include "prims/jvmtiExport.hpp"
  36 #include "runtime/fprofiler.hpp"
  37 #include "runtime/jniHandles.hpp"
  38 #include "runtime/thread.hpp"
  39 #include "runtime/vmThread.hpp"
  40 #include "services/management.hpp"
  41 
  42 //
  43 // ThreadRootsMarkingTask
  44 //
  45 
  46 void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
  47   assert(Universe::heap()->is_gc_active(), "called outside gc");
  48 
  49   ResourceMark rm;
  50 
  51   NOT_PRODUCT(TraceTime tm("ThreadRootsMarkingTask",
  52     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
  53   ParCompactionManager* cm =
  54     ParCompactionManager::gc_thread_compaction_manager(which);
  55 
  56   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
  57   CLDToOopClosure mark_and_push_from_clds(&mark_and_push_closure, true);
  58   CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
  59 
  60   if (_java_thread != NULL)
  61     _java_thread->oops_do(
  62         &mark_and_push_closure,
  63         &mark_and_push_from_clds,
  64         &mark_and_push_in_blobs);
  65 
  66   if (_vm_thread != NULL)
  67     _vm_thread->oops_do(
  68         &mark_and_push_closure,
  69         &mark_and_push_from_clds,
  70         &mark_and_push_in_blobs);
  71 
  72   // Do the real work
  73   cm->follow_marking_stacks();
  74 }
  75 
  76 
  77 void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) {
  78   assert(Universe::heap()->is_gc_active(), "called outside gc");
  79 
  80   NOT_PRODUCT(TraceTime tm("MarkFromRootsTask",
  81     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
  82   ParCompactionManager* cm =
  83     ParCompactionManager::gc_thread_compaction_manager(which);
  84   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
  85   PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure);
  86 
  87   switch (_root_type) {
  88     case universe:
  89       Universe::oops_do(&mark_and_push_closure);
  90       break;
  91 
  92     case jni_handles:
  93       JNIHandles::oops_do(&mark_and_push_closure);
  94       break;
  95 
  96     case threads:
  97     {
  98       ResourceMark rm;
  99       CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
 100       CLDToOopClosure mark_and_push_from_cld(&mark_and_push_closure);
 101       Threads::oops_do(&mark_and_push_closure, &mark_and_push_from_cld, &each_active_code_blob);


 131       //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
 132       break;
 133 
 134     default:
 135       fatal("Unknown root type");
 136   }
 137 
 138   // Do the real work
 139   cm->follow_marking_stacks();
 140 }
 141 
 142 
 143 //
 144 // RefProcTaskProxy
 145 //
 146 
 147 void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
 148 {
 149   assert(Universe::heap()->is_gc_active(), "called outside gc");
 150 
 151   NOT_PRODUCT(TraceTime tm("RefProcTask",
 152     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
 153   ParCompactionManager* cm =
 154     ParCompactionManager::gc_thread_compaction_manager(which);
 155   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
 156   PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
 157   _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(),
 158                 mark_and_push_closure, follow_stack_closure);
 159 }
 160 
 161 //
 162 // RefProcTaskExecutor
 163 //
 164 
 165 void RefProcTaskExecutor::execute(ProcessTask& task)
 166 {
 167   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
 168   uint parallel_gc_threads = heap->gc_task_manager()->workers();
 169   uint active_gc_threads = heap->gc_task_manager()->active_workers();
 170   RegionTaskQueueSet* qset = ParCompactionManager::region_array();
 171   ParallelTaskTerminator terminator(active_gc_threads, qset);
 172   GCTaskQueue* q = GCTaskQueue::create();


 187 {
 188   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
 189   uint parallel_gc_threads = heap->gc_task_manager()->workers();
 190   GCTaskQueue* q = GCTaskQueue::create();
 191   for(uint i=0; i<parallel_gc_threads; i++) {
 192     q->enqueue(new RefEnqueueTaskProxy(task, i));
 193   }
 194   PSParallelCompact::gc_task_manager()->execute_and_wait(q);
 195 }
 196 
 197 //
 198 // StealMarkingTask
 199 //
 200 
 201 StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) :
 202   _terminator(t) {}
 203 
 204 void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
 205   assert(Universe::heap()->is_gc_active(), "called outside gc");
 206 
 207   NOT_PRODUCT(TraceTime tm("StealMarkingTask",
 208     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
 209 
 210   ParCompactionManager* cm =
 211     ParCompactionManager::gc_thread_compaction_manager(which);
 212   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
 213 
 214   oop obj = NULL;
 215   ObjArrayTask task;
 216   int random_seed = 17;
 217   do {
 218     while (ParCompactionManager::steal_objarray(which, &random_seed, task)) {
 219       ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass();
 220       k->oop_follow_contents(cm, task.obj(), task.index());
 221       cm->follow_marking_stacks();
 222     }
 223     while (ParCompactionManager::steal(which, &random_seed, obj)) {
 224       obj->follow_contents(cm);
 225       cm->follow_marking_stacks();
 226     }
 227   } while (!terminator()->offer_termination());
 228 }
 229 
 230 //
 231 // StealRegionCompactionTask
 232 //
 233 
 234 StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
 235   _terminator(t) {}
 236 
 237 void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
 238   assert(Universe::heap()->is_gc_active(), "called outside gc");
 239 
 240   NOT_PRODUCT(TraceTime tm("StealRegionCompactionTask",
 241     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
 242 
 243   ParCompactionManager* cm =
 244     ParCompactionManager::gc_thread_compaction_manager(which);
 245 
 246 
 247   // If not all threads are active, get a draining stack
 248   // from the list.  Else, just use this threads draining stack.
 249   uint which_stack_index;
 250   bool use_all_workers = manager->all_workers_active();
 251   if (use_all_workers) {
 252     which_stack_index = which;
 253     assert(manager->active_workers() == ParallelGCThreads,
 254            err_msg("all_workers_active has been incorrectly set: "
 255                    " active %d  ParallelGCThreads %d", manager->active_workers(),
 256                    ParallelGCThreads));
 257   } else {
 258     which_stack_index = ParCompactionManager::pop_recycled_stack_index();
 259   }
 260 
 261   cm->set_region_stack_index(which_stack_index);


 287       cm->drain_region_stacks();
 288     } else {
 289       if (terminator()->offer_termination()) {
 290         break;
 291       }
 292       // Go around again.
 293     }
 294   }
 295   return;
 296 }
 297 
 298 UpdateDensePrefixTask::UpdateDensePrefixTask(
 299                                    PSParallelCompact::SpaceId space_id,
 300                                    size_t region_index_start,
 301                                    size_t region_index_end) :
 302   _space_id(space_id), _region_index_start(region_index_start),
 303   _region_index_end(region_index_end) {}
 304 
 305 void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) {
 306 
 307   NOT_PRODUCT(TraceTime tm("UpdateDensePrefixTask",
 308     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
 309 
 310   ParCompactionManager* cm =
 311     ParCompactionManager::gc_thread_compaction_manager(which);
 312 
 313   PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
 314                                                          _space_id,
 315                                                          _region_index_start,
 316                                                          _region_index_end);
 317 }
 318 
 319 void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
 320   assert(Universe::heap()->is_gc_active(), "called outside gc");
 321 
 322   NOT_PRODUCT(TraceTime tm("DrainStacksCompactionTask",
 323     PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
 324 
 325   ParCompactionManager* cm =
 326     ParCompactionManager::gc_thread_compaction_manager(which);
 327 
 328   uint which_stack_index;
 329   bool use_all_workers = manager->all_workers_active();
 330   if (use_all_workers) {
 331     which_stack_index = which;
 332     assert(manager->active_workers() == ParallelGCThreads,
 333            err_msg("all_workers_active has been incorrectly set: "
 334                    " active %d  ParallelGCThreads %d", manager->active_workers(),
 335                    ParallelGCThreads));
 336   } else {
 337     which_stack_index = stack_index();
 338   }
 339 
 340   cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
 341   if (TraceDynamicGCThreads) {
 342     gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d "
 343                            "which_stack_index = %d/empty(%d) "




  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc_implementation/parallelScavenge/pcTasks.hpp"
  29 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
  30 #include "gc_implementation/shared/gcTimer.hpp"
  31 #include "gc_implementation/shared/gcTraceTime.hpp"
  32 #include "gc_interface/collectedHeap.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/objArrayKlass.inline.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "oops/oop.pcgc.inline.hpp"
  37 #include "prims/jvmtiExport.hpp"
  38 #include "runtime/fprofiler.hpp"
  39 #include "runtime/jniHandles.hpp"
  40 #include "runtime/thread.hpp"
  41 #include "runtime/vmThread.hpp"
  42 #include "services/management.hpp"
  43 
  44 //
  45 // ThreadRootsMarkingTask
  46 //
  47 
  48 void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
  49   assert(Universe::heap()->is_gc_active(), "called outside gc");
  50 
  51   ResourceMark rm;
  52 
  53   NOT_PRODUCT(GCTraceTime tm("ThreadRootsMarkingTask",
  54     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
  55   ParCompactionManager* cm =
  56     ParCompactionManager::gc_thread_compaction_manager(which);
  57 
  58   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
  59   CLDToOopClosure mark_and_push_from_clds(&mark_and_push_closure, true);
  60   CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
  61 
  62   if (_java_thread != NULL)
  63     _java_thread->oops_do(
  64         &mark_and_push_closure,
  65         &mark_and_push_from_clds,
  66         &mark_and_push_in_blobs);
  67 
  68   if (_vm_thread != NULL)
  69     _vm_thread->oops_do(
  70         &mark_and_push_closure,
  71         &mark_and_push_from_clds,
  72         &mark_and_push_in_blobs);
  73 
  74   // Do the real work
  75   cm->follow_marking_stacks();
  76 }
  77 
  78 
  79 void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) {
  80   assert(Universe::heap()->is_gc_active(), "called outside gc");
  81 
  82   NOT_PRODUCT(GCTraceTime tm("MarkFromRootsTask",
  83     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
  84   ParCompactionManager* cm =
  85     ParCompactionManager::gc_thread_compaction_manager(which);
  86   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
  87   PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure);
  88 
  89   switch (_root_type) {
  90     case universe:
  91       Universe::oops_do(&mark_and_push_closure);
  92       break;
  93 
  94     case jni_handles:
  95       JNIHandles::oops_do(&mark_and_push_closure);
  96       break;
  97 
  98     case threads:
  99     {
 100       ResourceMark rm;
 101       CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
 102       CLDToOopClosure mark_and_push_from_cld(&mark_and_push_closure);
 103       Threads::oops_do(&mark_and_push_closure, &mark_and_push_from_cld, &each_active_code_blob);


 133       //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
 134       break;
 135 
 136     default:
 137       fatal("Unknown root type");
 138   }
 139 
 140   // Do the real work
 141   cm->follow_marking_stacks();
 142 }
 143 
 144 
 145 //
 146 // RefProcTaskProxy
 147 //
 148 
 149 void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
 150 {
 151   assert(Universe::heap()->is_gc_active(), "called outside gc");
 152 
 153   NOT_PRODUCT(GCTraceTime tm("RefProcTask",
 154     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
 155   ParCompactionManager* cm =
 156     ParCompactionManager::gc_thread_compaction_manager(which);
 157   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
 158   PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
 159   _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(),
 160                 mark_and_push_closure, follow_stack_closure);
 161 }
 162 
 163 //
 164 // RefProcTaskExecutor
 165 //
 166 
 167 void RefProcTaskExecutor::execute(ProcessTask& task)
 168 {
 169   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
 170   uint parallel_gc_threads = heap->gc_task_manager()->workers();
 171   uint active_gc_threads = heap->gc_task_manager()->active_workers();
 172   RegionTaskQueueSet* qset = ParCompactionManager::region_array();
 173   ParallelTaskTerminator terminator(active_gc_threads, qset);
 174   GCTaskQueue* q = GCTaskQueue::create();


 189 {
 190   ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
 191   uint parallel_gc_threads = heap->gc_task_manager()->workers();
 192   GCTaskQueue* q = GCTaskQueue::create();
 193   for(uint i=0; i<parallel_gc_threads; i++) {
 194     q->enqueue(new RefEnqueueTaskProxy(task, i));
 195   }
 196   PSParallelCompact::gc_task_manager()->execute_and_wait(q);
 197 }
 198 
 199 //
 200 // StealMarkingTask
 201 //
 202 
 203 StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) :
 204   _terminator(t) {}
 205 
 206 void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
 207   assert(Universe::heap()->is_gc_active(), "called outside gc");
 208 
 209   NOT_PRODUCT(GCTraceTime tm("StealMarkingTask",
 210     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
 211 
 212   ParCompactionManager* cm =
 213     ParCompactionManager::gc_thread_compaction_manager(which);
 214   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
 215 
 216   oop obj = NULL;
 217   ObjArrayTask task;
 218   int random_seed = 17;
 219   do {
 220     while (ParCompactionManager::steal_objarray(which, &random_seed, task)) {
 221       ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass();
 222       k->oop_follow_contents(cm, task.obj(), task.index());
 223       cm->follow_marking_stacks();
 224     }
 225     while (ParCompactionManager::steal(which, &random_seed, obj)) {
 226       obj->follow_contents(cm);
 227       cm->follow_marking_stacks();
 228     }
 229   } while (!terminator()->offer_termination());
 230 }
 231 
 232 //
 233 // StealRegionCompactionTask
 234 //
 235 
 236 StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
 237   _terminator(t) {}
 238 
 239 void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
 240   assert(Universe::heap()->is_gc_active(), "called outside gc");
 241 
 242   NOT_PRODUCT(GCTraceTime tm("StealRegionCompactionTask",
 243     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
 244 
 245   ParCompactionManager* cm =
 246     ParCompactionManager::gc_thread_compaction_manager(which);
 247 
 248 
 249   // If not all threads are active, get a draining stack
 250   // from the list.  Else, just use this threads draining stack.
 251   uint which_stack_index;
 252   bool use_all_workers = manager->all_workers_active();
 253   if (use_all_workers) {
 254     which_stack_index = which;
 255     assert(manager->active_workers() == ParallelGCThreads,
 256            err_msg("all_workers_active has been incorrectly set: "
 257                    " active %d  ParallelGCThreads %d", manager->active_workers(),
 258                    ParallelGCThreads));
 259   } else {
 260     which_stack_index = ParCompactionManager::pop_recycled_stack_index();
 261   }
 262 
 263   cm->set_region_stack_index(which_stack_index);


 289       cm->drain_region_stacks();
 290     } else {
 291       if (terminator()->offer_termination()) {
 292         break;
 293       }
 294       // Go around again.
 295     }
 296   }
 297   return;
 298 }
 299 
 300 UpdateDensePrefixTask::UpdateDensePrefixTask(
 301                                    PSParallelCompact::SpaceId space_id,
 302                                    size_t region_index_start,
 303                                    size_t region_index_end) :
 304   _space_id(space_id), _region_index_start(region_index_start),
 305   _region_index_end(region_index_end) {}
 306 
 307 void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) {
 308 
 309   NOT_PRODUCT(GCTraceTime tm("UpdateDensePrefixTask",
 310     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
 311 
 312   ParCompactionManager* cm =
 313     ParCompactionManager::gc_thread_compaction_manager(which);
 314 
 315   PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
 316                                                          _space_id,
 317                                                          _region_index_start,
 318                                                          _region_index_end);
 319 }
 320 
 321 void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
 322   assert(Universe::heap()->is_gc_active(), "called outside gc");
 323 
 324   NOT_PRODUCT(GCTraceTime tm("DrainStacksCompactionTask",
 325     PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
 326 
 327   ParCompactionManager* cm =
 328     ParCompactionManager::gc_thread_compaction_manager(which);
 329 
 330   uint which_stack_index;
 331   bool use_all_workers = manager->all_workers_active();
 332   if (use_all_workers) {
 333     which_stack_index = which;
 334     assert(manager->active_workers() == ParallelGCThreads,
 335            err_msg("all_workers_active has been incorrectly set: "
 336                    " active %d  ParallelGCThreads %d", manager->active_workers(),
 337                    ParallelGCThreads));
 338   } else {
 339     which_stack_index = stack_index();
 340   }
 341 
 342   cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
 343   if (TraceDynamicGCThreads) {
 344     gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d "
 345                            "which_stack_index = %d/empty(%d) "