1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/parallel/objectStartArray.inline.hpp"
27 #include "gc/parallel/parallelArguments.hpp"
28 #include "gc/parallel/parallelScavengeHeap.hpp"
29 #include "gc/parallel/psAdaptiveSizePolicy.hpp"
30 #include "gc/parallel/psCardTable.hpp"
31 #include "gc/parallel/psFileBackedVirtualspace.hpp"
32 #include "gc/parallel/psMarkSweepDecorator.hpp"
33 #include "gc/parallel/psOldGen.hpp"
34 #include "gc/shared/cardTableBarrierSet.hpp"
35 #include "gc/shared/gcLocker.hpp"
36 #include "gc/shared/spaceDecorator.inline.hpp"
37 #include "logging/log.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/java.hpp"
40 #include "utilities/align.hpp"
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);
66
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");
70
71 initialize_performance_counters(perf_data_name, level);
72 }
73
74 void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
75
76 if(ParallelArguments::is_heterogeneous_heap()) {
77 _virtual_space = new PSFileBackedVirtualSpace(rs, alignment, AllocateOldGenAt);
78 if (!(static_cast <PSFileBackedVirtualSpace*>(_virtual_space))->initialize()) {
131 guarantee(ct->is_card_aligned(_reserved.start()), "generation must be card aligned");
132 if (_reserved.end() != heap->reserved_region().end()) {
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.
135 guarantee(ct->is_card_aligned(_reserved.end()), "generation must be card aligned");
136 }
137
138 //
139 // ObjectSpace stuff
140 //
141
142 _object_space = new MutableSpace(virtual_space()->alignment());
143
144 if (_object_space == NULL)
145 vm_exit_during_initialization("Could not allocate an old gen space");
146
147 object_space()->initialize(cmr,
148 SpaceDecorator::Clear,
149 SpaceDecorator::Mangle);
150
151 #if INCLUDE_SERIALGC
152 _object_mark_sweep = new PSMarkSweepDecorator(_object_space, start_array(), MarkSweepDeadRatio);
153
154 if (_object_mark_sweep == NULL) {
155 vm_exit_during_initialization("Could not complete allocation of old generation");
156 }
157 #endif // INCLUDE_SERIALGC
158
159 // Update the start_array
160 start_array()->set_covered_region(cmr);
161 }
162
163 void PSOldGen::initialize_performance_counters(const char* perf_data_name, int level) {
164 // Generation Counters, generation 'level', 1 subspace
165 _gen_counters = new PSGenerationCounters(perf_data_name, level, 1, _min_gen_size,
166 _max_gen_size, virtual_space());
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
178 #if INCLUDE_SERIALGC
179
180 void PSOldGen::precompact() {
181 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
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
200 #endif // INCLUDE_SERIALGC
201
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!
208 HeapWord* PSOldGen::allocate(size_t word_size) {
209 assert_locked_or_safepoint(Heap_lock);
210 HeapWord* res = allocate_noexpand(word_size);
211
212 if (res == NULL) {
213 res = expand_and_allocate(word_size);
214 }
215
216 // Allocations in the old generation need to be reported
217 if (res != NULL) {
218 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
219 heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
220 }
|
1 /*
2 * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/parallel/objectStartArray.inline.hpp"
27 #include "gc/parallel/parallelArguments.hpp"
28 #include "gc/parallel/parallelScavengeHeap.hpp"
29 #include "gc/parallel/psAdaptiveSizePolicy.hpp"
30 #include "gc/parallel/psCardTable.hpp"
31 #include "gc/parallel/psFileBackedVirtualspace.hpp"
32 #include "gc/parallel/psOldGen.hpp"
33 #include "gc/shared/cardTableBarrierSet.hpp"
34 #include "gc/shared/gcLocker.hpp"
35 #include "gc/shared/spaceDecorator.inline.hpp"
36 #include "logging/log.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "runtime/java.hpp"
39 #include "utilities/align.hpp"
40
41 inline const char* PSOldGen::old_gen_name() {
42 return "ParOldGen";
43 }
44
45 PSOldGen::PSOldGen(ReservedSpace rs, size_t alignment,
46 size_t initial_size, size_t min_size, size_t max_size,
47 const char* perf_data_name, int level):
48 _name(old_gen_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
49 _max_gen_size(max_size)
50 {
51 initialize(rs, alignment, perf_data_name, level);
52 }
53
54 PSOldGen::PSOldGen(size_t initial_size,
55 size_t min_size, size_t max_size,
56 const char* perf_data_name, int level):
57 _name(old_gen_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
58 _max_gen_size(max_size)
59 {}
60
61 void PSOldGen::initialize(ReservedSpace rs, size_t alignment,
62 const char* perf_data_name, int level) {
63 initialize_virtual_space(rs, alignment);
64 initialize_work(perf_data_name, level);
65
66 // The old gen can grow to gen_size_limit(). _reserve reflects only
67 // the current maximum that can be committed.
68 assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check");
69
70 initialize_performance_counters(perf_data_name, level);
71 }
72
73 void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
74
75 if(ParallelArguments::is_heterogeneous_heap()) {
76 _virtual_space = new PSFileBackedVirtualSpace(rs, alignment, AllocateOldGenAt);
77 if (!(static_cast <PSFileBackedVirtualSpace*>(_virtual_space))->initialize()) {
130 guarantee(ct->is_card_aligned(_reserved.start()), "generation must be card aligned");
131 if (_reserved.end() != heap->reserved_region().end()) {
132 // Don't check at the very end of the heap as we'll assert that we're probing off
133 // the end if we try.
134 guarantee(ct->is_card_aligned(_reserved.end()), "generation must be card aligned");
135 }
136
137 //
138 // ObjectSpace stuff
139 //
140
141 _object_space = new MutableSpace(virtual_space()->alignment());
142
143 if (_object_space == NULL)
144 vm_exit_during_initialization("Could not allocate an old gen space");
145
146 object_space()->initialize(cmr,
147 SpaceDecorator::Clear,
148 SpaceDecorator::Mangle);
149
150 // Update the start_array
151 start_array()->set_covered_region(cmr);
152 }
153
154 void PSOldGen::initialize_performance_counters(const char* perf_data_name, int level) {
155 // Generation Counters, generation 'level', 1 subspace
156 _gen_counters = new PSGenerationCounters(perf_data_name, level, 1, _min_gen_size,
157 _max_gen_size, virtual_space());
158 _space_counters = new SpaceCounters(perf_data_name, 0,
159 virtual_space()->reserved_size(),
160 _object_space, _gen_counters);
161 }
162
163 // Assume that the generation has been allocated if its
164 // reserved size is not 0.
165 bool PSOldGen::is_allocated() {
166 return virtual_space()->reserved_size() != 0;
167 }
168
169 size_t PSOldGen::contiguous_available() const {
170 return object_space()->free_in_bytes() + virtual_space()->uncommitted_size();
171 }
172
173 // Allocation. We report all successful allocations to the size policy
174 // Note that the perm gen does not use this method, and should not!
175 HeapWord* PSOldGen::allocate(size_t word_size) {
176 assert_locked_or_safepoint(Heap_lock);
177 HeapWord* res = allocate_noexpand(word_size);
178
179 if (res == NULL) {
180 res = expand_and_allocate(word_size);
181 }
182
183 // Allocations in the old generation need to be reported
184 if (res != NULL) {
185 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
186 heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
187 }
|