33 #include "gc/shared/space.hpp"
34 #include "gc/shared/vmGCOperations.hpp"
35 #include "logging/log.hpp"
36 #include "memory/universe.hpp"
37 #include "runtime/arguments.hpp"
38 #include "runtime/globals_extension.hpp"
39 #include "runtime/handles.inline.hpp"
40 #include "runtime/java.hpp"
41 #include "runtime/thread.inline.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "utilities/macros.hpp"
44
45 // CollectorPolicy methods
46
47 CollectorPolicy::CollectorPolicy() :
48 _space_alignment(0),
49 _heap_alignment(0),
50 _initial_heap_byte_size(InitialHeapSize),
51 _max_heap_byte_size(MaxHeapSize),
52 _min_heap_byte_size(Arguments::min_heap_size()),
53 _size_policy(NULL),
54 _should_clear_all_soft_refs(false),
55 _all_soft_refs_clear(false)
56 {}
57
58 #ifdef ASSERT
59 void CollectorPolicy::assert_flags() {
60 assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
61 assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment");
62 assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment");
63 }
64
65 void CollectorPolicy::assert_size_info() {
66 assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage");
67 assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage");
68 assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes");
69 assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes");
70 assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes");
71 assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment");
72 assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment");
73 assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment");
139 }
140
141 void CollectorPolicy::initialize_size_info() {
142 log_debug(gc, heap)("Minimum heap " SIZE_FORMAT " Initial heap " SIZE_FORMAT " Maximum heap " SIZE_FORMAT,
143 _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
144
145 DEBUG_ONLY(CollectorPolicy::assert_size_info();)
146 }
147
148 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
149 bool result = _should_clear_all_soft_refs;
150 set_should_clear_all_soft_refs(false);
151 return result;
152 }
153
154 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
155 return new CardTableRS(whole_heap);
156 }
157
158 void CollectorPolicy::cleared_all_soft_refs() {
159 // If near gc overhear limit, continue to clear SoftRefs. SoftRefs may
160 // have been cleared in the last collection but if the gc overhear
161 // limit continues to be near, SoftRefs should still be cleared.
162 if (size_policy() != NULL) {
163 _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
164 }
165 _all_soft_refs_clear = true;
166 }
167
168 size_t CollectorPolicy::compute_heap_alignment() {
169 // The card marking array and the offset arrays for old generations are
170 // committed in os pages as well. Make sure they are entirely full (to
171 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
172 // byte entry and the os page size is 4096, the maximum heap size should
173 // be 512*4096 = 2MB aligned.
174
175 size_t alignment = CardTableRS::ct_max_alignment_constraint();
176
177 if (UseLargePages) {
178 // In presence of large pages we have to make sure that our
179 // alignment is large page aware.
180 alignment = lcm(os::large_page_size(), alignment);
181 }
182
183 return alignment;
184 }
185
186 // GenCollectorPolicy methods
187
188 GenCollectorPolicy::GenCollectorPolicy() :
189 _min_young_size(0),
190 _initial_young_size(0),
191 _max_young_size(0),
192 _min_old_size(0),
193 _initial_old_size(0),
194 _max_old_size(0),
195 _gen_alignment(0),
196 _young_gen_spec(NULL),
197 _old_gen_spec(NULL)
198 {}
199
200 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
201 return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
202 }
203
204 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
205 size_t maximum_size) {
206 size_t max_minus = maximum_size - _gen_alignment;
207 return desired_size < max_minus ? desired_size : max_minus;
208 }
209
210
211 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
212 size_t init_promo_size,
213 size_t init_survivor_size) {
214 const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
215 _size_policy = new AdaptiveSizePolicy(init_eden_size,
216 init_promo_size,
217 init_survivor_size,
218 max_gc_pause_sec,
219 GCTimeRatio);
220 }
221
222 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
223 // The young generation must be aligned and have room for eden + two survivors
224 return align_up(3 * _space_alignment, _gen_alignment);
225 }
226
227 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
228 return align_up(_space_alignment, _gen_alignment);
229 }
230
231 #ifdef ASSERT
232 void GenCollectorPolicy::assert_flags() {
233 CollectorPolicy::assert_flags();
234 assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
235 assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
236 assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
237 assert(NewSize % _gen_alignment == 0, "NewSize alignment");
238 assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
239 assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
|
33 #include "gc/shared/space.hpp"
34 #include "gc/shared/vmGCOperations.hpp"
35 #include "logging/log.hpp"
36 #include "memory/universe.hpp"
37 #include "runtime/arguments.hpp"
38 #include "runtime/globals_extension.hpp"
39 #include "runtime/handles.inline.hpp"
40 #include "runtime/java.hpp"
41 #include "runtime/thread.inline.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "utilities/macros.hpp"
44
45 // CollectorPolicy methods
46
47 CollectorPolicy::CollectorPolicy() :
48 _space_alignment(0),
49 _heap_alignment(0),
50 _initial_heap_byte_size(InitialHeapSize),
51 _max_heap_byte_size(MaxHeapSize),
52 _min_heap_byte_size(Arguments::min_heap_size()),
53 _should_clear_all_soft_refs(false),
54 _all_soft_refs_clear(false)
55 {}
56
57 #ifdef ASSERT
58 void CollectorPolicy::assert_flags() {
59 assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
60 assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment");
61 assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment");
62 }
63
64 void CollectorPolicy::assert_size_info() {
65 assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage");
66 assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage");
67 assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes");
68 assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes");
69 assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes");
70 assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment");
71 assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment");
72 assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment");
138 }
139
140 void CollectorPolicy::initialize_size_info() {
141 log_debug(gc, heap)("Minimum heap " SIZE_FORMAT " Initial heap " SIZE_FORMAT " Maximum heap " SIZE_FORMAT,
142 _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
143
144 DEBUG_ONLY(CollectorPolicy::assert_size_info();)
145 }
146
147 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
148 bool result = _should_clear_all_soft_refs;
149 set_should_clear_all_soft_refs(false);
150 return result;
151 }
152
153 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
154 return new CardTableRS(whole_heap);
155 }
156
157 void CollectorPolicy::cleared_all_soft_refs() {
158 _all_soft_refs_clear = true;
159 }
160
161 size_t CollectorPolicy::compute_heap_alignment() {
162 // The card marking array and the offset arrays for old generations are
163 // committed in os pages as well. Make sure they are entirely full (to
164 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
165 // byte entry and the os page size is 4096, the maximum heap size should
166 // be 512*4096 = 2MB aligned.
167
168 size_t alignment = CardTableRS::ct_max_alignment_constraint();
169
170 if (UseLargePages) {
171 // In presence of large pages we have to make sure that our
172 // alignment is large page aware.
173 alignment = lcm(os::large_page_size(), alignment);
174 }
175
176 return alignment;
177 }
178
179 // GenCollectorPolicy methods
180
181 GenCollectorPolicy::GenCollectorPolicy() :
182 _min_young_size(0),
183 _initial_young_size(0),
184 _max_young_size(0),
185 _min_old_size(0),
186 _initial_old_size(0),
187 _max_old_size(0),
188 _gen_alignment(0),
189 _young_gen_spec(NULL),
190 _old_gen_spec(NULL),
191 _size_policy(NULL)
192 {}
193
194 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
195 return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
196 }
197
198 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
199 size_t maximum_size) {
200 size_t max_minus = maximum_size - _gen_alignment;
201 return desired_size < max_minus ? desired_size : max_minus;
202 }
203
204
205 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
206 size_t init_promo_size,
207 size_t init_survivor_size) {
208 const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
209 _size_policy = new AdaptiveSizePolicy(init_eden_size,
210 init_promo_size,
211 init_survivor_size,
212 max_gc_pause_sec,
213 GCTimeRatio);
214 }
215
216 void GenCollectorPolicy::cleared_all_soft_refs() {
217 // If near gc overhear limit, continue to clear SoftRefs. SoftRefs may
218 // have been cleared in the last collection but if the gc overhear
219 // limit continues to be near, SoftRefs should still be cleared.
220 if (size_policy() != NULL) {
221 _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
222 }
223
224 this->CollectorPolicy::cleared_all_soft_refs();
225 }
226
227 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
228 // The young generation must be aligned and have room for eden + two survivors
229 return align_up(3 * _space_alignment, _gen_alignment);
230 }
231
232 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
233 return align_up(_space_alignment, _gen_alignment);
234 }
235
236 #ifdef ASSERT
237 void GenCollectorPolicy::assert_flags() {
238 CollectorPolicy::assert_flags();
239 assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
240 assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
241 assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
242 assert(NewSize % _gen_alignment == 0, "NewSize alignment");
243 assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
244 assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
|