g1CollectorPolicy.cpp revision 1472
1472N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 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 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 1394N/A // Incremental CSet attributes 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 1394N/A // calculate_young_list_target_length 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. 1394N/A // We may immediately start allocating regions and placing them on the 1394N/A // collection set list. Initialize the per-collection set info 545N/A// Create the jstat counters for the policy. 342N/A // we are in fully-young mode and there are free regions in the heap 1394N/A // if we're still under the pause target... 1394N/A // We make sure that the shortest young length that makes sense 1394N/A // fits within the target pause time. 1394N/A // The shortest young length will fit within the target pause time; 1394N/A // we'll now check whether the absolute maximum number of young 1394N/A // regions will fit in the target pause time. If not, we'll do 1394N/A // a binary search between min_young_length and max_young_length 1394N/A // Let's check if the initial max young length will fit within the 1394N/A // target pause. If so then there is no need to search for a maximal 1394N/A // young length - we'll return the initial maximum 1394N/A // The maximum young length will satisfy the target pause time. 1394N/A // We are done so set min young length to this maximum length. 1394N/A // The code after the loop will then set final_young_length using 1394N/A // the value cached in the minimum length. 1394N/A // The maximum possible number of young regions will not fit within 1394N/A // the target pause time so let's search.... 1394N/A // The current max young length will fit within the target 1394N/A // pause time. Note we do not exit the loop here. By setting 1394N/A // min = max, and then increasing the max below means that 1394N/A // we will continue searching for an upper bound in the 1394N/A // the above loop found a maximal young length that will fit 1394N/A // within the target pause time. 342N/A // we should have at least one region in the target young length 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 1394N/A#
endif // TRACE_CALC_YOUNG_LENGTH 1394N/A // bummer; this means that, if we do a pause when the maximal 1394N/A // length 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 // leave this in for debugging, just in case 1394N/A#
endif // TRACE_CALC_YOUNG_LENGTH 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 1394N/A#
endif // TRACE_CALC_YOUNG_LENGTH 1394N/A // we'll do the pause as soon as possible by choosing the minimum 1394N/A// This is used by: calculate_young_list_target_length(rs_length). It 1394N/A// the predicted pause time for the given young list will not overflow 1394N/A// the predicted amount of surviving data will not overflow the 1394N/A// the amount of free space available for survivor regions. 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// 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 1359N/A // Note: this might have already been set, if during the last 1359N/A // pause we decided to start a cycle but at the beginning of 1359N/A // this pause we decided to postpone it. That's OK. 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 "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 1394N/A#
endif // PREDICTIONS_VERBOSE 1394N/A // The _predicted_pause_time_ms field is referenced in code 1394N/A // not under PREDICTIONS_VERBOSE. Let's initialize it. 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... 1359N/A // We might want to do something different here. However, 1359N/A // right now we don't support the non-generational G1 mode 1359N/A // (and in fact we are planning to remove the associated code, 1359N/A // see CR 6814390). So, let's leave it as is and this will be 1359N/A // removed some time in the future 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. 1359N/A // We are about to decide on whether this pause will be an 1359N/A // First, during_initial_mark_pause() should not be already set. We 1359N/A // will set it here if we have to. However, it should be cleared by 1359N/A // the end of the pause (it's only set for the duration of an 1359N/A // We had noticed on a previous pause that the heap occupancy has 1359N/A // gone over the initiating threshold and we should start a 1359N/A // concurrent marking cycle. So we might initiate one. 1359N/A // The concurrent marking thread is not "during a cycle", i.e., 1359N/A // it has completed the last one. So we can go ahead and 1359N/A // And we can now clear initiate_conc_mark_if_possible() as 1359N/A // we've already acted on it. 1359N/A // The concurrent marking thread is still finishing up the 1359N/A // previous cycle. If we start one right now the two cycles 1359N/A // overlap. In particular, the concurrent marking thread might 1359N/A // be in the process of clearing the next marking bitmap (which 1359N/A // we will use for the next cycle if we start one). Starting a 1359N/A // cycle now will be bad given that parts of the marking 1359N/A // information might get cleared by the marking thread. And we 1359N/A // cannot wait for the marking thread to finish the cycle as it 1359N/A // periodically yields while clearing the next marking bitmap 1359N/A // and, if it's in a yield point, it's waiting for us to 1359N/A // finish. So, at this point we will not start a cycle and we'll 1359N/A // let the concurrent marking thread complete the last one. 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. 1394N/A// Add the heap region at the head of the non-incremental collection set 1394N/A// Initialize the per-collection-set information 1394N/A // This routine is used when: 1394N/A // * adding survivor regions to the incremental cset at the end of an 1394N/A // * adding the current allocation region to the incremental cset 1394N/A // * updating existing policy information for a region in the 1394N/A // incremental cset via young list RSet sampling. 1394N/A // Therefore this routine may be called at a safepoint by the 1394N/A // VM thread, or in-between safepoints by mutator threads (when 1394N/A // retiring the current allocation region) or a concurrent 1394N/A // refine thread (RSet sampling). 1394N/A // Cache the values we have added to the aggregated informtion 1394N/A // in the heap region in case we have to remove this region from 1394N/A // the incremental collection set, or it is updated by the 1394N/A // Record the number of bytes used in this region 1394N/A // Cache the values we have added to the aggregated informtion 1394N/A // in the heap region in case we have to remove this region from 1394N/A // the incremental collection set, or it is updated by the 1394N/A#
endif // PREDICTIONS_VERBOSE 1394N/A // This routine is currently only called as part of the updating of 1394N/A // existing policy information for regions in the incremental cset that 1394N/A // is performed by the concurrent refine thread(s) as part of young list 1394N/A // RSet sampling. Therefore we should not be at a safepoint. 1394N/A // the given heap region from the collection set info. 1394N/A // Clear the values cached in the heap region 1394N/A // Subtract the number of bytes used in this region 1394N/A // Clear the values cached in the heap region 1394N/A#
endif // PREDICTIONS_VERBOSE 1394N/A // Update the collection set information that is dependent on the new RS length 1394N/A // information in the heap region here (before the region gets added 1394N/A // to the collection set). An individual heap region's cached values 1394N/A // are calculated, aggregated with the policy collection set info, 1394N/A // and cached in the heap region here (initially) and (subsequently) 1394N/A // by the Young List sampling code. 1394N/A// Add the region at the RHS of the incremental cset 1394N/A // We should only ever be appending survivors at the end of a pause 1394N/A // Now add the region at the right hand side 1394N/A// Add the region to the LHS of the incremental cset 1394N/A // Survivors should be added to the RHS at the end of a pause 1394N/A // Add the region at the left hand side 1394N/A "age: %4d, y: %d, surv: %d",
1394N/A // Set this here - in case we're not doing young collections. 1394N/A // The result that this routine will return. This will be set to 1394N/A // * we're doing a young or partially young collection and we 1394N/A // have added the youg regions to collection set, or 1394N/A // * we add old regions to the collection set. 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. 1394N/A // The young list is laid with the survivor regions from the previous 1394N/A // pause are appended to the RHS of the young list, i.e. 1394N/A // [Newly Young Regions ++ Survivors from last pause]. 1394N/A // Clear the fields that point to the survivor list - they are 1394N/A // For young regions in the collection set, we assume the worst 1394N/A // case of complete survival 1394N/A // The number of recorded young regions is the incremental 1394N/A // collection set's current size 1394N/A#
endif // PREDICTIONS_VERBOSE 1394N/A // We are doing young collections so reset this. 1394N/A // Note we can use either _collection_set_size or 342N/A // don't bother adding more regions... 1394N/A // Save the current size of the collection set to detect 1394N/A // if we actually added any old regions. 1394N/A // We actually added old regions to the collection set 1394N/A // so we are not abandoning this collection.