Skip to content

Commit 9852a6f

Browse files
author
Thomas Schatzl
committedAug 7, 2020
8248401: Refactor/unify RMI gc support functionality
Move recent timestamp of most recent whole heap liveness analysis into CollectedHeap, removing the duplicates in all collectors Reviewed-by: kbarrett, ayang, stefank
1 parent 1ad1659 commit 9852a6f

25 files changed

+56
-166
lines changed
 

‎src/hotspot/share/gc/epsilon/epsilonHeap.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ class EpsilonHeap : public CollectedHeap {
129129
virtual void prepare_for_verify() {}
130130
virtual void verify(VerifyOption option) {}
131131

132-
virtual jlong millis_since_last_gc() {
133-
// Report time since the VM start
134-
return os::elapsed_counter() / NANOSECS_PER_MILLISEC;
135-
}
136-
137132
MemRegion reserved_region() const { return _reserved; }
138133
bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
139134

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

+10-15
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ G1CollectedHeap::G1CollectedHeap() :
14171417
_young_gen_sampling_thread(NULL),
14181418
_workers(NULL),
14191419
_card_table(NULL),
1420+
_collection_pause_end(Ticks::now()),
14201421
_soft_ref_policy(),
14211422
_old_set("Old Region Set", new OldRegionSetChecker()),
14221423
_archive_set("Archive Region Set", new ArchiveRegionSetChecker()),
@@ -1966,7 +1967,8 @@ void G1CollectedHeap::increment_old_marking_cycles_started() {
19661967
_old_marking_cycles_started++;
19671968
}
19681969

1969-
void G1CollectedHeap::increment_old_marking_cycles_completed(bool concurrent) {
1970+
void G1CollectedHeap::increment_old_marking_cycles_completed(bool concurrent,
1971+
bool whole_heap_examined) {
19701972
MonitorLocker ml(G1OldGCCount_lock, Mutex::_no_safepoint_check_flag);
19711973

19721974
// We assume that if concurrent == true, then the caller is a
@@ -1998,6 +2000,10 @@ void G1CollectedHeap::increment_old_marking_cycles_completed(bool concurrent) {
19982000
_old_marking_cycles_started, _old_marking_cycles_completed);
19992001

20002002
_old_marking_cycles_completed += 1;
2003+
if (whole_heap_examined) {
2004+
// Signal that we have completed a visit to all live objects.
2005+
record_whole_heap_examined_timestamp();
2006+
}
20012007

20022008
// We need to clear the "in_progress" flag in the CM thread before
20032009
// we wake up any waiters (especially when ExplicitInvokesConcurrent
@@ -2366,19 +2372,6 @@ size_t G1CollectedHeap::max_reserved_capacity() const {
23662372
return _hrm->max_length() * HeapRegion::GrainBytes;
23672373
}
23682374

2369-
jlong G1CollectedHeap::millis_since_last_gc() {
2370-
// See the notes in GenCollectedHeap::millis_since_last_gc()
2371-
// for more information about the implementation.
2372-
jlong ret_val = (os::javaTimeNanos() / NANOSECS_PER_MILLISEC) -
2373-
_policy->collection_pause_end_millis();
2374-
if (ret_val < 0) {
2375-
log_warning(gc)("millis_since_last_gc() would return : " JLONG_FORMAT
2376-
". returning zero instead.", ret_val);
2377-
return 0;
2378-
}
2379-
return ret_val;
2380-
}
2381-
23822375
void G1CollectedHeap::deduplicate_string(oop str) {
23832376
assert(java_lang_String::is_instance(str), "invariant");
23842377

@@ -2641,7 +2634,7 @@ void G1CollectedHeap::gc_epilogue(bool full) {
26412634
// Update common counters.
26422635
if (full) {
26432636
// Update the number of full collections that have been completed.
2644-
increment_old_marking_cycles_completed(false /* concurrent */);
2637+
increment_old_marking_cycles_completed(false /* concurrent */, true /* liveness_completed */);
26452638
}
26462639

26472640
// We are at the end of the GC. Total collections has already been increased.
@@ -2665,6 +2658,8 @@ void G1CollectedHeap::gc_epilogue(bool full) {
26652658

26662659
// Print NUMA statistics.
26672660
_numa->print_statistics();
2661+
2662+
_collection_pause_end = Ticks::now();
26682663
}
26692664

26702665
void G1CollectedHeap::verify_numa_regions(const char* desc) {

‎src/hotspot/share/gc/g1/g1CollectedHeap.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class G1CollectedHeap : public CollectedHeap {
159159
WorkGang* _workers;
160160
G1CardTable* _card_table;
161161

162+
Ticks _collection_pause_end;
163+
162164
SoftRefPolicy _soft_ref_policy;
163165

164166
static size_t _humongous_object_threshold_in_words;
@@ -644,7 +646,10 @@ class G1CollectedHeap : public CollectedHeap {
644646
// the G1OldGCCount_lock in case a Java thread is waiting for a full
645647
// GC to happen (e.g., it called System.gc() with
646648
// +ExplicitGCInvokesConcurrent).
647-
void increment_old_marking_cycles_completed(bool concurrent);
649+
// whole_heap_examined should indicate that during that old marking
650+
// cycle the whole heap has been examined for live objects (as opposed
651+
// to only parts, or aborted before completion).
652+
void increment_old_marking_cycles_completed(bool concurrent, bool whole_heap_examined);
648653

649654
uint old_marking_cycles_completed() {
650655
return _old_marking_cycles_completed;
@@ -1288,8 +1293,7 @@ class G1CollectedHeap : public CollectedHeap {
12881293
// Return the size of reserved memory. Returns different value than max_capacity() when AllocateOldGenAt is used.
12891294
virtual size_t max_reserved_capacity() const;
12901295

1291-
virtual jlong millis_since_last_gc();
1292-
1296+
Tickspan time_since_last_collection() const { return Ticks::now() - _collection_pause_end; }
12931297

12941298
// Convenience function to be used in situations where the heap type can be
12951299
// asserted to be this type.

‎src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ void G1ConcurrentMarkThread::run_service() {
268268
// called System.gc() with +ExplicitGCInvokesConcurrent).
269269
{
270270
SuspendibleThreadSetJoiner sts_join;
271-
g1h->increment_old_marking_cycles_completed(true /* concurrent */);
271+
g1h->increment_old_marking_cycles_completed(true /* concurrent */,
272+
!_cm->has_aborted() /* liveness_completed */);
272273

273274
_cm->concurrent_cycle_end();
274275
ConcurrentGCBreakpoints::notify_active_to_idle();

‎src/hotspot/share/gc/g1/g1Policy.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ G1Policy::G1Policy(STWGCTimer* gc_timer) :
6060
_ihop_control(create_ihop_control(&_predictor)),
6161
_policy_counters(new GCPolicyCounters("GarbageFirst", 1, 2)),
6262
_full_collection_start_sec(0.0),
63-
_collection_pause_end_millis(os::javaTimeNanos() / NANOSECS_PER_MILLISEC),
6463
_young_list_target_length(0),
6564
_young_list_fixed_length(0),
6665
_young_list_max_length(0),
@@ -648,8 +647,6 @@ void G1Policy::record_collection_pause_end(double pause_time_ms) {
648647

649648
record_pause(this_pause, end_time_sec - pause_time_ms / 1000.0, end_time_sec);
650649

651-
_collection_pause_end_millis = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
652-
653650
if (is_concurrent_start_pause(this_pause)) {
654651
record_concurrent_mark_init_end(0.0);
655652
} else {

‎src/hotspot/share/gc/g1/g1Policy.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class G1Policy: public CHeapObj<mtGC> {
7474

7575
double _full_collection_start_sec;
7676

77-
jlong _collection_pause_end_millis;
78-
7977
uint _young_list_target_length;
8078
uint _young_list_fixed_length;
8179

@@ -260,8 +258,6 @@ class G1Policy: public CHeapObj<mtGC> {
260258
// percentage of the current heap capacity.
261259
double reclaimable_bytes_percent(size_t reclaimable_bytes) const;
262260

263-
jlong collection_pause_end_millis() { return _collection_pause_end_millis; }
264-
265261
private:
266262
void clear_collection_set_candidates();
267263
// Sets up marking if proper conditions are met.

‎src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ void G1YoungRemSetSamplingThread::sleep_before_next_cycle() {
5656
}
5757

5858
bool G1YoungRemSetSamplingThread::should_start_periodic_gc() {
59+
G1CollectedHeap* g1h = G1CollectedHeap::heap();
5960
// If we are currently in a concurrent mark we are going to uncommit memory soon.
60-
if (G1CollectedHeap::heap()->concurrent_mark()->cm_thread()->during_cycle()) {
61+
if (g1h->concurrent_mark()->cm_thread()->during_cycle()) {
6162
log_debug(gc, periodic)("Concurrent cycle in progress. Skipping.");
6263
return false;
6364
}
6465

6566
// Check if enough time has passed since the last GC.
66-
uintx time_since_last_gc = (uintx)Universe::heap()->millis_since_last_gc();
67+
uintx time_since_last_gc = (uintx)g1h->time_since_last_collection().milliseconds();
6768
if ((time_since_last_gc < G1PeriodicGCInterval)) {
6869
log_debug(gc, periodic)("Last GC occurred " UINTX_FORMAT "ms before which is below threshold " UINTX_FORMAT "ms. Skipping.",
6970
time_since_last_gc, G1PeriodicGCInterval);

‎src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,6 @@ bool ParallelScavengeHeap::block_is_obj(const HeapWord* addr) const {
559559
return block_start(addr) == addr;
560560
}
561561

562-
jlong ParallelScavengeHeap::millis_since_last_gc() {
563-
return PSParallelCompact::millis_since_last_gc();
564-
}
565-
566562
void ParallelScavengeHeap::prepare_for_verify() {
567563
ensure_parsability(false); // no need to retire TLABs for verification
568564
}

‎src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ class ParallelScavengeHeap : public CollectedHeap {
213213
HeapWord* block_start(const void* addr) const;
214214
bool block_is_obj(const HeapWord* addr) const;
215215

216-
jlong millis_since_last_gc();
217-
218216
void prepare_for_verify();
219217
PSHeapSummary create_ps_heap_summary();
220218
virtual void print_on(outputStream* st) const;

‎src/hotspot/share/gc/parallel/psParallelCompact.cpp

+2-22
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ ParallelOldTracer PSParallelCompact::_gc_tracer;
843843
elapsedTimer PSParallelCompact::_accumulated_time;
844844
unsigned int PSParallelCompact::_total_invocations = 0;
845845
unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0;
846-
jlong PSParallelCompact::_time_of_last_gc = 0;
847846
CollectorCounters* PSParallelCompact::_counters = NULL;
848847
ParMarkBitMap PSParallelCompact::_mark_bitmap;
849848
ParallelCompactData PSParallelCompact::_summary_data;
@@ -1070,8 +1069,8 @@ void PSParallelCompact::post_compact()
10701069
heap->gen_mangle_unused_area();
10711070
}
10721071

1073-
// Update time of last GC
1074-
reset_millis_since_last_gc();
1072+
// Signal that we have completed a visit to all live objects.
1073+
Universe::heap()->record_whole_heap_examined_timestamp();
10751074
}
10761075

10771076
HeapWord*
@@ -3192,25 +3191,6 @@ void PSParallelCompact::fill_blocks(size_t region_idx)
31923191
}
31933192
}
31943193

3195-
jlong PSParallelCompact::millis_since_last_gc() {
3196-
// We need a monotonically non-decreasing time in ms but
3197-
// os::javaTimeMillis() does not guarantee monotonicity.
3198-
jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
3199-
jlong ret_val = now - _time_of_last_gc;
3200-
// XXX See note in genCollectedHeap::millis_since_last_gc().
3201-
if (ret_val < 0) {
3202-
NOT_PRODUCT(log_warning(gc)("time warp: " JLONG_FORMAT, ret_val);)
3203-
return 0;
3204-
}
3205-
return ret_val;
3206-
}
3207-
3208-
void PSParallelCompact::reset_millis_since_last_gc() {
3209-
// We need a monotonically non-decreasing time in ms but
3210-
// os::javaTimeMillis() does not guarantee monotonicity.
3211-
_time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
3212-
}
3213-
32143194
ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full()
32153195
{
32163196
if (source() != copy_destination()) {

‎src/hotspot/share/gc/parallel/psParallelCompact.hpp

-7
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,6 @@ class PSParallelCompact : AllStatic {
10091009
static elapsedTimer _accumulated_time;
10101010
static unsigned int _total_invocations;
10111011
static unsigned int _maximum_compaction_gc_num;
1012-
static jlong _time_of_last_gc; // ms
10131012
static CollectorCounters* _counters;
10141013
static ParMarkBitMap _mark_bitmap;
10151014
static ParallelCompactData _summary_data;
@@ -1123,9 +1122,6 @@ class PSParallelCompact : AllStatic {
11231122
static void enqueue_dense_prefix_tasks(TaskQueue& task_queue,
11241123
uint parallel_gc_threads);
11251124

1126-
// Reset time since last full gc
1127-
static void reset_millis_since_last_gc();
1128-
11291125
#ifndef PRODUCT
11301126
// Print generic summary data
11311127
static void print_generic_summary_data(ParallelCompactData& summary_data,
@@ -1249,9 +1245,6 @@ class PSParallelCompact : AllStatic {
12491245
// Return the SpaceId for the given address.
12501246
static SpaceId space_id(HeapWord* addr);
12511247

1252-
// Time since last full gc (in milliseconds).
1253-
static jlong millis_since_last_gc();
1254-
12551248
static void print_on_error(outputStream* st);
12561249

12571250
#ifndef PRODUCT

‎src/hotspot/share/gc/serial/defNewGeneration.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,6 @@ void DefNewGeneration::collect(bool full,
680680
from()->set_concurrent_iteration_safe_limit(from()->top());
681681
to()->set_concurrent_iteration_safe_limit(to()->top());
682682

683-
// We need to use a monotonically non-decreasing time in ms
684-
// or we will see time-warp warnings and os::javaTimeMillis()
685-
// does not guarantee monotonicity.
686-
jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
687-
update_time_of_last_gc(now);
688-
689683
heap->trace_heap_after_gc(&gc_tracer);
690684

691685
_gc_timer->register_gc_end();

‎src/hotspot/share/gc/serial/genMarkSweep.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,8 @@ void GenMarkSweep::invoke_at_safepoint(ReferenceProcessor* rp, bool clear_all_so
137137
// input to soft ref clearing policy at the next gc.
138138
Universe::update_heap_info_at_gc();
139139

140-
// Update time of last gc for all generations we collected
141-
// (which currently is all the generations in the heap).
142-
// We need to use a monotonically non-decreasing time in ms
143-
// or we will see time-warp warnings and os::javaTimeMillis()
144-
// does not guarantee monotonicity.
145-
jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
146-
gch->update_time_of_last_gc(now);
140+
// Signal that we have completed a visit to all live objects.
141+
Universe::heap()->record_whole_heap_examined_timestamp();
147142

148143
gch->trace_heap_after_gc(_gc_tracer);
149144
}

‎src/hotspot/share/gc/shared/collectedHeap.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ bool CollectedHeap::is_oop(oop object) const {
191191

192192
CollectedHeap::CollectedHeap() :
193193
_is_gc_active(false),
194+
_last_whole_heap_examined_time_ns(os::javaTimeNanos()),
194195
_total_collections(0),
195196
_total_full_collections(0),
196197
_gc_cause(GCCause::_no_gc),
@@ -488,6 +489,14 @@ void CollectedHeap::resize_all_tlabs() {
488489
}
489490
}
490491

492+
jlong CollectedHeap::millis_since_last_whole_heap_examined() {
493+
return (os::javaTimeNanos() - _last_whole_heap_examined_time_ns) / NANOSECS_PER_MILLISEC;
494+
}
495+
496+
void CollectedHeap::record_whole_heap_examined_timestamp() {
497+
_last_whole_heap_examined_time_ns = os::javaTimeNanos();
498+
}
499+
491500
void CollectedHeap::full_gc_dump(GCTimer* timer, bool before) {
492501
assert(timer != NULL, "timer is null");
493502
if ((HeapDumpBeforeFullGC && before) || (HeapDumpAfterFullGC && !before)) {

‎src/hotspot/share/gc/shared/collectedHeap.hpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ class CollectedHeap : public CHeapObj<mtInternal> {
112112
// Used for filler objects (static, but initialized in ctor).
113113
static size_t _filler_array_max_size;
114114

115+
// Last time the whole heap has been examined in support of RMI
116+
// MaxObjectInspectionAge.
117+
// This timestamp must be monotonically non-decreasing to avoid
118+
// time-warp warnings.
119+
jlong _last_whole_heap_examined_time_ns;
120+
115121
unsigned int _total_collections; // ... started
116122
unsigned int _total_full_collections; // ... started
117123
NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;)
@@ -404,15 +410,18 @@ class CollectedHeap : public CHeapObj<mtInternal> {
404410
// Keep alive an object that was loaded with AS_NO_KEEPALIVE.
405411
virtual void keep_alive(oop obj) {}
406412

407-
// Returns the longest time (in ms) that has elapsed since the last
408-
// time that any part of the heap was examined by a garbage collection.
409-
virtual jlong millis_since_last_gc() = 0;
410-
411413
// Perform any cleanup actions necessary before allowing a verification.
412414
virtual void prepare_for_verify() = 0;
413415

414-
// Generate any dumps preceding or following a full gc
416+
// Returns the longest time (in ms) that has elapsed since the last
417+
// time that the whole heap has been examined by a garbage collection.
418+
jlong millis_since_last_whole_heap_examined();
419+
// GC should call this when the next whole heap analysis has completed to
420+
// satisfy above requirement.
421+
void record_whole_heap_examined_timestamp();
422+
415423
private:
424+
// Generate any dumps preceding or following a full gc
416425
void full_gc_dump(GCTimer* timer, bool before);
417426

418427
virtual void initialize_serviceability() = 0;

‎src/hotspot/share/gc/shared/genCollectedHeap.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -1354,37 +1354,3 @@ oop GenCollectedHeap::handle_failed_promotion(Generation* old_gen,
13541354
}
13551355
return oop(result);
13561356
}
1357-
1358-
class GenTimeOfLastGCClosure: public GenCollectedHeap::GenClosure {
1359-
jlong _time; // in ms
1360-
jlong _now; // in ms
1361-
1362-
public:
1363-
GenTimeOfLastGCClosure(jlong now) : _time(now), _now(now) { }
1364-
1365-
jlong time() { return _time; }
1366-
1367-
void do_generation(Generation* gen) {
1368-
_time = MIN2(_time, gen->time_of_last_gc(_now));
1369-
}
1370-
};
1371-
1372-
jlong GenCollectedHeap::millis_since_last_gc() {
1373-
// javaTimeNanos() is guaranteed to be monotonically non-decreasing
1374-
// provided the underlying platform provides such a time source
1375-
// (and it is bug free). So we still have to guard against getting
1376-
// back a time later than 'now'.
1377-
jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
1378-
GenTimeOfLastGCClosure tolgc_cl(now);
1379-
// iterate over generations getting the oldest
1380-
// time that a generation was collected
1381-
generation_iterate(&tolgc_cl, false);
1382-
1383-
jlong retVal = now - tolgc_cl.time();
1384-
if (retVal < 0) {
1385-
log_warning(gc)("millis_since_last_gc() would return : " JLONG_FORMAT
1386-
". returning zero instead.", retVal);
1387-
return 0;
1388-
}
1389-
return retVal;
1390-
}

0 commit comments

Comments
 (0)
Please sign in to comment.