g1CollectorPolicy.cpp revision 1356
579N/A * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. 342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 342N/A * This code is free software; you can redistribute it and/or modify it 342N/A * under the terms of the GNU General Public License version 2 only, as 342N/A * published by the Free Software Foundation. 342N/A * This code is distributed in the hope that it will be useful, but WITHOUT 342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 342N/A * version 2 for more details (a copy is included in the LICENSE file that 342N/A * accompanied this code). 342N/A * You should have received a copy of the GNU General Public License version 342N/A * 2 along with this work; if not, write to the Free Software Foundation, 342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 342N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 342N/A * CA 95054 USA or visit www.sun.com if you need additional information or 342N/A#
include "incls/_precompiled.incl" 342N/A// Different defaults for different number of GC threads 342N/A// They were chosen by running GCOld and SPECjbb on debris with different 342N/A// numbers of GC threads and choosing them based on the results 342N/A 0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0 342N/A 0.01,
0.005,
0.005,
0.003,
0.003,
0.002,
0.002,
0.0015 342N/A 1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0 342N/A 1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0 342N/A 0.015,
0.01,
0.01,
0.008,
0.008,
0.0055,
0.0055,
0.005 342N/A 0.00006,
0.00003,
0.00003,
0.000015,
0.000015,
0.00001,
0.00001,
0.000009 342N/A// these should be pretty consistent 342N/A 5.0,
5.0,
5.0,
5.0,
5.0,
5.0,
5.0,
5.0 342N/A 0.3,
0.2,
0.2,
0.15,
0.15,
0.12,
0.12,
0.1 342N/A 1.0,
0.7,
0.7,
0.5,
0.5,
0.42,
0.42,
0.30 342N/A // G1PausesBtwnConcMark defaults to -1 342N/A // so the hack is to do the cast QQQ FIXME 342N/A#
ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away 342N/A // add here any more surv rate groups 942N/A // Set up the region size and associated fields. Given that the 942N/A // policy is created before the heap, we have to set this up here, 942N/A // so it's done as soon as possible. 342N/A // start conservatively 342N/A "Max GC time should not be greater than the time slice");
342N/A // start conservatively (around 50ms is about right) 1282N/A // if G1FixedSurvivorSpaceSize is 0 which means the size is not 1282N/A // fixed, then _max_survivor_regions will be calculated at 1282N/A // calculate_young_list_target_config during initialization 1356N/A "we should have set it to a default value set_g1_gc_flags() " 342N/A// Increment "i", mod "len" 1285N/A// The easiest way to deal with the parsing of the NewSize / 1285N/A// MaxNewSize / etc. parameteres is to re-use the code in the 1285N/A// TwoGenerationCollectorPolicy class. This is similar to what 1285N/A// ParallelScavenge does with its GenerationSizer class (see 1285N/A// ParallelScavengeHeap::initialize()). We might change this in the 1285N/A// future, but it's a good start. 342N/A // Set aside an initial future to_space. 545N/A// Create the jstat counters for the policy. 342N/A// This method calculate the optimal scan-only set for a fixed young 342N/A// gen size. I couldn't work out how to reuse the more elaborate one, 342N/A// i.e. calculate_young_list_target_config(rs_length), as the loops are 342N/A// fundamentally different (the other one finds a config for different 342N/A// S-O lengths, whereas here we need to do the opposite). 342N/A // we won't use a scan-only set at the beginning to allow the rest 342N/A // of the predictors to warm up 342N/A // then, we'll only set the S-O set to 1 for a little bit of time, 342N/A // to get enough information on the scanning cost 342N/A // set it to 95% of the optimal to make sure we sample the "area" 342N/A // around the optimal length to get up-to-date survival rate data 342N/A// This is a really cool piece of code! It finds the best 342N/A// target configuration (young length / scan-only prefix length) so 342N/A// that GC efficiency is maximized and that we also meet a pause 342N/A// time. It's a triple nested loop. These loops are explained below 342N/A// from the inside-out :-) 342N/A// (a) The innermost loop will try to find the optimal young length 342N/A// for a fixed S-O length. It uses a binary search to speed up the 342N/A// process. We assume that, for a fixed S-O length, as we add more 342N/A// young regions to the CSet, the GC efficiency will only go up (I'll 342N/A// skip the proof). So, using a binary search to optimize this process 342N/A// (b) The middle loop will fix the S-O length before calling the 342N/A// innermost one. It will vary it between two parameters, increasing 342N/A// it by a given increment. 342N/A// (c) The outermost loop will call the middle loop three times. 342N/A// (1) The first time it will explore all possible S-O length values 342N/A// from 0 to as large as it can get, using a coarse increment (to 342N/A// quickly "home in" to where the optimal seems to be). 342N/A// (2) The second time it will explore the values around the optimal 342N/A// that was found by the first iteration using a fine increment. 342N/A// (3) Once the optimal config has been determined by the second 342N/A// iteration, we'll redo the calculation, but setting the S-O length 342N/A// to 95% of the optimal to make sure we sample the "area" 342N/A// around the optimal length to get up-to-date survival rate data 342N/A// Termination conditions for the iterations are several: the pause 342N/A// time is over the limit, we do not have enough to-space, etc. 342N/A // we are in fully-young mode and there are free regions in the heap 342N/A // we won't use a scan-only set at the beginning to allow the rest 342N/A // of the predictors to warm up 342N/A // then, we'll only set the S-O set to 1 for a little bit of time, 342N/A // to get enough information on the scanning cost 342N/A // no S-O prefix during a marking phase either, as at the end 342N/A // of the marking phase we'll have to use a very small young 342N/A // length target to fill up the rest of the CSet with 342N/A // non-young regions and, if we have lots of scan-only regions 342N/A // left-over, we will not be able to add any more non-young 342N/A // this is the common case; we'll never reach the maximum, we 342N/A // one of the end conditions will fire well before that 342N/A // no S-O prefix, as the switch is not set, but we still need to 342N/A // do one iteration to calculate the best young target that 342N/A // meets the pause time; this way we reuse the same code instead 342N/A // calculate this once, so that we don't have to recalculate it in 342N/A // we'll also keep track of how many times we go into the inner loop 342N/A // this is for profiling reasons 342N/A // this determines which of the three iterations the outer loop is in 342N/A // range of the outer loop's iteration 342N/A // this will keep the S-O length that's found by the second 342N/A // iteration of the outer loop; we'll keep it just in case the third 342N/A // iteration fails to find something 342N/A // the increment step for the coarse (first) iteration 342N/A // the common case, we'll start with the coarse iteration 342N/A // not point in doing the coarse iteration, we'll go directly into 342N/A // the fine one (we essentially trying to find the optimal young 342N/A // length for a fixed S-O length). 342N/A // again, the range is too short so no point in foind the coarse 342N/A // this is the outermost loop 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // this determines whether a configuration was found 342N/A // this is the middle loop 342N/A // base time, which excludes region-related time; again we 342N/A // calculate it once to avoid recalculating it in the 342N/A // it's already over the pause target, go around 342N/A // we make sure that the short young length that makes sense 342N/A // (one more than the S-O length) is feasible 342N/A // the shortest young length is indeed feasible; we'll know 342N/A // set up the max young length and we'll do a binary search 342N/A // between min_young_length and max_young_length 342N/A // the innermost loop! (finally!) 342N/A // we'll make sure that min_young_length is always at a 342N/A // the innermost loop found a config 342N/A // it's the best config so far, so we'll keep it 342N/A // incremental the fixed S-O length and go around 342N/A // this is the end of the outermost loop and we need to decide 342N/A // what to do during the next iteration 342N/A // we just did the coarse pass (first iteration) 342N/A // we didn't find a feasible config so we'll just bail out; of 342N/A // course, it might be the case that we missed it; but I'd say 342N/A // We did find a feasible config with optimal GC eff during 342N/A // the first pass. So the second pass we'll only consider the 342N/A // S-O lengths around that config with a fine increment. 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // we just finished the second pass 342N/A // we didn't find a feasible config (yes, it's possible; 342N/A // notice that, sometimes, we go directly into the fine 342N/A // iteration and skip the coarse one) so we bail out 342N/A // We did find a feasible config with optimal GC eff 342N/A // The config is of an empty S-O set, so we'll just bail out 342N/A // we'll go around once more, setting the S-O length to 95% 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // we just finished the final (third) pass 342N/A // we didn't find a feasible config, so we'll just use the one 342N/A // we found during the second pass, which we saved 342N/A // we now go around the outermost loop 342N/A // we should have at least one region in the target young length 342N/A // and we need to ensure that the S-O length is not greater than 342N/A // the target young length (this is being a bit careful) 342N/A // let's keep an eye of how long we spend on this calculation 342N/A // right now, I assume that we'll print it when we need it; we 342N/A // should really adde it to the breakdown of a pause 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // bummer; this means that, if we do a pause when the optimal 342N/A // config dictates, we'll violate the pause spacing target (the 342N/A // min length was calculate based on the application's current 342N/A // so, we have to bite the bullet, and allocate the minimum 342N/A // number. We'll violate our target, but we just can't meet it. 342N/A // a note further up explains why we do not want an S-O length 342N/A // but we can still try to see whether we can find an optimal 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // we are in a partially-young mode or we've run out of regions (due 342N/A // to evacuation failure) 342N/A // leave this in for debugging, just in case 545N/A#
endif // TRACE_CALC_YOUNG_CONFIG 342N/A // we'll do the pause as soon as possible and with no S-O prefix 342N/A // (see above for the reasons behind the latter) 342N/A// This is used by: calculate_optimal_so_length(length). It returns 342N/A// the GC eff and predicted pause time for a particular config 342N/A// This is used by: calculate_young_list_target_config(rs_length). It 342N/A// returns the GC eff of a particular config. It returns false if that 342N/A// config violates any of the end conditions of the search in the 342N/A// calling method, or true upon success. The end conditions were put 342N/A// here since it's called twice and it was best not to replicate them 342N/A// in the caller. Also, passing the parameteres avoids having to 342N/A// recalculate them in the innermost loop. 342N/A // end condition 1: not enough space for the young regions 342N/A // end condition 2: over the target pause time 342N/A // end condition 3: out of to-space (conservatively) 342N/A // add 10% to avoid having to recalculate often 342N/A// This method controls how a collector handles one or more 342N/A// of its generations being fully allocated. 342N/A // also call verify_young_ages on any additional surv rate groups 342N/A // Release the future to-space so that it is available for compaction into. 342N/A // Consider this like a collection pause for the purposes of allocation 342N/A // transitions and make sure we start with fully young GCs after the 342N/A // also call this on any additional surv rate groups 545N/A // Reset survivors SurvRateGroup. 342N/A // initialise these to something well known so that we can spot 342N/A // if they are not set properly 342N/A // do that for any other surv rate groups 342N/A // done in a way that it can be extended for other surv rate groups too... 342N/A// The important thing about this is that it includes "os::elapsedTime". 342N/A // We did a marking, so reset the "since_last_mark" variables. 342N/A // If there are available processors, concurrent activity is free... 342N/A for (
int i = 0; i < n; i++) {
342N/A// Anything below that is considered to be zero 342N/A // do that for any other surv rate groups too 342N/A // This assert is exempted when we're doing parallel collection pauses, 342N/A // because the fragmentation caused by the parallel GC allocation buffers 342N/A // can lead to more memory being used during collection than was used 342N/A // before. Best leave this out until the fragmentation problem is fixed. 342N/A // Pauses in which evacuation failed can also lead to negative 342N/A // collections, since no space is reclaimed from a region containing an 342N/A // object whose evacuation failed. 342N/A // Further, we're now always doing parallel collection. But I'm still 342N/A // leaving this here as a placeholder for a more precise assertion later. 342N/A "Negative collection");
342N/A // We exempt parallel collection from this check because Alloc Buffer 342N/A // fragmentation can produce negative collections. Same with evac 342N/A // Further, we're now always doing parallel collection. But I'm still 342N/A // leaving this here as a placeholder for a more precise assertion later. 342N/A "Or else negative collection!");
342N/A // this is where we update the allocation rate of the application 342N/A // This usually happens due to the timer not having the required 342N/A // granularity. Some Linuxes are the usual culprits. 342N/A // We'll just set it to something (arbitrarily) small. 1086N/A // Dump info to allow post-facto debugging 1087N/A // In debug mode, terminate the JVM if the user wants to debug at this point. 1087N/A // Clip ratio between 0.0 and 1.0, and continue. This will be fixed in 1087N/A // CR 6902692 by redoing the manner in which the ratio is incrementally computed. 342N/A " CH Strong: %10.6f ms (avg: %10.6f ms)\n" 342N/A " G1 Strong: %10.6f ms (avg: %10.6f ms)\n" 342N/A " Evac: %10.6f ms (avg: %10.6f ms)\n" 342N/A " ET-RS: %10.6f ms (avg: %10.6f ms)\n" 342N/A " survival : %6.2f%% (%6.2f%% avg)",
342N/A // Reset marks-between-pauses counter. 342N/A // Update the efficiency-since-mark vars. 342N/A // This usually happens due to the timer not having the required 342N/A // granularity. Some Linuxes are the usual culprits. 342N/A // We'll just set it to something (arbitrarily) small. 342N/A // do that for any other surv rate groupsx 342N/A // this means that the other time was predicted to be longer than 342N/A // than the max pause time 342N/A "SCAN_ONLY_SCAN %1.6lf %1.6lf " 342N/A "RS_UPDATE %1.6lf %1.6lf RS_SCAN %1.6lf %1.6lf " 342N/A "SURVIVAL_RATIO %1.6lf %1.6lf " 342N/A "OBJECT_COPY %1.6lf %1.6lf OTHER_CONSTANT %1.6lf %1.6lf " 342N/A "OTHER_YOUNG %1.6lf %1.6lf " 342N/A "OTHER_NON_YOUNG %1.6lf %1.6lf " 342N/A "VTIME_DIFF %1.6lf TERMINATION %1.6lf " 342N/A "ELAPSED %1.6lf %1.6lf ",
1111N/A // Note that _mmu_tracker->max_gc_time() returns the time in seconds. 1111N/A g = (
int)(g *
dec_k);
// Can become 0, that's OK. That would mean a mutator-only processing. 1111N/A // Change the refinement threads params 1111N/A // Change the barrier params 342N/A#
endif // PREDICTIONS_VERBOSE 342N/A#
endif // PREDICTIONS_VERBOSE 342N/A#
endif // PREDICTIONS_VERBOSE 342N/A // I don't think we need to do this when in young GC mode since 342N/A // marking will be initiated next time we hit the soft limit anyway... 342N/A // no point in doing another partial one 342N/A // We exempt parallel collection from this check because Alloc Buffer 342N/A // fragmentation can produce negative collections. 342N/A // Further, we're now always doing parallel collection. But I'm still 342N/A // leaving this here as a placeholder for a more precise assertion later. 342N/A return 1.0;
// Be conservative. 342N/A // We exempt parallel collection from this check because Alloc Buffer 342N/A // fragmentation can produce negative collections. 342N/A // Further, we're now always doing parallel collection. But I'm still 342N/A // leaving this here as a placeholder for a more precise assertion later. 342N/A // In the parallel case, LAB fragmentation can produce "negative 342N/A // collections"; so can evac failure. Cap at 1.0 751N/A // We will double the existing space, or take 751N/A // G1ExpandByPercentOfAvailable % of the available expansion 751N/A // space, whichever is smaller, bounded below by a minimum 751N/A // expansion (unless that's all that's left.) 342N/A "committed = %d%s, uncommited = %d%s, via pct = %d%s.\n" 342N/A "Tenured %8d (%6.2lf%%)",
342N/A // add this call for any other surv rate groups 342N/A// for debugging, bit of a hack... 545N/A// Calculates survivor space parameters. 342N/A // We only include humongous regions in collection 342N/A // sets when concurrent mark shows that their contained object is 342N/A // Do we have any marking information for this region? 342N/A // We don't include humongous regions in collection 342N/A // sets because we collect them immediately at the end of a marking 342N/A // cycle. We also don't include young regions because we *must* 342N/A // include them in the next collection pause. 342N/A // We only include humongous regions in collection 342N/A // sets when concurrent mark shows that their contained object is 342N/A // Do we have any marking information for this region? 342N/A // We don't include humongous regions in collection 342N/A // sets because we collect them immediately at the end of a marking 342N/A // We also do not include young regions in collection sets 342N/A // Back to zero for the claim value. 342N/A// Add the heap region to the collection set and return the conservative 342N/A// estimate of the number of live bytes. 342N/A "should not already be in the CSet");
677N/A "_target_pause_time_ms should have been set!");
342N/A // the 10% and 50% values are arbitrary... 342N/A // We figure out the number of bytes available for future to-space. 342N/A // For new regions without marking information, we must assume the 342N/A // worst-case of complete survival. If we have marking information for a 342N/A // region, we can bound the amount of live data. We can add a number of 342N/A // such regions, as long as the sum of the live data bounds does not 342N/A // exceed the available evacuation space. 342N/A // Adjust for expansion and slop. 342N/A // don't bother adding more regions...