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 "code/nmethod.hpp"
27 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
29 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
30 #include "gc_implementation/g1/heapRegion.inline.hpp"
31 #include "gc_implementation/g1/heapRegionRemSet.hpp"
32 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
33 #include "memory/genOopClosures.inline.hpp"
34 #include "memory/iterator.hpp"
35 #include "oops/oop.inline.hpp"
36
37 int HeapRegion::LogOfHRGrainBytes = 0;
38 int HeapRegion::LogOfHRGrainWords = 0;
39 size_t HeapRegion::GrainBytes = 0;
40 size_t HeapRegion::GrainWords = 0;
41 size_t HeapRegion::CardsPerRegion = 0;
42
43 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
44 HeapRegion* hr, ExtendedOopClosure* cl,
45 CardTableModRefBS::PrecisionStyle precision,
46 FilterKind fk) :
47 ContiguousSpaceDCTOC(hr, cl, precision, NULL),
48 _hr(hr), _fk(fk), _g1(g1) { }
132 }
133 }
134 }
135
136 // Minimum region size; we won't go lower than that.
137 // We might want to decrease this in the future, to deal with small
138 // heaps a bit more efficiently.
139 #define MIN_REGION_SIZE ( 1024 * 1024 )
140
141 // Maximum region size; we don't go higher than that. There's a good
142 // reason for having an upper bound. We don't want regions to get too
143 // large, otherwise cleanup's effectiveness would decrease as there
144 // will be fewer opportunities to find totally empty regions after
145 // marking.
146 #define MAX_REGION_SIZE ( 32 * 1024 * 1024 )
147
148 // The automatic region size calculation will try to have around this
149 // many regions in the heap (based on the min heap size).
150 #define TARGET_REGION_NUMBER 2048
151
152 void HeapRegion::setup_heap_region_size(uintx min_heap_size) {
153 // region_size in bytes
154 uintx region_size = G1HeapRegionSize;
155 if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
156 // We base the automatic calculation on the min heap size. This
157 // can be problematic if the spread between min and max is quite
158 // wide, imagine -Xms128m -Xmx32g. But, if we decided it based on
159 // the max size, the region size might be way too large for the
160 // min size. Either way, some users might have to set the region
161 // size manually for some -Xms / -Xmx combos.
162
163 region_size = MAX2(min_heap_size / TARGET_REGION_NUMBER,
164 (uintx) MIN_REGION_SIZE);
165 }
166
167 int region_size_log = log2_long((jlong) region_size);
168 // Recalculate the region size to make sure it's a power of
169 // 2. This means that region_size is the largest power of 2 that's
170 // <= what we've calculated so far.
171 region_size = ((uintx)1 << region_size_log);
172
173 // Now make sure that we don't go over or under our limits.
174 if (region_size < MIN_REGION_SIZE) {
175 region_size = MIN_REGION_SIZE;
176 } else if (region_size > MAX_REGION_SIZE) {
177 region_size = MAX_REGION_SIZE;
178 }
179
180 if (region_size != G1HeapRegionSize) {
181 // Update the flag to make sure that PrintFlagsFinal logs the correct value
182 FLAG_SET_ERGO(uintx, G1HeapRegionSize, region_size);
183 }
184
185 // And recalculate the log.
186 region_size_log = log2_long((jlong) region_size);
187
188 // Now, set up the globals.
189 guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
190 LogOfHRGrainBytes = region_size_log;
191
192 guarantee(LogOfHRGrainWords == 0, "we should only set it once");
193 LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize;
194
195 guarantee(GrainBytes == 0, "we should only set it once");
196 // The cast to int is safe, given that we've bounded region_size by
197 // MIN_REGION_SIZE and MAX_REGION_SIZE.
198 GrainBytes = (size_t)region_size;
199
200 guarantee(GrainWords == 0, "we should only set it once");
201 GrainWords = GrainBytes >> LogHeapWordSize;
202 guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity");
203
204 guarantee(CardsPerRegion == 0, "we should only set it once");
205 CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
206 }
207
|
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 "code/nmethod.hpp"
27 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
29 #include "gc_implementation/g1/g1Log.hpp"
30 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
31 #include "gc_implementation/g1/heapRegion.inline.hpp"
32 #include "gc_implementation/g1/heapRegionRemSet.hpp"
33 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
34 #include "memory/genOopClosures.inline.hpp"
35 #include "memory/iterator.hpp"
36 #include "oops/oop.inline.hpp"
37
38 int HeapRegion::LogOfHRGrainBytes = 0;
39 int HeapRegion::LogOfHRGrainWords = 0;
40 size_t HeapRegion::GrainBytes = 0;
41 size_t HeapRegion::GrainWords = 0;
42 size_t HeapRegion::CardsPerRegion = 0;
43
44 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
45 HeapRegion* hr, ExtendedOopClosure* cl,
46 CardTableModRefBS::PrecisionStyle precision,
47 FilterKind fk) :
48 ContiguousSpaceDCTOC(hr, cl, precision, NULL),
49 _hr(hr), _fk(fk), _g1(g1) { }
133 }
134 }
135 }
136
137 // Minimum region size; we won't go lower than that.
138 // We might want to decrease this in the future, to deal with small
139 // heaps a bit more efficiently.
140 #define MIN_REGION_SIZE ( 1024 * 1024 )
141
142 // Maximum region size; we don't go higher than that. There's a good
143 // reason for having an upper bound. We don't want regions to get too
144 // large, otherwise cleanup's effectiveness would decrease as there
145 // will be fewer opportunities to find totally empty regions after
146 // marking.
147 #define MAX_REGION_SIZE ( 32 * 1024 * 1024 )
148
149 // The automatic region size calculation will try to have around this
150 // many regions in the heap (based on the min heap size).
151 #define TARGET_REGION_NUMBER 2048
152
153 void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) {
154 uintx region_size = G1HeapRegionSize;
155 if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
156 size_t average_heap_size = (initial_heap_size + max_heap_size) / 2;
157 region_size = MAX2(average_heap_size / TARGET_REGION_NUMBER,
158 (uintx) MIN_REGION_SIZE);
159 }
160
161 int region_size_log = log2_long((jlong) region_size);
162 // Recalculate the region size to make sure it's a power of
163 // 2. This means that region_size is the largest power of 2 that's
164 // <= what we've calculated so far.
165 region_size = ((uintx)1 << region_size_log);
166
167 // Now make sure that we don't go over or under our limits.
168 if (region_size < MIN_REGION_SIZE) {
169 region_size = MIN_REGION_SIZE;
170 } else if (region_size > MAX_REGION_SIZE) {
171 region_size = MAX_REGION_SIZE;
172 }
173
174 if (region_size != G1HeapRegionSize) {
175 // Update the flag to make sure that PrintFlagsFinal logs the correct value
176 FLAG_SET_ERGO(uintx, G1HeapRegionSize, region_size);
177 }
178
179 // And recalculate the log.
180 region_size_log = log2_long((jlong) region_size);
181
182 if (G1Log::fine()) {
183 gclog_or_tty->print_cr("G1 Heap region size: " SIZE_FORMAT "M", region_size / M);
184 }
185
186 // Now, set up the globals.
187 guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
188 LogOfHRGrainBytes = region_size_log;
189
190 guarantee(LogOfHRGrainWords == 0, "we should only set it once");
191 LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize;
192
193 guarantee(GrainBytes == 0, "we should only set it once");
194 // The cast to int is safe, given that we've bounded region_size by
195 // MIN_REGION_SIZE and MAX_REGION_SIZE.
196 GrainBytes = (size_t)region_size;
197
198 guarantee(GrainWords == 0, "we should only set it once");
199 GrainWords = GrainBytes >> LogHeapWordSize;
200 guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity");
201
202 guarantee(CardsPerRegion == 0, "we should only set it once");
203 CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
204 }
205
|