author | stefank |
Fri, 18 Mar 2016 08:59:07 +0100 | |
changeset 37146 | 209e0fe518bb |
parent 37073 | c39d0903390b |
child 46619 | a3919f5e8d2b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
35862
411842d0c882
8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents:
35492
diff
changeset
|
2 |
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
35862
411842d0c882
8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents:
35492
diff
changeset
|
26 |
#include "gc/parallel/objectStartArray.inline.hpp" |
30764 | 27 |
#include "gc/parallel/parallelScavengeHeap.hpp" |
28 |
#include "gc/parallel/psAdaptiveSizePolicy.hpp" |
|
29 |
#include "gc/parallel/psMarkSweepDecorator.hpp" |
|
30 |
#include "gc/parallel/psOldGen.hpp" |
|
31 |
#include "gc/shared/cardTableModRefBS.hpp" |
|
32 |
#include "gc/shared/gcLocker.inline.hpp" |
|
33 |
#include "gc/shared/spaceDecorator.hpp" |
|
35061 | 34 |
#include "logging/log.hpp" |
7397 | 35 |
#include "oops/oop.inline.hpp" |
36 |
#include "runtime/java.hpp" |
|
1 | 37 |
|
38 |
inline const char* PSOldGen::select_name() { |
|
39 |
return UseParallelOldGC ? "ParOldGen" : "PSOldGen"; |
|
40 |
} |
|
41 |
||
42 |
PSOldGen::PSOldGen(ReservedSpace rs, size_t alignment, |
|
43 |
size_t initial_size, size_t min_size, size_t max_size, |
|
44 |
const char* perf_data_name, int level): |
|
45 |
_name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size), |
|
46 |
_max_gen_size(max_size) |
|
47 |
{ |
|
48 |
initialize(rs, alignment, perf_data_name, level); |
|
49 |
} |
|
50 |
||
51 |
PSOldGen::PSOldGen(size_t initial_size, |
|
52 |
size_t min_size, size_t max_size, |
|
53 |
const char* perf_data_name, int level): |
|
54 |
_name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size), |
|
55 |
_max_gen_size(max_size) |
|
56 |
{} |
|
57 |
||
58 |
void PSOldGen::initialize(ReservedSpace rs, size_t alignment, |
|
59 |
const char* perf_data_name, int level) { |
|
60 |
initialize_virtual_space(rs, alignment); |
|
61 |
initialize_work(perf_data_name, level); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
62 |
|
1 | 63 |
// The old gen can grow to gen_size_limit(). _reserve reflects only |
64 |
// the current maximum that can be committed. |
|
65 |
assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
66 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
67 |
initialize_performance_counters(perf_data_name, level); |
1 | 68 |
} |
69 |
||
70 |
void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) { |
|
71 |
||
72 |
_virtual_space = new PSVirtualSpace(rs, alignment); |
|
73 |
if (!_virtual_space->expand_by(_init_gen_size)) { |
|
74 |
vm_exit_during_initialization("Could not reserve enough space for " |
|
75 |
"object heap"); |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
void PSOldGen::initialize_work(const char* perf_data_name, int level) { |
|
80 |
// |
|
81 |
// Basic memory initialization |
|
82 |
// |
|
83 |
||
84 |
MemRegion limit_reserved((HeapWord*)virtual_space()->low_boundary(), |
|
85 |
heap_word_size(_max_gen_size)); |
|
86 |
assert(limit_reserved.byte_size() == _max_gen_size, |
|
87 |
"word vs bytes confusion"); |
|
88 |
// |
|
89 |
// Object start stuff |
|
90 |
// |
|
91 |
||
92 |
start_array()->initialize(limit_reserved); |
|
93 |
||
94 |
_reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), |
|
95 |
(HeapWord*)virtual_space()->high_boundary()); |
|
96 |
||
97 |
// |
|
98 |
// Card table stuff |
|
99 |
// |
|
100 |
||
101 |
MemRegion cmr((HeapWord*)virtual_space()->low(), |
|
102 |
(HeapWord*)virtual_space()->high()); |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
103 |
if (ZapUnusedHeapArea) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
104 |
// Mangle newly committed space immediately rather than |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
105 |
// waiting for the initialization of the space even though |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
106 |
// mangling is related to spaces. Doing it here eliminates |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
107 |
// the need to carry along information that a complete mangling |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
108 |
// (bottom to end) needs to be done. |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
109 |
SpaceMangler::mangle_region(cmr); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
110 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
111 |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
112 |
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); |
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
113 |
BarrierSet* bs = heap->barrier_set(); |
1 | 114 |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
115 |
bs->resize_covered_region(cmr); |
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
116 |
|
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
117 |
CardTableModRefBS* ct = barrier_set_cast<CardTableModRefBS>(bs); |
1 | 118 |
|
119 |
// Verify that the start and end of this generation is the start of a card. |
|
120 |
// If this wasn't true, a single card could span more than one generation, |
|
121 |
// which would cause problems when we commit/uncommit memory, and when we |
|
122 |
// clear and dirty cards. |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
123 |
guarantee(ct->is_card_aligned(_reserved.start()), "generation must be card aligned"); |
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
124 |
if (_reserved.end() != heap->reserved_region().end()) { |
1 | 125 |
// Don't check at the very end of the heap as we'll assert that we're probing off |
126 |
// the end if we try. |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
127 |
guarantee(ct->is_card_aligned(_reserved.end()), "generation must be card aligned"); |
1 | 128 |
} |
129 |
||
130 |
// |
|
131 |
// ObjectSpace stuff |
|
132 |
// |
|
133 |
||
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
1412
diff
changeset
|
134 |
_object_space = new MutableSpace(virtual_space()->alignment()); |
1 | 135 |
|
136 |
if (_object_space == NULL) |
|
137 |
vm_exit_during_initialization("Could not allocate an old gen space"); |
|
138 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
139 |
object_space()->initialize(cmr, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
140 |
SpaceDecorator::Clear, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
141 |
SpaceDecorator::Mangle); |
1 | 142 |
|
143 |
_object_mark_sweep = new PSMarkSweepDecorator(_object_space, start_array(), MarkSweepDeadRatio); |
|
144 |
||
145 |
if (_object_mark_sweep == NULL) |
|
146 |
vm_exit_during_initialization("Could not complete allocation of old generation"); |
|
147 |
||
148 |
// Update the start_array |
|
149 |
start_array()->set_covered_region(cmr); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
150 |
} |
1 | 151 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
152 |
void PSOldGen::initialize_performance_counters(const char* perf_data_name, int level) { |
1 | 153 |
// Generation Counters, generation 'level', 1 subspace |
26324
6b9c12e15535
8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents:
24424
diff
changeset
|
154 |
_gen_counters = new PSGenerationCounters(perf_data_name, level, 1, _min_gen_size, |
6b9c12e15535
8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents:
24424
diff
changeset
|
155 |
_max_gen_size, virtual_space()); |
1 | 156 |
_space_counters = new SpaceCounters(perf_data_name, 0, |
157 |
virtual_space()->reserved_size(), |
|
158 |
_object_space, _gen_counters); |
|
159 |
} |
|
160 |
||
161 |
// Assume that the generation has been allocated if its |
|
162 |
// reserved size is not 0. |
|
163 |
bool PSOldGen::is_allocated() { |
|
164 |
return virtual_space()->reserved_size() != 0; |
|
165 |
} |
|
166 |
||
167 |
void PSOldGen::precompact() { |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
168 |
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); |
1 | 169 |
|
170 |
// Reset start array first. |
|
171 |
start_array()->reset(); |
|
172 |
||
173 |
object_mark_sweep()->precompact(); |
|
174 |
||
175 |
// Now compact the young gen |
|
176 |
heap->young_gen()->precompact(); |
|
177 |
} |
|
178 |
||
179 |
void PSOldGen::adjust_pointers() { |
|
180 |
object_mark_sweep()->adjust_pointers(); |
|
181 |
} |
|
182 |
||
183 |
void PSOldGen::compact() { |
|
184 |
object_mark_sweep()->compact(ZapUnusedHeapArea); |
|
185 |
} |
|
186 |
||
187 |
size_t PSOldGen::contiguous_available() const { |
|
188 |
return object_space()->free_in_bytes() + virtual_space()->uncommitted_size(); |
|
189 |
} |
|
190 |
||
191 |
// Allocation. We report all successful allocations to the size policy |
|
192 |
// Note that the perm gen does not use this method, and should not! |
|
9997
b75b7939f448
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
9423
diff
changeset
|
193 |
HeapWord* PSOldGen::allocate(size_t word_size) { |
1 | 194 |
assert_locked_or_safepoint(Heap_lock); |
9997
b75b7939f448
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
9423
diff
changeset
|
195 |
HeapWord* res = allocate_noexpand(word_size); |
1 | 196 |
|
197 |
if (res == NULL) { |
|
9997
b75b7939f448
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
9423
diff
changeset
|
198 |
res = expand_and_allocate(word_size); |
1 | 199 |
} |
200 |
||
201 |
// Allocations in the old generation need to be reported |
|
202 |
if (res != NULL) { |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
203 |
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); |
31359 | 204 |
heap->size_policy()->tenured_allocation(word_size * HeapWordSize); |
1 | 205 |
} |
206 |
||
207 |
return res; |
|
208 |
} |
|
209 |
||
9997
b75b7939f448
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
9423
diff
changeset
|
210 |
HeapWord* PSOldGen::expand_and_allocate(size_t word_size) { |
1 | 211 |
expand(word_size*HeapWordSize); |
212 |
if (GCExpandToAllocateDelayMillis > 0) { |
|
213 |
os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
|
214 |
} |
|
9997
b75b7939f448
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
9423
diff
changeset
|
215 |
return allocate_noexpand(word_size); |
1 | 216 |
} |
217 |
||
218 |
HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) { |
|
219 |
expand(word_size*HeapWordSize); |
|
220 |
if (GCExpandToAllocateDelayMillis > 0) { |
|
221 |
os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
|
222 |
} |
|
223 |
return cas_allocate_noexpand(word_size); |
|
224 |
} |
|
225 |
||
226 |
void PSOldGen::expand(size_t bytes) { |
|
979
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
227 |
if (bytes == 0) { |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
228 |
return; |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
229 |
} |
1 | 230 |
MutexLocker x(ExpandHeap_lock); |
231 |
const size_t alignment = virtual_space()->alignment(); |
|
232 |
size_t aligned_bytes = align_size_up(bytes, alignment); |
|
233 |
size_t aligned_expand_bytes = align_size_up(MinHeapDeltaBytes, alignment); |
|
9423
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
234 |
|
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
235 |
if (UseNUMA) { |
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
236 |
// With NUMA we use round-robin page allocation for the old gen. Expand by at least |
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
237 |
// providing a page per lgroup. Alignment is larger or equal to the page size. |
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
238 |
aligned_expand_bytes = MAX2(aligned_expand_bytes, alignment * os::numa_get_groups_num()); |
a977bd202cec
7041501: NUMA: Expand the old gen more aggressively
iveresov
parents:
9178
diff
changeset
|
239 |
} |
979
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
240 |
if (aligned_bytes == 0){ |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
241 |
// The alignment caused the number of bytes to wrap. An expand_by(0) will |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
242 |
// return true with the implication that and expansion was done when it |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
243 |
// was not. A call to expand implies a best effort to expand by "bytes" |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
244 |
// but not a guarantee. Align down to give a best effort. This is likely |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
245 |
// the most that the generation can expand since it has some capacity to |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
246 |
// start with. |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
247 |
aligned_bytes = align_size_down(bytes, alignment); |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
248 |
} |
1 | 249 |
|
250 |
bool success = false; |
|
251 |
if (aligned_expand_bytes > aligned_bytes) { |
|
252 |
success = expand_by(aligned_expand_bytes); |
|
253 |
} |
|
254 |
if (!success) { |
|
255 |
success = expand_by(aligned_bytes); |
|
256 |
} |
|
257 |
if (!success) { |
|
258 |
success = expand_to_reserved(); |
|
259 |
} |
|
260 |
||
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35061
diff
changeset
|
261 |
if (success && GCLocker::is_active_and_needs_gc()) { |
35061 | 262 |
log_debug(gc)("Garbage collection disabled, expanded heap instead"); |
1 | 263 |
} |
264 |
} |
|
265 |
||
266 |
bool PSOldGen::expand_by(size_t bytes) { |
|
267 |
assert_lock_strong(ExpandHeap_lock); |
|
268 |
assert_locked_or_safepoint(Heap_lock); |
|
979
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
269 |
if (bytes == 0) { |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
270 |
return true; // That's what virtual_space()->expand_by(0) would return |
c9479f1e0a94
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
971
diff
changeset
|
271 |
} |
1 | 272 |
bool result = virtual_space()->expand_by(bytes); |
273 |
if (result) { |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
274 |
if (ZapUnusedHeapArea) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
275 |
// We need to mangle the newly expanded area. The memregion spans |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
276 |
// end -> new_end, we assume that top -> end is already mangled. |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
277 |
// Do the mangling before post_resize() is called because |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
278 |
// the space is available for allocation after post_resize(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
279 |
HeapWord* const virtual_space_high = (HeapWord*) virtual_space()->high(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
280 |
assert(object_space()->end() < virtual_space_high, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
281 |
"Should be true before post_resize()"); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
282 |
MemRegion mangle_region(object_space()->end(), virtual_space_high); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
283 |
// Note that the object space has not yet been updated to |
22551 | 284 |
// coincide with the new underlying virtual space. |
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
285 |
SpaceMangler::mangle_region(mangle_region); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
286 |
} |
1 | 287 |
post_resize(); |
288 |
if (UsePerfData) { |
|
289 |
_space_counters->update_capacity(); |
|
290 |
_gen_counters->update_all(); |
|
291 |
} |
|
292 |
} |
|
293 |
||
35061 | 294 |
if (result) { |
1 | 295 |
size_t new_mem_size = virtual_space()->committed_size(); |
296 |
size_t old_mem_size = new_mem_size - bytes; |
|
35061 | 297 |
log_debug(gc)("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
298 |
name(), old_mem_size/K, bytes/K, new_mem_size/K); |
|
1 | 299 |
} |
300 |
||
301 |
return result; |
|
302 |
} |
|
303 |
||
304 |
bool PSOldGen::expand_to_reserved() { |
|
305 |
assert_lock_strong(ExpandHeap_lock); |
|
306 |
assert_locked_or_safepoint(Heap_lock); |
|
307 |
||
308 |
bool result = true; |
|
309 |
const size_t remaining_bytes = virtual_space()->uncommitted_size(); |
|
310 |
if (remaining_bytes > 0) { |
|
311 |
result = expand_by(remaining_bytes); |
|
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
35862
diff
changeset
|
312 |
DEBUG_ONLY(if (!result) log_warning(gc)("grow to reserve failed")); |
1 | 313 |
} |
314 |
return result; |
|
315 |
} |
|
316 |
||
317 |
void PSOldGen::shrink(size_t bytes) { |
|
318 |
assert_lock_strong(ExpandHeap_lock); |
|
319 |
assert_locked_or_safepoint(Heap_lock); |
|
320 |
||
321 |
size_t size = align_size_down(bytes, virtual_space()->alignment()); |
|
322 |
if (size > 0) { |
|
323 |
assert_lock_strong(ExpandHeap_lock); |
|
324 |
virtual_space()->shrink_by(bytes); |
|
325 |
post_resize(); |
|
326 |
||
35061 | 327 |
size_t new_mem_size = virtual_space()->committed_size(); |
328 |
size_t old_mem_size = new_mem_size + bytes; |
|
329 |
log_debug(gc)("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
|
330 |
name(), old_mem_size/K, bytes/K, new_mem_size/K); |
|
1 | 331 |
} |
332 |
} |
|
333 |
||
334 |
void PSOldGen::resize(size_t desired_free_space) { |
|
335 |
const size_t alignment = virtual_space()->alignment(); |
|
336 |
const size_t size_before = virtual_space()->committed_size(); |
|
337 |
size_t new_size = used_in_bytes() + desired_free_space; |
|
338 |
if (new_size < used_in_bytes()) { |
|
339 |
// Overflowed the addition. |
|
340 |
new_size = gen_size_limit(); |
|
341 |
} |
|
342 |
// Adjust according to our min and max |
|
343 |
new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size()); |
|
344 |
||
345 |
assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?"); |
|
346 |
new_size = align_size_up(new_size, alignment); |
|
347 |
||
348 |
const size_t current_size = capacity_in_bytes(); |
|
349 |
||
35061 | 350 |
log_trace(gc, ergo)("AdaptiveSizePolicy::old generation size: " |
351 |
"desired free: " SIZE_FORMAT " used: " SIZE_FORMAT |
|
352 |
" new size: " SIZE_FORMAT " current size " SIZE_FORMAT |
|
353 |
" gen limits: " SIZE_FORMAT " / " SIZE_FORMAT, |
|
354 |
desired_free_space, used_in_bytes(), new_size, current_size, |
|
355 |
gen_size_limit(), min_gen_size()); |
|
1 | 356 |
|
357 |
if (new_size == current_size) { |
|
358 |
// No change requested |
|
359 |
return; |
|
360 |
} |
|
361 |
if (new_size > current_size) { |
|
362 |
size_t change_bytes = new_size - current_size; |
|
363 |
expand(change_bytes); |
|
364 |
} else { |
|
365 |
size_t change_bytes = current_size - new_size; |
|
366 |
// shrink doesn't grab this lock, expand does. Is that right? |
|
367 |
MutexLocker x(ExpandHeap_lock); |
|
368 |
shrink(change_bytes); |
|
369 |
} |
|
370 |
||
35061 | 371 |
log_trace(gc, ergo)("AdaptiveSizePolicy::old generation size: collection: %d (" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ", |
372 |
ParallelScavengeHeap::heap()->total_collections(), |
|
373 |
size_before, |
|
374 |
virtual_space()->committed_size()); |
|
1 | 375 |
} |
376 |
||
377 |
// NOTE! We need to be careful about resizing. During a GC, multiple |
|
378 |
// allocators may be active during heap expansion. If we allow the |
|
379 |
// heap resizing to become visible before we have correctly resized |
|
380 |
// all heap related data structures, we may cause program failures. |
|
381 |
void PSOldGen::post_resize() { |
|
382 |
// First construct a memregion representing the new size |
|
383 |
MemRegion new_memregion((HeapWord*)virtual_space()->low(), |
|
384 |
(HeapWord*)virtual_space()->high()); |
|
385 |
size_t new_word_size = new_memregion.word_size(); |
|
386 |
||
387 |
start_array()->set_covered_region(new_memregion); |
|
30173
13cf7580b000
8077413: Avoid use of Universe::heap() inside collectors
pliden
parents:
29798
diff
changeset
|
388 |
ParallelScavengeHeap::heap()->barrier_set()->resize_covered_region(new_memregion); |
1 | 389 |
|
390 |
// ALWAYS do this last!! |
|
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
1412
diff
changeset
|
391 |
object_space()->initialize(new_memregion, |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
1412
diff
changeset
|
392 |
SpaceDecorator::DontClear, |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
1412
diff
changeset
|
393 |
SpaceDecorator::DontMangle); |
1 | 394 |
|
395 |
assert(new_word_size == heap_word_size(object_space()->capacity_in_bytes()), |
|
396 |
"Sanity"); |
|
397 |
} |
|
398 |
||
399 |
size_t PSOldGen::gen_size_limit() { |
|
400 |
return _max_gen_size; |
|
401 |
} |
|
402 |
||
403 |
void PSOldGen::reset_after_change() { |
|
404 |
ShouldNotReachHere(); |
|
405 |
return; |
|
406 |
} |
|
407 |
||
408 |
size_t PSOldGen::available_for_expansion() { |
|
409 |
ShouldNotReachHere(); |
|
410 |
return 0; |
|
411 |
} |
|
412 |
||
413 |
size_t PSOldGen::available_for_contraction() { |
|
414 |
ShouldNotReachHere(); |
|
415 |
return 0; |
|
416 |
} |
|
417 |
||
418 |
void PSOldGen::print() const { print_on(tty);} |
|
419 |
void PSOldGen::print_on(outputStream* st) const { |
|
420 |
st->print(" %-15s", name()); |
|
35061 | 421 |
st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", |
422 |
capacity_in_bytes()/K, used_in_bytes()/K); |
|
1 | 423 |
st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", |
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
29325
diff
changeset
|
424 |
p2i(virtual_space()->low_boundary()), |
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
29325
diff
changeset
|
425 |
p2i(virtual_space()->high()), |
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
29325
diff
changeset
|
426 |
p2i(virtual_space()->high_boundary())); |
1 | 427 |
|
428 |
st->print(" object"); object_space()->print_on(st); |
|
429 |
} |
|
430 |
||
431 |
void PSOldGen::print_used_change(size_t prev_used) const { |
|
35061 | 432 |
log_info(gc, heap)("%s: " SIZE_FORMAT "K->" SIZE_FORMAT "K(" SIZE_FORMAT "K)", |
433 |
name(), prev_used / K, used_in_bytes() / K, capacity_in_bytes() / K); |
|
1 | 434 |
} |
435 |
||
436 |
void PSOldGen::update_counters() { |
|
437 |
if (UsePerfData) { |
|
438 |
_space_counters->update_all(); |
|
439 |
_gen_counters->update_all(); |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
#ifndef PRODUCT |
|
444 |
||
445 |
void PSOldGen::space_invariants() { |
|
446 |
assert(object_space()->end() == (HeapWord*) virtual_space()->high(), |
|
447 |
"Space invariant"); |
|
448 |
assert(object_space()->bottom() == (HeapWord*) virtual_space()->low(), |
|
449 |
"Space invariant"); |
|
450 |
assert(virtual_space()->low_boundary() <= virtual_space()->low(), |
|
451 |
"Space invariant"); |
|
452 |
assert(virtual_space()->high_boundary() >= virtual_space()->high(), |
|
453 |
"Space invariant"); |
|
454 |
assert(virtual_space()->low_boundary() == (char*) _reserved.start(), |
|
455 |
"Space invariant"); |
|
456 |
assert(virtual_space()->high_boundary() == (char*) _reserved.end(), |
|
457 |
"Space invariant"); |
|
458 |
assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(), |
|
459 |
"Space invariant"); |
|
460 |
} |
|
461 |
#endif |
|
462 |
||
12379 | 463 |
void PSOldGen::verify() { |
464 |
object_space()->verify(); |
|
1 | 465 |
} |
466 |
class VerifyObjectStartArrayClosure : public ObjectClosure { |
|
32623
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
31359
diff
changeset
|
467 |
PSOldGen* _old_gen; |
1 | 468 |
ObjectStartArray* _start_array; |
469 |
||
470 |
public: |
|
32623
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
31359
diff
changeset
|
471 |
VerifyObjectStartArrayClosure(PSOldGen* old_gen, ObjectStartArray* start_array) : |
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
31359
diff
changeset
|
472 |
_old_gen(old_gen), _start_array(start_array) { } |
1 | 473 |
|
474 |
virtual void do_object(oop obj) { |
|
475 |
HeapWord* test_addr = (HeapWord*)obj + 1; |
|
476 |
guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object"); |
|
477 |
guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation"); |
|
478 |
} |
|
479 |
}; |
|
480 |
||
481 |
void PSOldGen::verify_object_start_array() { |
|
482 |
VerifyObjectStartArrayClosure check( this, &_start_array ); |
|
483 |
object_iterate(&check); |
|
484 |
} |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
485 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
486 |
#ifndef PRODUCT |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
487 |
void PSOldGen::record_spaces_top() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
488 |
assert(ZapUnusedHeapArea, "Not mangling unused space"); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
489 |
object_space()->set_top_for_allocations(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
490 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
1
diff
changeset
|
491 |
#endif |