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