58 size_t alignment) {
59 assert(_init_gen_size != 0, "Should have a finite size");
60 _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
61 if (!_virtual_space->expand_by(_init_gen_size)) {
62 vm_exit_during_initialization("Could not reserve enough space for "
63 "object heap");
64 }
65 }
66
67 void ASPSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
68 initialize_virtual_space(rs, alignment);
69 initialize_work();
70 }
71
72 size_t ASPSYoungGen::available_for_expansion() {
73 size_t current_committed_size = virtual_space()->committed_size();
74 assert((gen_size_limit() >= current_committed_size),
75 "generation size limit is wrong");
76 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
77 size_t result = gen_size_limit() - current_committed_size;
78 size_t result_aligned = align_size_down(result, heap->young_gen_alignment());
79 return result_aligned;
80 }
81
82 // Return the number of bytes the young gen is willing give up.
83 //
84 // Future implementations could check the survivors and if to_space is in the
85 // right place (below from_space), take a chunk from to_space.
86 size_t ASPSYoungGen::available_for_contraction() {
87 size_t uncommitted_bytes = virtual_space()->uncommitted_size();
88 if (uncommitted_bytes != 0) {
89 return uncommitted_bytes;
90 }
91
92 if (eden_space()->is_empty()) {
93 // Respect the minimum size for eden and for the young gen as a whole.
94 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
95 const size_t eden_alignment = heap->intra_heap_alignment();
96 const size_t gen_alignment = heap->young_gen_alignment();
97
98 assert(eden_space()->capacity_in_bytes() >= eden_alignment,
99 "Alignment is wrong");
100 size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
101 eden_avail = align_size_down(eden_avail, gen_alignment);
102
103 assert(virtual_space()->committed_size() >= min_gen_size(),
104 "minimum gen size is wrong");
105 size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
106 assert(virtual_space()->is_aligned(gen_avail), "not aligned");
107
108 const size_t max_contraction = MIN2(eden_avail, gen_avail);
109 // See comment for ASPSOldGen::available_for_contraction()
110 // for reasons the "increment" fraction is used.
111 PSAdaptiveSizePolicy* policy = heap->size_policy();
112 size_t result = policy->eden_increment_aligned_down(max_contraction);
113 size_t result_aligned = align_size_down(result, gen_alignment);
114 if (PrintAdaptiveSizePolicy && Verbose) {
115 gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: %d K",
116 result_aligned/K);
117 gclog_or_tty->print_cr(" max_contraction %d K", max_contraction/K);
118 gclog_or_tty->print_cr(" eden_avail %d K", eden_avail/K);
119 gclog_or_tty->print_cr(" gen_avail %d K", gen_avail/K);
120 }
121 return result_aligned;
122 }
123
124 return 0;
125 }
126
127 // The current implementation only considers to the end of eden.
128 // If to_space is below from_space, to_space is not considered.
129 // to_space can be.
130 size_t ASPSYoungGen::available_to_live() {
131 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
132 const size_t alignment = heap->intra_heap_alignment();
133
134 // Include any space that is committed but is not in eden.
135 size_t available = pointer_delta(eden_space()->bottom(),
136 virtual_space()->low(),
137 sizeof(char));
138
139 const size_t eden_capacity = eden_space()->capacity_in_bytes();
140 if (eden_space()->is_empty() && eden_capacity > alignment) {
141 available += eden_capacity - alignment;
142 }
143 return available;
144 }
145
146 // Similar to PSYoungGen::resize_generation() but
147 // allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
148 // expands at the low end of the virtual space
149 // moves the boundary between the generations in order to expand
150 // some additional diagnostics
151 // If no additional changes are required, this can be deleted
152 // and the changes factored back into PSYoungGen::resize_generation().
276 // There's nothing to do if the new sizes are the same as the current
277 if (requested_survivor_size == to_space()->capacity_in_bytes() &&
278 requested_survivor_size == from_space()->capacity_in_bytes() &&
279 requested_eden_size == eden_space()->capacity_in_bytes()) {
280 if (PrintAdaptiveSizePolicy && Verbose) {
281 gclog_or_tty->print_cr(" capacities are the right sizes, returning");
282 }
283 return;
284 }
285
286 char* eden_start = (char*)virtual_space()->low();
287 char* eden_end = (char*)eden_space()->end();
288 char* from_start = (char*)from_space()->bottom();
289 char* from_end = (char*)from_space()->end();
290 char* to_start = (char*)to_space()->bottom();
291 char* to_end = (char*)to_space()->end();
292
293 assert(eden_start < from_start, "Cannot push into from_space");
294
295 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
296 const size_t alignment = heap->intra_heap_alignment();
297 const bool maintain_minimum =
298 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
299
300 bool eden_from_to_order = from_start < to_start;
301 // Check whether from space is below to space
302 if (eden_from_to_order) {
303 // Eden, from, to
304
305 if (PrintAdaptiveSizePolicy && Verbose) {
306 gclog_or_tty->print_cr(" Eden, from, to:");
307 }
308
309 // Set eden
310 // "requested_eden_size" is a goal for the size of eden
311 // and may not be attainable. "eden_size" below is
312 // calculated based on the location of from-space and
313 // the goal for the size of eden. from-space is
314 // fixed in place because it contains live data.
315 // The calculation is done this way to avoid 32bit
316 // overflow (i.e., eden_start + requested_eden_size
|
58 size_t alignment) {
59 assert(_init_gen_size != 0, "Should have a finite size");
60 _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
61 if (!_virtual_space->expand_by(_init_gen_size)) {
62 vm_exit_during_initialization("Could not reserve enough space for "
63 "object heap");
64 }
65 }
66
67 void ASPSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
68 initialize_virtual_space(rs, alignment);
69 initialize_work();
70 }
71
72 size_t ASPSYoungGen::available_for_expansion() {
73 size_t current_committed_size = virtual_space()->committed_size();
74 assert((gen_size_limit() >= current_committed_size),
75 "generation size limit is wrong");
76 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
77 size_t result = gen_size_limit() - current_committed_size;
78 size_t result_aligned = align_size_down(result, heap->generation_alignment());
79 return result_aligned;
80 }
81
82 // Return the number of bytes the young gen is willing give up.
83 //
84 // Future implementations could check the survivors and if to_space is in the
85 // right place (below from_space), take a chunk from to_space.
86 size_t ASPSYoungGen::available_for_contraction() {
87 size_t uncommitted_bytes = virtual_space()->uncommitted_size();
88 if (uncommitted_bytes != 0) {
89 return uncommitted_bytes;
90 }
91
92 if (eden_space()->is_empty()) {
93 // Respect the minimum size for eden and for the young gen as a whole.
94 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
95 const size_t eden_alignment = heap->space_alignment();
96 const size_t gen_alignment = heap->generation_alignment();
97
98 assert(eden_space()->capacity_in_bytes() >= eden_alignment,
99 "Alignment is wrong");
100 size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
101 eden_avail = align_size_down(eden_avail, gen_alignment);
102
103 assert(virtual_space()->committed_size() >= min_gen_size(),
104 "minimum gen size is wrong");
105 size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
106 assert(virtual_space()->is_aligned(gen_avail), "not aligned");
107
108 const size_t max_contraction = MIN2(eden_avail, gen_avail);
109 // See comment for ASPSOldGen::available_for_contraction()
110 // for reasons the "increment" fraction is used.
111 PSAdaptiveSizePolicy* policy = heap->size_policy();
112 size_t result = policy->eden_increment_aligned_down(max_contraction);
113 size_t result_aligned = align_size_down(result, gen_alignment);
114 if (PrintAdaptiveSizePolicy && Verbose) {
115 gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: %d K",
116 result_aligned/K);
117 gclog_or_tty->print_cr(" max_contraction %d K", max_contraction/K);
118 gclog_or_tty->print_cr(" eden_avail %d K", eden_avail/K);
119 gclog_or_tty->print_cr(" gen_avail %d K", gen_avail/K);
120 }
121 return result_aligned;
122 }
123
124 return 0;
125 }
126
127 // The current implementation only considers to the end of eden.
128 // If to_space is below from_space, to_space is not considered.
129 // to_space can be.
130 size_t ASPSYoungGen::available_to_live() {
131 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
132 const size_t alignment = heap->space_alignment();
133
134 // Include any space that is committed but is not in eden.
135 size_t available = pointer_delta(eden_space()->bottom(),
136 virtual_space()->low(),
137 sizeof(char));
138
139 const size_t eden_capacity = eden_space()->capacity_in_bytes();
140 if (eden_space()->is_empty() && eden_capacity > alignment) {
141 available += eden_capacity - alignment;
142 }
143 return available;
144 }
145
146 // Similar to PSYoungGen::resize_generation() but
147 // allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
148 // expands at the low end of the virtual space
149 // moves the boundary between the generations in order to expand
150 // some additional diagnostics
151 // If no additional changes are required, this can be deleted
152 // and the changes factored back into PSYoungGen::resize_generation().
276 // There's nothing to do if the new sizes are the same as the current
277 if (requested_survivor_size == to_space()->capacity_in_bytes() &&
278 requested_survivor_size == from_space()->capacity_in_bytes() &&
279 requested_eden_size == eden_space()->capacity_in_bytes()) {
280 if (PrintAdaptiveSizePolicy && Verbose) {
281 gclog_or_tty->print_cr(" capacities are the right sizes, returning");
282 }
283 return;
284 }
285
286 char* eden_start = (char*)virtual_space()->low();
287 char* eden_end = (char*)eden_space()->end();
288 char* from_start = (char*)from_space()->bottom();
289 char* from_end = (char*)from_space()->end();
290 char* to_start = (char*)to_space()->bottom();
291 char* to_end = (char*)to_space()->end();
292
293 assert(eden_start < from_start, "Cannot push into from_space");
294
295 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
296 const size_t alignment = heap->space_alignment();
297 const bool maintain_minimum =
298 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
299
300 bool eden_from_to_order = from_start < to_start;
301 // Check whether from space is below to space
302 if (eden_from_to_order) {
303 // Eden, from, to
304
305 if (PrintAdaptiveSizePolicy && Verbose) {
306 gclog_or_tty->print_cr(" Eden, from, to:");
307 }
308
309 // Set eden
310 // "requested_eden_size" is a goal for the size of eden
311 // and may not be attainable. "eden_size" below is
312 // calculated based on the location of from-space and
313 // the goal for the size of eden. from-space is
314 // fixed in place because it contains live data.
315 // The calculation is done this way to avoid 32bit
316 // overflow (i.e., eden_start + requested_eden_size
|