annotate src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp @ 889:15c5903cf9e1

6865703: G1: Parallelize hot card cache cleanup Summary: Have the GC worker threads clear the hot card cache in parallel by having each worker thread claim a chunk of the card cache and process the cards in that chunk. The size of the chunks that each thread will claim is determined at VM initialization from the size of the card cache and the number of worker threads. Reviewed-by: jmasa, tonyp
author johnc
date Mon, 03 Aug 2009 12:59:30 -0700
parents bd02caa94611
children 6cb8e9df7174
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
844
bd02caa94611 6862919: Update copyright year
xdono
parents: 799
diff changeset
2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
21 * have any questions.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
25 #include "incls/_precompiled.incl"
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
26 #include "incls/_concurrentG1Refine.cpp.incl"
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
27
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
28 ConcurrentG1Refine::ConcurrentG1Refine() :
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
29 _card_counts(NULL), _cur_card_count_histo(NULL), _cum_card_count_histo(NULL),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
30 _hot_cache(NULL),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
31 _def_use_cache(false), _use_cache(false),
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
32 _n_periods(0), _total_cards(0), _total_travs(0),
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
33 _threads(NULL), _n_threads(0)
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
34 {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
35 if (G1ConcRefine) {
795
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
36 _n_threads = (int)thread_num();
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
37 if (_n_threads > 0) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
38 _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads);
795
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
39 int worker_id_offset = (int)DirtyCardQueueSet::num_par_ids();
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
40 ConcurrentG1RefineThread *next = NULL;
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
41 for (int i = _n_threads - 1; i >= 0; i--) {
795
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
42 ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, worker_id_offset, i);
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
43 assert(t != NULL, "Conc refine should have been created");
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
44 assert(t->cg1r() == this, "Conc refine thread should refer to this");
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
45 _threads[i] = t;
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
46 next = t;
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
47 }
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
48 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
49 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
50 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
51
795
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
52 size_t ConcurrentG1Refine::thread_num() {
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
53 if (G1ConcRefine) {
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
54 return (G1ParallelRSetThreads > 0) ? G1ParallelRSetThreads : ParallelGCThreads;
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
55 }
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
56 return 0;
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
57 }
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
58
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
59 void ConcurrentG1Refine::init() {
889
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
60 G1CollectedHeap* g1h = G1CollectedHeap::heap();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
62 _n_card_counts =
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
63 (unsigned) (g1h->g1_reserved_obj_bytes() >> CardTableModRefBS::card_shift);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
64 _card_counts = NEW_C_HEAP_ARRAY(unsigned char, _n_card_counts);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
65 for (size_t i = 0; i < _n_card_counts; i++) _card_counts[i] = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
66 ModRefBarrierSet* bs = g1h->mr_bs();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
67 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
68 CardTableModRefBS* ctbs = (CardTableModRefBS*)bs;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
69 _ct_bot = ctbs->byte_for_const(g1h->reserved_region().start());
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
70 if (G1ConcRSCountTraversals) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
71 _cur_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
72 _cum_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
73 for (int i = 0; i < 256; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
74 _cur_card_count_histo[i] = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
75 _cum_card_count_histo[i] = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
76 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
77 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
78 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
79 if (G1ConcRSLogCacheSize > 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
80 _def_use_cache = true;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
81 _use_cache = true;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
82 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
83 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
84 _n_hot = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
85 _hot_cache_idx = 0;
889
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
86
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
87 // For refining the cards in the hot cache in parallel
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
88 int n_workers = (ParallelGCThreads > 0 ?
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
89 g1h->workers()->total_workers() : 1);
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
90 _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / n_workers);
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
91 _hot_cache_par_claimed_idx = 0;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
92 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
93 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
94
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
95 void ConcurrentG1Refine::stop() {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
96 if (_threads != NULL) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
97 for (int i = 0; i < _n_threads; i++) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
98 _threads[i]->stop();
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
99 }
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
100 }
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
101 }
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
102
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
103 ConcurrentG1Refine::~ConcurrentG1Refine() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
104 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
105 assert(_card_counts != NULL, "Logic");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
106 FREE_C_HEAP_ARRAY(unsigned char, _card_counts);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
107 assert(_cur_card_count_histo != NULL, "Logic");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
108 FREE_C_HEAP_ARRAY(unsigned, _cur_card_count_histo);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
109 assert(_cum_card_count_histo != NULL, "Logic");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
110 FREE_C_HEAP_ARRAY(unsigned, _cum_card_count_histo);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
111 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
112 if (G1ConcRSLogCacheSize > 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
113 assert(_hot_cache != NULL, "Logic");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
114 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
115 }
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
116 if (_threads != NULL) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
117 for (int i = 0; i < _n_threads; i++) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
118 delete _threads[i];
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
119 }
799
f89cf529c3c7 6849122: G1: Typo introduced during implementation of the parallel refinement
iveresov
parents: 795
diff changeset
120 FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
121 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
122 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
123
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
124 void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
125 if (_threads != NULL) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
126 for (int i = 0; i < _n_threads; i++) {
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
127 tc->do_thread(_threads[i]);
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 637
diff changeset
128 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
129 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
130 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
131
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
132
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
133 int ConcurrentG1Refine::add_card_count(jbyte* card_ptr) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
134 size_t card_num = (card_ptr - _ct_bot);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
135 guarantee(0 <= card_num && card_num < _n_card_counts, "Bounds");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
136 unsigned char cnt = _card_counts[card_num];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
137 if (cnt < 255) _card_counts[card_num]++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
138 return cnt;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
139 _total_travs++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
140 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
141
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
142 jbyte* ConcurrentG1Refine::cache_insert(jbyte* card_ptr) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
143 int count = add_card_count(card_ptr);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
144 // Count previously unvisited cards.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
145 if (count == 0) _total_cards++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
146 // We'll assume a traversal unless we store it in the cache.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
147 if (count < G1ConcRSHotCardLimit) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
148 _total_travs++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
149 return card_ptr;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
150 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
151 // Otherwise, it's hot.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
152 jbyte* res = NULL;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
153 MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
154 if (_n_hot == _hot_cache_size) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
155 _total_travs++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
156 res = _hot_cache[_hot_cache_idx];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
157 _n_hot--;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
158 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
159 // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
160 _hot_cache[_hot_cache_idx] = card_ptr;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
161 _hot_cache_idx++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
162 if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
163 _n_hot++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
164 return res;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
165 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
166
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
167
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
168 void ConcurrentG1Refine::clean_up_cache(int worker_i, G1RemSet* g1rs) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
169 assert(!use_cache(), "cache should be disabled");
889
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
170 int start_idx;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
171
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
172 while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
173 int end_idx = start_idx + _hot_cache_par_chunk_size;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
174
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
175 if (start_idx ==
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
176 Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
177 // The current worker has successfully claimed the chunk [start_idx..end_idx)
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
178 end_idx = MIN2(end_idx, _n_hot);
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
179 for (int i = start_idx; i < end_idx; i++) {
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
180 jbyte* entry = _hot_cache[i];
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
181 if (entry != NULL) {
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
182 g1rs->concurrentRefineOneCard(entry, worker_i);
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
183 }
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 844
diff changeset
184 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
185 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
186 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
187 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
188
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
189 void ConcurrentG1Refine::clear_and_record_card_counts() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
190 if (G1ConcRSLogCacheSize == 0 && !G1ConcRSCountTraversals) return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
191 _n_periods++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
192 if (G1ConcRSCountTraversals) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
193 for (size_t i = 0; i < _n_card_counts; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
194 unsigned char bucket = _card_counts[i];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
195 _cur_card_count_histo[bucket]++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
196 _card_counts[i] = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
197 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
198 gclog_or_tty->print_cr("Card counts:");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
199 for (int i = 0; i < 256; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
200 if (_cur_card_count_histo[i] > 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
201 gclog_or_tty->print_cr(" %3d: %9d", i, _cur_card_count_histo[i]);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
202 _cum_card_count_histo[i] += _cur_card_count_histo[i];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
203 _cur_card_count_histo[i] = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
204 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
205 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
206 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
207 assert(G1ConcRSLogCacheSize > 0, "Logic");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
208 Copy::fill_to_words((HeapWord*)(&_card_counts[0]),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
209 _n_card_counts / HeapWordSize);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
210 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
211 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
212
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
213 void
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
214 ConcurrentG1Refine::
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
215 print_card_count_histo_range(unsigned* histo, int from, int to,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
216 float& cum_card_pct,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
217 float& cum_travs_pct) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
218 unsigned cards = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
219 unsigned travs = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
220 guarantee(to <= 256, "Precondition");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
221 for (int i = from; i < to-1; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
222 cards += histo[i];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
223 travs += histo[i] * i;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
224 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
225 if (to == 256) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
226 unsigned histo_card_sum = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
227 unsigned histo_trav_sum = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
228 for (int i = 1; i < 255; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
229 histo_trav_sum += histo[i] * i;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
230 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
231 cards += histo[255];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
232 // correct traversals for the last one.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
233 unsigned travs_255 = (unsigned) (_total_travs - histo_trav_sum);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
234 travs += travs_255;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
235
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
236 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
237 cards += histo[to-1];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
238 travs += histo[to-1] * (to-1);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
239 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
240 float fperiods = (float)_n_periods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
241 float f_tot_cards = (float)_total_cards/fperiods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
242 float f_tot_travs = (float)_total_travs/fperiods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
243 if (cards > 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
244 float fcards = (float)cards/fperiods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
245 float ftravs = (float)travs/fperiods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
246 if (to == 256) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
247 gclog_or_tty->print(" %4d- %10.2f%10.2f", from, fcards, ftravs);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
248 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
249 gclog_or_tty->print(" %4d-%4d %10.2f%10.2f", from, to-1, fcards, ftravs);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
250 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
251 float pct_cards = fcards*100.0/f_tot_cards;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
252 cum_card_pct += pct_cards;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
253 float pct_travs = ftravs*100.0/f_tot_travs;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
254 cum_travs_pct += pct_travs;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
255 gclog_or_tty->print_cr("%10.2f%10.2f%10.2f%10.2f",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
256 pct_cards, cum_card_pct,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
257 pct_travs, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
258 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
259 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
260
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
261 void ConcurrentG1Refine::print_final_card_counts() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
262 if (!G1ConcRSCountTraversals) return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
263
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
264 gclog_or_tty->print_cr("Did %d total traversals of %d distinct cards.",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
265 _total_travs, _total_cards);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
266 float fperiods = (float)_n_periods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
267 gclog_or_tty->print_cr(" This is an average of %8.2f traversals, %8.2f cards, "
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
268 "per collection.", (float)_total_travs/fperiods,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
269 (float)_total_cards/fperiods);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
270 gclog_or_tty->print_cr(" This is an average of %8.2f traversals/distinct "
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
271 "dirty card.\n",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
272 _total_cards > 0 ?
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
273 (float)_total_travs/(float)_total_cards : 0.0);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
274
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
275
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
276 gclog_or_tty->print_cr("Histogram:\n\n%10s %10s%10s%10s%10s%10s%10s",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
277 "range", "# cards", "# travs", "% cards", "(cum)",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
278 "% travs", "(cum)");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
279 gclog_or_tty->print_cr("------------------------------------------------------------"
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
280 "-------------");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
281 float cum_cards_pct = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
282 float cum_travs_pct = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
283 for (int i = 1; i < 10; i++) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
284 print_card_count_histo_range(_cum_card_count_histo, i, i+1,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
285 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
286 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
287 for (int i = 10; i < 100; i += 10) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
288 print_card_count_histo_range(_cum_card_count_histo, i, i+10,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
289 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
290 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
291 print_card_count_histo_range(_cum_card_count_histo, 100, 150,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
292 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
293 print_card_count_histo_range(_cum_card_count_histo, 150, 200,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
294 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
295 print_card_count_histo_range(_cum_card_count_histo, 150, 255,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
296 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
297 print_card_count_histo_range(_cum_card_count_histo, 255, 256,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
298 cum_cards_pct, cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
299 }