Skip to content

Commit 02ba519

Browse files
committedNov 30, 2020
8255001: Move G1PeriodicGCTask to its own file
Reviewed-by: tschatzl, lkorinth
1 parent 8aaee53 commit 02ba519

6 files changed

+137
-72
lines changed
 

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

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "gc/g1/g1OopClosures.inline.hpp"
5353
#include "gc/g1/g1ParallelCleaning.hpp"
5454
#include "gc/g1/g1ParScanThreadState.inline.hpp"
55+
#include "gc/g1/g1PeriodicGCTask.hpp"
5556
#include "gc/g1/g1Policy.hpp"
5657
#include "gc/g1/g1RedirtyCardsQueue.hpp"
5758
#include "gc/g1/g1RegionToSpaceMapper.hpp"
@@ -1390,6 +1391,7 @@ class HumongousRegionSetChecker : public HeapRegionSetChecker {
13901391
G1CollectedHeap::G1CollectedHeap() :
13911392
CollectedHeap(),
13921393
_service_thread(NULL),
1394+
_periodic_gc_task(NULL),
13931395
_workers(NULL),
13941396
_card_table(NULL),
13951397
_collection_pause_end(Ticks::now()),
@@ -1689,6 +1691,10 @@ jint G1CollectedHeap::initialize() {
16891691
// Initialize and schedule sampling task on service thread.
16901692
_rem_set->initialize_sampling_task(service_thread());
16911693

1694+
// Create and schedule the periodic gc task on the service thread.
1695+
_periodic_gc_task = new G1PeriodicGCTask("Periodic GC Task");
1696+
_service_thread->register_task(_periodic_gc_task);
1697+
16921698
{
16931699
G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
16941700
dcqs.set_process_cards_threshold(concurrent_refine()->yellow_zone());

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

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class G1CollectionSet;
7979
class G1Policy;
8080
class G1HotCardCache;
8181
class G1RemSet;
82+
class G1ServiceTask;
8283
class G1ServiceThread;
8384
class G1ConcurrentMark;
8485
class G1ConcurrentMarkThread;
@@ -154,6 +155,7 @@ class G1CollectedHeap : public CollectedHeap {
154155

155156
private:
156157
G1ServiceThread* _service_thread;
158+
G1ServiceTask* _periodic_gc_task;
157159

158160
WorkGang* _workers;
159161
G1CardTable* _card_table;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#include "precompiled.hpp"
26+
#include "gc/g1/g1CollectedHeap.inline.hpp"
27+
#include "gc/g1/g1ConcurrentMark.inline.hpp"
28+
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
29+
#include "gc/g1/g1PeriodicGCTask.hpp"
30+
#include "logging/log.hpp"
31+
#include "runtime/globals.hpp"
32+
#include "runtime/os.hpp"
33+
#include "utilities/globalDefinitions.hpp"
34+
35+
bool G1PeriodicGCTask::should_start_periodic_gc() {
36+
G1CollectedHeap* g1h = G1CollectedHeap::heap();
37+
// If we are currently in a concurrent mark we are going to uncommit memory soon.
38+
if (g1h->concurrent_mark()->cm_thread()->in_progress()) {
39+
log_debug(gc, periodic)("Concurrent cycle in progress. Skipping.");
40+
return false;
41+
}
42+
43+
// Check if enough time has passed since the last GC.
44+
uintx time_since_last_gc = (uintx)g1h->time_since_last_collection().milliseconds();
45+
if ((time_since_last_gc < G1PeriodicGCInterval)) {
46+
log_debug(gc, periodic)("Last GC occurred " UINTX_FORMAT "ms before which is below threshold " UINTX_FORMAT "ms. Skipping.",
47+
time_since_last_gc, G1PeriodicGCInterval);
48+
return false;
49+
}
50+
51+
// Check if load is lower than max.
52+
double recent_load;
53+
if ((G1PeriodicGCSystemLoadThreshold > 0.0f) &&
54+
(os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) {
55+
log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.",
56+
recent_load, G1PeriodicGCSystemLoadThreshold);
57+
return false;
58+
}
59+
return true;
60+
}
61+
62+
void G1PeriodicGCTask::check_for_periodic_gc() {
63+
// If disabled, just return.
64+
if (G1PeriodicGCInterval == 0) {
65+
return;
66+
}
67+
68+
log_debug(gc, periodic)("Checking for periodic GC.");
69+
if (should_start_periodic_gc()) {
70+
if (!G1CollectedHeap::heap()->try_collect(GCCause::_g1_periodic_collection)) {
71+
log_debug(gc, periodic)("GC request denied. Skipping.");
72+
}
73+
}
74+
}
75+
76+
G1PeriodicGCTask::G1PeriodicGCTask(const char* name) :
77+
G1ServiceTask(name) { }
78+
79+
void G1PeriodicGCTask::execute() {
80+
check_for_periodic_gc();
81+
// G1PeriodicGCInterval is a manageable flag and can be updated
82+
// during runtime. If no value is set, wait a second and run it
83+
// again to see if the value has been updated. Otherwise use the
84+
// real value provided.
85+
schedule(G1PeriodicGCInterval == 0 ? 1000 : G1PeriodicGCInterval);
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef SHARE_GC_G1_G1PERIODICGCTASK_HPP
26+
#define SHARE_GC_G1_G1PERIODICGCTASK_HPP
27+
28+
#include "gc/g1/g1ServiceThread.hpp"
29+
30+
// Task handling periodic GCs
31+
class G1PeriodicGCTask : public G1ServiceTask {
32+
bool should_start_periodic_gc();
33+
void check_for_periodic_gc();
34+
35+
public:
36+
G1PeriodicGCTask(const char* name);
37+
virtual void execute();
38+
};
39+
40+
#endif // SHARE_GC_G1_G1PERIODICGCTASK_HPP

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

+3-68
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
*/
2424

2525
#include "precompiled.hpp"
26-
#include "gc/g1/g1CollectedHeap.inline.hpp"
27-
#include "gc/g1/g1ConcurrentMark.inline.hpp"
28-
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
2926
#include "gc/g1/g1ServiceThread.hpp"
30-
#include "memory/universe.hpp"
27+
#include "logging/log.hpp"
3128
#include "runtime/mutexLocker.hpp"
29+
#include "runtime/timer.hpp"
3230
#include "runtime/os.hpp"
3331

3432
G1SentinelTask::G1SentinelTask() : G1ServiceTask("Sentinel Task") {
@@ -40,77 +38,17 @@ void G1SentinelTask::execute() {
4038
guarantee(false, "Sentinel service task should never be executed.");
4139
}
4240

43-
// Task handling periodic GCs
44-
class G1PeriodicGCTask : public G1ServiceTask {
45-
bool should_start_periodic_gc() {
46-
G1CollectedHeap* g1h = G1CollectedHeap::heap();
47-
// If we are currently in a concurrent mark we are going to uncommit memory soon.
48-
if (g1h->concurrent_mark()->cm_thread()->in_progress()) {
49-
log_debug(gc, periodic)("Concurrent cycle in progress. Skipping.");
50-
return false;
51-
}
52-
53-
// Check if enough time has passed since the last GC.
54-
uintx time_since_last_gc = (uintx)g1h->time_since_last_collection().milliseconds();
55-
if ((time_since_last_gc < G1PeriodicGCInterval)) {
56-
log_debug(gc, periodic)("Last GC occurred " UINTX_FORMAT "ms before which is below threshold " UINTX_FORMAT "ms. Skipping.",
57-
time_since_last_gc, G1PeriodicGCInterval);
58-
return false;
59-
}
60-
61-
// Check if load is lower than max.
62-
double recent_load;
63-
if ((G1PeriodicGCSystemLoadThreshold > 0.0f) &&
64-
(os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) {
65-
log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.",
66-
recent_load, G1PeriodicGCSystemLoadThreshold);
67-
return false;
68-
}
69-
return true;
70-
}
71-
72-
void check_for_periodic_gc(){
73-
// If disabled, just return.
74-
if (G1PeriodicGCInterval == 0) {
75-
return;
76-
}
77-
78-
log_debug(gc, periodic)("Checking for periodic GC.");
79-
if (should_start_periodic_gc()) {
80-
if (!G1CollectedHeap::heap()->try_collect(GCCause::_g1_periodic_collection)) {
81-
log_debug(gc, periodic)("GC request denied. Skipping.");
82-
}
83-
}
84-
}
85-
public:
86-
G1PeriodicGCTask(const char* name) : G1ServiceTask(name) { }
87-
88-
virtual void execute() {
89-
check_for_periodic_gc();
90-
// G1PeriodicGCInterval is a manageable flag and can be updated
91-
// during runtime. If no value is set, wait a second and run it
92-
// again to see if the value has been updated. Otherwise use the
93-
// real value provided.
94-
schedule(G1PeriodicGCInterval == 0 ? 1000 : G1PeriodicGCInterval);
95-
}
96-
};
97-
9841
G1ServiceThread::G1ServiceThread() :
9942
ConcurrentGCThread(),
10043
_monitor(Mutex::nonleaf,
10144
"G1ServiceThread monitor",
10245
true,
10346
Monitor::_safepoint_check_never),
104-
_task_queue(),
105-
_periodic_gc_task(new G1PeriodicGCTask("Periodic GC Task")) {
47+
_task_queue() {
10648
set_name("G1 Service");
10749
create_and_start();
10850
}
10951

110-
G1ServiceThread::~G1ServiceThread() {
111-
delete _periodic_gc_task;
112-
}
113-
11452
void G1ServiceThread::register_task(G1ServiceTask* task, jlong delay_ms) {
11553
guarantee(!task->is_registered(), "Task already registered");
11654
guarantee(task->next() == NULL, "Task already in queue");
@@ -215,9 +153,6 @@ void G1ServiceThread::run_task(G1ServiceTask* task) {
215153
}
216154

217155
void G1ServiceThread::run_service() {
218-
// Register the tasks handled by the service thread.
219-
register_task(_periodic_gc_task);
220-
221156
while (!should_terminate()) {
222157
G1ServiceTask* task = pop_due_task();
223158
if (task != NULL) {

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

-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "gc/shared/concurrentGCThread.hpp"
2929
#include "runtime/mutex.hpp"
3030

31-
class G1PeriodicGCTask;
3231
class G1ServiceTaskQueue;
3332
class G1ServiceThread;
3433

@@ -105,8 +104,6 @@ class G1ServiceThread: public ConcurrentGCThread {
105104
Monitor _monitor;
106105
G1ServiceTaskQueue _task_queue;
107106

108-
G1PeriodicGCTask* _periodic_gc_task;
109-
110107
void run_service();
111108
void stop_service();
112109

@@ -129,7 +126,6 @@ class G1ServiceThread: public ConcurrentGCThread {
129126

130127
public:
131128
G1ServiceThread();
132-
~G1ServiceThread();
133129

134130
// Register a task with the service thread. The task is guaranteed not to run
135131
// until at least `delay_ms` has passed. If no delay is specified or the

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Nov 30, 2020

@openjdk-notifier[bot]
Please sign in to comment.