aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP aoqi@0: aoqi@0: #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1_specialized_oop_closures.hpp" aoqi@0: #include "gc_implementation/g1/survRateGroup.hpp" aoqi@0: #include "gc_implementation/shared/ageTable.hpp" aoqi@0: #include "gc_implementation/shared/spaceDecorator.hpp" aoqi@0: #include "memory/space.inline.hpp" aoqi@0: #include "memory/watermark.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: aoqi@0: // A HeapRegion is the smallest piece of a G1CollectedHeap that aoqi@0: // can be collected independently. aoqi@0: aoqi@0: // NOTE: Although a HeapRegion is a Space, its aoqi@0: // Space::initDirtyCardClosure method must not be called. aoqi@0: // The problem is that the existence of this method breaks aoqi@0: // the independence of barrier sets from remembered sets. aoqi@0: // The solution is to remove this method from the definition aoqi@0: // of a Space. aoqi@0: aoqi@0: class CompactibleSpace; aoqi@0: class ContiguousSpace; aoqi@0: class HeapRegionRemSet; aoqi@0: class HeapRegionRemSetIterator; aoqi@0: class HeapRegion; aoqi@0: class HeapRegionSetBase; aoqi@0: class nmethod; aoqi@0: aoqi@0: #define HR_FORMAT "%u:(%s)["PTR_FORMAT","PTR_FORMAT","PTR_FORMAT"]" aoqi@0: #define HR_FORMAT_PARAMS(_hr_) \ aoqi@0: (_hr_)->hrs_index(), \ aoqi@0: (_hr_)->is_survivor() ? "S" : (_hr_)->is_young() ? "E" : \ aoqi@0: (_hr_)->startsHumongous() ? "HS" : \ aoqi@0: (_hr_)->continuesHumongous() ? "HC" : \ aoqi@0: !(_hr_)->is_empty() ? "O" : "F", \ aoqi@0: p2i((_hr_)->bottom()), p2i((_hr_)->top()), p2i((_hr_)->end()) aoqi@0: aoqi@0: // sentinel value for hrs_index aoqi@0: #define G1_NULL_HRS_INDEX ((uint) -1) aoqi@0: aoqi@0: // A dirty card to oop closure for heap regions. It aoqi@0: // knows how to get the G1 heap and how to use the bitmap aoqi@0: // in the concurrent marker used by G1 to filter remembered aoqi@0: // sets. aoqi@0: aoqi@0: class HeapRegionDCTOC : public ContiguousSpaceDCTOC { aoqi@0: public: aoqi@0: // Specification of possible DirtyCardToOopClosure filtering. aoqi@0: enum FilterKind { aoqi@0: NoFilterKind, aoqi@0: IntoCSFilterKind, aoqi@0: OutOfRegionFilterKind aoqi@0: }; aoqi@0: aoqi@0: protected: aoqi@0: HeapRegion* _hr; aoqi@0: FilterKind _fk; aoqi@0: G1CollectedHeap* _g1; aoqi@0: aoqi@0: void walk_mem_region_with_cl(MemRegion mr, aoqi@0: HeapWord* bottom, HeapWord* top, aoqi@0: ExtendedOopClosure* cl); aoqi@0: aoqi@0: // We don't specialize this for FilteringClosure; filtering is handled by aoqi@0: // the "FilterKind" mechanism. But we provide this to avoid a compiler aoqi@0: // warning. aoqi@0: void walk_mem_region_with_cl(MemRegion mr, aoqi@0: HeapWord* bottom, HeapWord* top, aoqi@0: FilteringClosure* cl) { aoqi@0: HeapRegionDCTOC::walk_mem_region_with_cl(mr, bottom, top, aoqi@0: (ExtendedOopClosure*)cl); aoqi@0: } aoqi@0: aoqi@0: // Get the actual top of the area on which the closure will aoqi@0: // operate, given where the top is assumed to be (the end of the aoqi@0: // memory region passed to do_MemRegion) and where the object aoqi@0: // at the top is assumed to start. For example, an object may aoqi@0: // start at the top but actually extend past the assumed top, aoqi@0: // in which case the top becomes the end of the object. aoqi@0: HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj) { aoqi@0: return ContiguousSpaceDCTOC::get_actual_top(top, top_obj); aoqi@0: } aoqi@0: aoqi@0: // Walk the given memory region from bottom to (actual) top aoqi@0: // looking for objects and applying the oop closure (_cl) to aoqi@0: // them. The base implementation of this treats the area as aoqi@0: // blocks, where a block may or may not be an object. Sub- aoqi@0: // classes should override this to provide more accurate aoqi@0: // or possibly more efficient walking. aoqi@0: void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top) { aoqi@0: Filtering_DCTOC::walk_mem_region(mr, bottom, top); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: HeapRegionDCTOC(G1CollectedHeap* g1, aoqi@0: HeapRegion* hr, ExtendedOopClosure* cl, aoqi@0: CardTableModRefBS::PrecisionStyle precision, aoqi@0: FilterKind fk); aoqi@0: }; aoqi@0: aoqi@0: // The complicating factor is that BlockOffsetTable diverged aoqi@0: // significantly, and we need functionality that is only in the G1 version. aoqi@0: // So I copied that code, which led to an alternate G1 version of aoqi@0: // OffsetTableContigSpace. If the two versions of BlockOffsetTable could aoqi@0: // be reconciled, then G1OffsetTableContigSpace could go away. aoqi@0: aoqi@0: // The idea behind time stamps is the following. Doing a save_marks on aoqi@0: // all regions at every GC pause is time consuming (if I remember aoqi@0: // well, 10ms or so). So, we would like to do that only for regions aoqi@0: // that are GC alloc regions. To achieve this, we use time aoqi@0: // stamps. For every evacuation pause, G1CollectedHeap generates a aoqi@0: // unique time stamp (essentially a counter that gets aoqi@0: // incremented). Every time we want to call save_marks on a region, aoqi@0: // we set the saved_mark_word to top and also copy the current GC aoqi@0: // time stamp to the time stamp field of the space. Reading the aoqi@0: // saved_mark_word involves checking the time stamp of the aoqi@0: // region. If it is the same as the current GC time stamp, then we aoqi@0: // can safely read the saved_mark_word field, as it is valid. If the aoqi@0: // time stamp of the region is not the same as the current GC time aoqi@0: // stamp, then we instead read top, as the saved_mark_word field is aoqi@0: // invalid. Time stamps (on the regions and also on the aoqi@0: // G1CollectedHeap) are reset at every cleanup (we iterate over aoqi@0: // the regions anyway) and at the end of a Full GC. The current scheme aoqi@0: // that uses sequential unsigned ints will fail only if we have 4b aoqi@0: // evacuation pauses between two cleanups, which is _highly_ unlikely. aoqi@0: aoqi@0: class G1OffsetTableContigSpace: public ContiguousSpace { aoqi@0: friend class VMStructs; aoqi@0: protected: aoqi@0: G1BlockOffsetArrayContigSpace _offsets; aoqi@0: Mutex _par_alloc_lock; aoqi@0: volatile unsigned _gc_time_stamp; aoqi@0: // When we need to retire an allocation region, while other threads aoqi@0: // are also concurrently trying to allocate into it, we typically aoqi@0: // allocate a dummy object at the end of the region to ensure that aoqi@0: // no more allocations can take place in it. However, sometimes we aoqi@0: // want to know where the end of the last "real" object we allocated aoqi@0: // into the region was and this is what this keeps track. aoqi@0: HeapWord* _pre_dummy_top; aoqi@0: aoqi@0: public: aoqi@0: G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray, aoqi@0: MemRegion mr); aoqi@0: aoqi@0: void set_bottom(HeapWord* value); aoqi@0: void set_end(HeapWord* value); aoqi@0: aoqi@0: virtual HeapWord* saved_mark_word() const; aoqi@0: virtual void set_saved_mark(); aoqi@0: void reset_gc_time_stamp() { _gc_time_stamp = 0; } aoqi@0: unsigned get_gc_time_stamp() { return _gc_time_stamp; } aoqi@0: aoqi@0: // See the comment above in the declaration of _pre_dummy_top for an aoqi@0: // explanation of what it is. aoqi@0: void set_pre_dummy_top(HeapWord* pre_dummy_top) { aoqi@0: assert(is_in(pre_dummy_top) && pre_dummy_top <= top(), "pre-condition"); aoqi@0: _pre_dummy_top = pre_dummy_top; aoqi@0: } aoqi@0: HeapWord* pre_dummy_top() { aoqi@0: return (_pre_dummy_top == NULL) ? top() : _pre_dummy_top; aoqi@0: } aoqi@0: void reset_pre_dummy_top() { _pre_dummy_top = NULL; } aoqi@0: aoqi@0: virtual void clear(bool mangle_space); aoqi@0: aoqi@0: HeapWord* block_start(const void* p); aoqi@0: HeapWord* block_start_const(const void* p) const; aoqi@0: aoqi@0: // Add offset table update. aoqi@0: virtual HeapWord* allocate(size_t word_size); aoqi@0: HeapWord* par_allocate(size_t word_size); aoqi@0: aoqi@0: // MarkSweep support phase3 aoqi@0: virtual HeapWord* initialize_threshold(); aoqi@0: virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end); aoqi@0: aoqi@0: virtual void print() const; aoqi@0: aoqi@0: void reset_bot() { aoqi@0: _offsets.zero_bottom_entry(); aoqi@0: _offsets.initialize_threshold(); aoqi@0: } aoqi@0: aoqi@0: void update_bot_for_object(HeapWord* start, size_t word_size) { aoqi@0: _offsets.alloc_block(start, word_size); aoqi@0: } aoqi@0: aoqi@0: void print_bot_on(outputStream* out) { aoqi@0: _offsets.print_on(out); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class HeapRegion: public G1OffsetTableContigSpace { aoqi@0: friend class VMStructs; aoqi@0: private: aoqi@0: aoqi@0: enum HumongousType { aoqi@0: NotHumongous = 0, aoqi@0: StartsHumongous, aoqi@0: ContinuesHumongous aoqi@0: }; aoqi@0: aoqi@0: // Requires that the region "mr" be dense with objects, and begin and end aoqi@0: // with an object. aoqi@0: void oops_in_mr_iterate(MemRegion mr, ExtendedOopClosure* cl); aoqi@0: aoqi@0: // The remembered set for this region. aoqi@0: // (Might want to make this "inline" later, to avoid some alloc failure aoqi@0: // issues.) aoqi@0: HeapRegionRemSet* _rem_set; aoqi@0: aoqi@0: G1BlockOffsetArrayContigSpace* offsets() { return &_offsets; } aoqi@0: aoqi@0: protected: aoqi@0: // The index of this region in the heap region sequence. aoqi@0: uint _hrs_index; aoqi@0: aoqi@0: HumongousType _humongous_type; aoqi@0: // For a humongous region, region in which it starts. aoqi@0: HeapRegion* _humongous_start_region; aoqi@0: // For the start region of a humongous sequence, it's original end(). aoqi@0: HeapWord* _orig_end; aoqi@0: aoqi@0: // True iff the region is in current collection_set. aoqi@0: bool _in_collection_set; aoqi@0: aoqi@0: // True iff an attempt to evacuate an object in the region failed. aoqi@0: bool _evacuation_failed; aoqi@0: aoqi@0: // A heap region may be a member one of a number of special subsets, each aoqi@0: // represented as linked lists through the field below. Currently, these aoqi@0: // sets include: aoqi@0: // The collection set. aoqi@0: // The set of allocation regions used in a collection pause. aoqi@0: // Spaces that may contain gray objects. aoqi@0: HeapRegion* _next_in_special_set; aoqi@0: aoqi@0: // next region in the young "generation" region set aoqi@0: HeapRegion* _next_young_region; aoqi@0: aoqi@0: // Next region whose cards need cleaning aoqi@0: HeapRegion* _next_dirty_cards_region; aoqi@0: aoqi@0: // Fields used by the HeapRegionSetBase class and subclasses. aoqi@0: HeapRegion* _next; aoqi@0: HeapRegion* _prev; aoqi@0: #ifdef ASSERT aoqi@0: HeapRegionSetBase* _containing_set; aoqi@0: #endif // ASSERT aoqi@0: bool _pending_removal; aoqi@0: aoqi@0: // For parallel heapRegion traversal. aoqi@0: jint _claimed; aoqi@0: aoqi@0: // We use concurrent marking to determine the amount of live data aoqi@0: // in each heap region. aoqi@0: size_t _prev_marked_bytes; // Bytes known to be live via last completed marking. aoqi@0: size_t _next_marked_bytes; // Bytes known to be live via in-progress marking. aoqi@0: aoqi@0: // The calculated GC efficiency of the region. aoqi@0: double _gc_efficiency; aoqi@0: aoqi@0: enum YoungType { aoqi@0: NotYoung, // a region is not young aoqi@0: Young, // a region is young aoqi@0: Survivor // a region is young and it contains survivors aoqi@0: }; aoqi@0: aoqi@0: volatile YoungType _young_type; aoqi@0: int _young_index_in_cset; aoqi@0: SurvRateGroup* _surv_rate_group; aoqi@0: int _age_index; aoqi@0: aoqi@0: // The start of the unmarked area. The unmarked area extends from this aoqi@0: // word until the top and/or end of the region, and is the part aoqi@0: // of the region for which no marking was done, i.e. objects may aoqi@0: // have been allocated in this part since the last mark phase. aoqi@0: // "prev" is the top at the start of the last completed marking. aoqi@0: // "next" is the top at the start of the in-progress marking (if any.) aoqi@0: HeapWord* _prev_top_at_mark_start; aoqi@0: HeapWord* _next_top_at_mark_start; aoqi@0: // If a collection pause is in progress, this is the top at the start aoqi@0: // of that pause. aoqi@0: aoqi@0: void init_top_at_mark_start() { aoqi@0: assert(_prev_marked_bytes == 0 && aoqi@0: _next_marked_bytes == 0, aoqi@0: "Must be called after zero_marked_bytes."); aoqi@0: HeapWord* bot = bottom(); aoqi@0: _prev_top_at_mark_start = bot; aoqi@0: _next_top_at_mark_start = bot; aoqi@0: } aoqi@0: aoqi@0: void set_young_type(YoungType new_type) { aoqi@0: //assert(_young_type != new_type, "setting the same type" ); aoqi@0: // TODO: add more assertions here aoqi@0: _young_type = new_type; aoqi@0: } aoqi@0: aoqi@0: // Cached attributes used in the collection set policy information aoqi@0: aoqi@0: // The RSet length that was added to the total value aoqi@0: // for the collection set. aoqi@0: size_t _recorded_rs_length; aoqi@0: aoqi@0: // The predicted elapsed time that was added to total value aoqi@0: // for the collection set. aoqi@0: double _predicted_elapsed_time_ms; aoqi@0: aoqi@0: // The predicted number of bytes to copy that was added to aoqi@0: // the total value for the collection set. aoqi@0: size_t _predicted_bytes_to_copy; aoqi@0: aoqi@0: public: aoqi@0: HeapRegion(uint hrs_index, aoqi@0: G1BlockOffsetSharedArray* sharedOffsetArray, aoqi@0: MemRegion mr); aoqi@0: aoqi@0: static int LogOfHRGrainBytes; aoqi@0: static int LogOfHRGrainWords; aoqi@0: aoqi@0: static size_t GrainBytes; aoqi@0: static size_t GrainWords; aoqi@0: static size_t CardsPerRegion; aoqi@0: aoqi@0: static size_t align_up_to_region_byte_size(size_t sz) { aoqi@0: return (sz + (size_t) GrainBytes - 1) & aoqi@0: ~((1 << (size_t) LogOfHRGrainBytes) - 1); aoqi@0: } aoqi@0: aoqi@0: static size_t max_region_size(); aoqi@0: aoqi@0: // It sets up the heap region size (GrainBytes / GrainWords), as aoqi@0: // well as other related fields that are based on the heap region aoqi@0: // size (LogOfHRGrainBytes / LogOfHRGrainWords / aoqi@0: // CardsPerRegion). All those fields are considered constant aoqi@0: // throughout the JVM's execution, therefore they should only be set aoqi@0: // up once during initialization time. aoqi@0: static void setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size); aoqi@0: aoqi@0: enum ClaimValues { aoqi@0: InitialClaimValue = 0, aoqi@0: FinalCountClaimValue = 1, aoqi@0: NoteEndClaimValue = 2, aoqi@0: ScrubRemSetClaimValue = 3, aoqi@0: ParVerifyClaimValue = 4, aoqi@0: RebuildRSClaimValue = 5, aoqi@0: ParEvacFailureClaimValue = 6, aoqi@0: AggregateCountClaimValue = 7, aoqi@0: VerifyCountClaimValue = 8, aoqi@0: ParMarkRootClaimValue = 9 aoqi@0: }; aoqi@0: aoqi@0: inline HeapWord* par_allocate_no_bot_updates(size_t word_size) { aoqi@0: assert(is_young(), "we can only skip BOT updates on young regions"); aoqi@0: return ContiguousSpace::par_allocate(word_size); aoqi@0: } aoqi@0: inline HeapWord* allocate_no_bot_updates(size_t word_size) { aoqi@0: assert(is_young(), "we can only skip BOT updates on young regions"); aoqi@0: return ContiguousSpace::allocate(word_size); aoqi@0: } aoqi@0: aoqi@0: // If this region is a member of a HeapRegionSeq, the index in that aoqi@0: // sequence, otherwise -1. aoqi@0: uint hrs_index() const { return _hrs_index; } aoqi@0: aoqi@0: // The number of bytes marked live in the region in the last marking phase. aoqi@0: size_t marked_bytes() { return _prev_marked_bytes; } aoqi@0: size_t live_bytes() { aoqi@0: return (top() - prev_top_at_mark_start()) * HeapWordSize + marked_bytes(); aoqi@0: } aoqi@0: aoqi@0: // The number of bytes counted in the next marking. aoqi@0: size_t next_marked_bytes() { return _next_marked_bytes; } aoqi@0: // The number of bytes live wrt the next marking. aoqi@0: size_t next_live_bytes() { aoqi@0: return aoqi@0: (top() - next_top_at_mark_start()) * HeapWordSize + next_marked_bytes(); aoqi@0: } aoqi@0: aoqi@0: // A lower bound on the amount of garbage bytes in the region. aoqi@0: size_t garbage_bytes() { aoqi@0: size_t used_at_mark_start_bytes = aoqi@0: (prev_top_at_mark_start() - bottom()) * HeapWordSize; aoqi@0: assert(used_at_mark_start_bytes >= marked_bytes(), aoqi@0: "Can't mark more than we have."); aoqi@0: return used_at_mark_start_bytes - marked_bytes(); aoqi@0: } aoqi@0: aoqi@0: // Return the amount of bytes we'll reclaim if we collect this aoqi@0: // region. This includes not only the known garbage bytes in the aoqi@0: // region but also any unallocated space in it, i.e., [top, end), aoqi@0: // since it will also be reclaimed if we collect the region. aoqi@0: size_t reclaimable_bytes() { aoqi@0: size_t known_live_bytes = live_bytes(); aoqi@0: assert(known_live_bytes <= capacity(), "sanity"); aoqi@0: return capacity() - known_live_bytes; aoqi@0: } aoqi@0: aoqi@0: // An upper bound on the number of live bytes in the region. aoqi@0: size_t max_live_bytes() { return used() - garbage_bytes(); } aoqi@0: aoqi@0: void add_to_marked_bytes(size_t incr_bytes) { aoqi@0: _next_marked_bytes = _next_marked_bytes + incr_bytes; aoqi@0: assert(_next_marked_bytes <= used(), "invariant" ); aoqi@0: } aoqi@0: aoqi@0: void zero_marked_bytes() { aoqi@0: _prev_marked_bytes = _next_marked_bytes = 0; aoqi@0: } aoqi@0: aoqi@0: bool isHumongous() const { return _humongous_type != NotHumongous; } aoqi@0: bool startsHumongous() const { return _humongous_type == StartsHumongous; } aoqi@0: bool continuesHumongous() const { return _humongous_type == ContinuesHumongous; } aoqi@0: // For a humongous region, region in which it starts. aoqi@0: HeapRegion* humongous_start_region() const { aoqi@0: return _humongous_start_region; aoqi@0: } aoqi@0: aoqi@0: // Return the number of distinct regions that are covered by this region: aoqi@0: // 1 if the region is not humongous, >= 1 if the region is humongous. aoqi@0: uint region_num() const { aoqi@0: if (!isHumongous()) { aoqi@0: return 1U; aoqi@0: } else { aoqi@0: assert(startsHumongous(), "doesn't make sense on HC regions"); aoqi@0: assert(capacity() % HeapRegion::GrainBytes == 0, "sanity"); aoqi@0: return (uint) (capacity() >> HeapRegion::LogOfHRGrainBytes); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Return the index + 1 of the last HC regions that's associated aoqi@0: // with this HS region. aoqi@0: uint last_hc_index() const { aoqi@0: assert(startsHumongous(), "don't call this otherwise"); aoqi@0: return hrs_index() + region_num(); aoqi@0: } aoqi@0: aoqi@0: // Same as Space::is_in_reserved, but will use the original size of the region. aoqi@0: // The original size is different only for start humongous regions. They get aoqi@0: // their _end set up to be the end of the last continues region of the aoqi@0: // corresponding humongous object. aoqi@0: bool is_in_reserved_raw(const void* p) const { aoqi@0: return _bottom <= p && p < _orig_end; aoqi@0: } aoqi@0: aoqi@0: // Makes the current region be a "starts humongous" region, i.e., aoqi@0: // the first region in a series of one or more contiguous regions aoqi@0: // that will contain a single "humongous" object. The two parameters aoqi@0: // are as follows: aoqi@0: // aoqi@0: // new_top : The new value of the top field of this region which aoqi@0: // points to the end of the humongous object that's being aoqi@0: // allocated. If there is more than one region in the series, top aoqi@0: // will lie beyond this region's original end field and on the last aoqi@0: // region in the series. aoqi@0: // aoqi@0: // new_end : The new value of the end field of this region which aoqi@0: // points to the end of the last region in the series. If there is aoqi@0: // one region in the series (namely: this one) end will be the same aoqi@0: // as the original end of this region. aoqi@0: // aoqi@0: // Updating top and end as described above makes this region look as aoqi@0: // if it spans the entire space taken up by all the regions in the aoqi@0: // series and an single allocation moved its top to new_top. This aoqi@0: // ensures that the space (capacity / allocated) taken up by all aoqi@0: // humongous regions can be calculated by just looking at the aoqi@0: // "starts humongous" regions and by ignoring the "continues aoqi@0: // humongous" regions. aoqi@0: void set_startsHumongous(HeapWord* new_top, HeapWord* new_end); aoqi@0: aoqi@0: // Makes the current region be a "continues humongous' aoqi@0: // region. first_hr is the "start humongous" region of the series aoqi@0: // which this region will be part of. aoqi@0: void set_continuesHumongous(HeapRegion* first_hr); aoqi@0: aoqi@0: // Unsets the humongous-related fields on the region. aoqi@0: void set_notHumongous(); aoqi@0: aoqi@0: // If the region has a remembered set, return a pointer to it. aoqi@0: HeapRegionRemSet* rem_set() const { aoqi@0: return _rem_set; aoqi@0: } aoqi@0: aoqi@0: // True iff the region is in current collection_set. aoqi@0: bool in_collection_set() const { aoqi@0: return _in_collection_set; aoqi@0: } aoqi@0: void set_in_collection_set(bool b) { aoqi@0: _in_collection_set = b; aoqi@0: } aoqi@0: HeapRegion* next_in_collection_set() { aoqi@0: assert(in_collection_set(), "should only invoke on member of CS."); aoqi@0: assert(_next_in_special_set == NULL || aoqi@0: _next_in_special_set->in_collection_set(), aoqi@0: "Malformed CS."); aoqi@0: return _next_in_special_set; aoqi@0: } aoqi@0: void set_next_in_collection_set(HeapRegion* r) { aoqi@0: assert(in_collection_set(), "should only invoke on member of CS."); aoqi@0: assert(r == NULL || r->in_collection_set(), "Malformed CS."); aoqi@0: _next_in_special_set = r; aoqi@0: } aoqi@0: aoqi@0: // Methods used by the HeapRegionSetBase class and subclasses. aoqi@0: aoqi@0: // Getter and setter for the next and prev fields used to link regions into aoqi@0: // linked lists. aoqi@0: HeapRegion* next() { return _next; } aoqi@0: HeapRegion* prev() { return _prev; } aoqi@0: aoqi@0: void set_next(HeapRegion* next) { _next = next; } aoqi@0: void set_prev(HeapRegion* prev) { _prev = prev; } aoqi@0: aoqi@0: // Every region added to a set is tagged with a reference to that aoqi@0: // set. This is used for doing consistency checking to make sure that aoqi@0: // the contents of a set are as they should be and it's only aoqi@0: // available in non-product builds. aoqi@0: #ifdef ASSERT aoqi@0: void set_containing_set(HeapRegionSetBase* containing_set) { aoqi@0: assert((containing_set == NULL && _containing_set != NULL) || aoqi@0: (containing_set != NULL && _containing_set == NULL), aoqi@0: err_msg("containing_set: "PTR_FORMAT" " aoqi@0: "_containing_set: "PTR_FORMAT, aoqi@0: p2i(containing_set), p2i(_containing_set))); aoqi@0: aoqi@0: _containing_set = containing_set; aoqi@0: } aoqi@0: aoqi@0: HeapRegionSetBase* containing_set() { return _containing_set; } aoqi@0: #else // ASSERT aoqi@0: void set_containing_set(HeapRegionSetBase* containing_set) { } aoqi@0: aoqi@0: // containing_set() is only used in asserts so there's no reason aoqi@0: // to provide a dummy version of it. aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: // If we want to remove regions from a list in bulk we can simply tag aoqi@0: // them with the pending_removal tag and call the aoqi@0: // remove_all_pending() method on the list. aoqi@0: aoqi@0: bool pending_removal() { return _pending_removal; } aoqi@0: aoqi@0: void set_pending_removal(bool pending_removal) { aoqi@0: if (pending_removal) { aoqi@0: assert(!_pending_removal && containing_set() != NULL, aoqi@0: "can only set pending removal to true if it's false and " aoqi@0: "the region belongs to a region set"); aoqi@0: } else { aoqi@0: assert( _pending_removal && containing_set() == NULL, aoqi@0: "can only set pending removal to false if it's true and " aoqi@0: "the region does not belong to a region set"); aoqi@0: } aoqi@0: aoqi@0: _pending_removal = pending_removal; aoqi@0: } aoqi@0: aoqi@0: HeapRegion* get_next_young_region() { return _next_young_region; } aoqi@0: void set_next_young_region(HeapRegion* hr) { aoqi@0: _next_young_region = hr; aoqi@0: } aoqi@0: aoqi@0: HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; } aoqi@0: HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; } aoqi@0: void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; } aoqi@0: bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; } aoqi@0: aoqi@0: HeapWord* orig_end() { return _orig_end; } aoqi@0: aoqi@0: // Allows logical separation between objects allocated before and after. aoqi@0: void save_marks(); aoqi@0: aoqi@0: // Reset HR stuff to default values. aoqi@0: void hr_clear(bool par, bool clear_space, bool locked = false); aoqi@0: void par_clear(); aoqi@0: aoqi@0: // Get the start of the unmarked area in this region. aoqi@0: HeapWord* prev_top_at_mark_start() const { return _prev_top_at_mark_start; } aoqi@0: HeapWord* next_top_at_mark_start() const { return _next_top_at_mark_start; } aoqi@0: aoqi@0: // Apply "cl->do_oop" to (the addresses of) all reference fields in objects aoqi@0: // allocated in the current region before the last call to "save_mark". aoqi@0: void oop_before_save_marks_iterate(ExtendedOopClosure* cl); aoqi@0: aoqi@0: // Note the start or end of marking. This tells the heap region aoqi@0: // that the collector is about to start or has finished (concurrently) aoqi@0: // marking the heap. aoqi@0: aoqi@0: // Notify the region that concurrent marking is starting. Initialize aoqi@0: // all fields related to the next marking info. aoqi@0: inline void note_start_of_marking(); aoqi@0: aoqi@0: // Notify the region that concurrent marking has finished. Copy the aoqi@0: // (now finalized) next marking info fields into the prev marking aoqi@0: // info fields. aoqi@0: inline void note_end_of_marking(); aoqi@0: aoqi@0: // Notify the region that it will be used as to-space during a GC aoqi@0: // and we are about to start copying objects into it. aoqi@0: inline void note_start_of_copying(bool during_initial_mark); aoqi@0: aoqi@0: // Notify the region that it ceases being to-space during a GC and aoqi@0: // we will not copy objects into it any more. aoqi@0: inline void note_end_of_copying(bool during_initial_mark); aoqi@0: aoqi@0: // Notify the region that we are about to start processing aoqi@0: // self-forwarded objects during evac failure handling. aoqi@0: void note_self_forwarding_removal_start(bool during_initial_mark, aoqi@0: bool during_conc_mark); aoqi@0: aoqi@0: // Notify the region that we have finished processing self-forwarded aoqi@0: // objects during evac failure handling. aoqi@0: void note_self_forwarding_removal_end(bool during_initial_mark, aoqi@0: bool during_conc_mark, aoqi@0: size_t marked_bytes); aoqi@0: aoqi@0: // Returns "false" iff no object in the region was allocated when the aoqi@0: // last mark phase ended. aoqi@0: bool is_marked() { return _prev_top_at_mark_start != bottom(); } aoqi@0: aoqi@0: void reset_during_compaction() { aoqi@0: assert(isHumongous() && startsHumongous(), aoqi@0: "should only be called for starts humongous regions"); aoqi@0: aoqi@0: zero_marked_bytes(); aoqi@0: init_top_at_mark_start(); aoqi@0: } aoqi@0: aoqi@0: void calc_gc_efficiency(void); aoqi@0: double gc_efficiency() { return _gc_efficiency;} aoqi@0: aoqi@0: bool is_young() const { return _young_type != NotYoung; } aoqi@0: bool is_survivor() const { return _young_type == Survivor; } aoqi@0: aoqi@0: int young_index_in_cset() const { return _young_index_in_cset; } aoqi@0: void set_young_index_in_cset(int index) { aoqi@0: assert( (index == -1) || is_young(), "pre-condition" ); aoqi@0: _young_index_in_cset = index; aoqi@0: } aoqi@0: aoqi@0: int age_in_surv_rate_group() { aoqi@0: assert( _surv_rate_group != NULL, "pre-condition" ); aoqi@0: assert( _age_index > -1, "pre-condition" ); aoqi@0: return _surv_rate_group->age_in_group(_age_index); aoqi@0: } aoqi@0: aoqi@0: void record_surv_words_in_group(size_t words_survived) { aoqi@0: assert( _surv_rate_group != NULL, "pre-condition" ); aoqi@0: assert( _age_index > -1, "pre-condition" ); aoqi@0: int age_in_group = age_in_surv_rate_group(); aoqi@0: _surv_rate_group->record_surviving_words(age_in_group, words_survived); aoqi@0: } aoqi@0: aoqi@0: int age_in_surv_rate_group_cond() { aoqi@0: if (_surv_rate_group != NULL) aoqi@0: return age_in_surv_rate_group(); aoqi@0: else aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: SurvRateGroup* surv_rate_group() { aoqi@0: return _surv_rate_group; aoqi@0: } aoqi@0: aoqi@0: void install_surv_rate_group(SurvRateGroup* surv_rate_group) { aoqi@0: assert( surv_rate_group != NULL, "pre-condition" ); aoqi@0: assert( _surv_rate_group == NULL, "pre-condition" ); aoqi@0: assert( is_young(), "pre-condition" ); aoqi@0: aoqi@0: _surv_rate_group = surv_rate_group; aoqi@0: _age_index = surv_rate_group->next_age_index(); aoqi@0: } aoqi@0: aoqi@0: void uninstall_surv_rate_group() { aoqi@0: if (_surv_rate_group != NULL) { aoqi@0: assert( _age_index > -1, "pre-condition" ); aoqi@0: assert( is_young(), "pre-condition" ); aoqi@0: aoqi@0: _surv_rate_group = NULL; aoqi@0: _age_index = -1; aoqi@0: } else { aoqi@0: assert( _age_index == -1, "pre-condition" ); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void set_young() { set_young_type(Young); } aoqi@0: aoqi@0: void set_survivor() { set_young_type(Survivor); } aoqi@0: aoqi@0: void set_not_young() { set_young_type(NotYoung); } aoqi@0: aoqi@0: // Determine if an object has been allocated since the last aoqi@0: // mark performed by the collector. This returns true iff the object aoqi@0: // is within the unmarked area of the region. aoqi@0: bool obj_allocated_since_prev_marking(oop obj) const { aoqi@0: return (HeapWord *) obj >= prev_top_at_mark_start(); aoqi@0: } aoqi@0: bool obj_allocated_since_next_marking(oop obj) const { aoqi@0: return (HeapWord *) obj >= next_top_at_mark_start(); aoqi@0: } aoqi@0: aoqi@0: // For parallel heapRegion traversal. aoqi@0: bool claimHeapRegion(int claimValue); aoqi@0: jint claim_value() { return _claimed; } aoqi@0: // Use this carefully: only when you're sure no one is claiming... aoqi@0: void set_claim_value(int claimValue) { _claimed = claimValue; } aoqi@0: aoqi@0: // Returns the "evacuation_failed" property of the region. aoqi@0: bool evacuation_failed() { return _evacuation_failed; } aoqi@0: aoqi@0: // Sets the "evacuation_failed" property of the region. aoqi@0: void set_evacuation_failed(bool b) { aoqi@0: _evacuation_failed = b; aoqi@0: aoqi@0: if (b) { aoqi@0: _next_marked_bytes = 0; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Requires that "mr" be entirely within the region. aoqi@0: // Apply "cl->do_object" to all objects that intersect with "mr". aoqi@0: // If the iteration encounters an unparseable portion of the region, aoqi@0: // or if "cl->abort()" is true after a closure application, aoqi@0: // terminate the iteration and return the address of the start of the aoqi@0: // subregion that isn't done. (The two can be distinguished by querying aoqi@0: // "cl->abort()".) Return of "NULL" indicates that the iteration aoqi@0: // completed. aoqi@0: HeapWord* aoqi@0: object_iterate_mem_careful(MemRegion mr, ObjectClosure* cl); aoqi@0: aoqi@0: // filter_young: if true and the region is a young region then we aoqi@0: // skip the iteration. aoqi@0: // card_ptr: if not NULL, and we decide that the card is not young aoqi@0: // and we iterate over it, we'll clean the card before we start the aoqi@0: // iteration. aoqi@0: HeapWord* aoqi@0: oops_on_card_seq_iterate_careful(MemRegion mr, aoqi@0: FilterOutOfRegionClosure* cl, aoqi@0: bool filter_young, aoqi@0: jbyte* card_ptr); aoqi@0: aoqi@0: // A version of block start that is guaranteed to find *some* block aoqi@0: // boundary at or before "p", but does not object iteration, and may aoqi@0: // therefore be used safely when the heap is unparseable. aoqi@0: HeapWord* block_start_careful(const void* p) const { aoqi@0: return _offsets.block_start_careful(p); aoqi@0: } aoqi@0: aoqi@0: // Requires that "addr" is within the region. Returns the start of the aoqi@0: // first ("careful") block that starts at or after "addr", or else the aoqi@0: // "end" of the region if there is no such block. aoqi@0: HeapWord* next_block_start_careful(HeapWord* addr); aoqi@0: aoqi@0: size_t recorded_rs_length() const { return _recorded_rs_length; } aoqi@0: double predicted_elapsed_time_ms() const { return _predicted_elapsed_time_ms; } aoqi@0: size_t predicted_bytes_to_copy() const { return _predicted_bytes_to_copy; } aoqi@0: aoqi@0: void set_recorded_rs_length(size_t rs_length) { aoqi@0: _recorded_rs_length = rs_length; aoqi@0: } aoqi@0: aoqi@0: void set_predicted_elapsed_time_ms(double ms) { aoqi@0: _predicted_elapsed_time_ms = ms; aoqi@0: } aoqi@0: aoqi@0: void set_predicted_bytes_to_copy(size_t bytes) { aoqi@0: _predicted_bytes_to_copy = bytes; aoqi@0: } aoqi@0: aoqi@0: #define HeapRegion_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ aoqi@0: virtual void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl); aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DECL) aoqi@0: aoqi@0: virtual CompactibleSpace* next_compaction_space() const; aoqi@0: aoqi@0: virtual void reset_after_compaction(); aoqi@0: aoqi@0: // Routines for managing a list of code roots (attached to the aoqi@0: // this region's RSet) that point into this heap region. aoqi@0: void add_strong_code_root(nmethod* nm); aoqi@0: void remove_strong_code_root(nmethod* nm); aoqi@0: aoqi@0: // During a collection, migrate the successfully evacuated aoqi@0: // strong code roots that referenced into this region to the aoqi@0: // new regions that they now point into. Unsuccessfully aoqi@0: // evacuated code roots are not migrated. aoqi@0: void migrate_strong_code_roots(); aoqi@0: aoqi@0: // Applies blk->do_code_blob() to each of the entries in aoqi@0: // the strong code roots list for this region aoqi@0: void strong_code_roots_do(CodeBlobClosure* blk) const; aoqi@0: aoqi@0: // Verify that the entries on the strong code root list for this aoqi@0: // region are live and include at least one pointer into this region. aoqi@0: void verify_strong_code_roots(VerifyOption vo, bool* failures) const; aoqi@0: aoqi@0: void print() const; aoqi@0: void print_on(outputStream* st) const; aoqi@0: aoqi@0: // vo == UsePrevMarking -> use "prev" marking information, aoqi@0: // vo == UseNextMarking -> use "next" marking information aoqi@0: // vo == UseMarkWord -> use the mark word in the object header aoqi@0: // aoqi@0: // NOTE: Only the "prev" marking information is guaranteed to be aoqi@0: // consistent most of the time, so most calls to this should use aoqi@0: // vo == UsePrevMarking. aoqi@0: // Currently, there is only one case where this is called with aoqi@0: // vo == UseNextMarking, which is to verify the "next" marking aoqi@0: // information at the end of remark. aoqi@0: // Currently there is only one place where this is called with aoqi@0: // vo == UseMarkWord, which is to verify the marking during a aoqi@0: // full GC. aoqi@0: void verify(VerifyOption vo, bool *failures) const; aoqi@0: aoqi@0: // Override; it uses the "prev" marking information aoqi@0: virtual void verify() const; aoqi@0: }; aoqi@0: aoqi@0: // HeapRegionClosure is used for iterating over regions. aoqi@0: // Terminates the iteration when the "doHeapRegion" method returns "true". aoqi@0: class HeapRegionClosure : public StackObj { aoqi@0: friend class HeapRegionSeq; aoqi@0: friend class G1CollectedHeap; aoqi@0: aoqi@0: bool _complete; aoqi@0: void incomplete() { _complete = false; } aoqi@0: aoqi@0: public: aoqi@0: HeapRegionClosure(): _complete(true) {} aoqi@0: aoqi@0: // Typically called on each region until it returns true. aoqi@0: virtual bool doHeapRegion(HeapRegion* r) = 0; aoqi@0: aoqi@0: // True after iteration if the closure was applied to all heap regions aoqi@0: // and returned "false" in all cases. aoqi@0: bool complete() { return _complete; } aoqi@0: }; aoqi@0: aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP