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