3202N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 482N/A// The SplitInfo class holds the information needed to 'split' a source region 482N/A// so that the live data can be copied to two destination *spaces*. Normally, 482N/A// all the live data in a region is copied to a single destination space (e.g., 482N/A// everything live in a region in eden is copied entirely into the old gen). 482N/A// However, when the heap is nearly full, all the live data in eden may not fit 482N/A// into the old gen. Copying only some of the regions from eden to old gen 482N/A// requires finding a region that does not contain a partial object (i.e., no 482N/A// live object crosses the region boundary) somewhere near the last object that 482N/A// does fit into the old gen. Since it's not always possible to find such a 482N/A// region, splitting is necessary for predictable behavior. 482N/A// A region is always split at the end of the partial object. This avoids 482N/A// additional tests when calculating the new location of a pointer, which is a 482N/A// very hot code path. The partial object and everything to its left will be 482N/A// copied to another space (call it dest_space_1). The live data to the right 482N/A// of the partial object will be copied either within the space itself, or to a 482N/A// different destination space (distinct from dest_space_1). 482N/A// Split points are identified during the summary phase, when region 482N/A// destinations are computed: data about the split, including the 482N/A// partial_object_size, is recorded in a SplitInfo record and the 482N/A// partial_object_size field in the summary data is set to zero. The zeroing is 482N/A// possible (and necessary) since the partial object will move to a different 482N/A// destination space than anything to its right, thus the partial object should 482N/A// not affect the locations of any objects to its right. 482N/A// The recorded data is used during the compaction phase, but only rarely: when 482N/A// the partial object on the split region will be copied across a destination 482N/A// region boundary. This test is made once each time a region is filled, and is 482N/A// a simple address comparison, so the overhead is negligible (see 482N/A// PSParallelCompact::first_src_addr()). 482N/A// Only regions with partial objects are split; a region without a partial 482N/A// object does not need any extra bookkeeping. 482N/A// At most one region is split per space, so the amount of data required is 482N/A// A region is split only when the destination space would overflow. Once that 482N/A// happens, the destination space is abandoned and no other data (even from 482N/A// other source spaces) is targeted to that destination space. Abandoning the 482N/A// destination space may leave a somewhat large unused area at the end, if a 482N/A// large object caused the overflow. 482N/A// More bookkeeping would be required to continue to use the destination space. 482N/A// The most general solution would allow data from regions in two different 482N/A// source spaces to be "joined" in a single destination region. At the very 482N/A// least, additional code would be required in next_src_region() to detect the 482N/A// join and skip to an out-of-order source region. If the join region was also 482N/A// the last destination region to which a split region was copied (the most 482N/A// likely case), then additional work would be needed to get fill_region() to 482N/A// stop iteration and switch to a new source region at the right point. Basic 482N/A// idea would be to use a fake value for the top of the source space. It is 482N/A// doable, if a bit tricky. 482N/A// A simpler (but less general) solution would fill the remainder of the 482N/A// destination region with a dummy object and continue filling the next 482N/A // Return true if this split info is valid (i.e., if a split has been 482N/A // recorded). The very first region cannot have a partial object and thus is 482N/A // never split, so 0 is the 'invalid' value. 482N/A // Return true if this split holds data for the specified source region. 482N/A // The index of the split region, the size of the partial object on that 482N/A // region and the destination of the partial object. 482N/A // The destination count of the partial object referenced by this split 482N/A // (either 1 or 2). This must be added to the destination count of the 482N/A // remainder of the source region. 482N/A // If a word within the partial object will be written to the first word of a 482N/A // destination region, this is the address of the destination region; 482N/A // otherwise this is NULL. 482N/A // If a word within the partial object will be written to the first word of a 482N/A // destination region, this is the address of that word within the partial 482N/A // object; otherwise this is NULL. 482N/A // Record the data necessary to split the region src_region_idx. 0N/A // Where the free space will start after the collection. Valid only after the 0N/A // summary phase completes. 0N/A // Allows new_top to be set. 0N/A // Where the smallest allowable dense prefix ends (used only for perm gen). 0N/A // Where the dense prefix ends, or the compacted region begins. 0N/A // The start array for the (generation containing the) space, or NULL if there 0N/A // is no start array. 0N/A // Sizes are in HeapWords, unless indicated otherwise. 375N/A // Mask for the bits in a size_t to get an offset within a region. 375N/A // Mask for the bits in a pointer to get an offset within a region. 375N/A // Mask for the bits in a pointer to get the address of the start of a region. 375N/A // Destination address of the region. 375N/A // The first region containing data destined for this region. 375N/A // The object (if any) starting in this region and ending in a different 375N/A // region that could not be updated during the main (parallel) compaction 0N/A // phase. This is different from _partial_obj_addr, which is an object that 375N/A // extends onto a source region. However, the two uses do not overlap in 0N/A // time, so the same field is used to save space. 375N/A // The starting address of the partial object extending onto the region. 375N/A // Size of the partial object extending onto the region (words). 375N/A // Size of live data that lies within this region due to objects that start 375N/A // in this region (words). This does not include the partial object 375N/A // extending onto the region (if any), or the part of an object that extends 375N/A // onto the next region (if any). 375N/A // Total live data that lies within the region (words). 375N/A // The destination_count is the number of other regions to which data from 375N/A // this region will be copied. At the end of the summary phase, the valid 0N/A // values of destination_count are 375N/A // 0 - data from the region will be compacted completely into itself, or the 375N/A // region is empty. The region can be claimed and then filled. 375N/A // 1 - data from the region will be compacted into 1 other region; some 375N/A // data from the region may also be compacted into the region itself. 375N/A // 2 - data from the region will be copied to 2 other regions. 375N/A // During compaction as regions are emptied, the destination_count is 0N/A // decremented (atomically) and when it reaches 0, it can be claimed and 375N/A // A region is claimed for processing by atomically changing the 375N/A // destination_count to the claimed value (dc_claimed). After a region has 0N/A // been filled, the destination_count should be set to the completed value 4535N/A // Whether the block table for this region has been filled. 4535N/A // Number of times the block table was filled. 375N/A // The location of the java heap data that corresponds to this region. 375N/A // The highest address referenced by objects in this region. 375N/A // Whether this region is available to be claimed, has been claimed, or has 375N/A // Minor subtlety: claimed() returns true if the region is marked 375N/A // completed(), which is desirable since a region must be claimed before it 0N/A // can be completed. 0N/A // These are not atomic. 0N/A // These are atomic. 375N/A // The type used to represent object sizes within a region. 0N/A // Constants for manipulating the _dc_and_los field, which holds both the 0N/A // destination count and live obj size. The live obj size lives at the 0N/A // least significant end so no masking is necessary when adding. 0N/A // These enable optimizations that are only partially implemented. Use 0N/A // debug builds to prevent the code fragments from breaking. 0N/A#
endif // #ifdef ASSERT 4535N/A // "Blocks" allow shorter sections of the bitmap to be searched. Each Block 4535N/A // holds an offset, which is the amount of live data in the Region to the left 4535N/A // of the first live object that starts in the Block. 375N/A // Convert region indices to/from RegionData pointers. 375N/A // Fill in the regions covering [beg, end) so that no data moves; i.e., the 375N/A // destination of region n is simply the start of region n. The argument beg 375N/A // must be region-aligned; end need not be. 375N/A // Return the number of words between addr and the start of the region 375N/A // Convert addresses to/from a region index or region pointer. 4535N/A // Analogous to region_offset() for blocks. 0N/A // Return the address one past the end of the partial object. 4535N/A // Return the location of the object after compaction. 0N/A // Return the updated address for the given klass 0N/A#
endif // #ifdef ASSERT 0N/A#
endif // #ifdef ASSERT 4535N/A // Debug builds count the number of times the table was filled. 375N/A// MT-unsafe claiming of a region. Should only be used during single threaded 0N/A#
endif // #ifdef ASSERT 0N/A// Abstract closure for use with ParMarkBitMap::iterate(), which will invoke the 0N/A// The closure is initialized with the number of heap words to process 0N/A// (words_remaining()), and becomes 'full' when it reaches 0. The do_addr() 0N/A// methods in subclasses should update the total as words are processed. Since 0N/A// only one subclass actually uses this mechanism to terminate iteration, the 0N/A// default initial value is > 0. The implementation is here and not in the 0N/A// single subclass that uses it to avoid making is_full() virtual, and thus 0N/A// adding a virtual call per live object. 375N/A// The UseParallelOldGC collector is a stop-the-world garbage collector that 375N/A// does parts of the collection using parallel threads. The collection includes 375N/A// the tenured generation and the young generation. The permanent generation is 375N/A// collected at the same time as the other two generations but the permanent 375N/A// generation is collect by a single GC thread. The permanent generation is 375N/A// collected serially because of the requirement that during the processing of a 375N/A// klass AAA, any objects reference by AAA must already have been processed. 375N/A// This requirement is enforced by a left (lower address) to right (higher 375N/A// address) sliding compaction. 263N/A// There are four phases of the collection. 263N/A// Roughly speaking these phases correspond, respectively, to 263N/A// - mark all the live objects 263N/A// - calculate the destination of each object at the end of the collection 263N/A// - move the objects to their destination 263N/A// - update some references and reinitialize some variables 375N/A// These three phases are invoked in PSParallelCompact::invoke_no_policy(). The 375N/A// marking phase is implemented in PSParallelCompact::marking_phase() and does a 375N/A// complete marking of the heap. The summary phase is implemented in 375N/A// PSParallelCompact::summary_phase(). The move and update phase is implemented 375N/A// in PSParallelCompact::compact(). 375N/A// A space that is being collected is divided into regions and with each region 375N/A// is associated an object of type ParallelCompactData. Each region is of a 375N/A// fixed size and typically will contain more than 1 object and may have parts 375N/A// of objects at the front and back of the region. 375N/A// region -----+---------------------+---------- 263N/A// objects covered [ AAA )[ BBB )[ CCC )[ DDD ) 375N/A// The marking phase does a complete marking of all live objects in the heap. 375N/A// The marking also compiles the size of the data for all live objects covered 375N/A// by the region. This size includes the part of any live object spanning onto 375N/A// the region (part of AAA if it is live) from the front, all live objects 375N/A// contained in the region (BBB and/or CCC if they are live), and the part of 375N/A// any live objects covered by the region that extends off the region (part of 375N/A// DDD if it is live). The marking phase uses multiple GC threads and marking 375N/A// is done in a bit array of type ParMarkBitMap. The marking of the bit map is 375N/A// done atomically as is the accumulation of the size of the live objects 375N/A// The summary phase calculates the total live data to the left of each region 375N/A// XXX. Based on that total and the bottom of the space, it can calculate the 375N/A// starting location of the live data in XXX. The summary phase calculates for 375N/A// each region XXX quantites such as 375N/A// - the amount of live data at the beginning of a region from an object 375N/A// - the location of the first live data on the region 375N/A// - a count of the number of regions receiving live data from XXX. 263N/A// See ParallelCompactData for precise details. The summary phase also 375N/A// calculates the dense prefix for the compaction. The dense prefix is a 375N/A// portion at the beginning of the space that is not moved. The objects in the 375N/A// dense prefix do need to have their object references updated. See method 375N/A// summarize_dense_prefix(). 263N/A// The summary phase is done using 1 GC thread. 375N/A// The compaction phase moves objects to their new location and updates all 375N/A// references in the object. 375N/A// A current exception is that objects that cross a region boundary are moved 375N/A// but do not have their references updated. References are not updated because 375N/A// it cannot easily be determined if the klass pointer KKK for the object AAA 375N/A// has been updated. KKK likely resides in a region to the left of the region 375N/A// containing AAA. These AAA's have there references updated at the end in a 375N/A// clean up phase. See the method PSParallelCompact::update_deferred_objects(). 375N/A// An alternate strategy is being investigated for this deferral of updating. 375N/A// Compaction is done on a region basis. A region that is ready to be filled is 375N/A// put on a ready list and GC threads take region off the list and fill them. A 375N/A// region is ready to be filled if it empty of live objects. Such a region may 375N/A// have been initially empty (only contained dead objects) or may have had all 375N/A// its live objects copied out already. A region that compacts into itself is 375N/A// also ready for filling. The ready list is initially filled with empty 375N/A// regions and regions compacting into themselves. There is always at least 1 375N/A// region that can be put on the ready list. The regions are atomically added 375N/A// and removed from the ready list. 0N/A // Convenient access to type names. 113N/A // Inline closure decls 989N/A // do not walk from thread stacks to the code cache on this phase 0N/A // Reference processing (used in ...follow_contents) 0N/A // Updated location of intArrayKlassObj. 0N/A // Values computed at initialization and used by dead_wood_limiter(). 0N/A#
endif // #ifdef ASSERT 0N/A // Closure accessors 0N/A // Return true if details about individual phases should be printed. 0N/A // Clear the marking bitmap and summary data that cover the specified space. 0N/A // Mark live objects 0N/A // Compute the dense prefix for the designated space. This is an experimental 0N/A // implementation currently not used in production. 0N/A // Methods used to compute the dense prefix. 0N/A // Compute the value of the normal distribution at x = density. The mean and 0N/A // standard deviation are values saved by initialize_dead_wood_limiter(). 0N/A // Initialize the static vars used by dead_wood_limiter(). 0N/A // Return the percentage of space that can be treated as "dead wood" (i.e., 375N/A // Find the first (left-most) region in the range [beg, end) that has at least 0N/A // dead_words of dead space to the left. The argument beg must be the first 375N/A // region in the space that is not completely live. 375N/A // Return a pointer to the first region in the range [beg, end) that is not 0N/A // Return a value indicating the benefit or 'yield' if the compacted region 0N/A // were to start (or equivalently if the dense prefix were to end) at the 375N/A // candidate region. Higher values are better. 0N/A // The value is based on the amount of space reclaimed vs. the costs of (a) 0N/A // updating references in the dense prefix plus (b) copying objects and 0N/A // updating references in the compacted region. 0N/A // Compute the dense prefix for the designated space. 375N/A // Return true if dead space crosses onto the specified Region; bit must be 375N/A // the bit index corresponding to the first word of the Region. 0N/A // Summary phase utility routine to fill dead space (if any) at the dense 0N/A // prefix boundary. Should only be called if the the dense prefix is 482N/A // Clear the summary data source_region field for the specified addresses. 483N/A // Routines to provoke splitting a young gen space (ParallelOldGCSplitALot). 483N/A // Fill the region [start, start + words) with live object(s). Only usable 483N/A // for the old and permanent generations. 483N/A // Include the new objects in the summary data. 496N/A // Add live objects to a survivor space since it's rare that both survivors 483N/A // Add live objects and/or choose the dense prefix to provoke splitting. 0N/A // Adjust addresses in roots. Does not adjust addresses in heap. 0N/A // Serial code executed in preparation for the compaction phase. 0N/A // Move objects to new locations. 375N/A // Add available regions to the stack and draining tasks to the task queue. 0N/A // Add dense prefix update tasks to the task queue. 375N/A // Add region stealing tasks to the task queue. 0N/A // If objects are left in eden after a collection, try to move the boundary 0N/A // and absorb them into the old gen. Returns true if eden was emptied. 0N/A // Reset time since last full gc 0N/A // The following arrays are saved since the time of the last GC and 0N/A // assist in tracking down problems where someone has done an errant 0N/A // store into the heap, usually to an oop that wasn't properly 0N/A // handleized across a GC. If we crash or otherwise fail before the 0N/A // next GC, we can query these arrays to find out the object we had 0N/A // intended to do the store to (assuming it is still alive) and the 0N/A // offset within that object. Covered under RecordMarkSweepCompaction. 0N/A // Convenient accessor for Universe::heap(). 0N/A // Perform initialization for PSParallelCompact that requires 0N/A // allocations. This should be called during the VM initialization 0N/A // at a pointer where it would be appropriate to return a JNI_ENOMEM 0N/A // in the event of a failure. 0N/A // Used to add tasks 113N/A // Check mark and maybe push on marking stack 0N/A // Compaction support. 0N/A // Return true if p is in the range [beg_addr, end_addr). 0N/A // Convenience wrappers for per-space data kept in _space_info. 0N/A // Return true if the klass should be updated. 0N/A // Move and update the live objects in the specified space. 375N/A // Process the end of the given region range in the dense prefix. 0N/A // This includes saving any object not updated. 375N/A // Update a region in the dense prefix. For each live object 375N/A // in the region, update it's interior references. For each 0N/A // dead object, fill it with deadwood. Dead space at the end 375N/A // of a region range will be filled to the start of the next 375N/A // live object regardless of the region_index_end. None of the 0N/A // objects in the dense prefix move and dead space is dead 0N/A // (holds only dead objects that don't need any processing), so 0N/A // dead space can be filled in any order. 0N/A // Return the address of the count + 1st live word in the range [beg, end). 0N/A // Return the address of the word to be copied to dest_addr, which must be 375N/A // aligned to a region boundary. 375N/A // Determine the next source region, set closure.source() to the start of the 375N/A // new region return the region index. Parameter end_addr is the address one 0N/A // beyond the end of source range just processed. If necessary, switch to a 0N/A // new source space and set src_space_id (in-out parameter) and src_space_top 0N/A // (out parameter) accordingly. 375N/A // Decrement the destination count for each non-empty source region in the 495N/A // range [beg_region, region(region_align_up(end_addr))). If the destination 495N/A // count for a region goes to 0 and it needs to be filled, enqueue it. 375N/A // Fill a region, copying objects from one or more source regions. 4535N/A // Fill in the block table for the specified region. 0N/A // Update the deferred objects in the space. 0N/A // Reference Processing 0N/A // Return the SpaceId for the given address. 0N/A // Time since last full gc (in milliseconds). 0N/A // Querying operation of RecordMarkSweepCompaction results. 0N/A // Finds and prints the current base oop and offset for a word 0N/A // within an oop that was live during the last GC. Helpful for 0N/A // tracking down heap stomps. 0N/A#
endif // #ifdef VALIDATE_MARK_SWEEP 0N/A // Call backs for class unloading 941N/A // Clear unmarked oops in MDOs at the end of marking. 0N/A // Debugging support. 0N/A#
endif // #ifndef PRODUCT 495N/A // Sanity check the new location of a word in the heap. 375N/A // Verify that all the regions have been emptied. 0N/A#
endif // #ifdef ASSERT 113N/A "roots shouldn't be things within the heap");
113N/A "should be forwarded");
113N/A // Just always do the update unconditionally? 113N/A "should be in object space");
0N/A // Dead space crosses the boundary if (1) a partial object does not extend 375N/A // onto the region, (2) an object does not start at the beginning of the 375N/A // region, and (3) an object does not end at the end of the prior region. 495N/A "must move left or to a different space");
0N/A // If the object will fit (size <= words_remaining()), copy it to the current 0N/A // destination, update the interior oops and the start array and return either 0N/A // full (if the closure is full) or incomplete. If the object will not fit, 0N/A // return would_overflow. 0N/A // Copy enough words to fill this closure, starting at source(). Interior 0N/A // oops and the start array are not updated. Return full. 0N/A // Copy enough words to fill this closure or to the end of an object, 0N/A // whichever is smaller, starting at source(). Interior oops and the start 0N/A // array are not updated. 0N/A // Update variables to indicate that word_count words were processed. 0N/A // Update the object. 0N/A "cannot use FillClosure in the young gen");
1879N/A#
endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP