< prev index next >

src/share/vm/gc/shared/genCollectedHeap.cpp

Print this page




  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/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/collectorCounters.hpp"

  33 #include "gc/shared/gcLocker.inline.hpp"
  34 #include "gc/shared/gcTrace.hpp"
  35 #include "gc/shared/gcTraceTime.hpp"
  36 #include "gc/shared/genCollectedHeap.hpp"
  37 #include "gc/shared/genOopClosures.inline.hpp"
  38 #include "gc/shared/generationSpec.hpp"
  39 #include "gc/shared/space.hpp"
  40 #include "gc/shared/strongRootsScope.hpp"
  41 #include "gc/shared/vmGCOperations.hpp"
  42 #include "gc/shared/workgroup.hpp"
  43 #include "memory/filemap.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "runtime/biasedLocking.hpp"
  47 #include "runtime/fprofiler.hpp"
  48 #include "runtime/handles.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/vmThread.hpp"
  52 #include "services/management.hpp"


 300 }
 301 
 302 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
 303   if (!UseConcMarkSweepGC) {
 304     return false;
 305   }
 306 
 307   switch (cause) {
 308     case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
 309     case GCCause::_java_lang_system_gc:
 310     case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
 311     default:                            return false;
 312   }
 313 }
 314 
 315 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
 316                                           bool is_tlab, bool run_verification, bool clear_soft_refs,
 317                                           bool restore_marks_for_biased_locking) {
 318   // Timer for individual generations. Last argument is false: no CR
 319   // FIXME: We should try to start the timing earlier to cover more of the GC pause
 320   // The PrintGCDetails logging starts before we have incremented the GC id. We will do that later
 321   // so we can assume here that the next GC id is what we want.
 322   GCTraceTime t1(gen->short_name(), PrintGCDetails, false, NULL, GCId::peek());
 323   TraceCollectorStats tcs(gen->counters());
 324   TraceMemoryManagerStats tmms(gen->kind(),gc_cause());
 325 
 326   size_t prev_used = gen->used();
 327   gen->stat_record()->invocations++;
 328   gen->stat_record()->accumulated_time.start();
 329 
 330   // Must be done anew before each collection because
 331   // a previous collection will do mangling and will
 332   // change top of some spaces.
 333   record_gen_tops_before_GC();
 334 
 335   if (PrintGC && Verbose) {
 336     // I didn't want to change the logging when removing the level concept,
 337     // but I guess this logging could say young/old or something instead of 0/1.
 338     uint level;
 339     if (heap()->is_young_gen(gen)) {
 340       level = 0;
 341     } else {
 342       level = 1;


 419 void GenCollectedHeap::do_collection(bool           full,
 420                                      bool           clear_all_soft_refs,
 421                                      size_t         size,
 422                                      bool           is_tlab,
 423                                      GenerationType max_generation) {
 424   ResourceMark rm;
 425   DEBUG_ONLY(Thread* my_thread = Thread::current();)
 426 
 427   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
 428   assert(my_thread->is_VM_thread() ||
 429          my_thread->is_ConcurrentGC_thread(),
 430          "incorrect thread type capability");
 431   assert(Heap_lock->is_locked(),
 432          "the requesting thread should have the Heap_lock");
 433   guarantee(!is_gc_active(), "collection is not reentrant");
 434 
 435   if (GC_locker::check_active_before_gc()) {
 436     return; // GC is disabled (e.g. JNI GetXXXCritical operation)
 437   }
 438 


 439   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
 440                           collector_policy()->should_clear_all_soft_refs();
 441 
 442   ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
 443 
 444   const size_t metadata_prev_used = MetaspaceAux::used_bytes();
 445 
 446   print_heap_before_gc();
 447 
 448   {
 449     FlagSetting fl(_is_gc_active, true);
 450 
 451     bool complete = full && (max_generation == OldGen);
 452     const char* gc_cause_prefix = complete ? "Full GC" : "GC";
 453     TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
 454     // The PrintGCDetails logging starts before we have incremented the GC id. We will do that later
 455     // so we can assume here that the next GC id is what we want.
 456     GCTraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, NULL, GCId::peek());
 457 
 458     gc_prologue(complete);
 459     increment_total_collections(complete);
 460 
 461     size_t gch_prev_used = used();
 462     bool run_verification = total_collections() >= VerifyGCStartAt;
 463 
 464     bool prepared_for_verification = false;
 465     bool collected_old = false;
 466     bool old_collects_young = complete &&
 467                               _old_gen->full_collects_young_generation();
 468     if (!old_collects_young &&
 469         _young_gen->should_collect(full, size, is_tlab)) {
 470       if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
 471         prepare_for_verify();
 472         prepared_for_verification = true;
 473       }
 474 
 475       assert(!_young_gen->performs_in_place_marking(), "No young generation do in place marking");
 476       collect_generation(_young_gen,
 477                          full,
 478                          size,
 479                          is_tlab,
 480                          run_verification && VerifyGCLevel <= 0,
 481                          do_clear_all_soft_refs,
 482                          false);
 483 
 484       if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
 485           size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
 486         // Allocation request was met by young GC.
 487         size = 0;
 488       }
 489     }
 490 
 491     bool must_restore_marks_for_biased_locking = false;
 492 
 493     if (max_generation == OldGen && _old_gen->should_collect(full, size, is_tlab)) {

 494       if (!complete) {
 495         // The full_collections increment was missed above.
 496         increment_total_full_collections();
 497       }
 498 
 499       pre_full_gc_dump(NULL);    // do any pre full gc dumps
 500 
 501       if (!prepared_for_verification && run_verification &&
 502           VerifyGCLevel <= 1 && VerifyBeforeGC) {
 503         prepare_for_verify();
 504       }
 505 
 506       assert(_old_gen->performs_in_place_marking(), "All old generations do in place marking");
 507       collect_generation(_old_gen,
 508                          full,
 509                          size,
 510                          is_tlab,
 511                          run_verification && VerifyGCLevel <= 1,
 512                          do_clear_all_soft_refs,
 513                          true);




  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/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/collectorCounters.hpp"
  33 #include "gc/shared/gcId.hpp"
  34 #include "gc/shared/gcLocker.inline.hpp"
  35 #include "gc/shared/gcTrace.hpp"
  36 #include "gc/shared/gcTraceTime.hpp"
  37 #include "gc/shared/genCollectedHeap.hpp"
  38 #include "gc/shared/genOopClosures.inline.hpp"
  39 #include "gc/shared/generationSpec.hpp"
  40 #include "gc/shared/space.hpp"
  41 #include "gc/shared/strongRootsScope.hpp"
  42 #include "gc/shared/vmGCOperations.hpp"
  43 #include "gc/shared/workgroup.hpp"
  44 #include "memory/filemap.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "oops/oop.inline.hpp"
  47 #include "runtime/biasedLocking.hpp"
  48 #include "runtime/fprofiler.hpp"
  49 #include "runtime/handles.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/vmThread.hpp"
  53 #include "services/management.hpp"


 301 }
 302 
 303 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
 304   if (!UseConcMarkSweepGC) {
 305     return false;
 306   }
 307 
 308   switch (cause) {
 309     case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
 310     case GCCause::_java_lang_system_gc:
 311     case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
 312     default:                            return false;
 313   }
 314 }
 315 
 316 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
 317                                           bool is_tlab, bool run_verification, bool clear_soft_refs,
 318                                           bool restore_marks_for_biased_locking) {
 319   // Timer for individual generations. Last argument is false: no CR
 320   // FIXME: We should try to start the timing earlier to cover more of the GC pause
 321   GCTraceTime t1(gen->short_name(), PrintGCDetails, false, NULL);


 322   TraceCollectorStats tcs(gen->counters());
 323   TraceMemoryManagerStats tmms(gen->kind(),gc_cause());
 324 
 325   size_t prev_used = gen->used();
 326   gen->stat_record()->invocations++;
 327   gen->stat_record()->accumulated_time.start();
 328 
 329   // Must be done anew before each collection because
 330   // a previous collection will do mangling and will
 331   // change top of some spaces.
 332   record_gen_tops_before_GC();
 333 
 334   if (PrintGC && Verbose) {
 335     // I didn't want to change the logging when removing the level concept,
 336     // but I guess this logging could say young/old or something instead of 0/1.
 337     uint level;
 338     if (heap()->is_young_gen(gen)) {
 339       level = 0;
 340     } else {
 341       level = 1;


 418 void GenCollectedHeap::do_collection(bool           full,
 419                                      bool           clear_all_soft_refs,
 420                                      size_t         size,
 421                                      bool           is_tlab,
 422                                      GenerationType max_generation) {
 423   ResourceMark rm;
 424   DEBUG_ONLY(Thread* my_thread = Thread::current();)
 425 
 426   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
 427   assert(my_thread->is_VM_thread() ||
 428          my_thread->is_ConcurrentGC_thread(),
 429          "incorrect thread type capability");
 430   assert(Heap_lock->is_locked(),
 431          "the requesting thread should have the Heap_lock");
 432   guarantee(!is_gc_active(), "collection is not reentrant");
 433 
 434   if (GC_locker::check_active_before_gc()) {
 435     return; // GC is disabled (e.g. JNI GetXXXCritical operation)
 436   }
 437 
 438   GCIdMark gc_id_mark;
 439 
 440   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
 441                           collector_policy()->should_clear_all_soft_refs();
 442 
 443   ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
 444 
 445   const size_t metadata_prev_used = MetaspaceAux::used_bytes();
 446 
 447   print_heap_before_gc();
 448 
 449   {
 450     FlagSetting fl(_is_gc_active, true);
 451 
 452     bool complete = full && (max_generation == OldGen);
 453     const char* gc_cause_prefix = complete ? "Full GC" : "GC";
 454     TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
 455     GCTraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, NULL);


 456 
 457     gc_prologue(complete);
 458     increment_total_collections(complete);
 459 
 460     size_t gch_prev_used = used();
 461     bool run_verification = total_collections() >= VerifyGCStartAt;
 462 
 463     bool prepared_for_verification = false;
 464     bool collected_old = false;
 465     bool old_collects_young = complete &&
 466                               _old_gen->full_collects_young_generation();
 467     if (!old_collects_young &&
 468         _young_gen->should_collect(full, size, is_tlab)) {
 469       if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
 470         prepare_for_verify();
 471         prepared_for_verification = true;
 472       }
 473 
 474       assert(!_young_gen->performs_in_place_marking(), "No young generation do in place marking");
 475       collect_generation(_young_gen,
 476                          full,
 477                          size,
 478                          is_tlab,
 479                          run_verification && VerifyGCLevel <= 0,
 480                          do_clear_all_soft_refs,
 481                          false);
 482 
 483       if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
 484           size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
 485         // Allocation request was met by young GC.
 486         size = 0;
 487       }
 488     }
 489 
 490     bool must_restore_marks_for_biased_locking = false;
 491 
 492     if (max_generation == OldGen && _old_gen->should_collect(full, size, is_tlab)) {
 493       GCIdMark gc_id_mark;
 494       if (!complete) {
 495         // The full_collections increment was missed above.
 496         increment_total_full_collections();
 497       }
 498 
 499       pre_full_gc_dump(NULL);    // do any pre full gc dumps
 500 
 501       if (!prepared_for_verification && run_verification &&
 502           VerifyGCLevel <= 1 && VerifyBeforeGC) {
 503         prepare_for_verify();
 504       }
 505 
 506       assert(_old_gen->performs_in_place_marking(), "All old generations do in place marking");
 507       collect_generation(_old_gen,
 508                          full,
 509                          size,
 510                          is_tlab,
 511                          run_verification && VerifyGCLevel <= 1,
 512                          do_clear_all_soft_refs,
 513                          true);


< prev index next >