< prev index next >

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Print this page
rev 52448 : 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>


1134   G1FullCollector collector(this, explicit_gc, do_clear_all_soft_refs);
1135   GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause(), true);
1136 
1137   collector.prepare_collection();
1138   collector.collect();
1139   collector.complete_collection();
1140 
1141   // Full collection was successfully completed.
1142   return true;
1143 }
1144 
1145 void G1CollectedHeap::do_full_collection(bool clear_all_soft_refs) {
1146   // Currently, there is no facility in the do_full_collection(bool) API to notify
1147   // the caller that the collection did not succeed (e.g., because it was locked
1148   // out by the GC locker). So, right now, we'll ignore the return value.
1149   bool dummy = do_full_collection(true,                /* explicit_gc */
1150                                   clear_all_soft_refs);
1151 }
1152 
1153 void G1CollectedHeap::resize_heap_if_necessary() {


1154   // Capacity, free and used after the GC counted as full regions to
1155   // include the waste in the following calculations.
1156   const size_t capacity_after_gc = capacity();
1157   const size_t used_after_gc = capacity_after_gc - unused_committed_regions_in_bytes();
1158 
1159   // This is enforced in arguments.cpp.
1160   assert(MinHeapFreeRatio <= MaxHeapFreeRatio,
1161          "otherwise the code below doesn't make sense");
1162 
1163   // We don't have floating point command-line arguments
1164   const double minimum_free_percentage = (double) MinHeapFreeRatio / 100.0;
1165   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
1166   const double maximum_free_percentage = (double) MaxHeapFreeRatio / 100.0;
1167   const double minimum_used_percentage = 1.0 - maximum_free_percentage;
1168 
1169   const size_t min_heap_size = collector_policy()->min_heap_byte_size();
1170   const size_t max_heap_size = collector_policy()->max_heap_byte_size();
1171 
1172   // We have to be careful here as these two calculations can overflow
1173   // 32-bit size_t's.


1956 
1957 size_t G1CollectedHeap::recalculate_used() const {
1958   SumUsedClosure blk;
1959   heap_region_iterate(&blk);
1960   return blk.result();
1961 }
1962 
1963 bool  G1CollectedHeap::is_user_requested_concurrent_full_gc(GCCause::Cause cause) {
1964   switch (cause) {
1965     case GCCause::_java_lang_system_gc:                 return ExplicitGCInvokesConcurrent;
1966     case GCCause::_dcmd_gc_run:                         return ExplicitGCInvokesConcurrent;
1967     case GCCause::_wb_conc_mark:                        return true;
1968     default :                                           return false;
1969   }
1970 }
1971 
1972 bool G1CollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
1973   switch (cause) {
1974     case GCCause::_gc_locker:               return GCLockerInvokesConcurrent;
1975     case GCCause::_g1_humongous_allocation: return true;

1976     default:                                return is_user_requested_concurrent_full_gc(cause);
1977   }
1978 }
1979 
1980 #ifndef PRODUCT
1981 void G1CollectedHeap::allocate_dummy_regions() {
1982   // Let's fill up most of the region
1983   size_t word_size = HeapRegion::GrainWords - 1024;
1984   // And as a result the region we'll allocate will be humongous.
1985   guarantee(is_humongous(word_size), "sanity");
1986 
1987   // _filler_array_max_size is set to humongous object threshold
1988   // but temporarily change it to use CollectedHeap::fill_with_object().
1989   SizeTFlagSetting fs(_filler_array_max_size, word_size);
1990 
1991   for (uintx i = 0; i < G1DummyRegionsPerGC; ++i) {
1992     // Let's use the existing mechanism for the allocation
1993     HeapWord* dummy_obj = humongous_obj_allocate(word_size);
1994     if (dummy_obj != NULL) {
1995       MemRegion mr(dummy_obj, word_size);




1134   G1FullCollector collector(this, explicit_gc, do_clear_all_soft_refs);
1135   GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause(), true);
1136 
1137   collector.prepare_collection();
1138   collector.collect();
1139   collector.complete_collection();
1140 
1141   // Full collection was successfully completed.
1142   return true;
1143 }
1144 
1145 void G1CollectedHeap::do_full_collection(bool clear_all_soft_refs) {
1146   // Currently, there is no facility in the do_full_collection(bool) API to notify
1147   // the caller that the collection did not succeed (e.g., because it was locked
1148   // out by the GC locker). So, right now, we'll ignore the return value.
1149   bool dummy = do_full_collection(true,                /* explicit_gc */
1150                                   clear_all_soft_refs);
1151 }
1152 
1153 void G1CollectedHeap::resize_heap_if_necessary() {
1154   assert_at_safepoint_on_vm_thread();
1155 
1156   // Capacity, free and used after the GC counted as full regions to
1157   // include the waste in the following calculations.
1158   const size_t capacity_after_gc = capacity();
1159   const size_t used_after_gc = capacity_after_gc - unused_committed_regions_in_bytes();
1160 
1161   // This is enforced in arguments.cpp.
1162   assert(MinHeapFreeRatio <= MaxHeapFreeRatio,
1163          "otherwise the code below doesn't make sense");
1164 
1165   // We don't have floating point command-line arguments
1166   const double minimum_free_percentage = (double) MinHeapFreeRatio / 100.0;
1167   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
1168   const double maximum_free_percentage = (double) MaxHeapFreeRatio / 100.0;
1169   const double minimum_used_percentage = 1.0 - maximum_free_percentage;
1170 
1171   const size_t min_heap_size = collector_policy()->min_heap_byte_size();
1172   const size_t max_heap_size = collector_policy()->max_heap_byte_size();
1173 
1174   // We have to be careful here as these two calculations can overflow
1175   // 32-bit size_t's.


1958 
1959 size_t G1CollectedHeap::recalculate_used() const {
1960   SumUsedClosure blk;
1961   heap_region_iterate(&blk);
1962   return blk.result();
1963 }
1964 
1965 bool  G1CollectedHeap::is_user_requested_concurrent_full_gc(GCCause::Cause cause) {
1966   switch (cause) {
1967     case GCCause::_java_lang_system_gc:                 return ExplicitGCInvokesConcurrent;
1968     case GCCause::_dcmd_gc_run:                         return ExplicitGCInvokesConcurrent;
1969     case GCCause::_wb_conc_mark:                        return true;
1970     default :                                           return false;
1971   }
1972 }
1973 
1974 bool G1CollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
1975   switch (cause) {
1976     case GCCause::_gc_locker:               return GCLockerInvokesConcurrent;
1977     case GCCause::_g1_humongous_allocation: return true;
1978     case GCCause::_g1_periodic_collection:  return G1PeriodicGCInvokesConcurrent;
1979     default:                                return is_user_requested_concurrent_full_gc(cause);
1980   }
1981 }
1982 
1983 #ifndef PRODUCT
1984 void G1CollectedHeap::allocate_dummy_regions() {
1985   // Let's fill up most of the region
1986   size_t word_size = HeapRegion::GrainWords - 1024;
1987   // And as a result the region we'll allocate will be humongous.
1988   guarantee(is_humongous(word_size), "sanity");
1989 
1990   // _filler_array_max_size is set to humongous object threshold
1991   // but temporarily change it to use CollectedHeap::fill_with_object().
1992   SizeTFlagSetting fs(_filler_array_max_size, word_size);
1993 
1994   for (uintx i = 0; i < G1DummyRegionsPerGC; ++i) {
1995     // Let's use the existing mechanism for the allocation
1996     HeapWord* dummy_obj = humongous_obj_allocate(word_size);
1997     if (dummy_obj != NULL) {
1998       MemRegion mr(dummy_obj, word_size);


< prev index next >