genMarkSweep.cpp revision 113
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 // hook up weak ref data so it can be used during Mark-Sweep 0N/A // When collecting the permanent generation methodOops may be moving, 0N/A // so we either have to flush all bcp data or convert it into bci. 0N/A // Increment the invocation count for the permanent generation, since it is 0N/A // implicitly collected whenever we do a full mark sweep collection. 0N/A // Capture heap size before collection for printing. 0N/A // Some of the card table updates below assume that the perm gen is 0N/A // also being collected. 0N/A "All generations are being collected, ergo perm gen too.");
0N/A // Capture used regions for each generation that will be 0N/A // subject to collection, so that card table adjustments can 0N/A // be made intelligently (see clear / invalidate further below). 0N/A // Don't add any more derived pointers during phase3 0N/A "should be the same size");
0N/A // Set saved marks for allocation profiler (and other things? -- dld) 0N/A // (Should this be in general part?) 0N/A // If compaction completely evacuated all generations younger than this 0N/A // one, then we can clear the card table. Otherwise, we must invalidate 0N/A // it (consider all cards dirty). In the future, we might consider doing 0N/A // compaction within generations only, and doing card-table sliding. 0N/A // We've evacuated all generations below us. 0N/A // Invalidate the cards corresponding to the currently used 0N/A // region and clear those corresponding to the evacuated region 0N/A // of all generations just collected (i.e. level and younger). 0N/A // refs processing: clean slate 0N/A // Update heap occupancy information which is used as 0N/A // input to soft ref clearing policy at the next gc. 0N/A // Update time of last gc for all generations we collected 0N/A // (which curently is all the generations in the heap). 0N/A // Scratch request on behalf of oldest generation; will do no 0N/A // $$$ To cut a corner, we'll only use the first scratch block, and then 0N/A // revert to malloc. 0N/A // Recursively traverse all live objects and mark them 0N/A // Because follow_root_closure is created statically, cannot 0N/A // use OopsInGenClosure constructor which takes a generation, 0N/A // as the Universe has not been created when the static constructors 0N/A false,
// Younger gens are not roots. 0N/A true,
// Collecting permanent generation. 0N/A // Process reference objects found during marking 0N/A // Follow system dictionary roots and unload classes 0N/A // Follow code cache roots 0N/A // Visit symbol and interned string tables and delete unmarked oops 0N/A // Now all live objects are marked, compute the new object addresses. 0N/A // It is imperative that we traverse perm_gen LAST. If dead space is 0N/A // allowed a range of dead object may get overwritten by a dead int 0N/A // array. If perm_gen is not traversed last a klassOop may get 0N/A // overwritten. This is fine since it is dead, but if the class has dead 0N/A // instances we have to skip them, and in order to find their size we 0N/A // need the klassOop! 0N/A // It is not required that we traverse spaces in the same order in 0N/A // phase2, phase3 and phase4, but the ValidateMarkSweep live oops 0N/A // tracking expects us to do so. See comment under phase4. 0N/A // Adjust the pointers to reflect the new locations 0N/A // Needs to be done before the system dictionary is adjusted. 0N/A // Because the two closures below are created statically, cannot 0N/A // use OopsInGenClosure constructor which takes a generation, 0N/A // as the Universe has not been created when the static constructors 0N/A false,
// Younger gens are not roots. 0N/A true,
// Collecting permanent generation. 0N/A // Now adjust pointers in remaining weak roots. (All of which should 0N/A // have been cleared if they pointed to non-surviving objects.) 0N/A // All pointers are now adjusted, move objects accordingly 0N/A // It is imperative that we traverse perm_gen first in phase4. All 0N/A // classes must be allocated earlier than their instances, and traversing 0N/A // perm_gen first makes sure that all klassOops have moved to their new 0N/A // location before any instance does a dispatch through it's klass! 0N/A // The ValidateMarkSweep live oops tracking expects us to traverse spaces 0N/A // in the same order in phase2, phase3 and phase4. We don't quite do that 0N/A // here (perm_gen first rather than last), so we tell the validate code 0N/A // to use a higher index (saved from phase2) when verifying perm_gen.