src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.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>
   1 /*
   2  * Copyright (c) 2002, 2012, 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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  27 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
  28 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
  29 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"

  30 #include "gc_implementation/shared/mutableSpace.hpp"
  31 #include "memory/memRegion.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "oops/oop.psgc.inline.hpp"
  34 
  35 PSPromotionManager**         PSPromotionManager::_manager_array = NULL;
  36 OopStarTaskQueueSet*         PSPromotionManager::_stack_array_depth = NULL;
  37 PSOldGen*                    PSPromotionManager::_old_gen = NULL;
  38 MutableSpace*                PSPromotionManager::_young_space = NULL;
  39 
  40 void PSPromotionManager::initialize() {
  41   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  42   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
  43 
  44   _old_gen = heap->old_gen();
  45   _young_space = heap->young_gen()->to_space();
  46 
  47   assert(_manager_array == NULL, "Attempt to initialize twice");
  48   _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1, mtGC);
  49   guarantee(_manager_array != NULL, "Could not initialize promotion manager");
  50 
  51   _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads);
  52   guarantee(_stack_array_depth != NULL, "Cound not initialize promotion manager");
  53 
  54   // Create and register the PSPromotionManager(s) for the worker threads.
  55   for(uint i=0; i<ParallelGCThreads; i++) {
  56     _manager_array[i] = new PSPromotionManager();
  57     guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager");
  58     stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth());
  59   }
  60 
  61   // The VMThread gets its own PSPromotionManager, which is not available
  62   // for work stealing.
  63   _manager_array[ParallelGCThreads] = new PSPromotionManager();
  64   guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager");
  65 }
  66 
  67 PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) {
  68   assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
  69   assert(_manager_array != NULL, "Sanity");
  70   return _manager_array[index];
  71 }
  72 
  73 PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() {
  74   assert(_manager_array != NULL, "Sanity");
  75   return _manager_array[ParallelGCThreads];
  76 }
  77 
  78 void PSPromotionManager::pre_scavenge() {
  79   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  80   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
  81 
  82   _young_space = heap->young_gen()->to_space();
  83 
  84   for(uint i=0; i<ParallelGCThreads+1; i++) {
  85     manager_array(i)->reset();
  86   }
  87 }
  88 
  89 void PSPromotionManager::post_scavenge() {


  90   TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats());
  91   for (uint i = 0; i < ParallelGCThreads + 1; i++) {
  92     PSPromotionManager* manager = manager_array(i);
  93     assert(manager->claimed_stack_depth()->is_empty(), "should be empty");




  94     manager->flush_labs();
  95   }

  96 }
  97 
  98 #if TASKQUEUE_STATS
  99 void
 100 PSPromotionManager::print_taskqueue_stats(uint i) const {
 101   tty->print("%3u ", i);
 102   _claimed_stack_depth.stats.print();
 103   tty->cr();
 104 }
 105 
 106 void
 107 PSPromotionManager::print_local_stats(uint i) const {
 108   #define FMT " " SIZE_FORMAT_W(10)
 109   tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals,
 110                 _arrays_chunked, _array_chunks_processed);
 111   #undef FMT
 112 }
 113 
 114 static const char* const pm_stats_hdr[] = {
 115   "    --------masked-------     arrays      array",


 170   reset();
 171 }
 172 
 173 void PSPromotionManager::reset() {
 174   assert(stacks_empty(), "reset of non-empty stack");
 175 
 176   // We need to get an assert in here to make sure the labs are always flushed.
 177 
 178   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 179   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 180 
 181   // Do not prefill the LAB's, save heap wastage!
 182   HeapWord* lab_base = young_space()->top();
 183   _young_lab.initialize(MemRegion(lab_base, (size_t)0));
 184   _young_gen_is_full = false;
 185 
 186   lab_base = old_gen()->object_space()->top();
 187   _old_lab.initialize(MemRegion(lab_base, (size_t)0));
 188   _old_gen_is_full = false;
 189 


 190   TASKQUEUE_STATS_ONLY(reset_stats());
 191 }
 192 
 193 
 194 void PSPromotionManager::drain_stacks_depth(bool totally_drain) {
 195   totally_drain = totally_drain || _totally_drain;
 196 
 197 #ifdef ASSERT
 198   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 199   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 200   MutableSpace* to_space = heap->young_gen()->to_space();
 201   MutableSpace* old_space = heap->old_gen()->object_space();
 202 #endif /* ASSERT */
 203 
 204   OopStarTaskQueue* const tq = claimed_stack_depth();
 205   do {
 206     StarTask p;
 207 
 208     // Drain overflow stack first, so other threads can steal from
 209     // claimed stack while we work.


 288 
 289   if (UseCompressedOops) {
 290     process_array_chunk_work<narrowOop>(obj, start, end);
 291   } else {
 292     process_array_chunk_work<oop>(obj, start, end);
 293   }
 294 }
 295 
 296 oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
 297   assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
 298 
 299   // Attempt to CAS in the header.
 300   // This tests if the header is still the same as when
 301   // this started.  If it is the same (i.e., no forwarding
 302   // pointer has been installed), then this thread owns
 303   // it.
 304   if (obj->cas_forward_to(obj, obj_mark)) {
 305     // We won any races, we "own" this object.
 306     assert(obj == obj->forwardee(), "Sanity");
 307 


 308     obj->push_contents(this);
 309 
 310     // Save the mark if needed
 311     PSScavenge::oop_promotion_failed(obj, obj_mark);
 312   }  else {
 313     // We lost, someone else "owns" this object
 314     guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
 315 
 316     // No unallocation to worry about.
 317     obj = obj->forwardee();
 318   }
 319 
 320 #ifndef PRODUCT
 321   if (TraceScavenge) {
 322     gclog_or_tty->print_cr("{%s %s 0x%x (%d)}",
 323                            "promotion-failure",
 324                            obj->klass()->internal_name(),
 325                            obj, obj->size());
 326 
 327   }
   1 /*
   2  * Copyright (c) 2002, 2013, 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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  27 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
  28 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
  29 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
  30 #include "gc_implementation/shared/gcTrace.hpp"
  31 #include "gc_implementation/shared/mutableSpace.hpp"
  32 #include "memory/memRegion.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "oops/oop.psgc.inline.hpp"
  35 
  36 PSPromotionManager**         PSPromotionManager::_manager_array = NULL;
  37 OopStarTaskQueueSet*         PSPromotionManager::_stack_array_depth = NULL;
  38 PSOldGen*                    PSPromotionManager::_old_gen = NULL;
  39 MutableSpace*                PSPromotionManager::_young_space = NULL;
  40 
  41 void PSPromotionManager::initialize() {
  42   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  43   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
  44 
  45   _old_gen = heap->old_gen();
  46   _young_space = heap->young_gen()->to_space();
  47 
  48   assert(_manager_array == NULL, "Attempt to initialize twice");
  49   _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1, mtGC);
  50   guarantee(_manager_array != NULL, "Could not initialize promotion manager");
  51 
  52   _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads);
  53   guarantee(_stack_array_depth != NULL, "Could not initialize promotion manager");
  54 
  55   // Create and register the PSPromotionManager(s) for the worker threads.
  56   for(uint i=0; i<ParallelGCThreads; i++) {
  57     _manager_array[i] = new PSPromotionManager();
  58     guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager");
  59     stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth());
  60   }
  61 
  62   // The VMThread gets its own PSPromotionManager, which is not available
  63   // for work stealing.
  64   _manager_array[ParallelGCThreads] = new PSPromotionManager();
  65   guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager");
  66 }
  67 
  68 PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) {
  69   assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
  70   assert(_manager_array != NULL, "Sanity");
  71   return _manager_array[index];
  72 }
  73 
  74 PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() {
  75   assert(_manager_array != NULL, "Sanity");
  76   return _manager_array[ParallelGCThreads];
  77 }
  78 
  79 void PSPromotionManager::pre_scavenge() {
  80   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  81   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
  82 
  83   _young_space = heap->young_gen()->to_space();
  84 
  85   for(uint i=0; i<ParallelGCThreads+1; i++) {
  86     manager_array(i)->reset();
  87   }
  88 }
  89 
  90 bool PSPromotionManager::post_scavenge(YoungGCTracer& gc_tracer) {
  91   bool promotion_failure_occurred = false;
  92 
  93   TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats());
  94   for (uint i = 0; i < ParallelGCThreads + 1; i++) {
  95     PSPromotionManager* manager = manager_array(i);
  96     assert(manager->claimed_stack_depth()->is_empty(), "should be empty");
  97     if (manager->_promotion_failed_info.has_failed()) {
  98       gc_tracer.report_promotion_failed(manager->_promotion_failed_info);
  99       promotion_failure_occurred = true;
 100     }
 101     manager->flush_labs();
 102   }
 103   return promotion_failure_occurred;
 104 }
 105 
 106 #if TASKQUEUE_STATS
 107 void
 108 PSPromotionManager::print_taskqueue_stats(uint i) const {
 109   tty->print("%3u ", i);
 110   _claimed_stack_depth.stats.print();
 111   tty->cr();
 112 }
 113 
 114 void
 115 PSPromotionManager::print_local_stats(uint i) const {
 116   #define FMT " " SIZE_FORMAT_W(10)
 117   tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals,
 118                 _arrays_chunked, _array_chunks_processed);
 119   #undef FMT
 120 }
 121 
 122 static const char* const pm_stats_hdr[] = {
 123   "    --------masked-------     arrays      array",


 178   reset();
 179 }
 180 
 181 void PSPromotionManager::reset() {
 182   assert(stacks_empty(), "reset of non-empty stack");
 183 
 184   // We need to get an assert in here to make sure the labs are always flushed.
 185 
 186   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 187   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 188 
 189   // Do not prefill the LAB's, save heap wastage!
 190   HeapWord* lab_base = young_space()->top();
 191   _young_lab.initialize(MemRegion(lab_base, (size_t)0));
 192   _young_gen_is_full = false;
 193 
 194   lab_base = old_gen()->object_space()->top();
 195   _old_lab.initialize(MemRegion(lab_base, (size_t)0));
 196   _old_gen_is_full = false;
 197 
 198   _promotion_failed_info.reset();
 199 
 200   TASKQUEUE_STATS_ONLY(reset_stats());
 201 }
 202 
 203 
 204 void PSPromotionManager::drain_stacks_depth(bool totally_drain) {
 205   totally_drain = totally_drain || _totally_drain;
 206 
 207 #ifdef ASSERT
 208   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 209   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 210   MutableSpace* to_space = heap->young_gen()->to_space();
 211   MutableSpace* old_space = heap->old_gen()->object_space();
 212 #endif /* ASSERT */
 213 
 214   OopStarTaskQueue* const tq = claimed_stack_depth();
 215   do {
 216     StarTask p;
 217 
 218     // Drain overflow stack first, so other threads can steal from
 219     // claimed stack while we work.


 298 
 299   if (UseCompressedOops) {
 300     process_array_chunk_work<narrowOop>(obj, start, end);
 301   } else {
 302     process_array_chunk_work<oop>(obj, start, end);
 303   }
 304 }
 305 
 306 oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
 307   assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
 308 
 309   // Attempt to CAS in the header.
 310   // This tests if the header is still the same as when
 311   // this started.  If it is the same (i.e., no forwarding
 312   // pointer has been installed), then this thread owns
 313   // it.
 314   if (obj->cas_forward_to(obj, obj_mark)) {
 315     // We won any races, we "own" this object.
 316     assert(obj == obj->forwardee(), "Sanity");
 317 
 318     _promotion_failed_info.register_copy_failure(obj->size());
 319 
 320     obj->push_contents(this);
 321 
 322     // Save the mark if needed
 323     PSScavenge::oop_promotion_failed(obj, obj_mark);
 324   }  else {
 325     // We lost, someone else "owns" this object
 326     guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
 327 
 328     // No unallocation to worry about.
 329     obj = obj->forwardee();
 330   }
 331 
 332 #ifndef PRODUCT
 333   if (TraceScavenge) {
 334     gclog_or_tty->print_cr("{%s %s 0x%x (%d)}",
 335                            "promotion-failure",
 336                            obj->klass()->internal_name(),
 337                            obj, obj->size());
 338 
 339   }