Skip to content

Commit 1b7a61f

Browse files
committed
8254999: Move G1RemSetSamplingTask to more appropriate location
Reviewed-by: tschatzl, ayang
1 parent 695117f commit 1b7a61f

File tree

5 files changed

+90
-80
lines changed

5 files changed

+90
-80
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,9 @@ jint G1CollectedHeap::initialize() {
17051705
return ecode;
17061706
}
17071707

1708+
// Initialize and schedule sampling task on service thread.
1709+
_rem_set->initialize_sampling_task(service_thread());
1710+
17081711
{
17091712
G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
17101713
dcqs.set_process_cards_threshold(concurrent_refine()->yellow_zone());

src/hotspot/share/gc/g1/g1RemSet.cpp

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
#include "gc/g1/g1GCPhaseTimes.hpp"
3636
#include "gc/g1/g1HotCardCache.hpp"
3737
#include "gc/g1/g1OopClosures.inline.hpp"
38+
#include "gc/g1/g1Policy.hpp"
3839
#include "gc/g1/g1RootClosures.hpp"
3940
#include "gc/g1/g1RemSet.hpp"
41+
#include "gc/g1/g1ServiceThread.hpp"
4042
#include "gc/g1/g1SharedDirtyCardQueue.hpp"
4143
#include "gc/g1/g1_globals.hpp"
4244
#include "gc/g1/heapRegion.inline.hpp"
@@ -488,17 +490,95 @@ G1RemSet::G1RemSet(G1CollectedHeap* g1h,
488490
_g1h(g1h),
489491
_ct(ct),
490492
_g1p(_g1h->policy()),
491-
_hot_card_cache(hot_card_cache) {
493+
_hot_card_cache(hot_card_cache),
494+
_sampling_task(NULL) {
492495
}
493496

494497
G1RemSet::~G1RemSet() {
495498
delete _scan_state;
499+
delete _sampling_task;
496500
}
497501

498502
void G1RemSet::initialize(uint max_reserved_regions) {
499503
_scan_state->initialize(max_reserved_regions);
500504
}
501505

506+
class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
507+
SuspendibleThreadSetJoiner* _sts;
508+
size_t _regions_visited;
509+
size_t _sampled_rs_length;
510+
public:
511+
G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
512+
HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_length(0) { }
513+
514+
virtual bool do_heap_region(HeapRegion* r) {
515+
size_t rs_length = r->rem_set()->occupied();
516+
_sampled_rs_length += rs_length;
517+
518+
// Update the collection set policy information for this region
519+
G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
520+
521+
_regions_visited++;
522+
523+
if (_regions_visited == 10) {
524+
if (_sts->should_yield()) {
525+
_sts->yield();
526+
// A gc may have occurred and our sampling data is stale and further
527+
// traversal of the collection set is unsafe
528+
return true;
529+
}
530+
_regions_visited = 0;
531+
}
532+
return false;
533+
}
534+
535+
size_t sampled_rs_length() const { return _sampled_rs_length; }
536+
};
537+
538+
// Task handling young gen remembered set sampling.
539+
class G1RemSetSamplingTask : public G1ServiceTask {
540+
// Sample the current length of remembered sets for young.
541+
//
542+
// At the end of the GC G1 determines the length of the young gen based on
543+
// how much time the next GC can take, and when the next GC may occur
544+
// according to the MMU.
545+
//
546+
// The assumption is that a significant part of the GC is spent on scanning
547+
// the remembered sets (and many other components), so this thread constantly
548+
// reevaluates the prediction for the remembered set scanning costs, and potentially
549+
// G1Policy resizes the young gen. This may do a premature GC or even
550+
// increase the young gen size to keep pause time length goal.
551+
void sample_young_list_rs_length(){
552+
SuspendibleThreadSetJoiner sts;
553+
G1CollectedHeap* g1h = G1CollectedHeap::heap();
554+
G1Policy* policy = g1h->policy();
555+
556+
if (policy->use_adaptive_young_list_length()) {
557+
G1YoungRemSetSamplingClosure cl(&sts);
558+
559+
G1CollectionSet* g1cs = g1h->collection_set();
560+
g1cs->iterate(&cl);
561+
562+
if (cl.is_complete()) {
563+
policy->revise_young_list_target_length_if_necessary(cl.sampled_rs_length());
564+
}
565+
}
566+
}
567+
568+
public:
569+
G1RemSetSamplingTask(const char* name) : G1ServiceTask(name) { }
570+
virtual void execute() {
571+
sample_young_list_rs_length();
572+
schedule(G1ConcRefinementServiceIntervalMillis);
573+
}
574+
};
575+
576+
void G1RemSet::initialize_sampling_task(G1ServiceThread* thread) {
577+
assert(_sampling_task == NULL, "Sampling task already initialized");
578+
_sampling_task = new G1RemSetSamplingTask("Remembered Set Sampling Task");
579+
thread->register_task(_sampling_task);
580+
}
581+
502582
// Helper class to scan and detect ranges of cards that need to be scanned on the
503583
// card table.
504584
class G1CardTableScanner : public StackObj {

src/hotspot/share/gc/g1/g1RemSet.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class G1ParScanThreadState;
4949
class G1ParScanThreadStateSet;
5050
class G1Policy;
5151
class G1ScanCardClosure;
52+
class G1ServiceTask;
53+
class G1ServiceThread;
5254
class HeapRegionClaimer;
5355

5456
// A G1RemSet in which each heap region has a rem set that records the
@@ -65,6 +67,7 @@ class G1RemSet: public CHeapObj<mtGC> {
6567
G1CardTable* _ct;
6668
G1Policy* _g1p;
6769
G1HotCardCache* _hot_card_cache;
70+
G1ServiceTask* _sampling_task;
6871

6972
void print_merge_heap_roots_stats();
7073

@@ -81,6 +84,9 @@ class G1RemSet: public CHeapObj<mtGC> {
8184
G1HotCardCache* hot_card_cache);
8285
~G1RemSet();
8386

87+
// Initialize and schedule young remembered set sampling task.
88+
void initialize_sampling_task(G1ServiceThread* thread);
89+
8490
// Scan all cards in the non-collection set regions that potentially contain
8591
// references into the current whole collection set.
8692
void scan_heap_roots(G1ParScanThreadState* pss,

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

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424

2525
#include "precompiled.hpp"
2626
#include "gc/g1/g1CollectedHeap.inline.hpp"
27-
#include "gc/g1/g1CollectionSet.hpp"
2827
#include "gc/g1/g1ConcurrentMark.inline.hpp"
2928
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
30-
#include "gc/g1/g1Policy.hpp"
3129
#include "gc/g1/g1ServiceThread.hpp"
32-
#include "gc/g1/heapRegion.inline.hpp"
33-
#include "gc/g1/heapRegionRemSet.hpp"
34-
#include "gc/shared/suspendibleThreadSet.hpp"
3530
#include "memory/universe.hpp"
3631
#include "runtime/mutexLocker.hpp"
3732
#include "runtime/os.hpp"
@@ -100,91 +95,20 @@ class G1PeriodicGCTask : public G1ServiceTask {
10095
}
10196
};
10297

103-
class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
104-
SuspendibleThreadSetJoiner* _sts;
105-
size_t _regions_visited;
106-
size_t _sampled_rs_length;
107-
public:
108-
G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
109-
HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_length(0) { }
110-
111-
virtual bool do_heap_region(HeapRegion* r) {
112-
size_t rs_length = r->rem_set()->occupied();
113-
_sampled_rs_length += rs_length;
114-
115-
// Update the collection set policy information for this region
116-
G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
117-
118-
_regions_visited++;
119-
120-
if (_regions_visited == 10) {
121-
if (_sts->should_yield()) {
122-
_sts->yield();
123-
// A gc may have occurred and our sampling data is stale and further
124-
// traversal of the collection set is unsafe
125-
return true;
126-
}
127-
_regions_visited = 0;
128-
}
129-
return false;
130-
}
131-
132-
size_t sampled_rs_length() const { return _sampled_rs_length; }
133-
};
134-
135-
// Task handling young gen remembered set sampling.
136-
class G1RemSetSamplingTask : public G1ServiceTask {
137-
// Sample the current length of remembered sets for young.
138-
//
139-
// At the end of the GC G1 determines the length of the young gen based on
140-
// how much time the next GC can take, and when the next GC may occur
141-
// according to the MMU.
142-
//
143-
// The assumption is that a significant part of the GC is spent on scanning
144-
// the remembered sets (and many other components), so this thread constantly
145-
// reevaluates the prediction for the remembered set scanning costs, and potentially
146-
// G1Policy resizes the young gen. This may do a premature GC or even
147-
// increase the young gen size to keep pause time length goal.
148-
void sample_young_list_rs_length(){
149-
SuspendibleThreadSetJoiner sts;
150-
G1CollectedHeap* g1h = G1CollectedHeap::heap();
151-
G1Policy* policy = g1h->policy();
152-
153-
if (policy->use_adaptive_young_list_length()) {
154-
G1YoungRemSetSamplingClosure cl(&sts);
155-
156-
G1CollectionSet* g1cs = g1h->collection_set();
157-
g1cs->iterate(&cl);
158-
159-
if (cl.is_complete()) {
160-
policy->revise_young_list_target_length_if_necessary(cl.sampled_rs_length());
161-
}
162-
}
163-
}
164-
public:
165-
G1RemSetSamplingTask(const char* name) : G1ServiceTask(name) { }
166-
virtual void execute() {
167-
sample_young_list_rs_length();
168-
schedule(G1ConcRefinementServiceIntervalMillis);
169-
}
170-
};
171-
17298
G1ServiceThread::G1ServiceThread() :
17399
ConcurrentGCThread(),
174100
_monitor(Mutex::nonleaf,
175101
"G1ServiceThread monitor",
176102
true,
177103
Monitor::_safepoint_check_never),
178104
_task_queue(),
179-
_remset_task(new G1RemSetSamplingTask("Remembered Set Sampling Task")),
180105
_periodic_gc_task(new G1PeriodicGCTask("Periodic GC Task")),
181106
_vtime_accum(0) {
182107
set_name("G1 Service");
183108
create_and_start();
184109
}
185110

186111
G1ServiceThread::~G1ServiceThread() {
187-
delete _remset_task;
188112
delete _periodic_gc_task;
189113
}
190114

@@ -295,7 +219,6 @@ void G1ServiceThread::run_service() {
295219

296220
// Register the tasks handled by the service thread.
297221
register_task(_periodic_gc_task);
298-
register_task(_remset_task);
299222

300223
while (!should_terminate()) {
301224
G1ServiceTask* task = pop_due_task();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "runtime/mutex.hpp"
3030

3131
class G1PeriodicGCTask;
32-
class G1RemSetSamplingTask;
3332
class G1ServiceTaskQueue;
3433
class G1ServiceThread;
3534

@@ -106,7 +105,6 @@ class G1ServiceThread: public ConcurrentGCThread {
106105
Monitor _monitor;
107106
G1ServiceTaskQueue _task_queue;
108107

109-
G1RemSetSamplingTask* _remset_task;
110108
G1PeriodicGCTask* _periodic_gc_task;
111109

112110
double _vtime_accum; // Accumulated virtual time.

0 commit comments

Comments
 (0)