8265259: G1: Fix HeapRegion::block_is_obj for unloading class in full gc

Reviewed-by: sjohanss, tschatzl
This commit is contained in:
Hamlin Li 2021-04-16 12:40:25 +00:00
parent ff5bb8cf69
commit 714298a58e

View File

@ -124,7 +124,7 @@ inline bool HeapRegion::is_obj_dead_with_size(const oop obj, const G1CMBitMap* c
assert(!is_humongous(), "Humongous objects not handled here");
bool obj_is_dead = is_obj_dead(obj, prev_bitmap);
if (ClassUnloadingWithConcurrentMark && obj_is_dead) {
if (ClassUnloading && obj_is_dead) {
assert(!block_is_obj(addr), "must be");
*size = block_size_using_bitmap(addr, prev_bitmap);
} else {
@ -141,14 +141,21 @@ inline bool HeapRegion::block_is_obj(const HeapWord* p) const {
assert(is_continues_humongous(), "This case can only happen for humongous regions");
return (p == humongous_start_region()->bottom());
}
if (ClassUnloadingWithConcurrentMark) {
// When class unloading is enabled it is not safe to only consider top() to conclude if the
// given pointer is a valid object. The situation can occur both for class unloading in a
// Full GC and during a concurrent cycle.
// During a Full GC regions can be excluded from compaction due to high live ratio, and
// because of this there can be stale objects for unloaded classes left in these regions.
// During a concurrent cycle class unloading is done after marking is complete and objects
// for the unloaded classes will be stale until the regions are collected.
if (ClassUnloading) {
return !g1h->is_obj_dead(cast_to_oop(p), this);
}
return p < top();
}
inline size_t HeapRegion::block_size_using_bitmap(const HeapWord* addr, const G1CMBitMap* const prev_bitmap) const {
assert(ClassUnloadingWithConcurrentMark,
assert(ClassUnloading,
"All blocks should be objects if class unloading isn't used, so this method should not be called. "
"HR: [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ") "
"addr: " PTR_FORMAT,