Skip to content

Commit a073e12

Browse files
author
Poonam Bajaj
committed
8229420: [Redo] jstat reports incorrect values for OU for CMS GC
Reviewed-by: tschatzl, sgehwolf
1 parent f0ff63c commit a073e12

8 files changed

+59
-3
lines changed

src/hotspot/share/gc/cms/cmsHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CompactibleFreeListSpacePool : public CollectedMemoryPool {
6262
}
6363

6464
size_t used_in_bytes() {
65-
return _space->used();
65+
return _space->used_stable();
6666
}
6767
};
6868

src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs, M
372372
)
373373
}
374374
_dictionary->set_par_lock(&_parDictionaryAllocLock);
375+
376+
_used_stable = 0;
375377
}
376378

377379
// Like CompactibleSpace forward() but always calls cross_threshold() to
@@ -577,6 +579,14 @@ size_t CompactibleFreeListSpace::used() const {
577579
return capacity() - free();
578580
}
579581

582+
size_t CompactibleFreeListSpace::used_stable() const {
583+
return _used_stable;
584+
}
585+
586+
void CompactibleFreeListSpace::recalculate_used_stable() {
587+
_used_stable = used();
588+
}
589+
580590
size_t CompactibleFreeListSpace::free() const {
581591
// "MT-safe, but not MT-precise"(TM), if you will: i.e.
582592
// if you do this while the structures are in flux you
@@ -1374,6 +1384,13 @@ HeapWord* CompactibleFreeListSpace::allocate(size_t size) {
13741384
debug_only(fc->mangleAllocated(size));
13751385
}
13761386

1387+
// During GC we do not need to recalculate the stable used value for
1388+
// every allocation in old gen. It is done once at the end of GC instead
1389+
// for performance reasons.
1390+
if (!CMSHeap::heap()->is_gc_active()) {
1391+
recalculate_used_stable();
1392+
}
1393+
13771394
return res;
13781395
}
13791396

src/hotspot/share/gc/cms/compactibleFreeListSpace.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ class CompactibleFreeListSpace: public CompactibleSpace {
192192
// Used to keep track of limit of sweep for the space
193193
HeapWord* _sweep_limit;
194194

195+
// Stable value of used().
196+
size_t _used_stable;
197+
195198
// Used to make the young collector update the mod union table
196199
MemRegionClosure* _preconsumptionDirtyCardClosure;
197200

@@ -412,6 +415,17 @@ class CompactibleFreeListSpace: public CompactibleSpace {
412415
// which overestimates the region by returning the entire
413416
// committed region (this is safe, but inefficient).
414417

418+
// Returns monotonically increasing stable used space bytes for CMS.
419+
// This is required for jstat and other memory monitoring tools
420+
// that might otherwise see inconsistent used space values during a garbage
421+
// collection, promotion or allocation into compactibleFreeListSpace.
422+
// The value returned by this function might be smaller than the
423+
// actual value.
424+
size_t used_stable() const;
425+
// Recalculate and cache the current stable used() value. Only to be called
426+
// in places where we can be sure that the result is stable.
427+
void recalculate_used_stable();
428+
415429
// Returns a subregion of the space containing all the objects in
416430
// the space.
417431
MemRegion used_region() const {

src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ ConcurrentMarkSweepGeneration::unsafe_max_alloc_nogc() const {
692692
return _cmsSpace->max_alloc_in_words() * HeapWordSize;
693693
}
694694

695+
size_t ConcurrentMarkSweepGeneration::used_stable() const {
696+
return cmsSpace()->used_stable();
697+
}
698+
695699
size_t ConcurrentMarkSweepGeneration::max_available() const {
696700
return free() + _virtual_space.uncommitted_size();
697701
}
@@ -1523,6 +1527,8 @@ void CMSCollector::compute_new_size() {
15231527
FreelistLocker z(this);
15241528
MetaspaceGC::compute_new_size();
15251529
_cmsGen->compute_new_size_free_list();
1530+
// recalculate CMS used space after CMS collection
1531+
_cmsGen->cmsSpace()->recalculate_used_stable();
15261532
}
15271533

15281534
// A work method used by the foreground collector to do
@@ -2051,6 +2057,7 @@ void ConcurrentMarkSweepGeneration::gc_prologue(bool full) {
20512057

20522058
_capacity_at_prologue = capacity();
20532059
_used_at_prologue = used();
2060+
_cmsSpace->recalculate_used_stable();
20542061

20552062
// We enable promotion tracking so that card-scanning can recognize
20562063
// which objects have been promoted during this GC and skip them.
@@ -2123,6 +2130,7 @@ void CMSCollector::gc_epilogue(bool full) {
21232130
_eden_chunk_index = 0;
21242131

21252132
size_t cms_used = _cmsGen->cmsSpace()->used();
2133+
_cmsGen->cmsSpace()->recalculate_used_stable();
21262134

21272135
// update performance counters - this uses a special version of
21282136
// update_counters() that allows the utilization to be passed as a
@@ -2816,6 +2824,8 @@ void CMSCollector::checkpointRootsInitial() {
28162824
rp->enable_discovery();
28172825
_collectorState = Marking;
28182826
}
2827+
2828+
_cmsGen->cmsSpace()->recalculate_used_stable();
28192829
}
28202830

28212831
void CMSCollector::checkpointRootsInitialWork() {
@@ -4177,6 +4187,7 @@ void CMSCollector::checkpointRootsFinal() {
41774187
MutexLocker y(bitMapLock(),
41784188
Mutex::_no_safepoint_check_flag);
41794189
checkpointRootsFinalWork();
4190+
_cmsGen->cmsSpace()->recalculate_used_stable();
41804191
}
41814192
verify_work_stacks_empty();
41824193
verify_overflow_empty();
@@ -5336,9 +5347,14 @@ void CMSCollector::sweep() {
53365347
// further below.
53375348
{
53385349
CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock());
5350+
53395351
// Update heap occupancy information which is used as
53405352
// input to soft ref clearing policy at the next gc.
53415353
Universe::update_heap_info_at_gc();
5354+
5355+
// recalculate CMS used space after CMS collection
5356+
_cmsGen->cmsSpace()->recalculate_used_stable();
5357+
53425358
_collectorState = Resizing;
53435359
}
53445360
}
@@ -5427,6 +5443,7 @@ void ConcurrentMarkSweepGeneration::update_gc_stats(Generation* current_generati
54275443
// Gather statistics on the young generation collection.
54285444
collector()->stats().record_gc0_end(used());
54295445
}
5446+
_cmsSpace->recalculate_used_stable();
54305447
}
54315448

54325449
void CMSCollector::sweepWork(ConcurrentMarkSweepGeneration* old_gen) {

src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ class ConcurrentMarkSweepGeneration: public CardGeneration {
11121112
double occupancy() const { return ((double)used())/((double)capacity()); }
11131113
size_t contiguous_available() const;
11141114
size_t unsafe_max_alloc_nogc() const;
1115+
size_t used_stable() const;
11151116

11161117
// over-rides
11171118
MemRegion used_region_at_save_marks() const;

src/hotspot/share/gc/cms/gSpaceCounters.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GSpaceCounters: public CHeapObj<mtGC> {
5959
}
6060

6161
inline void update_used() {
62-
_used->set_value(_gen->used());
62+
_used->set_value(_gen->used_stable());
6363
}
6464

6565
// special version of update_used() to allow the used value to be
@@ -103,7 +103,7 @@ class GenerationUsedHelper : public PerfLongSampleHelper {
103103
GenerationUsedHelper(Generation* g) : _gen(g) { }
104104

105105
inline jlong take_sample() {
106-
return _gen->used();
106+
return _gen->used_stable();
107107
}
108108
};
109109

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ size_t Generation::initial_size() {
6868
return gch->old_gen_spec()->init_size();
6969
}
7070

71+
// This is for CMS. It returns stable monotonic used space size.
72+
// Remove this when CMS is removed.
73+
size_t Generation::used_stable() const {
74+
return used();
75+
}
76+
7177
size_t Generation::max_capacity() const {
7278
return reserved().byte_size();
7379
}

src/hotspot/share/gc/shared/generation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class Generation: public CHeapObj<mtGC> {
156156
virtual size_t capacity() const = 0; // The maximum number of object bytes the
157157
// generation can currently hold.
158158
virtual size_t used() const = 0; // The number of used bytes in the gen.
159+
virtual size_t used_stable() const; // The number of used bytes for memory monitoring tools.
159160
virtual size_t free() const = 0; // The number of free bytes in the gen.
160161

161162
// Support for java.lang.Runtime.maxMemory(); see CollectedHeap.

0 commit comments

Comments
 (0)