Tue, 17 Dec 2019 05:26:57 +0000
8229420: [Redo] jstat reports incorrect values for OU for CMS GC
Reviewed-by: andrew
1.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Tue Dec 17 05:07:06 2019 +0000 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Tue Dec 17 05:26:57 2019 +0000 1.3 @@ -161,6 +161,8 @@ 1.4 } 1.5 _dictionary->set_par_lock(&_parDictionaryAllocLock); 1.6 } 1.7 + 1.8 + _used_stable = 0; 1.9 } 1.10 1.11 // Like CompactibleSpace forward() but always calls cross_threshold() to 1.12 @@ -377,6 +379,14 @@ 1.13 return capacity() - free(); 1.14 } 1.15 1.16 +size_t CompactibleFreeListSpace::used_stable() const { 1.17 + return _used_stable; 1.18 +} 1.19 + 1.20 +void CompactibleFreeListSpace::recalculate_used_stable() { 1.21 + _used_stable = used(); 1.22 +} 1.23 + 1.24 size_t CompactibleFreeListSpace::free() const { 1.25 // "MT-safe, but not MT-precise"(TM), if you will: i.e. 1.26 // if you do this while the structures are in flux you 1.27 @@ -1218,6 +1228,13 @@ 1.28 debug_only(fc->mangleAllocated(size)); 1.29 } 1.30 1.31 + // During GC we do not need to recalculate the stable used value for 1.32 + // every allocation in old gen. It is done once at the end of GC instead 1.33 + // for performance reasons. 1.34 + if (!Universe::heap()->is_gc_active()) { 1.35 + recalculate_used_stable(); 1.36 + } 1.37 + 1.38 return res; 1.39 } 1.40
2.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Tue Dec 17 05:07:06 2019 +0000 2.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Tue Dec 17 05:26:57 2019 +0000 2.3 @@ -148,6 +148,9 @@ 2.4 // Used to keep track of limit of sweep for the space 2.5 HeapWord* _sweep_limit; 2.6 2.7 + // Stable value of used(). 2.8 + size_t _used_stable; 2.9 + 2.10 // Support for compacting cms 2.11 HeapWord* cross_threshold(HeapWord* start, HeapWord* end); 2.12 HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top); 2.13 @@ -343,6 +346,17 @@ 2.14 // which overestimates the region by returning the entire 2.15 // committed region (this is safe, but inefficient). 2.16 2.17 + // Returns monotonically increasing stable used space bytes for CMS. 2.18 + // This is required for jstat and other memory monitoring tools 2.19 + // that might otherwise see inconsistent used space values during a garbage 2.20 + // collection, promotion or allocation into compactibleFreeListSpace. 2.21 + // The value returned by this function might be smaller than the 2.22 + // actual value. 2.23 + size_t used_stable() const; 2.24 + // Recalculate and cache the current stable used() value. Only to be called 2.25 + // in places where we can be sure that the result is stable. 2.26 + void recalculate_used_stable(); 2.27 + 2.28 // Returns a subregion of the space containing all the objects in 2.29 // the space. 2.30 MemRegion used_region() const {
3.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Tue Dec 17 05:07:06 2019 +0000 3.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Tue Dec 17 05:26:57 2019 +0000 3.3 @@ -869,6 +869,10 @@ 3.4 return _cmsSpace->max_alloc_in_words() * HeapWordSize; 3.5 } 3.6 3.7 +size_t ConcurrentMarkSweepGeneration::used_stable() const { 3.8 + return cmsSpace()->used_stable(); 3.9 +} 3.10 + 3.11 size_t ConcurrentMarkSweepGeneration::max_available() const { 3.12 return free() + _virtual_space.uncommitted_size(); 3.13 } 3.14 @@ -1955,6 +1959,8 @@ 3.15 FreelistLocker z(this); 3.16 MetaspaceGC::compute_new_size(); 3.17 _cmsGen->compute_new_size_free_list(); 3.18 + // recalculate CMS used space after CMS collection 3.19 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.20 } 3.21 3.22 // A work method used by foreground collection to determine 3.23 @@ -2768,6 +2774,7 @@ 3.24 3.25 _capacity_at_prologue = capacity(); 3.26 _used_at_prologue = used(); 3.27 + _cmsSpace->recalculate_used_stable(); 3.28 3.29 // Delegate to CMScollector which knows how to coordinate between 3.30 // this and any other CMS generations that it is responsible for 3.31 @@ -2837,6 +2844,7 @@ 3.32 _eden_chunk_index = 0; 3.33 3.34 size_t cms_used = _cmsGen->cmsSpace()->used(); 3.35 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.36 3.37 // update performance counters - this uses a special version of 3.38 // update_counters() that allows the utilization to be passed as a 3.39 @@ -3672,6 +3680,7 @@ 3.40 _collectorState = Marking; 3.41 } 3.42 SpecializationStats::print(); 3.43 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.44 } 3.45 3.46 void CMSCollector::checkpointRootsInitialWork(bool asynch) { 3.47 @@ -5066,10 +5075,12 @@ 3.48 Mutex::_no_safepoint_check_flag); 3.49 assert(!init_mark_was_synchronous, "but that's impossible!"); 3.50 checkpointRootsFinalWork(asynch, clear_all_soft_refs, false); 3.51 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.52 } else { 3.53 // already have all the locks 3.54 checkpointRootsFinalWork(asynch, clear_all_soft_refs, 3.55 init_mark_was_synchronous); 3.56 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.57 } 3.58 verify_work_stacks_empty(); 3.59 verify_overflow_empty(); 3.60 @@ -6368,6 +6379,10 @@ 3.61 // Update heap occupancy information which is used as 3.62 // input to soft ref clearing policy at the next gc. 3.63 Universe::update_heap_info_at_gc(); 3.64 + 3.65 + // recalculate CMS used space after CMS collection 3.66 + _cmsGen->cmsSpace()->recalculate_used_stable(); 3.67 + 3.68 _collectorState = Resizing; 3.69 } 3.70 } else { 3.71 @@ -6467,6 +6482,7 @@ 3.72 // Gather statistics on the young generation collection. 3.73 collector()->stats().record_gc0_end(used()); 3.74 } 3.75 + _cmsSpace->recalculate_used_stable(); 3.76 } 3.77 3.78 CMSAdaptiveSizePolicy* ConcurrentMarkSweepGeneration::size_policy() {
4.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Tue Dec 17 05:07:06 2019 +0000 4.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Tue Dec 17 05:26:57 2019 +0000 4.3 @@ -1190,6 +1190,7 @@ 4.4 double occupancy() const { return ((double)used())/((double)capacity()); } 4.5 size_t contiguous_available() const; 4.6 size_t unsafe_max_alloc_nogc() const; 4.7 + size_t used_stable() const; 4.8 4.9 // over-rides 4.10 MemRegion used_region() const;
5.1 --- a/src/share/vm/gc_implementation/shared/gSpaceCounters.hpp Tue Dec 17 05:07:06 2019 +0000 5.2 +++ b/src/share/vm/gc_implementation/shared/gSpaceCounters.hpp Tue Dec 17 05:26:57 2019 +0000 5.3 @@ -63,7 +63,7 @@ 5.4 } 5.5 5.6 inline void update_used() { 5.7 - _used->set_value(_gen->used()); 5.8 + _used->set_value(_gen->used_stable()); 5.9 } 5.10 5.11 // special version of update_used() to allow the used value to be 5.12 @@ -107,7 +107,7 @@ 5.13 GenerationUsedHelper(Generation* g) : _gen(g) { } 5.14 5.15 inline jlong take_sample() { 5.16 - return _gen->used(); 5.17 + return _gen->used_stable(); 5.18 } 5.19 }; 5.20
6.1 --- a/src/share/vm/memory/generation.cpp Tue Dec 17 05:07:06 2019 +0000 6.2 +++ b/src/share/vm/memory/generation.cpp Tue Dec 17 05:26:57 2019 +0000 6.3 @@ -68,6 +68,12 @@ 6.4 return gch->_gen_specs[level()]; 6.5 } 6.6 6.7 +// This is for CMS. It returns stable monotonic used space size. 6.8 +// Remove this when CMS is removed. 6.9 +size_t Generation::used_stable() const { 6.10 + return used(); 6.11 +} 6.12 + 6.13 size_t Generation::max_capacity() const { 6.14 return reserved().byte_size(); 6.15 }
7.1 --- a/src/share/vm/memory/generation.hpp Tue Dec 17 05:07:06 2019 +0000 7.2 +++ b/src/share/vm/memory/generation.hpp Tue Dec 17 05:26:57 2019 +0000 7.3 @@ -168,6 +168,7 @@ 7.4 virtual size_t capacity() const = 0; // The maximum number of object bytes the 7.5 // generation can currently hold. 7.6 virtual size_t used() const = 0; // The number of used bytes in the gen. 7.7 + virtual size_t used_stable() const; // The number of used bytes for memory monitoring tools. 7.8 virtual size_t free() const = 0; // The number of free bytes in the gen. 7.9 7.10 // Support for java.lang.Runtime.maxMemory(); see CollectedHeap.
8.1 --- a/src/share/vm/services/memoryPool.hpp Tue Dec 17 05:07:06 2019 +0000 8.2 +++ b/src/share/vm/services/memoryPool.hpp Tue Dec 17 05:26:57 2019 +0000 8.3 @@ -198,7 +198,7 @@ 8.4 bool support_usage_threshold); 8.5 8.6 MemoryUsage get_memory_usage(); 8.7 - size_t used_in_bytes() { return _space->used(); } 8.8 + size_t used_in_bytes() { return _space->used_stable(); } 8.9 }; 8.10 #endif // INCLUDE_ALL_GCS 8.11