/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
#include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
#include "gc_implementation/g1/survRateGroup.hpp"
#include "gc_implementation/shared/ageTable.hpp"
#include "gc_implementation/shared/spaceDecorator.hpp"
#include "memory/space.inline.hpp"
#include "memory/watermark.hpp"
#ifndef SERIALGC
// A HeapRegion is the smallest piece of a G1CollectedHeap that
// can be collected independently.
// NOTE: Although a HeapRegion is a Space, its
// Space::initDirtyCardClosure method must not be called.
// The problem is that the existence of this method breaks
// the independence of barrier sets from remembered sets.
// The solution is to remove this method from the definition
// of a Space.
class CompactibleSpace;
class ContiguousSpace;
class HeapRegionRemSet;
class HeapRegionRemSetIterator;
class HeapRegion;
class HeapRegionSetBase;
// sentinel value for hrs_index
// A dirty card to oop closure for heap regions. It
// knows how to get the G1 heap and how to use the bitmap
// in the concurrent marker used by G1 to filter remembered
// sets.
public:
// Specification of possible DirtyCardToOopClosure filtering.
enum FilterKind {
};
protected:
OopClosure* cl);
// We don't specialize this for FilteringClosure; filtering is handled by
// the "FilterKind" mechanism. But we provide this to avoid a compiler
// warning.
FilteringClosure* cl) {
(OopClosure*)cl);
}
// Get the actual top of the area on which the closure will
// operate, given where the top is assumed to be (the end of the
// memory region passed to do_MemRegion) and where the object
// at the top is assumed to start. For example, an object may
// start at the top but actually extend past the assumed top,
// in which case the top becomes the end of the object.
}
// Walk the given memory region from bottom to (actual) top
// looking for objects and applying the oop closure (_cl) to
// them. The base implementation of this treats the area as
// blocks, where a block may or may not be an object. Sub-
// classes should override this to provide more accurate
// or possibly more efficient walking.
}
public:
FilterKind fk);
};
// The complicating factor is that BlockOffsetTable diverged
// significantly, and we need functionality that is only in the G1 version.
// So I copied that code, which led to an alternate G1 version of
// OffsetTableContigSpace. If the two versions of BlockOffsetTable could
// be reconciled, then G1OffsetTableContigSpace could go away.
// The idea behind time stamps is the following. Doing a save_marks on
// all regions at every GC pause is time consuming (if I remember
// well, 10ms or so). So, we would like to do that only for regions
// that are GC alloc regions. To achieve this, we use time
// stamps. For every evacuation pause, G1CollectedHeap generates a
// unique time stamp (essentially a counter that gets
// incremented). Every time we want to call save_marks on a region,
// we set the saved_mark_word to top and also copy the current GC
// time stamp to the time stamp field of the space. Reading the
// saved_mark_word involves checking the time stamp of the
// region. If it is the same as the current GC time stamp, then we
// can safely read the saved_mark_word field, as it is valid. If the
// time stamp of the region is not the same as the current GC time
// stamp, then we instead read top, as the saved_mark_word field is
// invalid. Time stamps (on the regions and also on the
// G1CollectedHeap) are reset at every cleanup (we iterate over
// the regions anyway) and at the end of a Full GC. The current scheme
// that uses sequential unsigned ints will fail only if we have 4b
// evacuation pauses between two cleanups, which is _highly_ unlikely.
friend class VMStructs;
protected:
volatile unsigned _gc_time_stamp;
// When we need to retire an allocation region, while other threads
// are also concurrently trying to allocate into it, we typically
// allocate a dummy object at the end of the region to ensure that
// no more allocations can take place in it. However, sometimes we
// want to know where the end of the last "real" object we allocated
// into the region was and this is what this keeps track.
public:
// Constructor. If "is_zeroed" is true, the MemRegion "mr" may be
// assumed to contain zeros.
virtual HeapWord* saved_mark_word() const;
virtual void set_saved_mark();
// See the comment above in the declaration of _pre_dummy_top for an
// explanation of what it is.
}
}
virtual void clear(bool mangle_space);
HeapWord* block_start(const void* p);
HeapWord* block_start_const(const void* p) const;
// Add offset table update.
// MarkSweep support phase3
virtual HeapWord* initialize_threshold();
virtual void print() const;
void reset_bot() {
}
}
}
};
friend class VMStructs;
private:
enum HumongousType {
NotHumongous = 0,
};
// Requires that the region "mr" be dense with objects, and begin and end
// with an object.
// The remembered set for this region.
// (Might want to make this "inline" later, to avoid some alloc failure
// issues.)
protected:
// The index of this region in the heap region sequence.
// For a humongous region, region in which it starts.
// For the start region of a humongous sequence, it's original end().
// True iff the region is in current collection_set.
bool _in_collection_set;
// True iff an attempt to evacuate an object in the region failed.
bool _evacuation_failed;
// A heap region may be a member one of a number of special subsets, each
// represented as linked lists through the field below. Currently, these
// sets include:
// The collection set.
// The set of allocation regions used in a collection pause.
// Spaces that may contain gray objects.
// next region in the young "generation" region set
// Next region whose cards need cleaning
// Fields used by the HeapRegionSetBase class and subclasses.
#ifdef ASSERT
#endif // ASSERT
bool _pending_removal;
// For parallel heapRegion traversal.
// We use concurrent marking to determine the amount of live data
// in each heap region.
// The calculated GC efficiency of the region.
double _gc_efficiency;
enum YoungType {
};
int _young_index_in_cset;
int _age_index;
// The start of the unmarked area. The unmarked area extends from this
// of the region for which no marking was done, i.e. objects may
// have been allocated in this part since the last mark phase.
// "prev" is the top at the start of the last completed marking.
// "next" is the top at the start of the in-progress marking (if any.)
// If a collection pause is in progress, this is the top at the start
// of that pause.
void init_top_at_mark_start() {
assert(_prev_marked_bytes == 0 &&
_next_marked_bytes == 0,
"Must be called after zero_marked_bytes.");
}
//assert(_young_type != new_type, "setting the same type" );
// TODO: add more assertions here
}
// Cached attributes used in the collection set policy information
// The RSet length that was added to the total value
// for the collection set.
// The predicted elapsed time that was added to total value
// for the collection set.
double _predicted_elapsed_time_ms;
// The predicted number of bytes to copy that was added to
// the total value for the collection set.
public:
// If "is_zeroed" is "true", the region "mr" can be assumed to contain zeros.
static int LogOfHRGrainBytes;
static int LogOfHRGrainWords;
}
// It sets up the heap region size (GrainBytes / GrainWords), as
// well as other related fields that are based on the heap region
// size (LogOfHRGrainBytes / LogOfHRGrainWords /
// CardsPerRegion). All those fields are considered constant
// throughout the JVM's execution, therefore they should only be set
// up once during initialization time.
enum ClaimValues {
InitialClaimValue = 0,
};
}
}
// If this region is a member of a HeapRegionSeq, the index in that
// sequence, otherwise -1.
// The number of bytes marked live in the region in the last marking phase.
}
// The number of bytes counted in the next marking.
// The number of bytes live wrt the next marking.
return
}
// A lower bound on the amount of garbage bytes in the region.
"Can't mark more than we have.");
return used_at_mark_start_bytes - marked_bytes();
}
// Return the amount of bytes we'll reclaim if we collect this
// region. This includes not only the known garbage bytes in the
// region but also any unallocated space in it, i.e., [top, end),
// since it will also be reclaimed if we collect the region.
return capacity() - known_live_bytes;
}
// An upper bound on the number of live bytes in the region.
}
void zero_marked_bytes() {
}
// For a humongous region, region in which it starts.
return _humongous_start_region;
}
// Return the number of distinct regions that are covered by this region:
// 1 if the region is not humongous, >= 1 if the region is humongous.
if (!isHumongous()) {
return 1U;
} else {
}
}
// Return the index + 1 of the last HC regions that's associated
// with this HS region.
return hrs_index() + region_num();
}
// Same as Space::is_in_reserved, but will use the original size of the region.
// The original size is different only for start humongous regions. They get
// their _end set up to be the end of the last continues region of the
// corresponding humongous object.
bool is_in_reserved_raw(const void* p) const {
}
// Makes the current region be a "starts humongous" region, i.e.,
// the first region in a series of one or more contiguous regions
// that will contain a single "humongous" object. The two parameters
// are as follows:
//
// new_top : The new value of the top field of this region which
// points to the end of the humongous object that's being
// allocated. If there is more than one region in the series, top
// will lie beyond this region's original end field and on the last
// region in the series.
//
// new_end : The new value of the end field of this region which
// points to the end of the last region in the series. If there is
// one region in the series (namely: this one) end will be the same
// as the original end of this region.
//
// Updating top and end as described above makes this region look as
// if it spans the entire space taken up by all the regions in the
// series and an single allocation moved its top to new_top. This
// ensures that the space (capacity / allocated) taken up by all
// humongous regions can be calculated by just looking at the
// "starts humongous" regions and by ignoring the "continues
// humongous" regions.
// Makes the current region be a "continues humongous'
// region. first_hr is the "start humongous" region of the series
// which this region will be part of.
// Unsets the humongous-related fields on the region.
void set_notHumongous();
// If the region has a remembered set, return a pointer to it.
return _rem_set;
}
// True iff the region is in current collection_set.
bool in_collection_set() const {
return _in_collection_set;
}
void set_in_collection_set(bool b) {
_in_collection_set = b;
}
"Malformed CS.");
return _next_in_special_set;
}
_next_in_special_set = r;
}
// Methods used by the HeapRegionSetBase class and subclasses.
// Getter and setter for the next field used to link regions into
// linked lists.
// Every region added to a set is tagged with a reference to that
// set. This is used for doing consistency checking to make sure that
// the contents of a set are as they should be and it's only
// available in non-product builds.
#ifdef ASSERT
"_containing_set: "PTR_FORMAT,
}
#else // ASSERT
// containing_set() is only used in asserts so there's no reason
// to provide a dummy version of it.
#endif // ASSERT
// If we want to remove regions from a list in bulk we can simply tag
// them with the pending_removal tag and call the
// remove_all_pending() method on the list.
if (pending_removal) {
"can only set pending removal to true if it's false and "
"the region belongs to a region set");
} else {
"can only set pending removal to false if it's true and "
"the region does not belong to a region set");
}
}
}
// Allows logical separation between objects allocated before and after.
void save_marks();
// Reset HR stuff to default values.
void par_clear();
// Get the start of the unmarked area in this region.
// Apply "cl->do_oop" to (the addresses of) all reference fields in objects
// allocated in the current region before the last call to "save_mark".
// Note the start or end of marking. This tells the heap region
// that the collector is about to start or has finished (concurrently)
// marking the heap.
// Notify the region that concurrent marking is starting. Initialize
// all fields related to the next marking info.
inline void note_start_of_marking();
// Notify the region that concurrent marking has finished. Copy the
// (now finalized) next marking info fields into the prev marking
// info fields.
inline void note_end_of_marking();
// Notify the region that it will be used as to-space during a GC
// and we are about to start copying objects into it.
inline void note_start_of_copying(bool during_initial_mark);
// Notify the region that it ceases being to-space during a GC and
// we will not copy objects into it any more.
inline void note_end_of_copying(bool during_initial_mark);
// Notify the region that we are about to start processing
// self-forwarded objects during evac failure handling.
bool during_conc_mark);
// Notify the region that we have finished processing self-forwarded
// objects during evac failure handling.
bool during_conc_mark,
// Returns "false" iff no object in the region was allocated when the
// last mark phase ended.
void reset_during_compaction() {
"should only be called for starts humongous regions");
}
void calc_gc_efficiency(void);
}
int age_in_surv_rate_group() {
}
}
int age_in_surv_rate_group_cond() {
if (_surv_rate_group != NULL)
return age_in_surv_rate_group();
else
return -1;
}
return _surv_rate_group;
}
}
void uninstall_surv_rate_group() {
if (_surv_rate_group != NULL) {
_age_index = -1;
} else {
}
}
// Determine if an object has been allocated since the last
// mark performed by the collector. This returns true iff the object
// is within the unmarked area of the region.
}
}
// For parallel heapRegion traversal.
bool claimHeapRegion(int claimValue);
// Use this carefully: only when you're sure no one is claiming...
// Returns the "evacuation_failed" property of the region.
// Sets the "evacuation_failed" property of the region.
void set_evacuation_failed(bool b) {
_evacuation_failed = b;
if (b) {
_next_marked_bytes = 0;
}
}
// Requires that "mr" be entirely within the region.
// Apply "cl->do_object" to all objects that intersect with "mr".
// If the iteration encounters an unparseable portion of the region,
// or if "cl->abort()" is true after a closure application,
// terminate the iteration and return the address of the start of the
// subregion that isn't done. (The two can be distinguished by querying
// "cl->abort()".) Return of "NULL" indicates that the iteration
// completed.
// filter_young: if true and the region is a young region then we
// skip the iteration.
// card_ptr: if not NULL, and we decide that the card is not young
// and we iterate over it, we'll clean the card before we start the
// iteration.
bool filter_young,
// A version of block start that is guaranteed to find *some* block
// boundary at or before "p", but does not object iteration, and may
// therefore be used safely when the heap is unparseable.
return _offsets.block_start_careful(p);
}
// Requires that "addr" is within the region. Returns the start of the
// first ("careful") block that starts at or after "addr", or else the
// "end" of the region if there is no such block.
}
}
}
virtual CompactibleSpace* next_compaction_space() const;
virtual void reset_after_compaction();
void print() const;
// vo == UsePrevMarking -> use "prev" marking information,
// vo == UseNextMarking -> use "next" marking information
// vo == UseMarkWord -> use the mark word in the object header
//
// NOTE: Only the "prev" marking information is guaranteed to be
// consistent most of the time, so most calls to this should use
// vo == UsePrevMarking.
// Currently, there is only one case where this is called with
// vo == UseNextMarking, which is to verify the "next" marking
// information at the end of remark.
// Currently there is only one place where this is called with
// vo == UseMarkWord, which is to verify the marking during a
// full GC.
// Override; it uses the "prev" marking information
virtual void verify() const;
};
// HeapRegionClosure is used for iterating over regions.
// Terminates the iteration when the "doHeapRegion" method returns "true".
friend class HeapRegionSeq;
friend class G1CollectedHeap;
bool _complete;
public:
// Typically called on each region until it returns true.
virtual bool doHeapRegion(HeapRegion* r) = 0;
// True after iteration if the closure was applied to all heap regions
// and returned "false" in all cases.
};
#endif // SERIALGC
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP