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