Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp
38921 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP2627#include "gc_implementation/parallelScavenge/objectStartArray.hpp"28#include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"29#include "gc_implementation/parallelScavenge/psCompactionManager.hpp"30#include "gc_implementation/shared/collectorCounters.hpp"31#include "gc_implementation/shared/markSweep.hpp"32#include "gc_implementation/shared/mutableSpace.hpp"33#include "memory/sharedHeap.hpp"34#include "oops/oop.hpp"3536class ParallelScavengeHeap;37class PSAdaptiveSizePolicy;38class PSYoungGen;39class PSOldGen;40class ParCompactionManager;41class ParallelTaskTerminator;42class PSParallelCompact;43class GCTaskManager;44class GCTaskQueue;45class PreGCValues;46class MoveAndUpdateClosure;47class RefProcTaskExecutor;48class ParallelOldTracer;49class STWGCTimer;5051// The SplitInfo class holds the information needed to 'split' a source region52// so that the live data can be copied to two destination *spaces*. Normally,53// all the live data in a region is copied to a single destination space (e.g.,54// everything live in a region in eden is copied entirely into the old gen).55// However, when the heap is nearly full, all the live data in eden may not fit56// into the old gen. Copying only some of the regions from eden to old gen57// requires finding a region that does not contain a partial object (i.e., no58// live object crosses the region boundary) somewhere near the last object that59// does fit into the old gen. Since it's not always possible to find such a60// region, splitting is necessary for predictable behavior.61//62// A region is always split at the end of the partial object. This avoids63// additional tests when calculating the new location of a pointer, which is a64// very hot code path. The partial object and everything to its left will be65// copied to another space (call it dest_space_1). The live data to the right66// of the partial object will be copied either within the space itself, or to a67// different destination space (distinct from dest_space_1).68//69// Split points are identified during the summary phase, when region70// destinations are computed: data about the split, including the71// partial_object_size, is recorded in a SplitInfo record and the72// partial_object_size field in the summary data is set to zero. The zeroing is73// possible (and necessary) since the partial object will move to a different74// destination space than anything to its right, thus the partial object should75// not affect the locations of any objects to its right.76//77// The recorded data is used during the compaction phase, but only rarely: when78// the partial object on the split region will be copied across a destination79// region boundary. This test is made once each time a region is filled, and is80// a simple address comparison, so the overhead is negligible (see81// PSParallelCompact::first_src_addr()).82//83// Notes:84//85// Only regions with partial objects are split; a region without a partial86// object does not need any extra bookkeeping.87//88// At most one region is split per space, so the amount of data required is89// constant.90//91// A region is split only when the destination space would overflow. Once that92// happens, the destination space is abandoned and no other data (even from93// other source spaces) is targeted to that destination space. Abandoning the94// destination space may leave a somewhat large unused area at the end, if a95// large object caused the overflow.96//97// Future work:98//99// More bookkeeping would be required to continue to use the destination space.100// The most general solution would allow data from regions in two different101// source spaces to be "joined" in a single destination region. At the very102// least, additional code would be required in next_src_region() to detect the103// join and skip to an out-of-order source region. If the join region was also104// the last destination region to which a split region was copied (the most105// likely case), then additional work would be needed to get fill_region() to106// stop iteration and switch to a new source region at the right point. Basic107// idea would be to use a fake value for the top of the source space. It is108// doable, if a bit tricky.109//110// A simpler (but less general) solution would fill the remainder of the111// destination region with a dummy object and continue filling the next112// destination region.113114class SplitInfo115{116public:117// Return true if this split info is valid (i.e., if a split has been118// recorded). The very first region cannot have a partial object and thus is119// never split, so 0 is the 'invalid' value.120bool is_valid() const { return _src_region_idx > 0; }121122// Return true if this split holds data for the specified source region.123inline bool is_split(size_t source_region) const;124125// The index of the split region, the size of the partial object on that126// region and the destination of the partial object.127size_t src_region_idx() const { return _src_region_idx; }128size_t partial_obj_size() const { return _partial_obj_size; }129HeapWord* destination() const { return _destination; }130131// The destination count of the partial object referenced by this split132// (either 1 or 2). This must be added to the destination count of the133// remainder of the source region.134unsigned int destination_count() const { return _destination_count; }135136// If a word within the partial object will be written to the first word of a137// destination region, this is the address of the destination region;138// otherwise this is NULL.139HeapWord* dest_region_addr() const { return _dest_region_addr; }140141// If a word within the partial object will be written to the first word of a142// destination region, this is the address of that word within the partial143// object; otherwise this is NULL.144HeapWord* first_src_addr() const { return _first_src_addr; }145146// Record the data necessary to split the region src_region_idx.147void record(size_t src_region_idx, size_t partial_obj_size,148HeapWord* destination);149150void clear();151152DEBUG_ONLY(void verify_clear();)153154private:155size_t _src_region_idx;156size_t _partial_obj_size;157HeapWord* _destination;158unsigned int _destination_count;159HeapWord* _dest_region_addr;160HeapWord* _first_src_addr;161};162163inline bool SplitInfo::is_split(size_t region_idx) const164{165return _src_region_idx == region_idx && is_valid();166}167168class SpaceInfo169{170public:171MutableSpace* space() const { return _space; }172173// Where the free space will start after the collection. Valid only after the174// summary phase completes.175HeapWord* new_top() const { return _new_top; }176177// Allows new_top to be set.178HeapWord** new_top_addr() { return &_new_top; }179180// Where the smallest allowable dense prefix ends (used only for perm gen).181HeapWord* min_dense_prefix() const { return _min_dense_prefix; }182183// Where the dense prefix ends, or the compacted region begins.184HeapWord* dense_prefix() const { return _dense_prefix; }185186// The start array for the (generation containing the) space, or NULL if there187// is no start array.188ObjectStartArray* start_array() const { return _start_array; }189190SplitInfo& split_info() { return _split_info; }191192void set_space(MutableSpace* s) { _space = s; }193void set_new_top(HeapWord* addr) { _new_top = addr; }194void set_min_dense_prefix(HeapWord* addr) { _min_dense_prefix = addr; }195void set_dense_prefix(HeapWord* addr) { _dense_prefix = addr; }196void set_start_array(ObjectStartArray* s) { _start_array = s; }197198void publish_new_top() const { _space->set_top(_new_top); }199200private:201MutableSpace* _space;202HeapWord* _new_top;203HeapWord* _min_dense_prefix;204HeapWord* _dense_prefix;205ObjectStartArray* _start_array;206SplitInfo _split_info;207};208209class ParallelCompactData210{211public:212// Sizes are in HeapWords, unless indicated otherwise.213static const size_t Log2RegionSize;214static const size_t RegionSize;215static const size_t RegionSizeBytes;216217// Mask for the bits in a size_t to get an offset within a region.218static const size_t RegionSizeOffsetMask;219// Mask for the bits in a pointer to get an offset within a region.220static const size_t RegionAddrOffsetMask;221// Mask for the bits in a pointer to get the address of the start of a region.222static const size_t RegionAddrMask;223224static const size_t Log2BlockSize;225static const size_t BlockSize;226static const size_t BlockSizeBytes;227228static const size_t BlockSizeOffsetMask;229static const size_t BlockAddrOffsetMask;230static const size_t BlockAddrMask;231232static const size_t BlocksPerRegion;233static const size_t Log2BlocksPerRegion;234235class RegionData236{237public:238// Destination address of the region.239HeapWord* destination() const { return _destination; }240241// The first region containing data destined for this region.242size_t source_region() const { return _source_region; }243244// The object (if any) starting in this region and ending in a different245// region that could not be updated during the main (parallel) compaction246// phase. This is different from _partial_obj_addr, which is an object that247// extends onto a source region. However, the two uses do not overlap in248// time, so the same field is used to save space.249HeapWord* deferred_obj_addr() const { return _partial_obj_addr; }250251// The starting address of the partial object extending onto the region.252HeapWord* partial_obj_addr() const { return _partial_obj_addr; }253254// Size of the partial object extending onto the region (words).255size_t partial_obj_size() const { return _partial_obj_size; }256257// Size of live data that lies within this region due to objects that start258// in this region (words). This does not include the partial object259// extending onto the region (if any), or the part of an object that extends260// onto the next region (if any).261size_t live_obj_size() const { return _dc_and_los & los_mask; }262263// Total live data that lies within the region (words).264size_t data_size() const { return partial_obj_size() + live_obj_size(); }265266// The destination_count is the number of other regions to which data from267// this region will be copied. At the end of the summary phase, the valid268// values of destination_count are269//270// 0 - data from the region will be compacted completely into itself, or the271// region is empty. The region can be claimed and then filled.272// 1 - data from the region will be compacted into 1 other region; some273// data from the region may also be compacted into the region itself.274// 2 - data from the region will be copied to 2 other regions.275//276// During compaction as regions are emptied, the destination_count is277// decremented (atomically) and when it reaches 0, it can be claimed and278// then filled.279//280// A region is claimed for processing by atomically changing the281// destination_count to the claimed value (dc_claimed). After a region has282// been filled, the destination_count should be set to the completed value283// (dc_completed).284inline uint destination_count() const;285inline uint destination_count_raw() const;286287// Whether the block table for this region has been filled.288inline bool blocks_filled() const;289290// Number of times the block table was filled.291DEBUG_ONLY(inline size_t blocks_filled_count() const;)292293// The location of the java heap data that corresponds to this region.294inline HeapWord* data_location() const;295296// The highest address referenced by objects in this region.297inline HeapWord* highest_ref() const;298299// Whether this region is available to be claimed, has been claimed, or has300// been completed.301//302// Minor subtlety: claimed() returns true if the region is marked303// completed(), which is desirable since a region must be claimed before it304// can be completed.305bool available() const { return _dc_and_los < dc_one; }306bool claimed() const { return _dc_and_los >= dc_claimed; }307bool completed() const { return _dc_and_los >= dc_completed; }308309// These are not atomic.310void set_destination(HeapWord* addr) { _destination = addr; }311void set_source_region(size_t region) { _source_region = region; }312void set_deferred_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }313void set_partial_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }314void set_partial_obj_size(size_t words) {315_partial_obj_size = (region_sz_t) words;316}317inline void set_blocks_filled();318319inline void set_destination_count(uint count);320inline void set_live_obj_size(size_t words);321inline void set_data_location(HeapWord* addr);322inline void set_completed();323inline bool claim_unsafe();324325// These are atomic.326inline void add_live_obj(size_t words);327inline void set_highest_ref(HeapWord* addr);328inline void decrement_destination_count();329inline bool claim();330331private:332// The type used to represent object sizes within a region.333typedef uint region_sz_t;334335// Constants for manipulating the _dc_and_los field, which holds both the336// destination count and live obj size. The live obj size lives at the337// least significant end so no masking is necessary when adding.338static const region_sz_t dc_shift; // Shift amount.339static const region_sz_t dc_mask; // Mask for destination count.340static const region_sz_t dc_one; // 1, shifted appropriately.341static const region_sz_t dc_claimed; // Region has been claimed.342static const region_sz_t dc_completed; // Region has been completed.343static const region_sz_t los_mask; // Mask for live obj size.344345HeapWord* _destination;346size_t _source_region;347HeapWord* _partial_obj_addr;348region_sz_t _partial_obj_size;349region_sz_t volatile _dc_and_los;350bool volatile _blocks_filled;351352#ifdef ASSERT353size_t _blocks_filled_count; // Number of block table fills.354355// These enable optimizations that are only partially implemented. Use356// debug builds to prevent the code fragments from breaking.357HeapWord* _data_location;358HeapWord* _highest_ref;359#endif // #ifdef ASSERT360361#ifdef ASSERT362public:363uint _pushed; // 0 until region is pushed onto a stack364private:365#endif366};367368// "Blocks" allow shorter sections of the bitmap to be searched. Each Block369// holds an offset, which is the amount of live data in the Region to the left370// of the first live object that starts in the Block.371class BlockData372{373public:374typedef unsigned short int blk_ofs_t;375376blk_ofs_t offset() const { return _offset; }377void set_offset(size_t val) { _offset = (blk_ofs_t)val; }378379private:380blk_ofs_t _offset;381};382383public:384ParallelCompactData();385bool initialize(MemRegion covered_region);386387size_t region_count() const { return _region_count; }388size_t reserved_byte_size() const { return _reserved_byte_size; }389390// Convert region indices to/from RegionData pointers.391inline RegionData* region(size_t region_idx) const;392inline size_t region(const RegionData* const region_ptr) const;393394size_t block_count() const { return _block_count; }395inline BlockData* block(size_t block_idx) const;396inline size_t block(const BlockData* block_ptr) const;397398void add_obj(HeapWord* addr, size_t len);399void add_obj(oop p, size_t len) { add_obj((HeapWord*)p, len); }400401// Fill in the regions covering [beg, end) so that no data moves; i.e., the402// destination of region n is simply the start of region n. The argument beg403// must be region-aligned; end need not be.404void summarize_dense_prefix(HeapWord* beg, HeapWord* end);405406HeapWord* summarize_split_space(size_t src_region, SplitInfo& split_info,407HeapWord* destination, HeapWord* target_end,408HeapWord** target_next);409bool summarize(SplitInfo& split_info,410HeapWord* source_beg, HeapWord* source_end,411HeapWord** source_next,412HeapWord* target_beg, HeapWord* target_end,413HeapWord** target_next);414415void clear();416void clear_range(size_t beg_region, size_t end_region);417void clear_range(HeapWord* beg, HeapWord* end) {418clear_range(addr_to_region_idx(beg), addr_to_region_idx(end));419}420421// Return the number of words between addr and the start of the region422// containing addr.423inline size_t region_offset(const HeapWord* addr) const;424425// Convert addresses to/from a region index or region pointer.426inline size_t addr_to_region_idx(const HeapWord* addr) const;427inline RegionData* addr_to_region_ptr(const HeapWord* addr) const;428inline HeapWord* region_to_addr(size_t region) const;429inline HeapWord* region_to_addr(size_t region, size_t offset) const;430inline HeapWord* region_to_addr(const RegionData* region) const;431432inline HeapWord* region_align_down(HeapWord* addr) const;433inline HeapWord* region_align_up(HeapWord* addr) const;434inline bool is_region_aligned(HeapWord* addr) const;435436// Analogous to region_offset() for blocks.437size_t block_offset(const HeapWord* addr) const;438size_t addr_to_block_idx(const HeapWord* addr) const;439size_t addr_to_block_idx(const oop obj) const {440return addr_to_block_idx((HeapWord*) obj);441}442inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;443inline HeapWord* block_to_addr(size_t block) const;444inline size_t region_to_block_idx(size_t region) const;445446inline HeapWord* block_align_down(HeapWord* addr) const;447inline HeapWord* block_align_up(HeapWord* addr) const;448inline bool is_block_aligned(HeapWord* addr) const;449450// Return the address one past the end of the partial object.451HeapWord* partial_obj_end(size_t region_idx) const;452453// Return the location of the object after compaction.454HeapWord* calc_new_pointer(HeapWord* addr);455456HeapWord* calc_new_pointer(oop p) {457return calc_new_pointer((HeapWord*) p);458}459460#ifdef ASSERT461void verify_clear(const PSVirtualSpace* vspace);462void verify_clear();463#endif // #ifdef ASSERT464465private:466bool initialize_block_data();467bool initialize_region_data(size_t region_size);468PSVirtualSpace* create_vspace(size_t count, size_t element_size);469470private:471HeapWord* _region_start;472#ifdef ASSERT473HeapWord* _region_end;474#endif // #ifdef ASSERT475476PSVirtualSpace* _region_vspace;477size_t _reserved_byte_size;478RegionData* _region_data;479size_t _region_count;480481PSVirtualSpace* _block_vspace;482BlockData* _block_data;483size_t _block_count;484};485486inline uint487ParallelCompactData::RegionData::destination_count_raw() const488{489return _dc_and_los & dc_mask;490}491492inline uint493ParallelCompactData::RegionData::destination_count() const494{495return destination_count_raw() >> dc_shift;496}497498inline bool499ParallelCompactData::RegionData::blocks_filled() const500{501bool result = _blocks_filled;502OrderAccess::acquire();503return result;504}505506#ifdef ASSERT507inline size_t508ParallelCompactData::RegionData::blocks_filled_count() const509{510return _blocks_filled_count;511}512#endif // #ifdef ASSERT513514inline void515ParallelCompactData::RegionData::set_blocks_filled()516{517OrderAccess::release();518_blocks_filled = true;519// Debug builds count the number of times the table was filled.520DEBUG_ONLY(Atomic::inc_ptr(&_blocks_filled_count));521}522523inline void524ParallelCompactData::RegionData::set_destination_count(uint count)525{526assert(count <= (dc_completed >> dc_shift), "count too large");527const region_sz_t live_sz = (region_sz_t) live_obj_size();528_dc_and_los = (count << dc_shift) | live_sz;529}530531inline void ParallelCompactData::RegionData::set_live_obj_size(size_t words)532{533assert(words <= los_mask, "would overflow");534_dc_and_los = destination_count_raw() | (region_sz_t)words;535}536537inline void ParallelCompactData::RegionData::decrement_destination_count()538{539assert(_dc_and_los < dc_claimed, "already claimed");540assert(_dc_and_los >= dc_one, "count would go negative");541Atomic::add((int)dc_mask, (volatile int*)&_dc_and_los);542}543544inline HeapWord* ParallelCompactData::RegionData::data_location() const545{546DEBUG_ONLY(return _data_location;)547NOT_DEBUG(return NULL;)548}549550inline HeapWord* ParallelCompactData::RegionData::highest_ref() const551{552DEBUG_ONLY(return _highest_ref;)553NOT_DEBUG(return NULL;)554}555556inline void ParallelCompactData::RegionData::set_data_location(HeapWord* addr)557{558DEBUG_ONLY(_data_location = addr;)559}560561inline void ParallelCompactData::RegionData::set_completed()562{563assert(claimed(), "must be claimed first");564_dc_and_los = dc_completed | (region_sz_t) live_obj_size();565}566567// MT-unsafe claiming of a region. Should only be used during single threaded568// execution.569inline bool ParallelCompactData::RegionData::claim_unsafe()570{571if (available()) {572_dc_and_los |= dc_claimed;573return true;574}575return false;576}577578inline void ParallelCompactData::RegionData::add_live_obj(size_t words)579{580assert(words <= (size_t)los_mask - live_obj_size(), "overflow");581Atomic::add((int) words, (volatile int*) &_dc_and_los);582}583584inline void ParallelCompactData::RegionData::set_highest_ref(HeapWord* addr)585{586#ifdef ASSERT587HeapWord* tmp = _highest_ref;588while (addr > tmp) {589tmp = (HeapWord*)Atomic::cmpxchg_ptr(addr, &_highest_ref, tmp);590}591#endif // #ifdef ASSERT592}593594inline bool ParallelCompactData::RegionData::claim()595{596const int los = (int) live_obj_size();597const int old = Atomic::cmpxchg(dc_claimed | los,598(volatile int*) &_dc_and_los, los);599return old == los;600}601602inline ParallelCompactData::RegionData*603ParallelCompactData::region(size_t region_idx) const604{605assert(region_idx <= region_count(), "bad arg");606return _region_data + region_idx;607}608609inline size_t610ParallelCompactData::region(const RegionData* const region_ptr) const611{612assert(region_ptr >= _region_data, "bad arg");613assert(region_ptr <= _region_data + region_count(), "bad arg");614return pointer_delta(region_ptr, _region_data, sizeof(RegionData));615}616617inline ParallelCompactData::BlockData*618ParallelCompactData::block(size_t n) const {619assert(n < block_count(), "bad arg");620return _block_data + n;621}622623inline size_t624ParallelCompactData::region_offset(const HeapWord* addr) const625{626assert(addr >= _region_start, "bad addr");627assert(addr <= _region_end, "bad addr");628return (size_t(addr) & RegionAddrOffsetMask) >> LogHeapWordSize;629}630631inline size_t632ParallelCompactData::addr_to_region_idx(const HeapWord* addr) const633{634assert(addr >= _region_start, "bad addr");635assert(addr <= _region_end, "bad addr");636return pointer_delta(addr, _region_start) >> Log2RegionSize;637}638639inline ParallelCompactData::RegionData*640ParallelCompactData::addr_to_region_ptr(const HeapWord* addr) const641{642return region(addr_to_region_idx(addr));643}644645inline HeapWord*646ParallelCompactData::region_to_addr(size_t region) const647{648assert(region <= _region_count, "region out of range");649return _region_start + (region << Log2RegionSize);650}651652inline HeapWord*653ParallelCompactData::region_to_addr(const RegionData* region) const654{655return region_to_addr(pointer_delta(region, _region_data,656sizeof(RegionData)));657}658659inline HeapWord*660ParallelCompactData::region_to_addr(size_t region, size_t offset) const661{662assert(region <= _region_count, "region out of range");663assert(offset < RegionSize, "offset too big"); // This may be too strict.664return region_to_addr(region) + offset;665}666667inline HeapWord*668ParallelCompactData::region_align_down(HeapWord* addr) const669{670assert(addr >= _region_start, "bad addr");671assert(addr < _region_end + RegionSize, "bad addr");672return (HeapWord*)(size_t(addr) & RegionAddrMask);673}674675inline HeapWord*676ParallelCompactData::region_align_up(HeapWord* addr) const677{678assert(addr >= _region_start, "bad addr");679assert(addr <= _region_end, "bad addr");680return region_align_down(addr + RegionSizeOffsetMask);681}682683inline bool684ParallelCompactData::is_region_aligned(HeapWord* addr) const685{686return region_offset(addr) == 0;687}688689inline size_t690ParallelCompactData::block_offset(const HeapWord* addr) const691{692assert(addr >= _region_start, "bad addr");693assert(addr <= _region_end, "bad addr");694return (size_t(addr) & BlockAddrOffsetMask) >> LogHeapWordSize;695}696697inline size_t698ParallelCompactData::addr_to_block_idx(const HeapWord* addr) const699{700assert(addr >= _region_start, "bad addr");701assert(addr <= _region_end, "bad addr");702return pointer_delta(addr, _region_start) >> Log2BlockSize;703}704705inline ParallelCompactData::BlockData*706ParallelCompactData::addr_to_block_ptr(const HeapWord* addr) const707{708return block(addr_to_block_idx(addr));709}710711inline HeapWord*712ParallelCompactData::block_to_addr(size_t block) const713{714assert(block < _block_count, "block out of range");715return _region_start + (block << Log2BlockSize);716}717718inline size_t719ParallelCompactData::region_to_block_idx(size_t region) const720{721return region << Log2BlocksPerRegion;722}723724inline HeapWord*725ParallelCompactData::block_align_down(HeapWord* addr) const726{727assert(addr >= _region_start, "bad addr");728assert(addr < _region_end + RegionSize, "bad addr");729return (HeapWord*)(size_t(addr) & BlockAddrMask);730}731732inline HeapWord*733ParallelCompactData::block_align_up(HeapWord* addr) const734{735assert(addr >= _region_start, "bad addr");736assert(addr <= _region_end, "bad addr");737return block_align_down(addr + BlockSizeOffsetMask);738}739740inline bool741ParallelCompactData::is_block_aligned(HeapWord* addr) const742{743return block_offset(addr) == 0;744}745746// Abstract closure for use with ParMarkBitMap::iterate(), which will invoke the747// do_addr() method.748//749// The closure is initialized with the number of heap words to process750// (words_remaining()), and becomes 'full' when it reaches 0. The do_addr()751// methods in subclasses should update the total as words are processed. Since752// only one subclass actually uses this mechanism to terminate iteration, the753// default initial value is > 0. The implementation is here and not in the754// single subclass that uses it to avoid making is_full() virtual, and thus755// adding a virtual call per live object.756757class ParMarkBitMapClosure: public StackObj {758public:759typedef ParMarkBitMap::idx_t idx_t;760typedef ParMarkBitMap::IterationStatus IterationStatus;761762public:763inline ParMarkBitMapClosure(ParMarkBitMap* mbm, ParCompactionManager* cm,764size_t words = max_uintx);765766inline ParCompactionManager* compaction_manager() const;767inline ParMarkBitMap* bitmap() const;768inline size_t words_remaining() const;769inline bool is_full() const;770inline HeapWord* source() const;771772inline void set_source(HeapWord* addr);773774virtual IterationStatus do_addr(HeapWord* addr, size_t words) = 0;775776protected:777inline void decrement_words_remaining(size_t words);778779private:780ParMarkBitMap* const _bitmap;781ParCompactionManager* const _compaction_manager;782DEBUG_ONLY(const size_t _initial_words_remaining;) // Useful in debugger.783size_t _words_remaining; // Words left to copy.784785protected:786HeapWord* _source; // Next addr that would be read.787};788789inline790ParMarkBitMapClosure::ParMarkBitMapClosure(ParMarkBitMap* bitmap,791ParCompactionManager* cm,792size_t words):793_bitmap(bitmap), _compaction_manager(cm)794#ifdef ASSERT795, _initial_words_remaining(words)796#endif797{798_words_remaining = words;799_source = NULL;800}801802inline ParCompactionManager* ParMarkBitMapClosure::compaction_manager() const {803return _compaction_manager;804}805806inline ParMarkBitMap* ParMarkBitMapClosure::bitmap() const {807return _bitmap;808}809810inline size_t ParMarkBitMapClosure::words_remaining() const {811return _words_remaining;812}813814inline bool ParMarkBitMapClosure::is_full() const {815return words_remaining() == 0;816}817818inline HeapWord* ParMarkBitMapClosure::source() const {819return _source;820}821822inline void ParMarkBitMapClosure::set_source(HeapWord* addr) {823_source = addr;824}825826inline void ParMarkBitMapClosure::decrement_words_remaining(size_t words) {827assert(_words_remaining >= words, "processed too many words");828_words_remaining -= words;829}830831// The UseParallelOldGC collector is a stop-the-world garbage collector that832// does parts of the collection using parallel threads. The collection includes833// the tenured generation and the young generation. The permanent generation is834// collected at the same time as the other two generations but the permanent835// generation is collect by a single GC thread. The permanent generation is836// collected serially because of the requirement that during the processing of a837// klass AAA, any objects reference by AAA must already have been processed.838// This requirement is enforced by a left (lower address) to right (higher839// address) sliding compaction.840//841// There are four phases of the collection.842//843// - marking phase844// - summary phase845// - compacting phase846// - clean up phase847//848// Roughly speaking these phases correspond, respectively, to849// - mark all the live objects850// - calculate the destination of each object at the end of the collection851// - move the objects to their destination852// - update some references and reinitialize some variables853//854// These three phases are invoked in PSParallelCompact::invoke_no_policy(). The855// marking phase is implemented in PSParallelCompact::marking_phase() and does a856// complete marking of the heap. The summary phase is implemented in857// PSParallelCompact::summary_phase(). The move and update phase is implemented858// in PSParallelCompact::compact().859//860// A space that is being collected is divided into regions and with each region861// is associated an object of type ParallelCompactData. Each region is of a862// fixed size and typically will contain more than 1 object and may have parts863// of objects at the front and back of the region.864//865// region -----+---------------------+----------866// objects covered [ AAA )[ BBB )[ CCC )[ DDD )867//868// The marking phase does a complete marking of all live objects in the heap.869// The marking also compiles the size of the data for all live objects covered870// by the region. This size includes the part of any live object spanning onto871// the region (part of AAA if it is live) from the front, all live objects872// contained in the region (BBB and/or CCC if they are live), and the part of873// any live objects covered by the region that extends off the region (part of874// DDD if it is live). The marking phase uses multiple GC threads and marking875// is done in a bit array of type ParMarkBitMap. The marking of the bit map is876// done atomically as is the accumulation of the size of the live objects877// covered by a region.878//879// The summary phase calculates the total live data to the left of each region880// XXX. Based on that total and the bottom of the space, it can calculate the881// starting location of the live data in XXX. The summary phase calculates for882// each region XXX quantites such as883//884// - the amount of live data at the beginning of a region from an object885// entering the region.886// - the location of the first live data on the region887// - a count of the number of regions receiving live data from XXX.888//889// See ParallelCompactData for precise details. The summary phase also890// calculates the dense prefix for the compaction. The dense prefix is a891// portion at the beginning of the space that is not moved. The objects in the892// dense prefix do need to have their object references updated. See method893// summarize_dense_prefix().894//895// The summary phase is done using 1 GC thread.896//897// The compaction phase moves objects to their new location and updates all898// references in the object.899//900// A current exception is that objects that cross a region boundary are moved901// but do not have their references updated. References are not updated because902// it cannot easily be determined if the klass pointer KKK for the object AAA903// has been updated. KKK likely resides in a region to the left of the region904// containing AAA. These AAA's have there references updated at the end in a905// clean up phase. See the method PSParallelCompact::update_deferred_objects().906// An alternate strategy is being investigated for this deferral of updating.907//908// Compaction is done on a region basis. A region that is ready to be filled is909// put on a ready list and GC threads take region off the list and fill them. A910// region is ready to be filled if it empty of live objects. Such a region may911// have been initially empty (only contained dead objects) or may have had all912// its live objects copied out already. A region that compacts into itself is913// also ready for filling. The ready list is initially filled with empty914// regions and regions compacting into themselves. There is always at least 1915// region that can be put on the ready list. The regions are atomically added916// and removed from the ready list.917918class PSParallelCompact : AllStatic {919public:920// Convenient access to type names.921typedef ParMarkBitMap::idx_t idx_t;922typedef ParallelCompactData::RegionData RegionData;923typedef ParallelCompactData::BlockData BlockData;924925typedef enum {926old_space_id, eden_space_id,927from_space_id, to_space_id, last_space_id928} SpaceId;929930public:931// Inline closure decls932//933class IsAliveClosure: public BoolObjectClosure {934public:935virtual bool do_object_b(oop p);936};937938class KeepAliveClosure: public OopClosure {939private:940ParCompactionManager* _compaction_manager;941protected:942template <class T> inline void do_oop_work(T* p);943public:944KeepAliveClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }945virtual void do_oop(oop* p);946virtual void do_oop(narrowOop* p);947};948949class FollowStackClosure: public VoidClosure {950private:951ParCompactionManager* _compaction_manager;952public:953FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }954virtual void do_void();955};956957class AdjustPointerClosure: public OopClosure {958public:959virtual void do_oop(oop* p);960virtual void do_oop(narrowOop* p);961// do not walk from thread stacks to the code cache on this phase962virtual void do_code_blob(CodeBlob* cb) const { }963};964965class AdjustKlassClosure : public KlassClosure {966public:967void do_klass(Klass* klass);968};969970friend class KeepAliveClosure;971friend class FollowStackClosure;972friend class AdjustPointerClosure;973friend class AdjustKlassClosure;974friend class FollowKlassClosure;975friend class InstanceClassLoaderKlass;976friend class RefProcTaskProxy;977978private:979static STWGCTimer _gc_timer;980static ParallelOldTracer _gc_tracer;981static elapsedTimer _accumulated_time;982static unsigned int _total_invocations;983static unsigned int _maximum_compaction_gc_num;984static jlong _time_of_last_gc; // ms985static CollectorCounters* _counters;986static ParMarkBitMap _mark_bitmap;987static ParallelCompactData _summary_data;988static IsAliveClosure _is_alive_closure;989static SpaceInfo _space_info[last_space_id];990static bool _print_phases;991static AdjustPointerClosure _adjust_pointer_closure;992static AdjustKlassClosure _adjust_klass_closure;993994// Reference processing (used in ...follow_contents)995static ReferenceProcessor* _ref_processor;996997// Updated location of intArrayKlassObj.998static Klass* _updated_int_array_klass_obj;9991000// Values computed at initialization and used by dead_wood_limiter().1001static double _dwl_mean;1002static double _dwl_std_dev;1003static double _dwl_first_term;1004static double _dwl_adjustment;1005#ifdef ASSERT1006static bool _dwl_initialized;1007#endif // #ifdef ASSERT100810091010public:1011static ParallelOldTracer* gc_tracer() { return &_gc_tracer; }10121013private:10141015static void initialize_space_info();10161017// Return true if details about individual phases should be printed.1018static inline bool print_phases();10191020// Clear the marking bitmap and summary data that cover the specified space.1021static void clear_data_covering_space(SpaceId id);10221023static void pre_compact(PreGCValues* pre_gc_values);1024static void post_compact();10251026// Mark live objects1027static void marking_phase(ParCompactionManager* cm,1028bool maximum_heap_compaction,1029ParallelOldTracer *gc_tracer);10301031template <class T>1032static inline void follow_root(ParCompactionManager* cm, T* p);10331034// Compute the dense prefix for the designated space. This is an experimental1035// implementation currently not used in production.1036static HeapWord* compute_dense_prefix_via_density(const SpaceId id,1037bool maximum_compaction);10381039// Methods used to compute the dense prefix.10401041// Compute the value of the normal distribution at x = density. The mean and1042// standard deviation are values saved by initialize_dead_wood_limiter().1043static inline double normal_distribution(double density);10441045// Initialize the static vars used by dead_wood_limiter().1046static void initialize_dead_wood_limiter();10471048// Return the percentage of space that can be treated as "dead wood" (i.e.,1049// not reclaimed).1050static double dead_wood_limiter(double density, size_t min_percent);10511052// Find the first (left-most) region in the range [beg, end) that has at least1053// dead_words of dead space to the left. The argument beg must be the first1054// region in the space that is not completely live.1055static RegionData* dead_wood_limit_region(const RegionData* beg,1056const RegionData* end,1057size_t dead_words);10581059// Return a pointer to the first region in the range [beg, end) that is not1060// completely full.1061static RegionData* first_dead_space_region(const RegionData* beg,1062const RegionData* end);10631064// Return a value indicating the benefit or 'yield' if the compacted region1065// were to start (or equivalently if the dense prefix were to end) at the1066// candidate region. Higher values are better.1067//1068// The value is based on the amount of space reclaimed vs. the costs of (a)1069// updating references in the dense prefix plus (b) copying objects and1070// updating references in the compacted region.1071static inline double reclaimed_ratio(const RegionData* const candidate,1072HeapWord* const bottom,1073HeapWord* const top,1074HeapWord* const new_top);10751076// Compute the dense prefix for the designated space.1077static HeapWord* compute_dense_prefix(const SpaceId id,1078bool maximum_compaction);10791080// Return true if dead space crosses onto the specified Region; bit must be1081// the bit index corresponding to the first word of the Region.1082static inline bool dead_space_crosses_boundary(const RegionData* region,1083idx_t bit);10841085// Summary phase utility routine to fill dead space (if any) at the dense1086// prefix boundary. Should only be called if the the dense prefix is1087// non-empty.1088static void fill_dense_prefix_end(SpaceId id);10891090// Clear the summary data source_region field for the specified addresses.1091static void clear_source_region(HeapWord* beg_addr, HeapWord* end_addr);10921093#ifndef PRODUCT1094// Routines to provoke splitting a young gen space (ParallelOldGCSplitALot).10951096// Fill the region [start, start + words) with live object(s). Only usable1097// for the old and permanent generations.1098static void fill_with_live_objects(SpaceId id, HeapWord* const start,1099size_t words);1100// Include the new objects in the summary data.1101static void summarize_new_objects(SpaceId id, HeapWord* start);11021103// Add live objects to a survivor space since it's rare that both survivors1104// are non-empty.1105static void provoke_split_fill_survivor(SpaceId id);11061107// Add live objects and/or choose the dense prefix to provoke splitting.1108static void provoke_split(bool & maximum_compaction);1109#endif11101111static void summarize_spaces_quick();1112static void summarize_space(SpaceId id, bool maximum_compaction);1113static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);11141115// Adjust addresses in roots. Does not adjust addresses in heap.1116static void adjust_roots();11171118DEBUG_ONLY(static void write_block_fill_histogram(outputStream* const out);)11191120// Move objects to new locations.1121static void compact_perm(ParCompactionManager* cm);1122static void compact();11231124// Add available regions to the stack and draining tasks to the task queue.1125static void enqueue_region_draining_tasks(GCTaskQueue* q,1126uint parallel_gc_threads);11271128// Add dense prefix update tasks to the task queue.1129static void enqueue_dense_prefix_tasks(GCTaskQueue* q,1130uint parallel_gc_threads);11311132// Add region stealing tasks to the task queue.1133static void enqueue_region_stealing_tasks(1134GCTaskQueue* q,1135ParallelTaskTerminator* terminator_ptr,1136uint parallel_gc_threads);11371138// If objects are left in eden after a collection, try to move the boundary1139// and absorb them into the old gen. Returns true if eden was emptied.1140static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,1141PSYoungGen* young_gen,1142PSOldGen* old_gen);11431144// Reset time since last full gc1145static void reset_millis_since_last_gc();11461147public:1148class MarkAndPushClosure: public OopClosure {1149private:1150ParCompactionManager* _compaction_manager;1151public:1152MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }1153virtual void do_oop(oop* p);1154virtual void do_oop(narrowOop* p);1155};11561157// The one and only place to start following the classes.1158// Should only be applied to the ClassLoaderData klasses list.1159class FollowKlassClosure : public KlassClosure {1160private:1161MarkAndPushClosure* _mark_and_push_closure;1162public:1163FollowKlassClosure(MarkAndPushClosure* mark_and_push_closure) :1164_mark_and_push_closure(mark_and_push_closure) { }1165void do_klass(Klass* klass);1166};11671168PSParallelCompact();11691170// Convenient accessor for Universe::heap().1171static ParallelScavengeHeap* gc_heap() {1172return (ParallelScavengeHeap*)Universe::heap();1173}11741175static void invoke(bool maximum_heap_compaction);1176static bool invoke_no_policy(bool maximum_heap_compaction);11771178static void post_initialize();1179// Perform initialization for PSParallelCompact that requires1180// allocations. This should be called during the VM initialization1181// at a pointer where it would be appropriate to return a JNI_ENOMEM1182// in the event of a failure.1183static bool initialize();11841185// Closure accessors1186static OopClosure* adjust_pointer_closure() { return (OopClosure*)&_adjust_pointer_closure; }1187static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }1188static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }11891190// Public accessors1191static elapsedTimer* accumulated_time() { return &_accumulated_time; }1192static unsigned int total_invocations() { return _total_invocations; }1193static CollectorCounters* counters() { return _counters; }11941195// Used to add tasks1196static GCTaskManager* const gc_task_manager();1197static Klass* updated_int_array_klass_obj() {1198return _updated_int_array_klass_obj;1199}12001201// Marking support1202static inline bool mark_obj(oop obj);1203static inline bool is_marked(oop obj);1204// Check mark and maybe push on marking stack1205template <class T> static inline void mark_and_push(ParCompactionManager* cm,1206T* p);1207template <class T> static inline void adjust_pointer(T* p);12081209static inline void follow_klass(ParCompactionManager* cm, Klass* klass);12101211static void follow_class_loader(ParCompactionManager* cm,1212ClassLoaderData* klass);12131214// Compaction support.1215// Return true if p is in the range [beg_addr, end_addr).1216static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);1217static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);12181219// Convenience wrappers for per-space data kept in _space_info.1220static inline MutableSpace* space(SpaceId space_id);1221static inline HeapWord* new_top(SpaceId space_id);1222static inline HeapWord* dense_prefix(SpaceId space_id);1223static inline ObjectStartArray* start_array(SpaceId space_id);12241225// Move and update the live objects in the specified space.1226static void move_and_update(ParCompactionManager* cm, SpaceId space_id);12271228// Process the end of the given region range in the dense prefix.1229// This includes saving any object not updated.1230static void dense_prefix_regions_epilogue(ParCompactionManager* cm,1231size_t region_start_index,1232size_t region_end_index,1233idx_t exiting_object_offset,1234idx_t region_offset_start,1235idx_t region_offset_end);12361237// Update a region in the dense prefix. For each live object1238// in the region, update it's interior references. For each1239// dead object, fill it with deadwood. Dead space at the end1240// of a region range will be filled to the start of the next1241// live object regardless of the region_index_end. None of the1242// objects in the dense prefix move and dead space is dead1243// (holds only dead objects that don't need any processing), so1244// dead space can be filled in any order.1245static void update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,1246SpaceId space_id,1247size_t region_index_start,1248size_t region_index_end);12491250// Return the address of the count + 1st live word in the range [beg, end).1251static HeapWord* skip_live_words(HeapWord* beg, HeapWord* end, size_t count);12521253// Return the address of the word to be copied to dest_addr, which must be1254// aligned to a region boundary.1255static HeapWord* first_src_addr(HeapWord* const dest_addr,1256SpaceId src_space_id,1257size_t src_region_idx);12581259// Determine the next source region, set closure.source() to the start of the1260// new region return the region index. Parameter end_addr is the address one1261// beyond the end of source range just processed. If necessary, switch to a1262// new source space and set src_space_id (in-out parameter) and src_space_top1263// (out parameter) accordingly.1264static size_t next_src_region(MoveAndUpdateClosure& closure,1265SpaceId& src_space_id,1266HeapWord*& src_space_top,1267HeapWord* end_addr);12681269// Decrement the destination count for each non-empty source region in the1270// range [beg_region, region(region_align_up(end_addr))). If the destination1271// count for a region goes to 0 and it needs to be filled, enqueue it.1272static void decrement_destination_counts(ParCompactionManager* cm,1273SpaceId src_space_id,1274size_t beg_region,1275HeapWord* end_addr);12761277// Fill a region, copying objects from one or more source regions.1278static void fill_region(ParCompactionManager* cm, size_t region_idx);1279static void fill_and_update_region(ParCompactionManager* cm, size_t region) {1280fill_region(cm, region);1281}12821283// Fill in the block table for the specified region.1284static void fill_blocks(size_t region_idx);12851286// Update the deferred objects in the space.1287static void update_deferred_objects(ParCompactionManager* cm, SpaceId id);12881289static ParMarkBitMap* mark_bitmap() { return &_mark_bitmap; }1290static ParallelCompactData& summary_data() { return _summary_data; }12911292// Reference Processing1293static ReferenceProcessor* const ref_processor() { return _ref_processor; }12941295static STWGCTimer* gc_timer() { return &_gc_timer; }12961297// Return the SpaceId for the given address.1298static SpaceId space_id(HeapWord* addr);12991300// Time since last full gc (in milliseconds).1301static jlong millis_since_last_gc();13021303static void print_on_error(outputStream* st);13041305#ifndef PRODUCT1306// Debugging support.1307static const char* space_names[last_space_id];1308static void print_region_ranges();1309static void print_dense_prefix_stats(const char* const algorithm,1310const SpaceId id,1311const bool maximum_compaction,1312HeapWord* const addr);1313static void summary_phase_msg(SpaceId dst_space_id,1314HeapWord* dst_beg, HeapWord* dst_end,1315SpaceId src_space_id,1316HeapWord* src_beg, HeapWord* src_end);1317#endif // #ifndef PRODUCT13181319#ifdef ASSERT1320// Sanity check the new location of a word in the heap.1321static inline void check_new_location(HeapWord* old_addr, HeapWord* new_addr);1322// Verify that all the regions have been emptied.1323static void verify_complete(SpaceId space_id);1324#endif // #ifdef ASSERT1325};13261327inline bool PSParallelCompact::mark_obj(oop obj) {1328const int obj_size = obj->size();1329if (mark_bitmap()->mark_obj(obj, obj_size)) {1330_summary_data.add_obj(obj, obj_size);1331return true;1332} else {1333return false;1334}1335}13361337inline bool PSParallelCompact::is_marked(oop obj) {1338return mark_bitmap()->is_marked(obj);1339}13401341template <class T>1342inline void PSParallelCompact::follow_root(ParCompactionManager* cm, T* p) {1343assert(!Universe::heap()->is_in_reserved(p),1344"roots shouldn't be things within the heap");13451346T heap_oop = oopDesc::load_heap_oop(p);1347if (!oopDesc::is_null(heap_oop)) {1348oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);1349if (mark_bitmap()->is_unmarked(obj)) {1350if (mark_obj(obj)) {1351obj->follow_contents(cm);1352}1353}1354}1355cm->follow_marking_stacks();1356}13571358template <class T>1359inline void PSParallelCompact::mark_and_push(ParCompactionManager* cm, T* p) {1360T heap_oop = oopDesc::load_heap_oop(p);1361if (!oopDesc::is_null(heap_oop)) {1362oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);1363if (mark_bitmap()->is_unmarked(obj) && mark_obj(obj)) {1364cm->push(obj);1365}1366}1367}13681369template <class T>1370inline void PSParallelCompact::adjust_pointer(T* p) {1371T heap_oop = oopDesc::load_heap_oop(p);1372if (!oopDesc::is_null(heap_oop)) {1373oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);1374oop new_obj = (oop)summary_data().calc_new_pointer(obj);1375assert(new_obj != NULL, // is forwarding ptr?1376"should be forwarded");1377// Just always do the update unconditionally?1378if (new_obj != NULL) {1379assert(Universe::heap()->is_in_reserved(new_obj),1380"should be in object space");1381oopDesc::encode_store_heap_oop_not_null(p, new_obj);1382}1383}1384}13851386inline void PSParallelCompact::follow_klass(ParCompactionManager* cm, Klass* klass) {1387oop holder = klass->klass_holder();1388PSParallelCompact::mark_and_push(cm, &holder);1389}13901391template <class T>1392inline void PSParallelCompact::KeepAliveClosure::do_oop_work(T* p) {1393mark_and_push(_compaction_manager, p);1394}13951396inline bool PSParallelCompact::print_phases() {1397return _print_phases;1398}13991400inline double PSParallelCompact::normal_distribution(double density) {1401assert(_dwl_initialized, "uninitialized");1402const double squared_term = (density - _dwl_mean) / _dwl_std_dev;1403return _dwl_first_term * exp(-0.5 * squared_term * squared_term);1404}14051406inline bool1407PSParallelCompact::dead_space_crosses_boundary(const RegionData* region,1408idx_t bit)1409{1410assert(bit > 0, "cannot call this for the first bit/region");1411assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),1412"sanity check");14131414// Dead space crosses the boundary if (1) a partial object does not extend1415// onto the region, (2) an object does not start at the beginning of the1416// region, and (3) an object does not end at the end of the prior region.1417return region->partial_obj_size() == 0 &&1418!_mark_bitmap.is_obj_beg(bit) &&1419!_mark_bitmap.is_obj_end(bit - 1);1420}14211422inline bool1423PSParallelCompact::is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr) {1424return p >= beg_addr && p < end_addr;1425}14261427inline bool1428PSParallelCompact::is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr) {1429return is_in((HeapWord*)p, beg_addr, end_addr);1430}14311432inline MutableSpace* PSParallelCompact::space(SpaceId id) {1433assert(id < last_space_id, "id out of range");1434return _space_info[id].space();1435}14361437inline HeapWord* PSParallelCompact::new_top(SpaceId id) {1438assert(id < last_space_id, "id out of range");1439return _space_info[id].new_top();1440}14411442inline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {1443assert(id < last_space_id, "id out of range");1444return _space_info[id].dense_prefix();1445}14461447inline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {1448assert(id < last_space_id, "id out of range");1449return _space_info[id].start_array();1450}14511452#ifdef ASSERT1453inline void1454PSParallelCompact::check_new_location(HeapWord* old_addr, HeapWord* new_addr)1455{1456assert(old_addr >= new_addr || space_id(old_addr) != space_id(new_addr),1457"must move left or to a different space");1458assert(is_object_aligned((intptr_t)old_addr) && is_object_aligned((intptr_t)new_addr),1459"checking alignment");1460}1461#endif // ASSERT14621463class MoveAndUpdateClosure: public ParMarkBitMapClosure {1464public:1465inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, ParCompactionManager* cm,1466ObjectStartArray* start_array,1467HeapWord* destination, size_t words);14681469// Accessors.1470HeapWord* destination() const { return _destination; }14711472// If the object will fit (size <= words_remaining()), copy it to the current1473// destination, update the interior oops and the start array and return either1474// full (if the closure is full) or incomplete. If the object will not fit,1475// return would_overflow.1476virtual IterationStatus do_addr(HeapWord* addr, size_t size);14771478// Copy enough words to fill this closure, starting at source(). Interior1479// oops and the start array are not updated. Return full.1480IterationStatus copy_until_full();14811482// Copy enough words to fill this closure or to the end of an object,1483// whichever is smaller, starting at source(). Interior oops and the start1484// array are not updated.1485void copy_partial_obj();14861487protected:1488// Update variables to indicate that word_count words were processed.1489inline void update_state(size_t word_count);14901491protected:1492ObjectStartArray* const _start_array;1493HeapWord* _destination; // Next addr to be written.1494};14951496inline1497MoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap,1498ParCompactionManager* cm,1499ObjectStartArray* start_array,1500HeapWord* destination,1501size_t words) :1502ParMarkBitMapClosure(bitmap, cm, words), _start_array(start_array)1503{1504_destination = destination;1505}15061507inline void MoveAndUpdateClosure::update_state(size_t words)1508{1509decrement_words_remaining(words);1510_source += words;1511_destination += words;1512}15131514class UpdateOnlyClosure: public ParMarkBitMapClosure {1515private:1516const PSParallelCompact::SpaceId _space_id;1517ObjectStartArray* const _start_array;15181519public:1520UpdateOnlyClosure(ParMarkBitMap* mbm,1521ParCompactionManager* cm,1522PSParallelCompact::SpaceId space_id);15231524// Update the object.1525virtual IterationStatus do_addr(HeapWord* addr, size_t words);15261527inline void do_addr(HeapWord* addr);1528};15291530inline void UpdateOnlyClosure::do_addr(HeapWord* addr)1531{1532_start_array->allocate_block(addr);1533oop(addr)->update_contents(compaction_manager());1534}15351536class FillClosure: public ParMarkBitMapClosure1537{1538public:1539FillClosure(ParCompactionManager* cm, PSParallelCompact::SpaceId space_id) :1540ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm),1541_start_array(PSParallelCompact::start_array(space_id))1542{1543assert(space_id == PSParallelCompact::old_space_id,1544"cannot use FillClosure in the young gen");1545}15461547virtual IterationStatus do_addr(HeapWord* addr, size_t size) {1548CollectedHeap::fill_with_objects(addr, size);1549HeapWord* const end = addr + size;1550do {1551_start_array->allocate_block(addr);1552addr += oop(addr)->size();1553} while (addr < end);1554return ParMarkBitMap::incomplete;1555}15561557private:1558ObjectStartArray* const _start_array;1559};15601561#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP156215631564