1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parNew/asParNewGeneration.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,630 @@ 1.4 +/* 1.5 + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_asParNewGeneration.cpp.incl" 1.30 + 1.31 +ASParNewGeneration::ASParNewGeneration(ReservedSpace rs, 1.32 + size_t initial_byte_size, 1.33 + size_t min_byte_size, 1.34 + int level) : 1.35 + ParNewGeneration(rs, initial_byte_size, level), 1.36 + _min_gen_size(min_byte_size) {} 1.37 + 1.38 +const char* ASParNewGeneration::name() const { 1.39 + return "adaptive size par new generation"; 1.40 +} 1.41 + 1.42 +void ASParNewGeneration::adjust_desired_tenuring_threshold() { 1.43 + assert(UseAdaptiveSizePolicy, 1.44 + "Should only be used with UseAdaptiveSizePolicy"); 1.45 +} 1.46 + 1.47 +void ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) { 1.48 + // Resize the generation if needed. If the generation resize 1.49 + // reports false, do not attempt to resize the spaces. 1.50 + if (resize_generation(eden_size, survivor_size)) { 1.51 + // Then we lay out the spaces inside the generation 1.52 + resize_spaces(eden_size, survivor_size); 1.53 + 1.54 + space_invariants(); 1.55 + 1.56 + if (PrintAdaptiveSizePolicy && Verbose) { 1.57 + gclog_or_tty->print_cr("Young generation size: " 1.58 + "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT 1.59 + " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT 1.60 + " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT, 1.61 + eden_size, survivor_size, used(), capacity(), 1.62 + max_gen_size(), min_gen_size()); 1.63 + } 1.64 + } 1.65 +} 1.66 + 1.67 +size_t ASParNewGeneration::available_to_min_gen() { 1.68 + assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant"); 1.69 + return virtual_space()->committed_size() - min_gen_size(); 1.70 +} 1.71 + 1.72 +// This method assumes that from-space has live data and that 1.73 +// any shrinkage of the young gen is limited by location of 1.74 +// from-space. 1.75 +size_t ASParNewGeneration::available_to_live() const { 1.76 +#undef SHRINKS_AT_END_OF_EDEN 1.77 +#ifdef SHRINKS_AT_END_OF_EDEN 1.78 + size_t delta_in_survivor = 0; 1.79 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.80 + const size_t space_alignment = heap->intra_generation_alignment(); 1.81 + const size_t gen_alignment = heap->generation_alignment(); 1.82 + 1.83 + MutableSpace* space_shrinking = NULL; 1.84 + if (from_space()->end() > to_space()->end()) { 1.85 + space_shrinking = from_space(); 1.86 + } else { 1.87 + space_shrinking = to_space(); 1.88 + } 1.89 + 1.90 + // Include any space that is committed but not included in 1.91 + // the survivor spaces. 1.92 + assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(), 1.93 + "Survivor space beyond high end"); 1.94 + size_t unused_committed = pointer_delta(virtual_space()->high(), 1.95 + space_shrinking->end(), sizeof(char)); 1.96 + 1.97 + if (space_shrinking->is_empty()) { 1.98 + // Don't let the space shrink to 0 1.99 + assert(space_shrinking->capacity_in_bytes() >= space_alignment, 1.100 + "Space is too small"); 1.101 + delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment; 1.102 + } else { 1.103 + delta_in_survivor = pointer_delta(space_shrinking->end(), 1.104 + space_shrinking->top(), 1.105 + sizeof(char)); 1.106 + } 1.107 + 1.108 + size_t delta_in_bytes = unused_committed + delta_in_survivor; 1.109 + delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment); 1.110 + return delta_in_bytes; 1.111 +#else 1.112 + // The only space available for shrinking is in to-space if it 1.113 + // is above from-space. 1.114 + if (to()->bottom() > from()->bottom()) { 1.115 + const size_t alignment = os::vm_page_size(); 1.116 + if (to()->capacity() < alignment) { 1.117 + return 0; 1.118 + } else { 1.119 + return to()->capacity() - alignment; 1.120 + } 1.121 + } else { 1.122 + return 0; 1.123 + } 1.124 +#endif 1.125 +} 1.126 + 1.127 +// Return the number of bytes available for resizing down the young 1.128 +// generation. This is the minimum of 1.129 +// input "bytes" 1.130 +// bytes to the minimum young gen size 1.131 +// bytes to the size currently being used + some small extra 1.132 +size_t ASParNewGeneration::limit_gen_shrink (size_t bytes) { 1.133 + // Allow shrinkage into the current eden but keep eden large enough 1.134 + // to maintain the minimum young gen size 1.135 + bytes = MIN3(bytes, available_to_min_gen(), available_to_live()); 1.136 + return align_size_down(bytes, os::vm_page_size()); 1.137 +} 1.138 + 1.139 +// Note that the the alignment used is the OS page size as 1.140 +// opposed to an alignment associated with the virtual space 1.141 +// (as is done in the ASPSYoungGen/ASPSOldGen) 1.142 +bool ASParNewGeneration::resize_generation(size_t eden_size, 1.143 + size_t survivor_size) { 1.144 + const size_t alignment = os::vm_page_size(); 1.145 + size_t orig_size = virtual_space()->committed_size(); 1.146 + bool size_changed = false; 1.147 + 1.148 + // There used to be this guarantee there. 1.149 + // guarantee ((eden_size + 2*survivor_size) <= _max_gen_size, "incorrect input arguments"); 1.150 + // Code below forces this requirement. In addition the desired eden 1.151 + // size and disired survivor sizes are desired goals and may 1.152 + // exceed the total generation size. 1.153 + 1.154 + assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(), 1.155 + "just checking"); 1.156 + 1.157 + // Adjust new generation size 1.158 + const size_t eden_plus_survivors = 1.159 + align_size_up(eden_size + 2 * survivor_size, alignment); 1.160 + size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()), 1.161 + min_gen_size()); 1.162 + assert(desired_size <= max_gen_size(), "just checking"); 1.163 + 1.164 + if (desired_size > orig_size) { 1.165 + // Grow the generation 1.166 + size_t change = desired_size - orig_size; 1.167 + assert(change % alignment == 0, "just checking"); 1.168 + if (!virtual_space()->expand_by(change)) { 1.169 + return false; // Error if we fail to resize! 1.170 + } 1.171 + 1.172 + size_changed = true; 1.173 + } else if (desired_size < orig_size) { 1.174 + size_t desired_change = orig_size - desired_size; 1.175 + assert(desired_change % alignment == 0, "just checking"); 1.176 + 1.177 + desired_change = limit_gen_shrink(desired_change); 1.178 + 1.179 + if (desired_change > 0) { 1.180 + virtual_space()->shrink_by(desired_change); 1.181 + reset_survivors_after_shrink(); 1.182 + 1.183 + size_changed = true; 1.184 + } 1.185 + } else { 1.186 + if (Verbose && PrintGC) { 1.187 + if (orig_size == max_gen_size()) { 1.188 + gclog_or_tty->print_cr("ASParNew generation size at maximum: " 1.189 + SIZE_FORMAT "K", orig_size/K); 1.190 + } else if (orig_size == min_gen_size()) { 1.191 + gclog_or_tty->print_cr("ASParNew generation size at minium: " 1.192 + SIZE_FORMAT "K", orig_size/K); 1.193 + } 1.194 + } 1.195 + } 1.196 + 1.197 + if (size_changed) { 1.198 + MemRegion cmr((HeapWord*)virtual_space()->low(), 1.199 + (HeapWord*)virtual_space()->high()); 1.200 + GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr); 1.201 + 1.202 + if (Verbose && PrintGC) { 1.203 + size_t current_size = virtual_space()->committed_size(); 1.204 + gclog_or_tty->print_cr("ASParNew generation size changed: " 1.205 + SIZE_FORMAT "K->" SIZE_FORMAT "K", 1.206 + orig_size/K, current_size/K); 1.207 + } 1.208 + } 1.209 + 1.210 + guarantee(eden_plus_survivors <= virtual_space()->committed_size() || 1.211 + virtual_space()->committed_size() == max_gen_size(), "Sanity"); 1.212 + 1.213 + return true; 1.214 +} 1.215 + 1.216 +void ASParNewGeneration::reset_survivors_after_shrink() { 1.217 + 1.218 + GenCollectedHeap* gch = GenCollectedHeap::heap(); 1.219 + HeapWord* new_end = (HeapWord*)virtual_space()->high(); 1.220 + 1.221 + if (from()->end() > to()->end()) { 1.222 + assert(new_end >= from()->end(), "Shrinking past from-space"); 1.223 + } else { 1.224 + assert(new_end >= to()->bottom(), "Shrink was too large"); 1.225 + // Was there a shrink of the survivor space? 1.226 + if (new_end < to()->end()) { 1.227 + MemRegion mr(to()->bottom(), new_end); 1.228 + to()->initialize(mr, false /* clear */); 1.229 + } 1.230 + } 1.231 +} 1.232 +void ASParNewGeneration::resize_spaces(size_t requested_eden_size, 1.233 + size_t requested_survivor_size) { 1.234 + assert(UseAdaptiveSizePolicy, "sanity check"); 1.235 + assert(requested_eden_size > 0 && requested_survivor_size > 0, 1.236 + "just checking"); 1.237 + CollectedHeap* heap = Universe::heap(); 1.238 + assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity"); 1.239 + 1.240 + 1.241 + // We require eden and to space to be empty 1.242 + if ((!eden()->is_empty()) || (!to()->is_empty())) { 1.243 + return; 1.244 + } 1.245 + 1.246 + size_t cur_eden_size = eden()->capacity(); 1.247 + 1.248 + if (PrintAdaptiveSizePolicy && Verbose) { 1.249 + gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: " 1.250 + SIZE_FORMAT 1.251 + ", requested_survivor_size: " SIZE_FORMAT ")", 1.252 + requested_eden_size, requested_survivor_size); 1.253 + gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 1.254 + SIZE_FORMAT, 1.255 + eden()->bottom(), 1.256 + eden()->end(), 1.257 + pointer_delta(eden()->end(), 1.258 + eden()->bottom(), 1.259 + sizeof(char))); 1.260 + gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " 1.261 + SIZE_FORMAT, 1.262 + from()->bottom(), 1.263 + from()->end(), 1.264 + pointer_delta(from()->end(), 1.265 + from()->bottom(), 1.266 + sizeof(char))); 1.267 + gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " 1.268 + SIZE_FORMAT, 1.269 + to()->bottom(), 1.270 + to()->end(), 1.271 + pointer_delta( to()->end(), 1.272 + to()->bottom(), 1.273 + sizeof(char))); 1.274 + } 1.275 + 1.276 + // There's nothing to do if the new sizes are the same as the current 1.277 + if (requested_survivor_size == to()->capacity() && 1.278 + requested_survivor_size == from()->capacity() && 1.279 + requested_eden_size == eden()->capacity()) { 1.280 + if (PrintAdaptiveSizePolicy && Verbose) { 1.281 + gclog_or_tty->print_cr(" capacities are the right sizes, returning"); 1.282 + } 1.283 + return; 1.284 + } 1.285 + 1.286 + char* eden_start = (char*)eden()->bottom(); 1.287 + char* eden_end = (char*)eden()->end(); 1.288 + char* from_start = (char*)from()->bottom(); 1.289 + char* from_end = (char*)from()->end(); 1.290 + char* to_start = (char*)to()->bottom(); 1.291 + char* to_end = (char*)to()->end(); 1.292 + 1.293 + const size_t alignment = os::vm_page_size(); 1.294 + const bool maintain_minimum = 1.295 + (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size(); 1.296 + 1.297 + // Check whether from space is below to space 1.298 + if (from_start < to_start) { 1.299 + // Eden, from, to 1.300 + if (PrintAdaptiveSizePolicy && Verbose) { 1.301 + gclog_or_tty->print_cr(" Eden, from, to:"); 1.302 + } 1.303 + 1.304 + // Set eden 1.305 + // "requested_eden_size" is a goal for the size of eden 1.306 + // and may not be attainable. "eden_size" below is 1.307 + // calculated based on the location of from-space and 1.308 + // the goal for the size of eden. from-space is 1.309 + // fixed in place because it contains live data. 1.310 + // The calculation is done this way to avoid 32bit 1.311 + // overflow (i.e., eden_start + requested_eden_size 1.312 + // may too large for representation in 32bits). 1.313 + size_t eden_size; 1.314 + if (maintain_minimum) { 1.315 + // Only make eden larger than the requested size if 1.316 + // the minimum size of the generation has to be maintained. 1.317 + // This could be done in general but policy at a higher 1.318 + // level is determining a requested size for eden and that 1.319 + // should be honored unless there is a fundamental reason. 1.320 + eden_size = pointer_delta(from_start, 1.321 + eden_start, 1.322 + sizeof(char)); 1.323 + } else { 1.324 + eden_size = MIN2(requested_eden_size, 1.325 + pointer_delta(from_start, eden_start, sizeof(char))); 1.326 + } 1.327 + 1.328 +// tty->print_cr("eden_size before: " SIZE_FORMAT, eden_size); 1.329 + eden_size = align_size_down(eden_size, alignment); 1.330 +// tty->print_cr("eden_size after: " SIZE_FORMAT, eden_size); 1.331 + eden_end = eden_start + eden_size; 1.332 + assert(eden_end >= eden_start, "addition overflowed") 1.333 + 1.334 + // To may resize into from space as long as it is clear of live data. 1.335 + // From space must remain page aligned, though, so we need to do some 1.336 + // extra calculations. 1.337 + 1.338 + // First calculate an optimal to-space 1.339 + to_end = (char*)virtual_space()->high(); 1.340 + to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, 1.341 + sizeof(char)); 1.342 + 1.343 + // Does the optimal to-space overlap from-space? 1.344 + if (to_start < (char*)from()->end()) { 1.345 + // Calculate the minimum offset possible for from_end 1.346 + size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char)); 1.347 + 1.348 + // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME! 1.349 + if (from_size == 0) { 1.350 + from_size = alignment; 1.351 + } else { 1.352 + from_size = align_size_up(from_size, alignment); 1.353 + } 1.354 + 1.355 + from_end = from_start + from_size; 1.356 + assert(from_end > from_start, "addition overflow or from_size problem"); 1.357 + 1.358 + guarantee(from_end <= (char*)from()->end(), "from_end moved to the right"); 1.359 + 1.360 + // Now update to_start with the new from_end 1.361 + to_start = MAX2(from_end, to_start); 1.362 + } else { 1.363 + // If shrinking, move to-space down to abut the end of from-space 1.364 + // so that shrinking will move to-space down. If not shrinking 1.365 + // to-space is moving up to allow for growth on the next expansion. 1.366 + if (requested_eden_size <= cur_eden_size) { 1.367 + to_start = from_end; 1.368 + if (to_start + requested_survivor_size > to_start) { 1.369 + to_end = to_start + requested_survivor_size; 1.370 + } 1.371 + } 1.372 + // else leave to_end pointing to the high end of the virtual space. 1.373 + } 1.374 + 1.375 + guarantee(to_start != to_end, "to space is zero sized"); 1.376 + 1.377 + if (PrintAdaptiveSizePolicy && Verbose) { 1.378 + gclog_or_tty->print_cr(" [eden_start .. eden_end): " 1.379 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.380 + eden_start, 1.381 + eden_end, 1.382 + pointer_delta(eden_end, eden_start, sizeof(char))); 1.383 + gclog_or_tty->print_cr(" [from_start .. from_end): " 1.384 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.385 + from_start, 1.386 + from_end, 1.387 + pointer_delta(from_end, from_start, sizeof(char))); 1.388 + gclog_or_tty->print_cr(" [ to_start .. to_end): " 1.389 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.390 + to_start, 1.391 + to_end, 1.392 + pointer_delta( to_end, to_start, sizeof(char))); 1.393 + } 1.394 + } else { 1.395 + // Eden, to, from 1.396 + if (PrintAdaptiveSizePolicy && Verbose) { 1.397 + gclog_or_tty->print_cr(" Eden, to, from:"); 1.398 + } 1.399 + 1.400 + // Calculate the to-space boundaries based on 1.401 + // the start of from-space. 1.402 + to_end = from_start; 1.403 + to_start = (char*)pointer_delta(from_start, 1.404 + (char*)requested_survivor_size, 1.405 + sizeof(char)); 1.406 + // Calculate the ideal eden boundaries. 1.407 + // eden_end is already at the bottom of the generation 1.408 + assert(eden_start == virtual_space()->low(), 1.409 + "Eden is not starting at the low end of the virtual space"); 1.410 + if (eden_start + requested_eden_size >= eden_start) { 1.411 + eden_end = eden_start + requested_eden_size; 1.412 + } else { 1.413 + eden_end = to_start; 1.414 + } 1.415 + 1.416 + // Does eden intrude into to-space? to-space 1.417 + // gets priority but eden is not allowed to shrink 1.418 + // to 0. 1.419 + if (eden_end > to_start) { 1.420 + eden_end = to_start; 1.421 + } 1.422 + 1.423 + // Don't let eden shrink down to 0 or less. 1.424 + eden_end = MAX2(eden_end, eden_start + alignment); 1.425 + assert(eden_start + alignment >= eden_start, "Overflow"); 1.426 + 1.427 + size_t eden_size; 1.428 + if (maintain_minimum) { 1.429 + // Use all the space available. 1.430 + eden_end = MAX2(eden_end, to_start); 1.431 + eden_size = pointer_delta(eden_end, eden_start, sizeof(char)); 1.432 + eden_size = MIN2(eden_size, cur_eden_size); 1.433 + } else { 1.434 + eden_size = pointer_delta(eden_end, eden_start, sizeof(char)); 1.435 + } 1.436 + eden_size = align_size_down(eden_size, alignment); 1.437 + assert(maintain_minimum || eden_size <= requested_eden_size, 1.438 + "Eden size is too large"); 1.439 + assert(eden_size >= alignment, "Eden size is too small"); 1.440 + eden_end = eden_start + eden_size; 1.441 + 1.442 + // Move to-space down to eden. 1.443 + if (requested_eden_size < cur_eden_size) { 1.444 + to_start = eden_end; 1.445 + if (to_start + requested_survivor_size > to_start) { 1.446 + to_end = MIN2(from_start, to_start + requested_survivor_size); 1.447 + } else { 1.448 + to_end = from_start; 1.449 + } 1.450 + } 1.451 + 1.452 + // eden_end may have moved so again make sure 1.453 + // the to-space and eden don't overlap. 1.454 + to_start = MAX2(eden_end, to_start); 1.455 + 1.456 + // from-space 1.457 + size_t from_used = from()->used(); 1.458 + if (requested_survivor_size > from_used) { 1.459 + if (from_start + requested_survivor_size >= from_start) { 1.460 + from_end = from_start + requested_survivor_size; 1.461 + } 1.462 + if (from_end > virtual_space()->high()) { 1.463 + from_end = virtual_space()->high(); 1.464 + } 1.465 + } 1.466 + 1.467 + assert(to_start >= eden_end, "to-space should be above eden"); 1.468 + if (PrintAdaptiveSizePolicy && Verbose) { 1.469 + gclog_or_tty->print_cr(" [eden_start .. eden_end): " 1.470 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.471 + eden_start, 1.472 + eden_end, 1.473 + pointer_delta(eden_end, eden_start, sizeof(char))); 1.474 + gclog_or_tty->print_cr(" [ to_start .. to_end): " 1.475 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.476 + to_start, 1.477 + to_end, 1.478 + pointer_delta( to_end, to_start, sizeof(char))); 1.479 + gclog_or_tty->print_cr(" [from_start .. from_end): " 1.480 + "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 1.481 + from_start, 1.482 + from_end, 1.483 + pointer_delta(from_end, from_start, sizeof(char))); 1.484 + } 1.485 + } 1.486 + 1.487 + 1.488 + guarantee((HeapWord*)from_start <= from()->bottom(), 1.489 + "from start moved to the right"); 1.490 + guarantee((HeapWord*)from_end >= from()->top(), 1.491 + "from end moved into live data"); 1.492 + assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); 1.493 + assert(is_object_aligned((intptr_t)from_start), "checking alignment"); 1.494 + assert(is_object_aligned((intptr_t)to_start), "checking alignment"); 1.495 + 1.496 + MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); 1.497 + MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); 1.498 + MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); 1.499 + 1.500 + // Let's make sure the call to initialize doesn't reset "top"! 1.501 + HeapWord* old_from_top = from()->top(); 1.502 + 1.503 + // For PrintAdaptiveSizePolicy block below 1.504 + size_t old_from = from()->capacity(); 1.505 + size_t old_to = to()->capacity(); 1.506 + 1.507 + // The call to initialize NULL's the next compaction space 1.508 + eden()->initialize(edenMR, true); 1.509 + eden()->set_next_compaction_space(from()); 1.510 + to()->initialize(toMR , true); 1.511 + from()->initialize(fromMR, false); // Note, not cleared! 1.512 + 1.513 + assert(from()->top() == old_from_top, "from top changed!"); 1.514 + 1.515 + if (PrintAdaptiveSizePolicy) { 1.516 + GenCollectedHeap* gch = GenCollectedHeap::heap(); 1.517 + assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity"); 1.518 + 1.519 + gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: " 1.520 + "collection: %d " 1.521 + "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> " 1.522 + "(" SIZE_FORMAT ", " SIZE_FORMAT ") ", 1.523 + gch->total_collections(), 1.524 + old_from, old_to, 1.525 + from()->capacity(), 1.526 + to()->capacity()); 1.527 + gclog_or_tty->cr(); 1.528 + } 1.529 +} 1.530 + 1.531 +void ASParNewGeneration::compute_new_size() { 1.532 + GenCollectedHeap* gch = GenCollectedHeap::heap(); 1.533 + assert(gch->kind() == CollectedHeap::GenCollectedHeap, 1.534 + "not a CMS generational heap"); 1.535 + 1.536 + 1.537 + CMSAdaptiveSizePolicy* size_policy = 1.538 + (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy(); 1.539 + assert(size_policy->is_gc_cms_adaptive_size_policy(), 1.540 + "Wrong type of size policy"); 1.541 + 1.542 + size_t survived = from()->used(); 1.543 + if (!survivor_overflow()) { 1.544 + // Keep running averages on how much survived 1.545 + size_policy->avg_survived()->sample(survived); 1.546 + } else { 1.547 + size_t promoted = 1.548 + (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample(); 1.549 + assert(promoted < gch->capacity(), "Conversion problem?"); 1.550 + size_t survived_guess = survived + promoted; 1.551 + size_policy->avg_survived()->sample(survived_guess); 1.552 + } 1.553 + 1.554 + size_t survivor_limit = max_survivor_size(); 1.555 + _tenuring_threshold = 1.556 + size_policy->compute_survivor_space_size_and_threshold( 1.557 + _survivor_overflow, 1.558 + _tenuring_threshold, 1.559 + survivor_limit); 1.560 + size_policy->avg_young_live()->sample(used()); 1.561 + size_policy->avg_eden_live()->sample(eden()->used()); 1.562 + 1.563 + size_policy->compute_young_generation_free_space(eden()->capacity(), 1.564 + max_gen_size()); 1.565 + 1.566 + resize(size_policy->calculated_eden_size_in_bytes(), 1.567 + size_policy->calculated_survivor_size_in_bytes()); 1.568 + 1.569 + if (UsePerfData) { 1.570 + CMSGCAdaptivePolicyCounters* counters = 1.571 + (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters(); 1.572 + assert(counters->kind() == 1.573 + GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, 1.574 + "Wrong kind of counters"); 1.575 + counters->update_tenuring_threshold(_tenuring_threshold); 1.576 + counters->update_survivor_overflowed(_survivor_overflow); 1.577 + counters->update_young_capacity(capacity()); 1.578 + } 1.579 +} 1.580 + 1.581 + 1.582 +#ifndef PRODUCT 1.583 +// Changes from PSYoungGen version 1.584 +// value of "alignment" 1.585 +void ASParNewGeneration::space_invariants() { 1.586 + const size_t alignment = os::vm_page_size(); 1.587 + 1.588 + // Currently, our eden size cannot shrink to zero 1.589 + guarantee(eden()->capacity() >= alignment, "eden too small"); 1.590 + guarantee(from()->capacity() >= alignment, "from too small"); 1.591 + guarantee(to()->capacity() >= alignment, "to too small"); 1.592 + 1.593 + // Relationship of spaces to each other 1.594 + char* eden_start = (char*)eden()->bottom(); 1.595 + char* eden_end = (char*)eden()->end(); 1.596 + char* from_start = (char*)from()->bottom(); 1.597 + char* from_end = (char*)from()->end(); 1.598 + char* to_start = (char*)to()->bottom(); 1.599 + char* to_end = (char*)to()->end(); 1.600 + 1.601 + guarantee(eden_start >= virtual_space()->low(), "eden bottom"); 1.602 + guarantee(eden_start < eden_end, "eden space consistency"); 1.603 + guarantee(from_start < from_end, "from space consistency"); 1.604 + guarantee(to_start < to_end, "to space consistency"); 1.605 + 1.606 + // Check whether from space is below to space 1.607 + if (from_start < to_start) { 1.608 + // Eden, from, to 1.609 + guarantee(eden_end <= from_start, "eden/from boundary"); 1.610 + guarantee(from_end <= to_start, "from/to boundary"); 1.611 + guarantee(to_end <= virtual_space()->high(), "to end"); 1.612 + } else { 1.613 + // Eden, to, from 1.614 + guarantee(eden_end <= to_start, "eden/to boundary"); 1.615 + guarantee(to_end <= from_start, "to/from boundary"); 1.616 + guarantee(from_end <= virtual_space()->high(), "from end"); 1.617 + } 1.618 + 1.619 + // More checks that the virtual space is consistent with the spaces 1.620 + assert(virtual_space()->committed_size() >= 1.621 + (eden()->capacity() + 1.622 + to()->capacity() + 1.623 + from()->capacity()), "Committed size is inconsistent"); 1.624 + assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(), 1.625 + "Space invariant"); 1.626 + char* eden_top = (char*)eden()->top(); 1.627 + char* from_top = (char*)from()->top(); 1.628 + char* to_top = (char*)to()->top(); 1.629 + assert(eden_top <= virtual_space()->high(), "eden top"); 1.630 + assert(from_top <= virtual_space()->high(), "from top"); 1.631 + assert(to_top <= virtual_space()->high(), "to top"); 1.632 +} 1.633 +#endif