0N/A/*
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 *
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 *
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 *
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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
1879N/A
1879N/A#include "gc_implementation/parallelScavenge/objectStartArray.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
1879N/A#include "gc_implementation/shared/collectorCounters.hpp"
1879N/A#include "gc_implementation/shared/markSweep.hpp"
1879N/A#include "gc_implementation/shared/mutableSpace.hpp"
1879N/A#include "memory/sharedHeap.hpp"
1879N/A#include "oops/oop.hpp"
1879N/A
0N/Aclass ParallelScavengeHeap;
0N/Aclass PSAdaptiveSizePolicy;
0N/Aclass PSYoungGen;
0N/Aclass PSOldGen;
0N/Aclass PSPermGen;
0N/Aclass ParCompactionManager;
0N/Aclass ParallelTaskTerminator;
0N/Aclass PSParallelCompact;
0N/Aclass GCTaskManager;
0N/Aclass GCTaskQueue;
0N/Aclass PreGCValues;
0N/Aclass MoveAndUpdateClosure;
0N/Aclass RefProcTaskExecutor;
4141N/Aclass ParallelOldTracer;
4141N/Aclass STWGCTimer;
0N/A
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//
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//
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//
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//
482N/A// Notes:
482N/A//
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//
482N/A// At most one region is split per space, so the amount of data required is
482N/A// constant.
482N/A//
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//
482N/A// Future work:
482N/A//
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//
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// destination region.
482N/A
482N/Aclass SplitInfo
482N/A{
482N/Apublic:
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 bool is_valid() const { return _src_region_idx > 0; }
482N/A
482N/A // Return true if this split holds data for the specified source region.
482N/A inline bool is_split(size_t source_region) const;
482N/A
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 size_t src_region_idx() const { return _src_region_idx; }
482N/A size_t partial_obj_size() const { return _partial_obj_size; }
482N/A HeapWord* destination() const { return _destination; }
482N/A
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 unsigned int destination_count() const { return _destination_count; }
482N/A
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 HeapWord* dest_region_addr() const { return _dest_region_addr; }
482N/A
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 HeapWord* first_src_addr() const { return _first_src_addr; }
482N/A
482N/A // Record the data necessary to split the region src_region_idx.
482N/A void record(size_t src_region_idx, size_t partial_obj_size,
482N/A HeapWord* destination);
482N/A
482N/A void clear();
482N/A
482N/A DEBUG_ONLY(void verify_clear();)
482N/A
482N/Aprivate:
482N/A size_t _src_region_idx;
482N/A size_t _partial_obj_size;
482N/A HeapWord* _destination;
482N/A unsigned int _destination_count;
482N/A HeapWord* _dest_region_addr;
482N/A HeapWord* _first_src_addr;
482N/A};
482N/A
482N/Ainline bool SplitInfo::is_split(size_t region_idx) const
482N/A{
482N/A return _src_region_idx == region_idx && is_valid();
482N/A}
482N/A
0N/Aclass SpaceInfo
0N/A{
0N/A public:
0N/A MutableSpace* space() const { return _space; }
0N/A
0N/A // Where the free space will start after the collection. Valid only after the
0N/A // summary phase completes.
0N/A HeapWord* new_top() const { return _new_top; }
0N/A
0N/A // Allows new_top to be set.
0N/A HeapWord** new_top_addr() { return &_new_top; }
0N/A
0N/A // Where the smallest allowable dense prefix ends (used only for perm gen).
0N/A HeapWord* min_dense_prefix() const { return _min_dense_prefix; }
0N/A
0N/A // Where the dense prefix ends, or the compacted region begins.
0N/A HeapWord* dense_prefix() const { return _dense_prefix; }
0N/A
0N/A // The start array for the (generation containing the) space, or NULL if there
0N/A // is no start array.
0N/A ObjectStartArray* start_array() const { return _start_array; }
0N/A
482N/A SplitInfo& split_info() { return _split_info; }
482N/A
0N/A void set_space(MutableSpace* s) { _space = s; }
0N/A void set_new_top(HeapWord* addr) { _new_top = addr; }
0N/A void set_min_dense_prefix(HeapWord* addr) { _min_dense_prefix = addr; }
0N/A void set_dense_prefix(HeapWord* addr) { _dense_prefix = addr; }
0N/A void set_start_array(ObjectStartArray* s) { _start_array = s; }
0N/A
482N/A void publish_new_top() const { _space->set_top(_new_top); }
482N/A
0N/A private:
0N/A MutableSpace* _space;
0N/A HeapWord* _new_top;
0N/A HeapWord* _min_dense_prefix;
0N/A HeapWord* _dense_prefix;
0N/A ObjectStartArray* _start_array;
482N/A SplitInfo _split_info;
0N/A};
0N/A
0N/Aclass ParallelCompactData
0N/A{
0N/Apublic:
0N/A // Sizes are in HeapWords, unless indicated otherwise.
375N/A static const size_t Log2RegionSize;
375N/A static const size_t RegionSize;
375N/A static const size_t RegionSizeBytes;
0N/A
375N/A // Mask for the bits in a size_t to get an offset within a region.
375N/A static const size_t RegionSizeOffsetMask;
375N/A // Mask for the bits in a pointer to get an offset within a region.
375N/A static const size_t RegionAddrOffsetMask;
375N/A // Mask for the bits in a pointer to get the address of the start of a region.
375N/A static const size_t RegionAddrMask;
0N/A
4535N/A static const size_t Log2BlockSize;
4535N/A static const size_t BlockSize;
4535N/A static const size_t BlockSizeBytes;
4535N/A
4535N/A static const size_t BlockSizeOffsetMask;
4535N/A static const size_t BlockAddrOffsetMask;
4535N/A static const size_t BlockAddrMask;
4535N/A
4535N/A static const size_t BlocksPerRegion;
4535N/A static const size_t Log2BlocksPerRegion;
4535N/A
375N/A class RegionData
0N/A {
0N/A public:
375N/A // Destination address of the region.
0N/A HeapWord* destination() const { return _destination; }
0N/A
375N/A // The first region containing data destined for this region.
375N/A size_t source_region() const { return _source_region; }
0N/A
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.
0N/A HeapWord* deferred_obj_addr() const { return _partial_obj_addr; }
0N/A
375N/A // The starting address of the partial object extending onto the region.
0N/A HeapWord* partial_obj_addr() const { return _partial_obj_addr; }
0N/A
375N/A // Size of the partial object extending onto the region (words).
0N/A size_t partial_obj_size() const { return _partial_obj_size; }
0N/A
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).
0N/A size_t live_obj_size() const { return _dc_and_los & los_mask; }
0N/A
375N/A // Total live data that lies within the region (words).
0N/A size_t data_size() const { return partial_obj_size() + live_obj_size(); }
0N/A
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
0N/A //
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.
0N/A //
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
0N/A // then filled.
0N/A //
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
0N/A // (dc_completed).
0N/A inline uint destination_count() const;
0N/A inline uint destination_count_raw() const;
0N/A
4535N/A // Whether the block table for this region has been filled.
4535N/A inline bool blocks_filled() const;
4535N/A
4535N/A // Number of times the block table was filled.
4535N/A DEBUG_ONLY(inline size_t blocks_filled_count() const;)
4535N/A
375N/A // The location of the java heap data that corresponds to this region.
0N/A inline HeapWord* data_location() const;
0N/A
375N/A // The highest address referenced by objects in this region.
0N/A inline HeapWord* highest_ref() const;
0N/A
375N/A // Whether this region is available to be claimed, has been claimed, or has
0N/A // been completed.
0N/A //
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 bool available() const { return _dc_and_los < dc_one; }
0N/A bool claimed() const { return _dc_and_los >= dc_claimed; }
0N/A bool completed() const { return _dc_and_los >= dc_completed; }
0N/A
0N/A // These are not atomic.
0N/A void set_destination(HeapWord* addr) { _destination = addr; }
375N/A void set_source_region(size_t region) { _source_region = region; }
0N/A void set_deferred_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
0N/A void set_partial_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
0N/A void set_partial_obj_size(size_t words) {
375N/A _partial_obj_size = (region_sz_t) words;
0N/A }
4535N/A inline void set_blocks_filled();
0N/A
0N/A inline void set_destination_count(uint count);
0N/A inline void set_live_obj_size(size_t words);
0N/A inline void set_data_location(HeapWord* addr);
0N/A inline void set_completed();
0N/A inline bool claim_unsafe();
0N/A
0N/A // These are atomic.
0N/A inline void add_live_obj(size_t words);
0N/A inline void set_highest_ref(HeapWord* addr);
0N/A inline void decrement_destination_count();
0N/A inline bool claim();
0N/A
0N/A private:
375N/A // The type used to represent object sizes within a region.
375N/A typedef uint region_sz_t;
0N/A
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.
375N/A static const region_sz_t dc_shift; // Shift amount.
375N/A static const region_sz_t dc_mask; // Mask for destination count.
375N/A static const region_sz_t dc_one; // 1, shifted appropriately.
375N/A static const region_sz_t dc_claimed; // Region has been claimed.
375N/A static const region_sz_t dc_completed; // Region has been completed.
375N/A static const region_sz_t los_mask; // Mask for live obj size.
0N/A
375N/A HeapWord* _destination;
375N/A size_t _source_region;
375N/A HeapWord* _partial_obj_addr;
375N/A region_sz_t _partial_obj_size;
375N/A region_sz_t volatile _dc_and_los;
4535N/A bool _blocks_filled;
4535N/A
0N/A#ifdef ASSERT
4535N/A size_t _blocks_filled_count; // Number of block table fills.
4535N/A
0N/A // These enable optimizations that are only partially implemented. Use
0N/A // debug builds to prevent the code fragments from breaking.
375N/A HeapWord* _data_location;
375N/A HeapWord* _highest_ref;
0N/A#endif // #ifdef ASSERT
0N/A
0N/A#ifdef ASSERT
0N/A public:
4535N/A uint _pushed; // 0 until region is pushed onto a stack
0N/A private:
0N/A#endif
0N/A };
0N/A
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.
4535N/A class BlockData
4535N/A {
4535N/A public:
4535N/A typedef unsigned short int blk_ofs_t;
4535N/A
4535N/A blk_ofs_t offset() const { return _offset; }
4535N/A void set_offset(size_t val) { _offset = (blk_ofs_t)val; }
4535N/A
4535N/A private:
4535N/A blk_ofs_t _offset;
4535N/A };
4535N/A
0N/Apublic:
0N/A ParallelCompactData();
0N/A bool initialize(MemRegion covered_region);
0N/A
375N/A size_t region_count() const { return _region_count; }
4550N/A size_t reserved_byte_size() const { return _reserved_byte_size; }
0N/A
375N/A // Convert region indices to/from RegionData pointers.
375N/A inline RegionData* region(size_t region_idx) const;
375N/A inline size_t region(const RegionData* const region_ptr) const;
0N/A
4535N/A size_t block_count() const { return _block_count; }
4535N/A inline BlockData* block(size_t block_idx) const;
4535N/A inline size_t block(const BlockData* block_ptr) const;
0N/A
0N/A void add_obj(HeapWord* addr, size_t len);
0N/A void add_obj(oop p, size_t len) { add_obj((HeapWord*)p, len); }
0N/A
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.
0N/A void summarize_dense_prefix(HeapWord* beg, HeapWord* end);
0N/A
482N/A HeapWord* summarize_split_space(size_t src_region, SplitInfo& split_info,
482N/A HeapWord* destination, HeapWord* target_end,
482N/A HeapWord** target_next);
482N/A bool summarize(SplitInfo& split_info,
0N/A HeapWord* source_beg, HeapWord* source_end,
482N/A HeapWord** source_next,
482N/A HeapWord* target_beg, HeapWord* target_end,
482N/A HeapWord** target_next);
0N/A
0N/A void clear();
375N/A void clear_range(size_t beg_region, size_t end_region);
0N/A void clear_range(HeapWord* beg, HeapWord* end) {
375N/A clear_range(addr_to_region_idx(beg), addr_to_region_idx(end));
0N/A }
0N/A
375N/A // Return the number of words between addr and the start of the region
0N/A // containing addr.
375N/A inline size_t region_offset(const HeapWord* addr) const;
0N/A
375N/A // Convert addresses to/from a region index or region pointer.
375N/A inline size_t addr_to_region_idx(const HeapWord* addr) const;
375N/A inline RegionData* addr_to_region_ptr(const HeapWord* addr) const;
375N/A inline HeapWord* region_to_addr(size_t region) const;
375N/A inline HeapWord* region_to_addr(size_t region, size_t offset) const;
375N/A inline HeapWord* region_to_addr(const RegionData* region) const;
0N/A
375N/A inline HeapWord* region_align_down(HeapWord* addr) const;
375N/A inline HeapWord* region_align_up(HeapWord* addr) const;
375N/A inline bool is_region_aligned(HeapWord* addr) const;
0N/A
4535N/A // Analogous to region_offset() for blocks.
4535N/A size_t block_offset(const HeapWord* addr) const;
4535N/A size_t addr_to_block_idx(const HeapWord* addr) const;
4535N/A size_t addr_to_block_idx(const oop obj) const {
4535N/A return addr_to_block_idx((HeapWord*) obj);
4535N/A }
4535N/A inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;
4535N/A inline HeapWord* block_to_addr(size_t block) const;
4535N/A inline size_t region_to_block_idx(size_t region) const;
4535N/A
4535N/A inline HeapWord* block_align_down(HeapWord* addr) const;
4535N/A inline HeapWord* block_align_up(HeapWord* addr) const;
4535N/A inline bool is_block_aligned(HeapWord* addr) const;
4535N/A
0N/A // Return the address one past the end of the partial object.
375N/A HeapWord* partial_obj_end(size_t region_idx) const;
0N/A
4535N/A // Return the location of the object after compaction.
0N/A HeapWord* calc_new_pointer(HeapWord* addr);
0N/A
0N/A HeapWord* calc_new_pointer(oop p) {
0N/A return calc_new_pointer((HeapWord*) p);
0N/A }
0N/A
0N/A // Return the updated address for the given klass
0N/A klassOop calc_new_klass(klassOop);
0N/A
0N/A#ifdef ASSERT
0N/A void verify_clear(const PSVirtualSpace* vspace);
0N/A void verify_clear();
0N/A#endif // #ifdef ASSERT
0N/A
0N/Aprivate:
4535N/A bool initialize_block_data();
375N/A bool initialize_region_data(size_t region_size);
0N/A PSVirtualSpace* create_vspace(size_t count, size_t element_size);
0N/A
0N/Aprivate:
0N/A HeapWord* _region_start;
0N/A#ifdef ASSERT
0N/A HeapWord* _region_end;
0N/A#endif // #ifdef ASSERT
0N/A
375N/A PSVirtualSpace* _region_vspace;
4550N/A size_t _reserved_byte_size;
375N/A RegionData* _region_data;
375N/A size_t _region_count;
4535N/A
4535N/A PSVirtualSpace* _block_vspace;
4535N/A BlockData* _block_data;
4535N/A size_t _block_count;
0N/A};
0N/A
0N/Ainline uint
375N/AParallelCompactData::RegionData::destination_count_raw() const
0N/A{
0N/A return _dc_and_los & dc_mask;
0N/A}
0N/A
0N/Ainline uint
375N/AParallelCompactData::RegionData::destination_count() const
0N/A{
0N/A return destination_count_raw() >> dc_shift;
0N/A}
0N/A
4535N/Ainline bool
4535N/AParallelCompactData::RegionData::blocks_filled() const
4535N/A{
4535N/A return _blocks_filled;
4535N/A}
4535N/A
4535N/A#ifdef ASSERT
4535N/Ainline size_t
4535N/AParallelCompactData::RegionData::blocks_filled_count() const
4535N/A{
4535N/A return _blocks_filled_count;
4535N/A}
4535N/A#endif // #ifdef ASSERT
4535N/A
4535N/Ainline void
4535N/AParallelCompactData::RegionData::set_blocks_filled()
4535N/A{
4535N/A _blocks_filled = true;
4535N/A // Debug builds count the number of times the table was filled.
4535N/A DEBUG_ONLY(Atomic::inc_ptr(&_blocks_filled_count));
4535N/A}
4535N/A
0N/Ainline void
375N/AParallelCompactData::RegionData::set_destination_count(uint count)
0N/A{
0N/A assert(count <= (dc_completed >> dc_shift), "count too large");
375N/A const region_sz_t live_sz = (region_sz_t) live_obj_size();
0N/A _dc_and_los = (count << dc_shift) | live_sz;
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::set_live_obj_size(size_t words)
0N/A{
0N/A assert(words <= los_mask, "would overflow");
375N/A _dc_and_los = destination_count_raw() | (region_sz_t)words;
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::decrement_destination_count()
0N/A{
0N/A assert(_dc_and_los < dc_claimed, "already claimed");
0N/A assert(_dc_and_los >= dc_one, "count would go negative");
0N/A Atomic::add((int)dc_mask, (volatile int*)&_dc_and_los);
0N/A}
0N/A
375N/Ainline HeapWord* ParallelCompactData::RegionData::data_location() const
0N/A{
0N/A DEBUG_ONLY(return _data_location;)
0N/A NOT_DEBUG(return NULL;)
0N/A}
0N/A
375N/Ainline HeapWord* ParallelCompactData::RegionData::highest_ref() const
0N/A{
0N/A DEBUG_ONLY(return _highest_ref;)
0N/A NOT_DEBUG(return NULL;)
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::set_data_location(HeapWord* addr)
0N/A{
0N/A DEBUG_ONLY(_data_location = addr;)
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::set_completed()
0N/A{
0N/A assert(claimed(), "must be claimed first");
375N/A _dc_and_los = dc_completed | (region_sz_t) live_obj_size();
0N/A}
0N/A
375N/A// MT-unsafe claiming of a region. Should only be used during single threaded
0N/A// execution.
375N/Ainline bool ParallelCompactData::RegionData::claim_unsafe()
0N/A{
0N/A if (available()) {
0N/A _dc_and_los |= dc_claimed;
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::add_live_obj(size_t words)
0N/A{
0N/A assert(words <= (size_t)los_mask - live_obj_size(), "overflow");
0N/A Atomic::add((int) words, (volatile int*) &_dc_and_los);
0N/A}
0N/A
375N/Ainline void ParallelCompactData::RegionData::set_highest_ref(HeapWord* addr)
0N/A{
0N/A#ifdef ASSERT
0N/A HeapWord* tmp = _highest_ref;
0N/A while (addr > tmp) {
0N/A tmp = (HeapWord*)Atomic::cmpxchg_ptr(addr, &_highest_ref, tmp);
0N/A }
0N/A#endif // #ifdef ASSERT
0N/A}
0N/A
375N/Ainline bool ParallelCompactData::RegionData::claim()
0N/A{
0N/A const int los = (int) live_obj_size();
0N/A const int old = Atomic::cmpxchg(dc_claimed | los,
0N/A (volatile int*) &_dc_and_los, los);
0N/A return old == los;
0N/A}
0N/A
375N/Ainline ParallelCompactData::RegionData*
375N/AParallelCompactData::region(size_t region_idx) const
0N/A{
375N/A assert(region_idx <= region_count(), "bad arg");
375N/A return _region_data + region_idx;
0N/A}
0N/A
0N/Ainline size_t
375N/AParallelCompactData::region(const RegionData* const region_ptr) const
0N/A{
375N/A assert(region_ptr >= _region_data, "bad arg");
375N/A assert(region_ptr <= _region_data + region_count(), "bad arg");
375N/A return pointer_delta(region_ptr, _region_data, sizeof(RegionData));
0N/A}
0N/A
4535N/Ainline ParallelCompactData::BlockData*
4535N/AParallelCompactData::block(size_t n) const {
4535N/A assert(n < block_count(), "bad arg");
4535N/A return _block_data + n;
4535N/A}
4535N/A
0N/Ainline size_t
375N/AParallelCompactData::region_offset(const HeapWord* addr) const
0N/A{
0N/A assert(addr >= _region_start, "bad addr");
0N/A assert(addr <= _region_end, "bad addr");
375N/A return (size_t(addr) & RegionAddrOffsetMask) >> LogHeapWordSize;
0N/A}
0N/A
0N/Ainline size_t
375N/AParallelCompactData::addr_to_region_idx(const HeapWord* addr) const
0N/A{
0N/A assert(addr >= _region_start, "bad addr");
0N/A assert(addr <= _region_end, "bad addr");
375N/A return pointer_delta(addr, _region_start) >> Log2RegionSize;
0N/A}
0N/A
375N/Ainline ParallelCompactData::RegionData*
375N/AParallelCompactData::addr_to_region_ptr(const HeapWord* addr) const
0N/A{
375N/A return region(addr_to_region_idx(addr));
0N/A}
0N/A
0N/Ainline HeapWord*
375N/AParallelCompactData::region_to_addr(size_t region) const
0N/A{
375N/A assert(region <= _region_count, "region out of range");
375N/A return _region_start + (region << Log2RegionSize);
0N/A}
0N/A
0N/Ainline HeapWord*
375N/AParallelCompactData::region_to_addr(const RegionData* region) const
0N/A{
375N/A return region_to_addr(pointer_delta(region, _region_data,
375N/A sizeof(RegionData)));
0N/A}
0N/A
0N/Ainline HeapWord*
375N/AParallelCompactData::region_to_addr(size_t region, size_t offset) const
0N/A{
375N/A assert(region <= _region_count, "region out of range");
375N/A assert(offset < RegionSize, "offset too big"); // This may be too strict.
375N/A return region_to_addr(region) + offset;
0N/A}
0N/A
0N/Ainline HeapWord*
375N/AParallelCompactData::region_align_down(HeapWord* addr) const
0N/A{
0N/A assert(addr >= _region_start, "bad addr");
375N/A assert(addr < _region_end + RegionSize, "bad addr");
375N/A return (HeapWord*)(size_t(addr) & RegionAddrMask);
0N/A}
0N/A
0N/Ainline HeapWord*
375N/AParallelCompactData::region_align_up(HeapWord* addr) const
0N/A{
0N/A assert(addr >= _region_start, "bad addr");
0N/A assert(addr <= _region_end, "bad addr");
375N/A return region_align_down(addr + RegionSizeOffsetMask);
0N/A}
0N/A
0N/Ainline bool
375N/AParallelCompactData::is_region_aligned(HeapWord* addr) const
0N/A{
375N/A return region_offset(addr) == 0;
0N/A}
0N/A
4535N/Ainline size_t
4535N/AParallelCompactData::block_offset(const HeapWord* addr) const
4535N/A{
4535N/A assert(addr >= _region_start, "bad addr");
4535N/A assert(addr <= _region_end, "bad addr");
4535N/A return (size_t(addr) & BlockAddrOffsetMask) >> LogHeapWordSize;
4535N/A}
4535N/A
4535N/Ainline size_t
4535N/AParallelCompactData::addr_to_block_idx(const HeapWord* addr) const
4535N/A{
4535N/A assert(addr >= _region_start, "bad addr");
4535N/A assert(addr <= _region_end, "bad addr");
4535N/A return pointer_delta(addr, _region_start) >> Log2BlockSize;
4535N/A}
4535N/A
4535N/Ainline ParallelCompactData::BlockData*
4535N/AParallelCompactData::addr_to_block_ptr(const HeapWord* addr) const
4535N/A{
4535N/A return block(addr_to_block_idx(addr));
4535N/A}
4535N/A
4535N/Ainline HeapWord*
4535N/AParallelCompactData::block_to_addr(size_t block) const
4535N/A{
4535N/A assert(block < _block_count, "block out of range");
4535N/A return _region_start + (block << Log2BlockSize);
4535N/A}
4535N/A
4535N/Ainline size_t
4535N/AParallelCompactData::region_to_block_idx(size_t region) const
4535N/A{
4535N/A return region << Log2BlocksPerRegion;
4535N/A}
4535N/A
4535N/Ainline HeapWord*
4535N/AParallelCompactData::block_align_down(HeapWord* addr) const
4535N/A{
4535N/A assert(addr >= _region_start, "bad addr");
4535N/A assert(addr < _region_end + RegionSize, "bad addr");
4535N/A return (HeapWord*)(size_t(addr) & BlockAddrMask);
4535N/A}
4535N/A
4535N/Ainline HeapWord*
4535N/AParallelCompactData::block_align_up(HeapWord* addr) const
4535N/A{
4535N/A assert(addr >= _region_start, "bad addr");
4535N/A assert(addr <= _region_end, "bad addr");
4535N/A return block_align_down(addr + BlockSizeOffsetMask);
4535N/A}
4535N/A
4535N/Ainline bool
4535N/AParallelCompactData::is_block_aligned(HeapWord* addr) const
4535N/A{
4535N/A return block_offset(addr) == 0;
4535N/A}
4535N/A
0N/A// Abstract closure for use with ParMarkBitMap::iterate(), which will invoke the
0N/A// do_addr() method.
0N/A//
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.
0N/A
0N/Aclass ParMarkBitMapClosure: public StackObj {
0N/A public:
0N/A typedef ParMarkBitMap::idx_t idx_t;
0N/A typedef ParMarkBitMap::IterationStatus IterationStatus;
0N/A
0N/A public:
0N/A inline ParMarkBitMapClosure(ParMarkBitMap* mbm, ParCompactionManager* cm,
0N/A size_t words = max_uintx);
0N/A
0N/A inline ParCompactionManager* compaction_manager() const;
0N/A inline ParMarkBitMap* bitmap() const;
0N/A inline size_t words_remaining() const;
0N/A inline bool is_full() const;
0N/A inline HeapWord* source() const;
0N/A
0N/A inline void set_source(HeapWord* addr);
0N/A
0N/A virtual IterationStatus do_addr(HeapWord* addr, size_t words) = 0;
0N/A
0N/A protected:
0N/A inline void decrement_words_remaining(size_t words);
0N/A
0N/A private:
0N/A ParMarkBitMap* const _bitmap;
0N/A ParCompactionManager* const _compaction_manager;
0N/A DEBUG_ONLY(const size_t _initial_words_remaining;) // Useful in debugger.
0N/A size_t _words_remaining; // Words left to copy.
0N/A
0N/A protected:
0N/A HeapWord* _source; // Next addr that would be read.
0N/A};
0N/A
0N/Ainline
0N/AParMarkBitMapClosure::ParMarkBitMapClosure(ParMarkBitMap* bitmap,
0N/A ParCompactionManager* cm,
0N/A size_t words):
0N/A _bitmap(bitmap), _compaction_manager(cm)
0N/A#ifdef ASSERT
0N/A , _initial_words_remaining(words)
0N/A#endif
0N/A{
0N/A _words_remaining = words;
0N/A _source = NULL;
0N/A}
0N/A
0N/Ainline ParCompactionManager* ParMarkBitMapClosure::compaction_manager() const {
0N/A return _compaction_manager;
0N/A}
0N/A
0N/Ainline ParMarkBitMap* ParMarkBitMapClosure::bitmap() const {
0N/A return _bitmap;
0N/A}
0N/A
0N/Ainline size_t ParMarkBitMapClosure::words_remaining() const {
0N/A return _words_remaining;
0N/A}
0N/A
0N/Ainline bool ParMarkBitMapClosure::is_full() const {
0N/A return words_remaining() == 0;
0N/A}
0N/A
0N/Ainline HeapWord* ParMarkBitMapClosure::source() const {
0N/A return _source;
0N/A}
0N/A
0N/Ainline void ParMarkBitMapClosure::set_source(HeapWord* addr) {
0N/A _source = addr;
0N/A}
0N/A
0N/Ainline void ParMarkBitMapClosure::decrement_words_remaining(size_t words) {
0N/A assert(_words_remaining >= words, "processed too many words");
0N/A _words_remaining -= words;
0N/A}
0N/A
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//
263N/A// There are four phases of the collection.
263N/A//
263N/A// - marking phase
263N/A// - summary phase
263N/A// - compacting phase
263N/A// - clean up phase
263N/A//
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
263N/A//
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().
263N/A//
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.
263N/A//
375N/A// region -----+---------------------+----------
263N/A// objects covered [ AAA )[ BBB )[ CCC )[ DDD )
263N/A//
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// covered by a region.
263N/A//
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
263N/A//
375N/A// - the amount of live data at the beginning of a region from an object
375N/A// entering the region.
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//
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//
263N/A// The summary phase is done using 1 GC thread.
263N/A//
375N/A// The compaction phase moves objects to their new location and updates all
375N/A// references in the object.
263N/A//
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.
263N/A//
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.
375N/A
0N/Aclass PSParallelCompact : AllStatic {
0N/A public:
0N/A // Convenient access to type names.
0N/A typedef ParMarkBitMap::idx_t idx_t;
375N/A typedef ParallelCompactData::RegionData RegionData;
4535N/A typedef ParallelCompactData::BlockData BlockData;
0N/A
0N/A typedef enum {
0N/A perm_space_id, old_space_id, eden_space_id,
0N/A from_space_id, to_space_id, last_space_id
0N/A } SpaceId;
0N/A
0N/A public:
113N/A // Inline closure decls
0N/A //
0N/A class IsAliveClosure: public BoolObjectClosure {
0N/A public:
113N/A virtual void do_object(oop p);
113N/A virtual bool do_object_b(oop p);
0N/A };
0N/A
0N/A class KeepAliveClosure: public OopClosure {
113N/A private:
0N/A ParCompactionManager* _compaction_manager;
113N/A protected:
113N/A template <class T> inline void do_oop_work(T* p);
0N/A public:
113N/A KeepAliveClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
113N/A // Current unused
113N/A class FollowRootClosure: public OopsInGenClosure {
113N/A private:
0N/A ParCompactionManager* _compaction_manager;
0N/A public:
113N/A FollowRootClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
989N/A };
0N/A
0N/A class FollowStackClosure: public VoidClosure {
113N/A private:
0N/A ParCompactionManager* _compaction_manager;
0N/A public:
113N/A FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
113N/A virtual void do_void();
0N/A };
0N/A
0N/A class AdjustPointerClosure: public OopsInGenClosure {
113N/A private:
0N/A bool _is_root;
0N/A public:
113N/A AdjustPointerClosure(bool is_root) : _is_root(is_root) { }
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
989N/A // do not walk from thread stacks to the code cache on this phase
989N/A virtual void do_code_blob(CodeBlob* cb) const { }
0N/A };
0N/A
0N/A friend class KeepAliveClosure;
0N/A friend class FollowStackClosure;
0N/A friend class AdjustPointerClosure;
0N/A friend class FollowRootClosure;
0N/A friend class instanceKlassKlass;
0N/A friend class RefProcTaskProxy;
0N/A
0N/A private:
4141N/A static STWGCTimer _gc_timer;
4141N/A static ParallelOldTracer _gc_tracer;
0N/A static elapsedTimer _accumulated_time;
0N/A static unsigned int _total_invocations;
0N/A static unsigned int _maximum_compaction_gc_num;
0N/A static jlong _time_of_last_gc; // ms
0N/A static CollectorCounters* _counters;
0N/A static ParMarkBitMap _mark_bitmap;
0N/A static ParallelCompactData _summary_data;
0N/A static IsAliveClosure _is_alive_closure;
0N/A static SpaceInfo _space_info[last_space_id];
0N/A static bool _print_phases;
0N/A static AdjustPointerClosure _adjust_root_pointer_closure;
0N/A static AdjustPointerClosure _adjust_pointer_closure;
0N/A
0N/A // Reference processing (used in ...follow_contents)
0N/A static ReferenceProcessor* _ref_processor;
0N/A
0N/A // Updated location of intArrayKlassObj.
0N/A static klassOop _updated_int_array_klass_obj;
0N/A
0N/A // Values computed at initialization and used by dead_wood_limiter().
0N/A static double _dwl_mean;
0N/A static double _dwl_std_dev;
0N/A static double _dwl_first_term;
0N/A static double _dwl_adjustment;
0N/A#ifdef ASSERT
0N/A static bool _dwl_initialized;
0N/A#endif // #ifdef ASSERT
0N/A
0N/A private:
0N/A // Closure accessors
113N/A static OopClosure* adjust_pointer_closure() { return (OopClosure*)&_adjust_pointer_closure; }
0N/A static OopClosure* adjust_root_pointer_closure() { return (OopClosure*)&_adjust_root_pointer_closure; }
113N/A static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
0N/A
0N/A static void initialize_space_info();
0N/A
0N/A // Return true if details about individual phases should be printed.
0N/A static inline bool print_phases();
0N/A
0N/A // Clear the marking bitmap and summary data that cover the specified space.
0N/A static void clear_data_covering_space(SpaceId id);
0N/A
0N/A static void pre_compact(PreGCValues* pre_gc_values);
0N/A static void post_compact();
0N/A
0N/A // Mark live objects
4304N/A static void marking_phase(ParCompactionManager* cm, bool maximum_heap_compaction);
941N/A static void follow_weak_klass_links();
941N/A static void follow_mdo_weak_refs();
0N/A
113N/A template <class T> static inline void adjust_pointer(T* p, bool is_root);
0N/A static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); }
0N/A
113N/A template <class T>
113N/A static inline void follow_root(ParCompactionManager* cm, T* p);
0N/A
0N/A // Compute the dense prefix for the designated space. This is an experimental
0N/A // implementation currently not used in production.
0N/A static HeapWord* compute_dense_prefix_via_density(const SpaceId id,
0N/A bool maximum_compaction);
0N/A
0N/A // Methods used to compute the dense prefix.
0N/A
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 static inline double normal_distribution(double density);
0N/A
0N/A // Initialize the static vars used by dead_wood_limiter().
0N/A static void initialize_dead_wood_limiter();
0N/A
0N/A // Return the percentage of space that can be treated as "dead wood" (i.e.,
0N/A // not reclaimed).
0N/A static double dead_wood_limiter(double density, size_t min_percent);
0N/A
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 static RegionData* dead_wood_limit_region(const RegionData* beg,
375N/A const RegionData* end,
375N/A size_t dead_words);
0N/A
375N/A // Return a pointer to the first region in the range [beg, end) that is not
0N/A // completely full.
375N/A static RegionData* first_dead_space_region(const RegionData* beg,
375N/A const RegionData* end);
0N/A
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 //
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.
375N/A static inline double reclaimed_ratio(const RegionData* const candidate,
0N/A HeapWord* const bottom,
0N/A HeapWord* const top,
0N/A HeapWord* const new_top);
0N/A
0N/A // Compute the dense prefix for the designated space.
0N/A static HeapWord* compute_dense_prefix(const SpaceId id,
0N/A bool maximum_compaction);
0N/A
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.
375N/A static inline bool dead_space_crosses_boundary(const RegionData* region,
0N/A idx_t bit);
0N/A
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
0N/A // non-empty.
0N/A static void fill_dense_prefix_end(SpaceId id);
0N/A
482N/A // Clear the summary data source_region field for the specified addresses.
482N/A static void clear_source_region(HeapWord* beg_addr, HeapWord* end_addr);
482N/A
483N/A#ifndef PRODUCT
483N/A // Routines to provoke splitting a young gen space (ParallelOldGCSplitALot).
483N/A
483N/A // Fill the region [start, start + words) with live object(s). Only usable
483N/A // for the old and permanent generations.
483N/A static void fill_with_live_objects(SpaceId id, HeapWord* const start,
483N/A size_t words);
483N/A // Include the new objects in the summary data.
483N/A static void summarize_new_objects(SpaceId id, HeapWord* start);
483N/A
496N/A // Add live objects to a survivor space since it's rare that both survivors
496N/A // are non-empty.
496N/A static void provoke_split_fill_survivor(SpaceId id);
496N/A
483N/A // Add live objects and/or choose the dense prefix to provoke splitting.
483N/A static void provoke_split(bool & maximum_compaction);
483N/A#endif
483N/A
0N/A static void summarize_spaces_quick();
0N/A static void summarize_space(SpaceId id, bool maximum_compaction);
0N/A static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
0N/A
0N/A // Adjust addresses in roots. Does not adjust addresses in heap.
0N/A static void adjust_roots();
0N/A
0N/A // Serial code executed in preparation for the compaction phase.
0N/A static void compact_prologue();
0N/A
4535N/A DEBUG_ONLY(static void write_block_fill_histogram(outputStream* const out);)
4535N/A
0N/A // Move objects to new locations.
0N/A static void compact_perm(ParCompactionManager* cm);
0N/A static void compact();
0N/A
375N/A // Add available regions to the stack and draining tasks to the task queue.
375N/A static void enqueue_region_draining_tasks(GCTaskQueue* q,
375N/A uint parallel_gc_threads);
0N/A
0N/A // Add dense prefix update tasks to the task queue.
0N/A static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
0N/A uint parallel_gc_threads);
0N/A
375N/A // Add region stealing tasks to the task queue.
375N/A static void enqueue_region_stealing_tasks(
0N/A GCTaskQueue* q,
0N/A ParallelTaskTerminator* terminator_ptr,
0N/A uint parallel_gc_threads);
0N/A
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 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
0N/A PSYoungGen* young_gen,
0N/A PSOldGen* old_gen);
0N/A
0N/A // Reset time since last full gc
0N/A static void reset_millis_since_last_gc();
0N/A
0N/A protected:
0N/A#ifdef VALIDATE_MARK_SWEEP
113N/A static GrowableArray<void*>* _root_refs_stack;
0N/A static GrowableArray<oop> * _live_oops;
0N/A static GrowableArray<oop> * _live_oops_moved_to;
0N/A static GrowableArray<size_t>* _live_oops_size;
0N/A static size_t _live_oops_index;
0N/A static size_t _live_oops_index_at_perm;
113N/A static GrowableArray<void*>* _other_refs_stack;
113N/A static GrowableArray<void*>* _adjusted_pointers;
0N/A static bool _pointer_tracking;
0N/A static bool _root_tracking;
0N/A
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 static GrowableArray<HeapWord*> * _cur_gc_live_oops;
0N/A static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
0N/A static GrowableArray<size_t>* _cur_gc_live_oops_size;
0N/A static GrowableArray<HeapWord*> * _last_gc_live_oops;
0N/A static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
0N/A static GrowableArray<size_t>* _last_gc_live_oops_size;
0N/A#endif
0N/A
0N/A public:
0N/A class MarkAndPushClosure: public OopClosure {
113N/A private:
0N/A ParCompactionManager* _compaction_manager;
0N/A public:
113N/A MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A PSParallelCompact();
0N/A
0N/A // Convenient accessor for Universe::heap().
0N/A static ParallelScavengeHeap* gc_heap() {
0N/A return (ParallelScavengeHeap*)Universe::heap();
0N/A }
0N/A
0N/A static void invoke(bool maximum_heap_compaction);
3202N/A static bool invoke_no_policy(bool maximum_heap_compaction);
0N/A
0N/A static void post_initialize();
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 static bool initialize();
0N/A
0N/A // Public accessors
0N/A static elapsedTimer* accumulated_time() { return &_accumulated_time; }
0N/A static unsigned int total_invocations() { return _total_invocations; }
0N/A static CollectorCounters* counters() { return _counters; }
0N/A
0N/A // Used to add tasks
0N/A static GCTaskManager* const gc_task_manager();
0N/A static klassOop updated_int_array_klass_obj() {
0N/A return _updated_int_array_klass_obj;
0N/A }
0N/A
0N/A // Marking support
0N/A static inline bool mark_obj(oop obj);
113N/A // Check mark and maybe push on marking stack
113N/A template <class T> static inline void mark_and_push(ParCompactionManager* cm,
113N/A T* p);
0N/A
0N/A // Compaction support.
0N/A // Return true if p is in the range [beg_addr, end_addr).
0N/A static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
0N/A static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
0N/A
0N/A // Convenience wrappers for per-space data kept in _space_info.
0N/A static inline MutableSpace* space(SpaceId space_id);
0N/A static inline HeapWord* new_top(SpaceId space_id);
0N/A static inline HeapWord* dense_prefix(SpaceId space_id);
0N/A static inline ObjectStartArray* start_array(SpaceId space_id);
0N/A
0N/A // Return true if the klass should be updated.
0N/A static inline bool should_update_klass(klassOop k);
0N/A
0N/A // Move and update the live objects in the specified space.
0N/A static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
0N/A
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 static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
375N/A size_t region_start_index,
375N/A size_t region_end_index,
375N/A idx_t exiting_object_offset,
375N/A idx_t region_offset_start,
375N/A idx_t region_offset_end);
0N/A
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 static void update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,
0N/A SpaceId space_id,
375N/A size_t region_index_start,
375N/A size_t region_index_end);
0N/A
0N/A // Return the address of the count + 1st live word in the range [beg, end).
0N/A static HeapWord* skip_live_words(HeapWord* beg, HeapWord* end, size_t count);
0N/A
0N/A // Return the address of the word to be copied to dest_addr, which must be
375N/A // aligned to a region boundary.
0N/A static HeapWord* first_src_addr(HeapWord* const dest_addr,
482N/A SpaceId src_space_id,
375N/A size_t src_region_idx);
0N/A
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 static size_t next_src_region(MoveAndUpdateClosure& closure,
375N/A SpaceId& src_space_id,
375N/A HeapWord*& src_space_top,
375N/A HeapWord* end_addr);
0N/A
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.
0N/A static void decrement_destination_counts(ParCompactionManager* cm,
495N/A SpaceId src_space_id,
375N/A size_t beg_region,
0N/A HeapWord* end_addr);
0N/A
375N/A // Fill a region, copying objects from one or more source regions.
375N/A static void fill_region(ParCompactionManager* cm, size_t region_idx);
375N/A static void fill_and_update_region(ParCompactionManager* cm, size_t region) {
375N/A fill_region(cm, region);
0N/A }
0N/A
4535N/A // Fill in the block table for the specified region.
4535N/A static void fill_blocks(size_t region_idx);
4535N/A
0N/A // Update the deferred objects in the space.
0N/A static void update_deferred_objects(ParCompactionManager* cm, SpaceId id);
0N/A
0N/A static ParMarkBitMap* mark_bitmap() { return &_mark_bitmap; }
0N/A static ParallelCompactData& summary_data() { return _summary_data; }
0N/A
113N/A static inline void adjust_pointer(oop* p) { adjust_pointer(p, false); }
113N/A static inline void adjust_pointer(narrowOop* p) { adjust_pointer(p, false); }
113N/A
0N/A // Reference Processing
0N/A static ReferenceProcessor* const ref_processor() { return _ref_processor; }
0N/A
4141N/A static STWGCTimer* gc_timer() { return &_gc_timer; }
4141N/A
0N/A // Return the SpaceId for the given address.
0N/A static SpaceId space_id(HeapWord* addr);
0N/A
0N/A // Time since last full gc (in milliseconds).
0N/A static jlong millis_since_last_gc();
0N/A
0N/A#ifdef VALIDATE_MARK_SWEEP
113N/A static void track_adjusted_pointer(void* p, bool isroot);
113N/A static void check_adjust_pointer(void* p);
0N/A static void track_interior_pointers(oop obj);
0N/A static void check_interior_pointers();
0N/A
0N/A static void reset_live_oop_tracking(bool at_perm);
0N/A static void register_live_oop(oop p, size_t size);
0N/A static void validate_live_oop(oop p, size_t size);
0N/A static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
0N/A static void compaction_complete();
0N/A
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 static void print_new_location_of_heap_address(HeapWord* q);
0N/A#endif // #ifdef VALIDATE_MARK_SWEEP
0N/A
0N/A // Call backs for class unloading
0N/A // Update subklass/sibling/implementor links at end of marking.
0N/A static void revisit_weak_klass_link(ParCompactionManager* cm, Klass* k);
0N/A
941N/A // Clear unmarked oops in MDOs at the end of marking.
941N/A static void revisit_mdo(ParCompactionManager* cm, DataLayout* p);
941N/A
0N/A#ifndef PRODUCT
0N/A // Debugging support.
0N/A static const char* space_names[last_space_id];
375N/A static void print_region_ranges();
0N/A static void print_dense_prefix_stats(const char* const algorithm,
0N/A const SpaceId id,
0N/A const bool maximum_compaction,
0N/A HeapWord* const addr);
482N/A static void summary_phase_msg(SpaceId dst_space_id,
482N/A HeapWord* dst_beg, HeapWord* dst_end,
482N/A SpaceId src_space_id,
482N/A HeapWord* src_beg, HeapWord* src_end);
0N/A#endif // #ifndef PRODUCT
0N/A
0N/A#ifdef ASSERT
495N/A // Sanity check the new location of a word in the heap.
495N/A static inline void check_new_location(HeapWord* old_addr, HeapWord* new_addr);
375N/A // Verify that all the regions have been emptied.
0N/A static void verify_complete(SpaceId space_id);
0N/A#endif // #ifdef ASSERT
0N/A};
0N/A
113N/Ainline bool PSParallelCompact::mark_obj(oop obj) {
0N/A const int obj_size = obj->size();
0N/A if (mark_bitmap()->mark_obj(obj, obj_size)) {
0N/A _summary_data.add_obj(obj, obj_size);
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A}
0N/A
113N/Atemplate <class T>
113N/Ainline void PSParallelCompact::follow_root(ParCompactionManager* cm, T* p) {
113N/A assert(!Universe::heap()->is_in_reserved(p),
113N/A "roots shouldn't be things within the heap");
113N/A#ifdef VALIDATE_MARK_SWEEP
113N/A if (ValidateMarkSweep) {
113N/A guarantee(!_root_refs_stack->contains(p), "should only be in here once");
113N/A _root_refs_stack->push(p);
113N/A }
113N/A#endif
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A if (mark_bitmap()->is_unmarked(obj)) {
113N/A if (mark_obj(obj)) {
113N/A obj->follow_contents(cm);
113N/A }
113N/A }
113N/A }
1311N/A cm->follow_marking_stacks();
113N/A}
113N/A
113N/Atemplate <class T>
113N/Ainline void PSParallelCompact::mark_and_push(ParCompactionManager* cm, T* p) {
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
1558N/A if (mark_bitmap()->is_unmarked(obj) && mark_obj(obj)) {
1558N/A cm->push(obj);
113N/A }
113N/A }
113N/A}
113N/A
113N/Atemplate <class T>
113N/Ainline void PSParallelCompact::adjust_pointer(T* p, bool isroot) {
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A oop new_obj = (oop)summary_data().calc_new_pointer(obj);
113N/A assert(new_obj != NULL || // is forwarding ptr?
113N/A obj->is_shared(), // never forwarded?
113N/A "should be forwarded");
113N/A // Just always do the update unconditionally?
113N/A if (new_obj != NULL) {
113N/A assert(Universe::heap()->is_in_reserved(new_obj),
113N/A "should be in object space");
113N/A oopDesc::encode_store_heap_oop_not_null(p, new_obj);
113N/A }
113N/A }
113N/A VALIDATE_MARK_SWEEP_ONLY(track_adjusted_pointer(p, isroot));
113N/A}
113N/A
113N/Atemplate <class T>
113N/Ainline void PSParallelCompact::KeepAliveClosure::do_oop_work(T* p) {
113N/A#ifdef VALIDATE_MARK_SWEEP
113N/A if (ValidateMarkSweep) {
113N/A if (!Universe::heap()->is_in_reserved(p)) {
113N/A _root_refs_stack->push(p);
113N/A } else {
113N/A _other_refs_stack->push(p);
113N/A }
113N/A }
113N/A#endif
113N/A mark_and_push(_compaction_manager, p);
113N/A}
113N/A
113N/Ainline bool PSParallelCompact::print_phases() {
0N/A return _print_phases;
0N/A}
0N/A
113N/Ainline double PSParallelCompact::normal_distribution(double density) {
0N/A assert(_dwl_initialized, "uninitialized");
0N/A const double squared_term = (density - _dwl_mean) / _dwl_std_dev;
0N/A return _dwl_first_term * exp(-0.5 * squared_term * squared_term);
0N/A}
0N/A
0N/Ainline bool
375N/APSParallelCompact::dead_space_crosses_boundary(const RegionData* region,
0N/A idx_t bit)
0N/A{
375N/A assert(bit > 0, "cannot call this for the first bit/region");
375N/A assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),
0N/A "sanity check");
0N/A
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.
375N/A return region->partial_obj_size() == 0 &&
0N/A !_mark_bitmap.is_obj_beg(bit) &&
0N/A !_mark_bitmap.is_obj_end(bit - 1);
0N/A}
0N/A
0N/Ainline bool
0N/APSParallelCompact::is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr) {
0N/A return p >= beg_addr && p < end_addr;
0N/A}
0N/A
0N/Ainline bool
0N/APSParallelCompact::is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr) {
0N/A return is_in((HeapWord*)p, beg_addr, end_addr);
0N/A}
0N/A
0N/Ainline MutableSpace* PSParallelCompact::space(SpaceId id) {
0N/A assert(id < last_space_id, "id out of range");
0N/A return _space_info[id].space();
0N/A}
0N/A
0N/Ainline HeapWord* PSParallelCompact::new_top(SpaceId id) {
0N/A assert(id < last_space_id, "id out of range");
0N/A return _space_info[id].new_top();
0N/A}
0N/A
0N/Ainline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {
0N/A assert(id < last_space_id, "id out of range");
0N/A return _space_info[id].dense_prefix();
0N/A}
0N/A
0N/Ainline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {
0N/A assert(id < last_space_id, "id out of range");
0N/A return _space_info[id].start_array();
0N/A}
0N/A
0N/Ainline bool PSParallelCompact::should_update_klass(klassOop k) {
0N/A return ((HeapWord*) k) >= dense_prefix(perm_space_id);
0N/A}
0N/A
495N/A#ifdef ASSERT
495N/Ainline void
495N/APSParallelCompact::check_new_location(HeapWord* old_addr, HeapWord* new_addr)
495N/A{
495N/A assert(old_addr >= new_addr || space_id(old_addr) != space_id(new_addr),
495N/A "must move left or to a different space");
1491N/A assert(is_object_aligned((intptr_t)old_addr) && is_object_aligned((intptr_t)new_addr),
1491N/A "checking alignment");
495N/A}
495N/A#endif // ASSERT
495N/A
0N/Aclass MoveAndUpdateClosure: public ParMarkBitMapClosure {
0N/A public:
0N/A inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, ParCompactionManager* cm,
0N/A ObjectStartArray* start_array,
0N/A HeapWord* destination, size_t words);
0N/A
0N/A // Accessors.
0N/A HeapWord* destination() const { return _destination; }
0N/A
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 virtual IterationStatus do_addr(HeapWord* addr, size_t size);
0N/A
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 IterationStatus copy_until_full();
0N/A
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 void copy_partial_obj();
0N/A
0N/A protected:
0N/A // Update variables to indicate that word_count words were processed.
0N/A inline void update_state(size_t word_count);
0N/A
0N/A protected:
0N/A ObjectStartArray* const _start_array;
0N/A HeapWord* _destination; // Next addr to be written.
0N/A};
0N/A
0N/Ainline
0N/AMoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap,
0N/A ParCompactionManager* cm,
0N/A ObjectStartArray* start_array,
0N/A HeapWord* destination,
0N/A size_t words) :
0N/A ParMarkBitMapClosure(bitmap, cm, words), _start_array(start_array)
0N/A{
0N/A _destination = destination;
0N/A}
0N/A
0N/Ainline void MoveAndUpdateClosure::update_state(size_t words)
0N/A{
0N/A decrement_words_remaining(words);
0N/A _source += words;
0N/A _destination += words;
0N/A}
0N/A
0N/Aclass UpdateOnlyClosure: public ParMarkBitMapClosure {
0N/A private:
0N/A const PSParallelCompact::SpaceId _space_id;
0N/A ObjectStartArray* const _start_array;
0N/A
0N/A public:
0N/A UpdateOnlyClosure(ParMarkBitMap* mbm,
0N/A ParCompactionManager* cm,
0N/A PSParallelCompact::SpaceId space_id);
0N/A
0N/A // Update the object.
0N/A virtual IterationStatus do_addr(HeapWord* addr, size_t words);
0N/A
0N/A inline void do_addr(HeapWord* addr);
0N/A};
0N/A
113N/Ainline void UpdateOnlyClosure::do_addr(HeapWord* addr)
113N/A{
0N/A _start_array->allocate_block(addr);
0N/A oop(addr)->update_contents(compaction_manager());
0N/A}
0N/A
481N/Aclass FillClosure: public ParMarkBitMapClosure
481N/A{
481N/Apublic:
113N/A FillClosure(ParCompactionManager* cm, PSParallelCompact::SpaceId space_id) :
0N/A ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm),
481N/A _start_array(PSParallelCompact::start_array(space_id))
481N/A {
481N/A assert(space_id == PSParallelCompact::perm_space_id ||
481N/A space_id == PSParallelCompact::old_space_id,
0N/A "cannot use FillClosure in the young gen");
0N/A }
0N/A
0N/A virtual IterationStatus do_addr(HeapWord* addr, size_t size) {
481N/A CollectedHeap::fill_with_objects(addr, size);
481N/A HeapWord* const end = addr + size;
481N/A do {
481N/A _start_array->allocate_block(addr);
481N/A addr += oop(addr)->size();
481N/A } while (addr < end);
0N/A return ParMarkBitMap::incomplete;
0N/A }
0N/A
0N/Aprivate:
481N/A ObjectStartArray* const _start_array;
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP