defNewGeneration.cpp revision 0
0N/A * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 0N/A// DefNewGeneration functions. 0N/A// Methods of protected closure types. 0N/A // We never expect to see a null reference being processed 0N/A // as a weak reference. 0N/A // Card marking is trickier for weak refs. 0N/A // This oop is a 'next' field which was filled in while we 0N/A // were discovering weak references. While we might not need 0N/A // to take a special action to keep this reference alive, we 0N/A // will need to dirty a card as the field was modified. 0N/A // Alternatively, we could create a method which iterates through 0N/A // each generation, allowing them in turn to examine the modified 0N/A // We could check that p is also in an older generation, but 0N/A // dirty cards in the youngest gen are never scanned, so the 0N/A // extra check probably isn't worthwhile. 0N/A // Optimized for Defnew generation if it's the youngest generation: 0N/A // we set a younger_gen card if we have an older->youngest 0N/A // generation pointer. 0N/A "Failed to finish scan");
0N/A // Compute the maximum eden and survivor space sizes. These sizes 0N/A // are computed assuming the entire reserved space is committed. 0N/A // These values are exported as performance counters. 0N/A // allocate the performance counters 0N/A // Generation counters -- generation 0, 3 subspaces 0N/A // May happen due to 64Kb rounding, if so adjust eden size back up 0N/A // If minumum_eden_size != 0, we will not have cleared any 0N/A // portion of eden above its top. This can cause newly 0N/A // expanded space not to be mangled if using ZapUnusedHeapArea. 0N/A // We explicitly do such mangling here. 0N/A // The to-space is normally empty before a compaction so need 0N/A // not be considered. The exception is during promotion 0N/A // failure handling when to-space can contain live objects. 0N/A // The to-space is normally empty before a compaction so need 0N/A // not be considered. The exception is during promotion 0N/A // failure handling when to-space can contain live objects. 0N/A // Do not attempt an expand-to-the reserve size. The 0N/A // request should properly observe the maximum size of 0N/A // the generation so an expand-to-reserve should be 0N/A // unnecessary. Also a second call to expand-to-reserve 0N/A // value potentially can cause an undue expansion. 0N/A // For example if the first expand fail for unknown reasons, 0N/A // but the second succeeds and expands the heap to its maximum 0N/A // This is called after a gc that includes the following generation 0N/A // (which is required to exist.) So from-space will normally be empty. 0N/A // Note that we check both spaces, since if scavenge failed they revert roles. 0N/A // If not we bail out (otherwise we would have to relocate the objects) 0N/A "DefNewGeneration cannot be an oldest gen");
0N/A // All space sizes must be multiples of Generation::GenGrain. 0N/A // Compute desired new generation size based on NewRatio and 0N/A // NewSizeThreadIncrease 0N/A // Adjust new generation size 0N/A // If the heap failed to expand to the desired size, 0N/A // "changed" will be false. If the expansion failed 0N/A // (and at this point it was expected to succeed), 0N/A // ignore the failure (leaving "changed" as false). 0N/A // bail out of shrinking if objects in eden 0N/A // $$$ This may be wrong in case of "scavenge failure"? 0N/A assert(
false,
"NYI -- are you sure you want to call this?");
0N/A// The last collection bailed out, we are running out of heap space, 0N/A// so we try to allocate the from-space, too. 0N/A // If the Heap_lock is not locked by this thread, this will be called 0N/A // again later with the Heap_lock held. 0N/A // We don't attempt to expand the young generation (but perhaps we should.) 0N/A "This must be the youngest gen, and not the only gen");
0N/A // If the next generation is too full to accomodate promotion 0N/A // from this generation, pass on collection; let the next generation 0N/A // Capture heap used before collection (for printing). 0N/A // These can be shared for all code paths 0N/A "save marks have not been newly set.");
0N/A // FIXME: Are these storage leaks, or are they resource objects? 0N/A "save marks have not been newly set.");
0N/A true,
// Process younger gens, if any, as 0N/A false,
// not collecting permanent generation. 0N/A // "evacuate followers". 0N/A // Swap the survivor spaces. 0N/A // Set the desired survivor size to half the real survivor space 0N/A "Should not be here unless promotion failure handling is on");
0N/A // deallocate stack and it's elements 0N/A // Add to-space to the list of space to compact 0N/A // when a promotion failure has occurred. In that 0N/A // case there can be live objects in to-space 0N/A // as a result of a partial evacuation of eden 0N/A swap_spaces();
// For the sake of uniformity wrt ParNewGeneration::collect(). 0N/A // Reset the PromotionFailureALot counters. 0N/A // set new iteration safe limit for the survivor spaces 0N/A // Now restore saved marks, if any. 0N/A // prevent recursion in copy_to_survivor_space() 0N/A "shouldn't be scavenging this oop");
0N/A // Try allocating obj in to-space (unless too old) 0N/A // Otherwise try allocating obj tenured 0N/A // A failed promotion likely means the MaxLiveObjectEvacuationRatio flag 0N/A // is incorrectly set. In any case, its seriously wrong to be here! 0N/A // Prefetch beyond obj 0N/A // Increment age if obj still in new generation 0N/A // Done, insert forward pointer to obj in this header 0N/A /* $$$ Assert this? "trace" is a "MarkSweep" function so that's not appropriate. 0N/A if (to_space->top() > to_space->bottom()) { 0N/A trace("to_space not empty when contribute_scratch called"); 0N/A "This must be the youngest gen, and not the only gen");
0N/A // Decide if there's enough room for a full promotion 0N/A // When using extremely large edens, we effectively lose a 0N/A // large amount of old space. Use the "MaxLiveObjectEvacuationRatio" 0N/A // flag to reduce the minimum evacuation space requirements. If 0N/A // there is not enough space to evacuate eden during a scavenge, 0N/A // the VM will immediately exit with an out of memory error. 0N/A // This flag has not been tested 0N/A // with collectors other than simple mark & sweep. 0N/A // Note that with the addition of promotion failure handling, the 0N/A // VM will not immediately exit but will undo the young generation 0N/A // collection. The parameter is left here for compatibility. 0N/A // worst_case_evacuation is based on "used()". For the case where this 0N/A // method is called after a collection, this is still appropriate because 0N/A // the case that needs to be detected is one in which a full collection 0N/A // has been done and has overflowed into the young generation. In that 0N/A // case a minor collection will fail (the overflow of the full collection 0N/A // means there is no space in the old generation for any promotion). 0N/A // Check if the heap is approaching full after a collection has 0N/A // been done. Generally the young generation is empty at 0N/A // a minimum at the end of a collection. If it is not, then 0N/A // the heap is approaching full. 0N/A if (
full) {
// we seem to be running out of space 0N/A // update the generation and space performance counters 0N/A return "def new generation";