Mercurial > hg > graal-compiler
comparison src/share/vm/gc_implementation/g1/g1CardCounts.cpp @ 10246:194f52aa2f23
7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
Summary: Refactor G1's hot card cache and card counts table into their own files. Simplify the card counts table, including removing the encoding of the card index in each entry. The card counts table now has a 1:1 correspondence with the cards spanned by heap. Space for the card counts table is reserved from virtual memory (rather than C heap) during JVM startup and is committed/expanded when the heap is expanded. Changes were also reviewed-by Vitaly Davidovich.
Reviewed-by: tschatzl, jmasa
author | johnc |
---|---|
date | Thu, 09 May 2013 11:16:39 -0700 |
parents | |
children | bed55d125e37 |
comparison
equal
deleted
inserted
replaced
10245:923ac8d1df95 | 10246:194f52aa2f23 |
---|---|
1 /* | |
2 * Copyright (c) 2013, 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_implementation/g1/g1CardCounts.hpp" | |
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" | |
28 #include "gc_implementation/g1/g1CollectorPolicy.hpp" | |
29 #include "gc_implementation/g1/g1GCPhaseTimes.hpp" | |
30 #include "memory/cardTableModRefBS.hpp" | |
31 #include "services/memTracker.hpp" | |
32 #include "utilities/copy.hpp" | |
33 | |
34 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) { | |
35 if (has_count_table()) { | |
36 check_card_num(from_card_num, | |
37 err_msg("from card num out of range: "SIZE_FORMAT, from_card_num)); | |
38 assert(from_card_num < to_card_num, | |
39 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT, | |
40 from_card_num, to_card_num)); | |
41 assert(to_card_num <= _committed_max_card_num, | |
42 err_msg("to card num out of range: " | |
43 "to: "SIZE_FORMAT ", " | |
44 "max: "SIZE_FORMAT, | |
45 to_card_num, _committed_max_card_num)); | |
46 | |
47 to_card_num = MIN2(_committed_max_card_num, to_card_num); | |
48 | |
49 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num)); | |
50 } | |
51 } | |
52 | |
53 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h): | |
54 _g1h(g1h), _card_counts(NULL), | |
55 _reserved_max_card_num(0), _committed_max_card_num(0), | |
56 _committed_size(0) {} | |
57 | |
58 void G1CardCounts::initialize() { | |
59 assert(_g1h->max_capacity() > 0, "initialization order"); | |
60 assert(_g1h->capacity() == 0, "initialization order"); | |
61 | |
62 if (G1ConcRSHotCardLimit > 0) { | |
63 // The max value we can store in the counts table is | |
64 // max_jubyte. Guarantee the value of the hot | |
65 // threshold limit is no more than this. | |
66 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity"); | |
67 | |
68 ModRefBarrierSet* bs = _g1h->mr_bs(); | |
69 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition"); | |
70 _ct_bs = (CardTableModRefBS*)bs; | |
71 _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start()); | |
72 | |
73 // Allocate/Reserve the counts table | |
74 size_t reserved_bytes = _g1h->max_capacity(); | |
75 _reserved_max_card_num = reserved_bytes >> CardTableModRefBS::card_shift; | |
76 | |
77 size_t reserved_size = _reserved_max_card_num * sizeof(jbyte); | |
78 ReservedSpace rs(ReservedSpace::allocation_align_size_up(reserved_size)); | |
79 if (!rs.is_reserved()) { | |
80 warning("Could not reserve enough space for the card counts table"); | |
81 guarantee(!has_reserved_count_table(), "should be NULL"); | |
82 return; | |
83 } | |
84 | |
85 MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); | |
86 | |
87 _card_counts_storage.initialize(rs, 0); | |
88 _card_counts = (jubyte*) _card_counts_storage.low(); | |
89 } | |
90 } | |
91 | |
92 void G1CardCounts::resize(size_t heap_capacity) { | |
93 // Expand the card counts table to handle a heap with the given capacity. | |
94 | |
95 if (!has_reserved_count_table()) { | |
96 // Don't expand if we failed to reserve the card counts table. | |
97 return; | |
98 } | |
99 | |
100 assert(_committed_size == | |
101 ReservedSpace::allocation_align_size_up(_committed_size), | |
102 err_msg("Unaligned? committed_size: " SIZE_FORMAT, _committed_size)); | |
103 | |
104 // Verify that the committed space for the card counts | |
105 // matches our committed max card num. | |
106 size_t prev_committed_size = _committed_size; | |
107 size_t prev_committed_card_num = prev_committed_size / sizeof(jbyte); | |
108 assert(prev_committed_card_num == _committed_max_card_num, | |
109 err_msg("Card mismatch: " | |
110 "prev: " SIZE_FORMAT ", " | |
111 "committed: "SIZE_FORMAT, | |
112 prev_committed_card_num, _committed_max_card_num)); | |
113 | |
114 size_t new_size = (heap_capacity >> CardTableModRefBS::card_shift) * sizeof(jbyte); | |
115 size_t new_committed_size = ReservedSpace::allocation_align_size_up(new_size); | |
116 size_t new_committed_card_num = | |
117 MIN2(_reserved_max_card_num, new_committed_size / sizeof(jbyte)); | |
118 | |
119 if (_committed_max_card_num < new_committed_card_num) { | |
120 // we need to expand the backing store for the card counts | |
121 size_t expand_size = new_committed_size - prev_committed_size; | |
122 | |
123 if (!_card_counts_storage.expand_by(expand_size)) { | |
124 warning("Card counts table backing store commit failure"); | |
125 return; | |
126 } | |
127 assert(_card_counts_storage.committed_size() == new_committed_size, | |
128 "expansion commit failure"); | |
129 | |
130 _committed_size = new_committed_size; | |
131 _committed_max_card_num = new_committed_card_num; | |
132 | |
133 clear_range(prev_committed_card_num, _committed_max_card_num); | |
134 } | |
135 } | |
136 | |
137 uint G1CardCounts::add_card_count(jbyte* card_ptr) { | |
138 // Returns the number of times the card has been refined. | |
139 // If we failed to reserve/commit the counts table, return 0. | |
140 // If card_ptr is beyond the committed end of the counts table, | |
141 // return 0. | |
142 // Otherwise return the actual count. | |
143 // Unless G1ConcRSHotCardLimit has been set appropriately, | |
144 // returning 0 will result in the card being considered | |
145 // cold and will be refined immediately. | |
146 uint count = 0; | |
147 if (has_count_table()) { | |
148 size_t card_num = ptr_2_card_num(card_ptr); | |
149 if (card_num < _committed_max_card_num) { | |
150 count = (uint) _card_counts[card_num]; | |
151 if (count < G1ConcRSHotCardLimit) { | |
152 _card_counts[card_num] += 1; | |
153 } | |
154 assert(_card_counts[card_num] <= G1ConcRSHotCardLimit, | |
155 err_msg("Refinement count overflow? " | |
156 "new count: "UINT32_FORMAT, | |
157 (uint) _card_counts[card_num])); | |
158 } | |
159 } | |
160 return count; | |
161 } | |
162 | |
163 bool G1CardCounts::is_hot(uint count) { | |
164 return (count >= G1ConcRSHotCardLimit); | |
165 } | |
166 | |
167 void G1CardCounts::clear_region(HeapRegion* hr) { | |
168 assert(!hr->isHumongous(), "Should have been cleared"); | |
169 if (has_count_table()) { | |
170 HeapWord* bottom = hr->bottom(); | |
171 | |
172 // We use the last address in hr as hr could be the | |
173 // last region in the heap. In which case trying to find | |
174 // the card for hr->end() will be an OOB accesss to the | |
175 // card table. | |
176 HeapWord* last = hr->end() - 1; | |
177 assert(_g1h->g1_committed().contains(last), | |
178 err_msg("last not in committed: " | |
179 "last: " PTR_FORMAT ", " | |
180 "committed: [" PTR_FORMAT ", " PTR_FORMAT ")", | |
181 last, | |
182 _g1h->g1_committed().start(), | |
183 _g1h->g1_committed().end())); | |
184 | |
185 const jbyte* from_card_ptr = _ct_bs->byte_for_const(bottom); | |
186 const jbyte* last_card_ptr = _ct_bs->byte_for_const(last); | |
187 | |
188 #ifdef ASSERT | |
189 HeapWord* start_addr = _ct_bs->addr_for(from_card_ptr); | |
190 assert(start_addr == hr->bottom(), "alignment"); | |
191 HeapWord* last_addr = _ct_bs->addr_for(last_card_ptr); | |
192 assert((last_addr + CardTableModRefBS::card_size_in_words) == hr->end(), "alignment"); | |
193 #endif // ASSERT | |
194 | |
195 // Clear the counts for the (exclusive) card range. | |
196 size_t from_card_num = ptr_2_card_num(from_card_ptr); | |
197 size_t to_card_num = ptr_2_card_num(last_card_ptr) + 1; | |
198 clear_range(from_card_num, to_card_num); | |
199 } | |
200 } | |
201 | |
202 void G1CardCounts::clear_all() { | |
203 assert(SafepointSynchronize::is_at_safepoint(), "don't call this otherwise"); | |
204 clear_range((size_t)0, _committed_max_card_num); | |
205 } | |
206 | |
207 G1CardCounts::~G1CardCounts() { | |
208 if (has_reserved_count_table()) { | |
209 _card_counts_storage.release(); | |
210 } | |
211 } | |
212 |