2015-10-26 12:22:24 -04:00
|
|
|
/*
|
2019-03-04 11:49:16 +01:00
|
|
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
2015-10-26 12:22:24 -04:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
2016-03-07 17:23:59 +01:00
|
|
|
#include "gc/g1/g1CollectionSet.hpp"
|
2018-12-10 10:25:27 +01:00
|
|
|
#include "gc/g1/g1ConcurrentMark.inline.hpp"
|
|
|
|
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
|
2016-03-18 15:20:43 +01:00
|
|
|
#include "gc/g1/g1Policy.hpp"
|
2015-10-26 12:22:24 -04:00
|
|
|
#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
|
2016-02-25 11:20:03 +01:00
|
|
|
#include "gc/g1/heapRegion.inline.hpp"
|
|
|
|
#include "gc/g1/heapRegionRemSet.hpp"
|
2017-10-18 21:17:46 +02:00
|
|
|
#include "gc/shared/suspendibleThreadSet.hpp"
|
2019-05-09 14:28:30 +02:00
|
|
|
#include "memory/universe.hpp"
|
2015-10-26 12:22:24 -04:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
|
|
|
|
2016-02-29 11:32:12 -05:00
|
|
|
G1YoungRemSetSamplingThread::G1YoungRemSetSamplingThread() :
|
|
|
|
ConcurrentGCThread(),
|
|
|
|
_monitor(Mutex::nonleaf,
|
|
|
|
"G1YoungRemSetSamplingThread monitor",
|
|
|
|
true,
|
2018-12-10 10:25:27 +01:00
|
|
|
Monitor::_safepoint_check_never),
|
2018-12-17 11:37:40 +01:00
|
|
|
_last_periodic_gc_attempt_s(os::elapsedTime()),
|
|
|
|
_vtime_accum(0) {
|
2015-10-26 12:22:24 -04:00
|
|
|
set_name("G1 Young RemSet Sampling");
|
2016-02-03 09:31:22 -08:00
|
|
|
create_and_start();
|
2015-10-26 12:22:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void G1YoungRemSetSamplingThread::sleep_before_next_cycle() {
|
2019-04-29 16:01:52 -04:00
|
|
|
MonitorLocker ml(&_monitor, Mutex::_no_safepoint_check_flag);
|
2016-03-11 16:59:58 -05:00
|
|
|
if (!should_terminate()) {
|
2018-12-10 10:25:27 +01:00
|
|
|
uintx waitms = G1ConcRefinementServiceIntervalMillis;
|
2019-04-29 16:01:52 -04:00
|
|
|
ml.wait(waitms);
|
2015-10-26 12:22:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 10:25:27 +01:00
|
|
|
bool G1YoungRemSetSamplingThread::should_start_periodic_gc() {
|
|
|
|
// If we are currently in a concurrent mark we are going to uncommit memory soon.
|
|
|
|
if (G1CollectedHeap::heap()->concurrent_mark()->cm_thread()->during_cycle()) {
|
|
|
|
log_debug(gc, periodic)("Concurrent cycle in progress. Skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if enough time has passed since the last GC.
|
2019-01-16 11:43:51 +01:00
|
|
|
uintx time_since_last_gc = (uintx)Universe::heap()->millis_since_last_gc();
|
|
|
|
if ((time_since_last_gc < G1PeriodicGCInterval)) {
|
2018-12-10 10:25:27 +01:00
|
|
|
log_debug(gc, periodic)("Last GC occurred " UINTX_FORMAT "ms before which is below threshold " UINTX_FORMAT "ms. Skipping.",
|
|
|
|
time_since_last_gc, G1PeriodicGCInterval);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if load is lower than max.
|
|
|
|
double recent_load;
|
2018-12-20 19:44:33 +01:00
|
|
|
if ((G1PeriodicGCSystemLoadThreshold > 0.0f) &&
|
2018-12-10 10:25:27 +01:00
|
|
|
(os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) {
|
2018-12-20 19:44:33 +01:00
|
|
|
log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.",
|
2018-12-10 10:25:27 +01:00
|
|
|
recent_load, G1PeriodicGCSystemLoadThreshold);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1YoungRemSetSamplingThread::check_for_periodic_gc(){
|
2019-01-16 11:43:51 +01:00
|
|
|
// If disabled, just return.
|
|
|
|
if (G1PeriodicGCInterval == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-10 10:25:27 +01:00
|
|
|
if ((os::elapsedTime() - _last_periodic_gc_attempt_s) > (G1PeriodicGCInterval / 1000.0)) {
|
|
|
|
log_debug(gc, periodic)("Checking for periodic GC.");
|
|
|
|
if (should_start_periodic_gc()) {
|
2019-11-13 18:00:30 -05:00
|
|
|
if (!G1CollectedHeap::heap()->try_collect(GCCause::_g1_periodic_collection)) {
|
2019-03-04 11:49:16 +01:00
|
|
|
log_debug(gc, periodic)("GC request denied. Skipping.");
|
|
|
|
}
|
2018-12-10 10:25:27 +01:00
|
|
|
}
|
|
|
|
_last_periodic_gc_attempt_s = os::elapsedTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 12:22:24 -04:00
|
|
|
void G1YoungRemSetSamplingThread::run_service() {
|
|
|
|
double vtime_start = os::elapsedVTime();
|
|
|
|
|
2019-01-16 11:43:51 +01:00
|
|
|
// Print a message about periodic GC configuration.
|
|
|
|
if (G1PeriodicGCInterval != 0) {
|
|
|
|
log_info(gc)("Periodic GC enabled with interval " UINTX_FORMAT "ms", G1PeriodicGCInterval);
|
|
|
|
} else {
|
|
|
|
log_info(gc)("Periodic GC disabled");
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:59:58 -05:00
|
|
|
while (!should_terminate()) {
|
2019-08-07 10:29:07 +02:00
|
|
|
sample_young_list_rs_length();
|
2015-10-26 12:22:24 -04:00
|
|
|
|
|
|
|
if (os::supports_vtime()) {
|
|
|
|
_vtime_accum = (os::elapsedVTime() - vtime_start);
|
|
|
|
} else {
|
|
|
|
_vtime_accum = 0.0;
|
|
|
|
}
|
|
|
|
|
2018-12-10 10:25:27 +01:00
|
|
|
check_for_periodic_gc();
|
|
|
|
|
2015-10-26 12:22:24 -04:00
|
|
|
sleep_before_next_cycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1YoungRemSetSamplingThread::stop_service() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MutexLocker x(&_monitor, Mutex::_no_safepoint_check_flag);
|
2016-02-29 11:32:12 -05:00
|
|
|
_monitor.notify();
|
2015-10-26 12:22:24 -04:00
|
|
|
}
|
|
|
|
|
2016-07-06 11:22:55 +02:00
|
|
|
class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
|
|
|
|
SuspendibleThreadSetJoiner* _sts;
|
|
|
|
size_t _regions_visited;
|
2019-08-07 10:29:07 +02:00
|
|
|
size_t _sampled_rs_length;
|
2016-07-06 11:22:55 +02:00
|
|
|
public:
|
|
|
|
G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
|
2019-08-07 10:29:07 +02:00
|
|
|
HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_length(0) { }
|
2016-07-06 11:22:55 +02:00
|
|
|
|
2018-02-09 13:09:55 +01:00
|
|
|
virtual bool do_heap_region(HeapRegion* r) {
|
2016-07-06 11:22:55 +02:00
|
|
|
size_t rs_length = r->rem_set()->occupied();
|
2019-08-07 10:29:07 +02:00
|
|
|
_sampled_rs_length += rs_length;
|
2016-07-06 11:22:55 +02:00
|
|
|
|
|
|
|
// Update the collection set policy information for this region
|
|
|
|
G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
|
|
|
|
|
|
|
|
_regions_visited++;
|
|
|
|
|
|
|
|
if (_regions_visited == 10) {
|
|
|
|
if (_sts->should_yield()) {
|
|
|
|
_sts->yield();
|
|
|
|
// A gc may have occurred and our sampling data is stale and further
|
|
|
|
// traversal of the collection set is unsafe
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_regions_visited = 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-07 10:29:07 +02:00
|
|
|
size_t sampled_rs_length() const { return _sampled_rs_length; }
|
2016-07-06 11:22:55 +02:00
|
|
|
};
|
|
|
|
|
2019-08-07 10:29:07 +02:00
|
|
|
void G1YoungRemSetSamplingThread::sample_young_list_rs_length() {
|
2015-10-26 12:22:24 -04:00
|
|
|
SuspendibleThreadSetJoiner sts;
|
|
|
|
G1CollectedHeap* g1h = G1CollectedHeap::heap();
|
2019-03-04 11:49:16 +01:00
|
|
|
G1Policy* policy = g1h->policy();
|
2016-07-06 11:22:55 +02:00
|
|
|
|
2019-04-08 21:01:17 +02:00
|
|
|
if (policy->use_adaptive_young_list_length()) {
|
2016-07-06 11:22:55 +02:00
|
|
|
G1YoungRemSetSamplingClosure cl(&sts);
|
|
|
|
|
|
|
|
G1CollectionSet* g1cs = g1h->collection_set();
|
|
|
|
g1cs->iterate(&cl);
|
|
|
|
|
2018-02-09 13:09:55 +01:00
|
|
|
if (cl.is_complete()) {
|
2019-08-07 10:29:07 +02:00
|
|
|
policy->revise_young_list_target_length_if_necessary(cl.sampled_rs_length());
|
2015-10-26 12:22:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|