8332864: Parallel: Merge ParMarkBitMapClosure into MoveAndUpdateClosure

Reviewed-by: tschatzl
This commit is contained in:
Albert Mingkun Yang 2024-05-28 08:08:42 +00:00
parent 2f2cf38bb5
commit 1850914380
2 changed files with 45 additions and 96 deletions

View File

@ -2523,7 +2523,7 @@ void PSParallelCompact::fill_region(ParCompactionManager* cm, MoveAndUpdateClosu
void PSParallelCompact::fill_and_update_region(ParCompactionManager* cm, size_t region_idx) void PSParallelCompact::fill_and_update_region(ParCompactionManager* cm, size_t region_idx)
{ {
MoveAndUpdateClosure cl(mark_bitmap(), cm, region_idx); MoveAndUpdateClosure cl(mark_bitmap(), region_idx);
fill_region(cm, cl, region_idx); fill_region(cm, cl, region_idx);
} }
@ -2537,7 +2537,7 @@ void PSParallelCompact::fill_and_update_shadow_region(ParCompactionManager* cm,
// so use MoveAndUpdateClosure to fill the normal region. Otherwise, use // so use MoveAndUpdateClosure to fill the normal region. Otherwise, use
// MoveAndUpdateShadowClosure to fill the acquired shadow region. // MoveAndUpdateShadowClosure to fill the acquired shadow region.
if (shadow_region == ParCompactionManager::InvalidShadow) { if (shadow_region == ParCompactionManager::InvalidShadow) {
MoveAndUpdateClosure cl(mark_bitmap(), cm, region_idx); MoveAndUpdateClosure cl(mark_bitmap(), region_idx);
region_ptr->shadow_to_normal(); region_ptr->shadow_to_normal();
return fill_region(cm, cl, region_idx); return fill_region(cm, cl, region_idx);
} else { } else {
@ -2624,7 +2624,7 @@ void MoveAndUpdateClosure::complete_region(ParCompactionManager *cm, HeapWord *d
region_ptr->set_completed(); region_ptr->set_completed();
} }
ParMarkBitMapClosure::IterationStatus MoveAndUpdateClosure::IterationStatus
MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) { MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) {
assert(destination() != nullptr, "sanity"); assert(destination() != nullptr, "sanity");
_source = addr; _source = addr;

View File

@ -586,75 +586,6 @@ ParallelCompactData::is_region_aligned(HeapWord* addr) const
// single subclass that uses it to avoid making is_full() virtual, and thus // single subclass that uses it to avoid making is_full() virtual, and thus
// adding a virtual call per live object. // adding a virtual call per live object.
class ParMarkBitMapClosure: public StackObj {
public:
typedef ParMarkBitMap::idx_t idx_t;
typedef ParMarkBitMap::IterationStatus IterationStatus;
public:
inline ParMarkBitMapClosure(ParMarkBitMap* mbm, ParCompactionManager* cm,
size_t words = max_uintx);
inline ParCompactionManager* compaction_manager() const;
inline ParMarkBitMap* bitmap() const;
inline size_t words_remaining() const;
inline bool is_full() const;
inline HeapWord* source() const;
inline void set_source(HeapWord* addr);
virtual IterationStatus do_addr(HeapWord* addr, size_t words) = 0;
protected:
inline void decrement_words_remaining(size_t words);
private:
ParMarkBitMap* const _bitmap;
ParCompactionManager* const _compaction_manager;
size_t _words_remaining; // Words left to copy.
protected:
HeapWord* _source; // Next addr that would be read.
};
inline
ParMarkBitMapClosure::ParMarkBitMapClosure(ParMarkBitMap* bitmap,
ParCompactionManager* cm,
size_t words):
_bitmap(bitmap), _compaction_manager(cm)
{
_words_remaining = words;
_source = nullptr;
}
inline ParCompactionManager* ParMarkBitMapClosure::compaction_manager() const {
return _compaction_manager;
}
inline ParMarkBitMap* ParMarkBitMapClosure::bitmap() const {
return _bitmap;
}
inline size_t ParMarkBitMapClosure::words_remaining() const {
return _words_remaining;
}
inline bool ParMarkBitMapClosure::is_full() const {
return words_remaining() == 0;
}
inline HeapWord* ParMarkBitMapClosure::source() const {
return _source;
}
inline void ParMarkBitMapClosure::set_source(HeapWord* addr) {
_source = addr;
}
inline void ParMarkBitMapClosure::decrement_words_remaining(size_t words) {
assert(_words_remaining >= words, "processed too many words");
_words_remaining -= words;
}
// The Parallel collector is a stop-the-world garbage collector that // The Parallel collector is a stop-the-world garbage collector that
// does parts of the collection using parallel threads. The collection includes // does parts of the collection using parallel threads. The collection includes
@ -955,21 +886,44 @@ public:
#endif // #ifdef ASSERT #endif // #ifdef ASSERT
}; };
class MoveAndUpdateClosure: public ParMarkBitMapClosure { class MoveAndUpdateClosure: public StackObj {
private:
ParMarkBitMap* const _bitmap;
size_t _words_remaining; // Words left to copy.
static inline size_t calculate_words_remaining(size_t region); static inline size_t calculate_words_remaining(size_t region);
public:
inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, ParCompactionManager* cm,
size_t region);
// Accessors. protected:
HeapWord* destination() const { return _destination; } HeapWord* _source; // Next addr that would be read.
HeapWord* copy_destination() const { return _destination + _offset; } HeapWord* _destination; // Next addr to be written.
ObjectStartArray* const _start_array;
size_t _offset;
inline void decrement_words_remaining(size_t words);
// Update variables to indicate that word_count words were processed.
inline void update_state(size_t words);
public:
typedef ParMarkBitMap::idx_t idx_t;
typedef ParMarkBitMap::IterationStatus IterationStatus;
ParMarkBitMap* bitmap() const { return _bitmap; }
size_t words_remaining() const { return _words_remaining; }
bool is_full() const { return _words_remaining == 0; }
HeapWord* source() const { return _source; }
void set_source(HeapWord* addr) { _source = addr; }
// If the object will fit (size <= words_remaining()), copy it to the current // If the object will fit (size <= words_remaining()), copy it to the current
// destination, update the interior oops and the start array and return either // destination, update the interior oops and the start array and return either
// full (if the closure is full) or incomplete. If the object will not fit, // full (if the closure is full) or incomplete. If the object will not fit,
// return would_overflow. // return would_overflow.
IterationStatus do_addr(HeapWord* addr, size_t size); virtual IterationStatus do_addr(HeapWord* addr, size_t words);
inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, size_t region);
// Accessors.
HeapWord* destination() const { return _destination; }
HeapWord* copy_destination() const { return _destination + _offset; }
// Copy enough words to fill this closure or to the end of an object, // Copy enough words to fill this closure or to the end of an object,
// whichever is smaller, starting at source(). The start array is not // whichever is smaller, starting at source(). The start array is not
@ -978,17 +932,13 @@ class MoveAndUpdateClosure: public ParMarkBitMapClosure {
virtual void complete_region(ParCompactionManager* cm, HeapWord* dest_addr, virtual void complete_region(ParCompactionManager* cm, HeapWord* dest_addr,
PSParallelCompact::RegionData* region_ptr); PSParallelCompact::RegionData* region_ptr);
protected:
// Update variables to indicate that word_count words were processed.
inline void update_state(size_t word_count);
protected:
HeapWord* _destination; // Next addr to be written.
ObjectStartArray* const _start_array;
size_t _offset;
}; };
inline void MoveAndUpdateClosure::decrement_words_remaining(size_t words) {
assert(_words_remaining >= words, "processed too many words");
_words_remaining -= words;
}
inline size_t MoveAndUpdateClosure::calculate_words_remaining(size_t region) { inline size_t MoveAndUpdateClosure::calculate_words_remaining(size_t region) {
HeapWord* dest_addr = PSParallelCompact::summary_data().region_to_addr(region); HeapWord* dest_addr = PSParallelCompact::summary_data().region_to_addr(region);
PSParallelCompact::SpaceId dest_space_id = PSParallelCompact::space_id(dest_addr); PSParallelCompact::SpaceId dest_space_id = PSParallelCompact::space_id(dest_addr);
@ -999,14 +949,13 @@ inline size_t MoveAndUpdateClosure::calculate_words_remaining(size_t region) {
} }
inline inline
MoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap, MoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap, size_t region_idx) :
ParCompactionManager* cm, _bitmap(bitmap),
size_t region_idx) : _words_remaining(calculate_words_remaining(region_idx)),
ParMarkBitMapClosure(bitmap, cm, calculate_words_remaining(region_idx)), _source(nullptr),
_destination(PSParallelCompact::summary_data().region_to_addr(region_idx)), _destination(PSParallelCompact::summary_data().region_to_addr(region_idx)),
_start_array(PSParallelCompact::start_array(PSParallelCompact::space_id(_destination))), _start_array(PSParallelCompact::start_array(PSParallelCompact::space_id(_destination))),
_offset(0) { } _offset(0) {}
inline void MoveAndUpdateClosure::update_state(size_t words) inline void MoveAndUpdateClosure::update_state(size_t words)
{ {
@ -1040,7 +989,7 @@ MoveAndUpdateShadowClosure::MoveAndUpdateShadowClosure(ParMarkBitMap *bitmap,
ParCompactionManager *cm, ParCompactionManager *cm,
size_t region, size_t region,
size_t shadow) : size_t shadow) :
MoveAndUpdateClosure(bitmap, cm, region), MoveAndUpdateClosure(bitmap, region),
_shadow(shadow) { _shadow(shadow) {
_offset = calculate_shadow_offset(region, shadow); _offset = calculate_shadow_offset(region, shadow);
} }