annotate src/share/vm/gc_implementation/g1/g1HotCardCache.cpp @ 23472:047a642c9729

8065579: WB method to start G1 concurrent mark cycle should be introduced Summary: Add a WhiteBox callback to the VM to start a concurrent mark cycle in G1. Reviewed-by: tschatzl, sjohanss Contributed-by: Leonid Mesnik <leonid.mesnik@oracle.com>
author kevinw
date Wed, 02 Dec 2015 13:58:34 +0530
parents b6a1bf5222c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
1 /*
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
4 *
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
7 * published by the Free Software Foundation.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
8 *
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
13 * accompanied this code).
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
14 *
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
18 *
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
21 * questions.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
22 *
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
23 */
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
24
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
25 #include "precompiled.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
26 #include "gc_implementation/g1/dirtyCardQueue.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
28 #include "gc_implementation/g1/g1HotCardCache.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
29 #include "gc_implementation/g1/g1RemSet.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
30 #include "runtime/atomic.hpp"
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
31
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
33 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
34
20337
1f1d373cd044 8038423: G1: Decommit memory within heap
tschatzl
parents: 17844
diff changeset
35 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
36 if (default_use_cache()) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
37 _use_cache = true;
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
38
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
39 _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize;
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
40 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
41
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
42 reset_hot_cache_internal();
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
43
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
44 // For refining the cards in the hot cache in parallel
22902
ae374055ebce 8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents: 20481
diff changeset
45 _hot_cache_par_chunk_size = (int)(ParallelGCThreads > 0 ? ClaimChunkSize : _hot_cache_size);
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
46 _hot_cache_par_claimed_idx = 0;
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
47
20337
1f1d373cd044 8038423: G1: Decommit memory within heap
tschatzl
parents: 17844
diff changeset
48 _card_counts.initialize(card_counts_storage);
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
49 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
50 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
51
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
52 G1HotCardCache::~G1HotCardCache() {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
53 if (default_use_cache()) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
54 assert(_hot_cache != NULL, "Logic");
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
55 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache, mtGC);
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
56 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
57 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
58
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
59 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
60 uint count = _card_counts.add_card_count(card_ptr);
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
61 if (!_card_counts.is_hot(count)) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
62 // The card is not hot so do not store it in the cache;
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
63 // return it for immediate refining.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
64 return card_ptr;
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
65 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
66 // Otherwise, the card is hot.
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
67 size_t index = Atomic::add_ptr((intptr_t)1, (volatile intptr_t*)&_hot_cache_idx) - 1;
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
68 size_t masked_index = index & (_hot_cache_size - 1);
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
69 jbyte* current_ptr = _hot_cache[masked_index];
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
70
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
71 // Try to store the new card pointer into the cache. Compare-and-swap to guard
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
72 // against the unlikely event of a race resulting in another card pointer to
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
73 // have already been written to the cache. In this case we will return
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
74 // card_ptr in favor of the other option, which would be starting over. This
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
75 // should be OK since card_ptr will likely be the older card already when/if
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
76 // this ever happens.
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
77 jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr,
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
78 &_hot_cache[masked_index],
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
79 current_ptr);
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
80 return (previous_ptr == current_ptr) ? previous_ptr : card_ptr;
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
81 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
82
17844
8847586c9037 8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents: 10246
diff changeset
83 void G1HotCardCache::drain(uint worker_i,
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
84 G1RemSet* g1rs,
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
85 DirtyCardQueue* into_cset_dcq) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
86 if (!default_use_cache()) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
87 assert(_hot_cache == NULL, "Logic");
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
88 return;
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
89 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
90
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
91 assert(_hot_cache != NULL, "Logic");
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
92 assert(!use_cache(), "cache should be disabled");
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
93 while (_hot_cache_par_claimed_idx < _hot_cache_size) {
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
94 size_t end_idx = Atomic::add_ptr((intptr_t)_hot_cache_par_chunk_size,
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
95 (volatile intptr_t*)&_hot_cache_par_claimed_idx);
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
96 size_t start_idx = end_idx - _hot_cache_par_chunk_size;
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
97 // The current worker has successfully claimed the chunk [start_idx..end_idx)
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
98 end_idx = MIN2(end_idx, _hot_cache_size);
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
99 for (size_t i = start_idx; i < end_idx; i++) {
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
100 jbyte* card_ptr = _hot_cache[i];
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
101 if (card_ptr != NULL) {
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
102 if (g1rs->refine_card(card_ptr, worker_i, true)) {
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
103 // The part of the heap spanned by the card contains references
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
104 // that point into the current collection set.
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
105 // We need to record the card pointer in the DirtyCardQueueSet
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
106 // that we use for such cards.
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
107 //
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
108 // The only time we care about recording cards that contain
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
109 // references that point into the collection set is during
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
110 // RSet updating while within an evacuation pause.
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
111 // In this case worker_i should be the id of a GC worker thread
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
112 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
113 assert(worker_i < ParallelGCThreads,
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
114 err_msg("incorrect worker id: %u", worker_i));
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
115
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
116 into_cset_dcq->enqueue(card_ptr);
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
117 }
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
118 } else {
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
119 break;
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
120 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
121 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
122 }
22903
b6a1bf5222c5 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 22902
diff changeset
123
10246
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
124 // The existing entries in the hot card cache, which were just refined
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
125 // above, are discarded prior to re-enabling the cache near the end of the GC.
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
126 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
127
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
128 void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
129 _card_counts.clear_region(hr);
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
130 }
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
131
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
132 void G1HotCardCache::reset_card_counts() {
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
133 _card_counts.clear_all();
194f52aa2f23 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
134 }