< prev index next >

src/hotspot/share/gc/shared/vmGCOperations.cpp

Print this page
rev 52572 : JDK-8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
Summary: Issue optional, default enabled, concurrent cycles when the VM is idle to reclaim unused internal and Java heap memory.
Reviewed-by:
Contributed-by: Rodrigo Bruno <rbruno@gsd.inesc-id.pt>, Ruslan Synytsky <rs@jelastic.com>, Thomas Schatzl <thomas.schatzl@oracle.com>


  64 
  65 // Allocations may fail in several threads at about the same time,
  66 // resulting in multiple gc requests.  We only want to do one of them.
  67 // In case a GC locker is active and the need for a GC is already signaled,
  68 // we want to skip this GC attempt altogether, without doing a futile
  69 // safepoint operation.
  70 bool VM_GC_Operation::skip_operation() const {
  71   bool skip = (_gc_count_before != Universe::heap()->total_collections());
  72   if (_full && skip) {
  73     skip = (_full_gc_count_before != Universe::heap()->total_full_collections());
  74   }
  75   if (!skip && GCLocker::is_active_and_needs_gc()) {
  76     skip = Universe::heap()->is_maximal_no_gc();
  77     assert(!(skip && (_gc_cause == GCCause::_gc_locker)),
  78            "GCLocker cannot be active when initiating GC");
  79   }
  80   return skip;
  81 }
  82 
  83 bool VM_GC_Operation::doit_prologue() {
  84   assert(Thread::current()->is_Java_thread(), "just checking");
  85   assert(((_gc_cause != GCCause::_no_gc) &&
  86           (_gc_cause != GCCause::_no_cause_specified)), "Illegal GCCause");
  87 
  88   // To be able to handle a GC the VM initialization needs to be completed.
  89   if (!is_init_completed()) {
  90     vm_exit_during_initialization(
  91       err_msg("GC triggered before VM initialization completed. Try increasing "
  92               "NewSize, current value " SIZE_FORMAT "%s.",
  93               byte_size_in_proper_unit(NewSize),
  94               proper_unit_for_byte_size(NewSize)));
  95   }
  96 
  97   // If the GC count has changed someone beat us to the collection
  98   Heap_lock->lock();
  99 
 100   // Check invocations
 101   if (skip_operation()) {
 102     // skip collection
 103     Heap_lock->unlock();
 104     _prologue_succeeded = false;
 105   } else {
 106     _prologue_succeeded = true;
 107   }
 108   return _prologue_succeeded;
 109 }
 110 
 111 
 112 void VM_GC_Operation::doit_epilogue() {
 113   assert(Thread::current()->is_Java_thread(), "just checking");
 114   // Clean up old interpreter OopMap entries that were replaced
 115   // during the GC thread root traversal.
 116   OopMapCache::cleanup_old_entries();
 117   if (Universe::has_reference_pending_list()) {
 118     Heap_lock->notify_all();
 119   }
 120   Heap_lock->unlock();
 121 }
 122 
 123 bool VM_GC_HeapInspection::skip_operation() const {
 124   return false;
 125 }
 126 
 127 bool VM_GC_HeapInspection::collect() {
 128   if (GCLocker::is_active()) {
 129     return false;
 130   }
 131   Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
 132   return true;
 133 }




  64 
  65 // Allocations may fail in several threads at about the same time,
  66 // resulting in multiple gc requests.  We only want to do one of them.
  67 // In case a GC locker is active and the need for a GC is already signaled,
  68 // we want to skip this GC attempt altogether, without doing a futile
  69 // safepoint operation.
  70 bool VM_GC_Operation::skip_operation() const {
  71   bool skip = (_gc_count_before != Universe::heap()->total_collections());
  72   if (_full && skip) {
  73     skip = (_full_gc_count_before != Universe::heap()->total_full_collections());
  74   }
  75   if (!skip && GCLocker::is_active_and_needs_gc()) {
  76     skip = Universe::heap()->is_maximal_no_gc();
  77     assert(!(skip && (_gc_cause == GCCause::_gc_locker)),
  78            "GCLocker cannot be active when initiating GC");
  79   }
  80   return skip;
  81 }
  82 
  83 bool VM_GC_Operation::doit_prologue() {

  84   assert(((_gc_cause != GCCause::_no_gc) &&
  85           (_gc_cause != GCCause::_no_cause_specified)), "Illegal GCCause");
  86 
  87   // To be able to handle a GC the VM initialization needs to be completed.
  88   if (!is_init_completed()) {
  89     vm_exit_during_initialization(
  90       err_msg("GC triggered before VM initialization completed. Try increasing "
  91               "NewSize, current value " SIZE_FORMAT "%s.",
  92               byte_size_in_proper_unit(NewSize),
  93               proper_unit_for_byte_size(NewSize)));
  94   }
  95 
  96   // If the GC count has changed someone beat us to the collection
  97   Heap_lock->lock();
  98 
  99   // Check invocations
 100   if (skip_operation()) {
 101     // skip collection
 102     Heap_lock->unlock();
 103     _prologue_succeeded = false;
 104   } else {
 105     _prologue_succeeded = true;
 106   }
 107   return _prologue_succeeded;
 108 }
 109 
 110 
 111 void VM_GC_Operation::doit_epilogue() {

 112   // Clean up old interpreter OopMap entries that were replaced
 113   // during the GC thread root traversal.
 114   OopMapCache::cleanup_old_entries();
 115   if (Universe::has_reference_pending_list()) {
 116     Heap_lock->notify_all();
 117   }
 118   Heap_lock->unlock();
 119 }
 120 
 121 bool VM_GC_HeapInspection::skip_operation() const {
 122   return false;
 123 }
 124 
 125 bool VM_GC_HeapInspection::collect() {
 126   if (GCLocker::is_active()) {
 127     return false;
 128   }
 129   Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
 130   return true;
 131 }


< prev index next >