< prev index next > src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
Print this page
#include "precompiled.hpp"
#include "gc/shared/tlab_globals.hpp"
#include "gc/shenandoah/shenandoahAsserts.hpp"
#include "gc/shenandoah/shenandoahForwarding.inline.hpp"
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
+ #include "gc/shenandoah/shenandoahGeneration.hpp"
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
#include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
+ #include "gc/shenandoah/shenandoahOldGeneration.hpp"
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
#include "gc/shenandoah/shenandoahTaskqueue.inline.hpp"
#include "gc/shenandoah/shenandoahUtils.hpp"
#include "gc/shenandoah/shenandoahVerifier.hpp"
+ #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
#include "memory/allocation.hpp"
#include "memory/iterator.inline.hpp"
#include "memory/resourceArea.hpp"
#include "oops/compressedOops.inline.hpp"
#include "runtime/atomic.hpp"
ShenandoahHeap* _heap;
MarkBitMap* _map;
ShenandoahLivenessData* _ld;
void* _interior_loc;
oop _loc;
+ ShenandoahGeneration* _generation;
public:
ShenandoahVerifyOopClosure(ShenandoahVerifierStack* stack, MarkBitMap* map, ShenandoahLivenessData* ld,
const char* phase, ShenandoahVerifier::VerifyOptions options) :
_phase(phase),
_stack(stack),
_heap(ShenandoahHeap::heap()),
_map(map),
_ld(ld),
_interior_loc(nullptr),
! _loc(nullptr) {
if (options._verify_marked == ShenandoahVerifier::_verify_marked_complete_except_references ||
options._verify_marked == ShenandoahVerifier::_verify_marked_disable) {
set_ref_discoverer_internal(new ShenandoahIgnoreReferenceDiscoverer());
}
}
private:
void check(ShenandoahAsserts::SafeLevel level, oop obj, bool test, const char* label) {
if (!test) {
_stack(stack),
_heap(ShenandoahHeap::heap()),
_map(map),
_ld(ld),
_interior_loc(nullptr),
! _loc(nullptr),
+ _generation(nullptr) {
if (options._verify_marked == ShenandoahVerifier::_verify_marked_complete_except_references ||
options._verify_marked == ShenandoahVerifier::_verify_marked_disable) {
set_ref_discoverer_internal(new ShenandoahIgnoreReferenceDiscoverer());
}
+
+ if (_heap->mode()->is_generational()) {
+ _generation = _heap->active_generation();
+ assert(_generation != nullptr, "Expected active generation in this mode");
+ }
}
private:
void check(ShenandoahAsserts::SafeLevel level, oop obj, bool test, const char* label) {
if (!test) {
// methods.
//
// For performance reasons, only fully verify non-marked field values.
// We are here when the host object for *p is already marked.
! if (_map->par_mark(obj)) {
verify_oop_at(p, obj);
_stack->push(ShenandoahVerifierTask(obj));
}
}
}
void verify_oop(oop obj) {
// Perform consistency checks with gradually decreasing safety level. This guarantees
// that failure report would not try to touch something that was not yet verified to be
// safe to process.
check(ShenandoahAsserts::_safe_unknown, obj, _heap->is_in(obj),
"oop must be in heap");
check(ShenandoahAsserts::_safe_unknown, obj, is_object_aligned(obj),
"oop must be aligned");
! ShenandoahHeapRegion *obj_reg = _heap->heap_region_containing(obj);
Klass* obj_klass = obj->klass_or_null();
// Verify that obj is not in dead space:
{
// Do this before touching obj->size()
check(ShenandoahAsserts::_safe_unknown, obj, obj_klass != nullptr,
"Object klass pointer should not be null");
check(ShenandoahAsserts::_safe_unknown, obj, Metaspace::contains(obj_klass),
"Object klass pointer must go to metaspace");
! HeapWord *obj_addr = cast_from_oop<HeapWord*>(obj);
check(ShenandoahAsserts::_safe_unknown, obj, obj_addr < obj_reg->top(),
"Object start should be within the region");
if (!obj_reg->is_humongous()) {
check(ShenandoahAsserts::_safe_unknown, obj, (obj_addr + obj->size()) <= obj_reg->top(),
// methods.
//
// For performance reasons, only fully verify non-marked field values.
// We are here when the host object for *p is already marked.
! if ( in_generation(obj) && _map->par_mark(obj)) {
verify_oop_at(p, obj);
_stack->push(ShenandoahVerifierTask(obj));
}
}
}
+ bool in_generation(oop obj) {
+ if (_generation == nullptr) {
+ return true;
+ }
+
+ ShenandoahHeapRegion* region = _heap->heap_region_containing(obj);
+ return _generation->contains(region);
+ }
+
void verify_oop(oop obj) {
// Perform consistency checks with gradually decreasing safety level. This guarantees
// that failure report would not try to touch something that was not yet verified to be
// safe to process.
check(ShenandoahAsserts::_safe_unknown, obj, _heap->is_in(obj),
"oop must be in heap");
check(ShenandoahAsserts::_safe_unknown, obj, is_object_aligned(obj),
"oop must be aligned");
! ShenandoahHeapRegion* obj_reg = _heap->heap_region_containing(obj);
Klass* obj_klass = obj->klass_or_null();
// Verify that obj is not in dead space:
{
// Do this before touching obj->size()
check(ShenandoahAsserts::_safe_unknown, obj, obj_klass != nullptr,
"Object klass pointer should not be null");
check(ShenandoahAsserts::_safe_unknown, obj, Metaspace::contains(obj_klass),
"Object klass pointer must go to metaspace");
! HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);
check(ShenandoahAsserts::_safe_unknown, obj, obj_addr < obj_reg->top(),
"Object start should be within the region");
if (!obj_reg->is_humongous()) {
check(ShenandoahAsserts::_safe_unknown, obj, (obj_addr + obj->size()) <= obj_reg->top(),
break;
case ShenandoahVerifier::_verify_liveness_complete:
Atomic::add(&_ld[obj_reg->index()], (uint) obj->size(), memory_order_relaxed);
// fallthrough for fast failure for un-live regions:
case ShenandoahVerifier::_verify_liveness_conservative:
! check(ShenandoahAsserts::_safe_oop, obj, obj_reg->has_live(),
"Object must belong to region with live data");
break;
default:
assert(false, "Unhandled liveness verification");
}
break;
case ShenandoahVerifier::_verify_liveness_complete:
Atomic::add(&_ld[obj_reg->index()], (uint) obj->size(), memory_order_relaxed);
// fallthrough for fast failure for un-live regions:
case ShenandoahVerifier::_verify_liveness_conservative:
! check(ShenandoahAsserts::_safe_oop, obj, obj_reg->has_live() ||
+ (obj_reg->is_old() && ShenandoahHeap::heap()->is_gc_generation_young()),
"Object must belong to region with live data");
break;
default:
assert(false, "Unhandled liveness verification");
}
// Verify that forwardee is not in the dead space:
check(ShenandoahAsserts::_safe_oop, obj, !fwd_reg->is_humongous(),
"Should have no humongous forwardees");
! HeapWord *fwd_addr = cast_from_oop<HeapWord *>(fwd);
check(ShenandoahAsserts::_safe_oop, obj, fwd_addr < fwd_reg->top(),
"Forwardee start should be within the region");
check(ShenandoahAsserts::_safe_oop, obj, (fwd_addr + fwd->size()) <= fwd_reg->top(),
"Forwardee end should be within the region");
// Verify that forwardee is not in the dead space:
check(ShenandoahAsserts::_safe_oop, obj, !fwd_reg->is_humongous(),
"Should have no humongous forwardees");
! HeapWord* fwd_addr = cast_from_oop<HeapWord* >(fwd);
check(ShenandoahAsserts::_safe_oop, obj, fwd_addr < fwd_reg->top(),
"Forwardee start should be within the region");
check(ShenandoahAsserts::_safe_oop, obj, (fwd_addr + fwd->size()) <= fwd_reg->top(),
"Forwardee end should be within the region");
} else {
fwd_reg = obj_reg;
}
// ------------ obj and fwd are safe at this point --------------
!
switch (_options._verify_marked) {
case ShenandoahVerifier::_verify_marked_disable:
// skip
break;
case ShenandoahVerifier::_verify_marked_incomplete:
! check(ShenandoahAsserts::_safe_all, obj, _heap->marking_context()->is_marked(obj),
"Must be marked in incomplete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete:
! check(ShenandoahAsserts::_safe_all, obj, _heap->complete_marking_context()->is_marked(obj),
"Must be marked in complete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete_except_references:
! check(ShenandoahAsserts::_safe_all, obj, _heap->complete_marking_context()->is_marked(obj),
"Must be marked in complete bitmap, except j.l.r.Reference referents");
break;
default:
assert(false, "Unhandled mark verification");
}
} else {
fwd_reg = obj_reg;
}
// ------------ obj and fwd are safe at this point --------------
! // We allow for marked or old here for two reasons:
+ // 1. If this is a young collect, old objects wouldn't be marked. We've
+ // recently change the verifier traversal to only follow young objects
+ // during a young collect so this _shouldn't_ be necessary.
+ // 2. At present, we do not clear dead objects from the remembered set.
+ // Everything in the remembered set is old (ipso facto), so allowing for
+ // 'marked_or_old' covers the case of stale objects in rset.
+ // TODO: Just use 'is_marked' here.
switch (_options._verify_marked) {
case ShenandoahVerifier::_verify_marked_disable:
// skip
break;
case ShenandoahVerifier::_verify_marked_incomplete:
! check(ShenandoahAsserts::_safe_all, obj, _heap->marking_context()->is_marked_or_old(obj),
"Must be marked in incomplete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete:
! check(ShenandoahAsserts::_safe_all, obj, _heap->complete_marking_context()->is_marked_or_old(obj),
"Must be marked in complete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete_except_references:
! check(ShenandoahAsserts::_safe_all, obj, _heap->complete_marking_context()->is_marked_or_old(obj),
"Must be marked in complete bitmap, except j.l.r.Reference referents");
break;
default:
assert(false, "Unhandled mark verification");
}
virtual void do_oop(oop* p) { do_oop_work(p); }
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
};
class ShenandoahCalculateRegionStatsClosure : public ShenandoahHeapRegionClosure {
private:
! size_t _used, _committed, _garbage;
public:
! ShenandoahCalculateRegionStatsClosure() : _used(0), _committed(0), _garbage(0) {};
void heap_region_do(ShenandoahHeapRegion* r) {
_used += r->used();
_garbage += r->garbage();
_committed += r->is_committed() ? ShenandoahHeapRegion::region_size_bytes() : 0;
}
size_t used() { return _used; }
size_t committed() { return _committed; }
size_t garbage() { return _garbage; }
};
class ShenandoahVerifyHeapRegionClosure : public ShenandoahHeapRegionClosure {
private:
ShenandoahHeap* _heap;
virtual void do_oop(oop* p) { do_oop_work(p); }
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
};
+ // This closure computes the amounts of used, committed, and garbage memory and the number of regions contained within
+ // a subset (e.g. the young generation or old generation) of the total heap.
class ShenandoahCalculateRegionStatsClosure : public ShenandoahHeapRegionClosure {
private:
! size_t _used, _committed, _garbage, _regions;
public:
! ShenandoahCalculateRegionStatsClosure() : _used(0), _committed(0), _garbage(0), _regions(0) {};
void heap_region_do(ShenandoahHeapRegion* r) {
_used += r->used();
+ log_debug(gc)("ShenandoahCalculateRegionStatsClosure added " SIZE_FORMAT " for %s Region " SIZE_FORMAT ", yielding: " SIZE_FORMAT,
+ r->used(), r->is_humongous()? "humongous": "regular", r->index(), _used);
_garbage += r->garbage();
_committed += r->is_committed() ? ShenandoahHeapRegion::region_size_bytes() : 0;
+ _regions++;
}
size_t used() { return _used; }
size_t committed() { return _committed; }
size_t garbage() { return _garbage; }
+ size_t regions() { return _regions; }
+
+ // span is the total memory affiliated with these stats (some of which is in use and other is available)
+ size_t span() { return _regions * ShenandoahHeapRegion::region_size_bytes(); }
+ };
+
+ class ShenandoahGenerationStatsClosure : public ShenandoahHeapRegionClosure {
+ public:
+ ShenandoahCalculateRegionStatsClosure old;
+ ShenandoahCalculateRegionStatsClosure young;
+ ShenandoahCalculateRegionStatsClosure global;
+
+ void heap_region_do(ShenandoahHeapRegion* r) override {
+ switch (r->affiliation()) {
+ default:
+ ShouldNotReachHere();
+ return;
+ case FREE: return;
+ case YOUNG_GENERATION:
+ young.heap_region_do(r);
+ break;
+ case OLD_GENERATION:
+ old.heap_region_do(r);
+ break;
+ }
+ global.heap_region_do(r);
+ }
+
+ static void log_usage(ShenandoahGeneration* generation, ShenandoahCalculateRegionStatsClosure& stats) {
+ log_debug(gc)("Safepoint verification: %s verified usage: " SIZE_FORMAT "%s, recorded usage: " SIZE_FORMAT "%s",
+ generation->name(),
+ byte_size_in_proper_unit(generation->used()), proper_unit_for_byte_size(generation->used()),
+ byte_size_in_proper_unit(stats.used()), proper_unit_for_byte_size(stats.used()));
+ }
+
+ static void validate_usage(const char* label, ShenandoahGeneration* generation, ShenandoahCalculateRegionStatsClosure& stats) {
+ size_t generation_used = generation->used();
+ guarantee(stats.used() == generation_used,
+ "%s: generation (%s) used size must be consistent: generation-used = " SIZE_FORMAT "%s, regions-used = " SIZE_FORMAT "%s",
+ label, generation->name(),
+ byte_size_in_proper_unit(generation_used), proper_unit_for_byte_size(generation_used),
+ byte_size_in_proper_unit(stats.used()), proper_unit_for_byte_size(stats.used()));
+
+ guarantee(stats.regions() == generation->used_regions(),
+ "%s: generation (%s) used regions (" SIZE_FORMAT ") must equal regions that are in use (" SIZE_FORMAT ")",
+ label, generation->name(), generation->used_regions(), stats.regions());
+
+ size_t capacity = generation->adjusted_capacity();
+ guarantee(stats.span() <= capacity,
+ "%s: generation (%s) size spanned by regions (" SIZE_FORMAT ") must not exceed current capacity (" SIZE_FORMAT "%s)",
+ label, generation->name(), stats.regions(),
+ byte_size_in_proper_unit(capacity), proper_unit_for_byte_size(capacity));
+
+ }
};
class ShenandoahVerifyHeapRegionClosure : public ShenandoahHeapRegionClosure {
private:
ShenandoahHeap* _heap;
"TLAB alloc count should not be larger than capacity");
verify(r, r->get_gclab_allocs() <= r->capacity(),
"GCLAB alloc count should not be larger than capacity");
! verify(r, r->get_shared_allocs() + r->get_tlab_allocs() + r->get_gclab_allocs() == r->used(),
! "Accurate accounting: shared + TLAB + GCLAB = used");
verify(r, !r->is_empty() || !r->has_live(),
"Empty regions should not have live data");
verify(r, r->is_cset() == _heap->collection_set()->is_in(r),
"TLAB alloc count should not be larger than capacity");
verify(r, r->get_gclab_allocs() <= r->capacity(),
"GCLAB alloc count should not be larger than capacity");
! verify(r, r->get_plab_allocs() <= r->capacity(),
! "PLAB alloc count should not be larger than capacity");
+
+ verify(r, r->get_shared_allocs() + r->get_tlab_allocs() + r->get_gclab_allocs() + r->get_plab_allocs() == r->used(),
+ "Accurate accounting: shared + TLAB + GCLAB + PLAB = used");
verify(r, !r->is_empty() || !r->has_live(),
"Empty regions should not have live data");
verify(r, r->is_cset() == _heap->collection_set()->is_in(r),
class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
private:
const char* _label;
ShenandoahVerifier::VerifyOptions _options;
! ShenandoahHeap *_heap;
MarkBitMap* _bitmap;
ShenandoahLivenessData* _ld;
volatile size_t _claimed;
volatile size_t _processed;
public:
ShenandoahVerifierMarkedRegionTask(MarkBitMap* bitmap,
ShenandoahLivenessData* ld,
const char* label,
class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
private:
const char* _label;
ShenandoahVerifier::VerifyOptions _options;
! ShenandoahHeap* _heap;
MarkBitMap* _bitmap;
ShenandoahLivenessData* _ld;
volatile size_t _claimed;
volatile size_t _processed;
+ ShenandoahGeneration* _generation;
public:
ShenandoahVerifierMarkedRegionTask(MarkBitMap* bitmap,
ShenandoahLivenessData* ld,
const char* label,
_options(options),
_heap(ShenandoahHeap::heap()),
_bitmap(bitmap),
_ld(ld),
_claimed(0),
! _processed(0) {};
size_t processed() {
return Atomic::load(&_processed);
}
_options(options),
_heap(ShenandoahHeap::heap()),
_bitmap(bitmap),
_ld(ld),
_claimed(0),
! _processed(0),
+ _generation(nullptr) {
+ if (_heap->mode()->is_generational()) {
+ _generation = _heap->active_generation();
+ assert(_generation != nullptr, "Expected active generation in this mode.");
+ }
+ };
size_t processed() {
return Atomic::load(&_processed);
}
while (true) {
size_t v = Atomic::fetch_and_add(&_claimed, 1u, memory_order_relaxed);
if (v < _heap->num_regions()) {
ShenandoahHeapRegion* r = _heap->get_region(v);
+ if (!in_generation(r)) {
+ continue;
+ }
+
if (!r->is_humongous() && !r->is_trash()) {
work_regular(r, stack, cl);
} else if (r->is_humongous_start()) {
work_humongous(r, stack, cl);
}
break;
}
}
}
! virtual void work_humongous(ShenandoahHeapRegion *r, ShenandoahVerifierStack& stack, ShenandoahVerifyOopClosure& cl) {
size_t processed = 0;
HeapWord* obj = r->bottom();
if (_heap->complete_marking_context()->is_marked(cast_to_oop(obj))) {
verify_and_follow(obj, stack, cl, &processed);
}
Atomic::add(&_processed, processed, memory_order_relaxed);
}
! virtual void work_regular(ShenandoahHeapRegion *r, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl) {
size_t processed = 0;
ShenandoahMarkingContext* ctx = _heap->complete_marking_context();
HeapWord* tams = ctx->top_at_mark_start(r);
// Bitmaps, before TAMS
break;
}
}
}
! bool in_generation(ShenandoahHeapRegion* r) {
+ return _generation == nullptr || _generation->contains(r);
+ }
+
+ virtual void work_humongous(ShenandoahHeapRegion* r, ShenandoahVerifierStack& stack, ShenandoahVerifyOopClosure& cl) {
size_t processed = 0;
HeapWord* obj = r->bottom();
if (_heap->complete_marking_context()->is_marked(cast_to_oop(obj))) {
verify_and_follow(obj, stack, cl, &processed);
}
Atomic::add(&_processed, processed, memory_order_relaxed);
}
! virtual void work_regular(ShenandoahHeapRegion* r, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl) {
size_t processed = 0;
ShenandoahMarkingContext* ctx = _heap->complete_marking_context();
HeapWord* tams = ctx->top_at_mark_start(r);
// Bitmaps, before TAMS
}
Atomic::add(&_processed, processed, memory_order_relaxed);
}
! void verify_and_follow(HeapWord *addr, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl, size_t *processed) {
if (!_bitmap->par_mark(addr)) return;
// Verify the object itself:
oop obj = cast_to_oop(addr);
cl.verify_oop_standalone(obj);
}
Atomic::add(&_processed, processed, memory_order_relaxed);
}
! void verify_and_follow(HeapWord* addr, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl, size_t* processed) {
if (!_bitmap->par_mark(addr)) return;
// Verify the object itself:
oop obj = cast_to_oop(addr);
cl.verify_oop_standalone(obj);
public:
VerifyThreadGCState(const char* label, char expected) : _label(label), _expected(expected) {}
void do_thread(Thread* t) {
char actual = ShenandoahThreadLocalData::gc_state(t);
! if (actual != _expected) {
fatal("%s: Thread %s: expected gc-state %d, actual %d", _label, t->name(), _expected, actual);
}
}
};
! void ShenandoahVerifier::verify_at_safepoint(const char *label,
VerifyForwarded forwarded, VerifyMarked marked,
VerifyCollectionSet cset,
VerifyLiveness liveness, VerifyRegions regions,
VerifyGCState gcstate) {
guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
public:
VerifyThreadGCState(const char* label, char expected) : _label(label), _expected(expected) {}
void do_thread(Thread* t) {
char actual = ShenandoahThreadLocalData::gc_state(t);
! if (actual != _expected && !(actual & ShenandoahHeap::OLD_MARKING)) {
fatal("%s: Thread %s: expected gc-state %d, actual %d", _label, t->name(), _expected, actual);
}
}
};
! void ShenandoahVerifier::verify_at_safepoint(const char* label,
+ VerifyRememberedSet remembered,
VerifyForwarded forwarded, VerifyMarked marked,
VerifyCollectionSet cset,
VerifyLiveness liveness, VerifyRegions regions,
VerifyGCState gcstate) {
guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
if (!_heap->is_stw_gc_in_progress()) {
// Only concurrent GC sets this.
expected |= ShenandoahHeap::WEAK_ROOTS;
}
break;
+ case _verify_gcstate_updating:
+ enabled = true;
+ expected = ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::UPDATEREFS;
+ break;
case _verify_gcstate_stable:
enabled = true;
expected = ShenandoahHeap::STABLE;
break;
case _verify_gcstate_stable_weakroots:
assert(false, "Unhandled gc-state verification");
}
if (enabled) {
char actual = _heap->gc_state();
! if (actual != expected) {
fatal("%s: Global gc-state: expected %d, actual %d", label, expected, actual);
}
VerifyThreadGCState vtgcs(label, expected);
Threads::java_threads_do(&vtgcs);
assert(false, "Unhandled gc-state verification");
}
if (enabled) {
char actual = _heap->gc_state();
! // Old generation marking is allowed in all states.
+ if (actual != expected && !(actual & ShenandoahHeap::OLD_MARKING)) {
fatal("%s: Global gc-state: expected %d, actual %d", label, expected, actual);
}
VerifyThreadGCState vtgcs(label, expected);
Threads::java_threads_do(&vtgcs);
label,
byte_size_in_proper_unit(heap_committed), proper_unit_for_byte_size(heap_committed),
byte_size_in_proper_unit(cl.committed()), proper_unit_for_byte_size(cl.committed()));
}
// Internal heap region checks
if (ShenandoahVerifyLevel >= 1) {
ShenandoahVerifyHeapRegionClosure cl(label, regions);
! _heap->heap_region_iterate(&cl);
}
OrderAccess::fence();
if (UseTLAB) {
_heap->labs_make_parsable();
}
label,
byte_size_in_proper_unit(heap_committed), proper_unit_for_byte_size(heap_committed),
byte_size_in_proper_unit(cl.committed()), proper_unit_for_byte_size(cl.committed()));
}
+ log_debug(gc)("Safepoint verification finished heap usage verification");
+
+ ShenandoahGeneration* generation;
+ if (_heap->mode()->is_generational()) {
+ generation = _heap->active_generation();
+ guarantee(generation != nullptr, "Need to know which generation to verify.");
+ } else {
+ generation = nullptr;
+ }
+
+ if (generation != nullptr) {
+ ShenandoahHeapLocker lock(_heap->lock());
+
+ if (remembered == _verify_remembered_for_marking) {
+ log_debug(gc)("Safepoint verification of remembered set at mark");
+ } else if (remembered == _verify_remembered_for_updating_references) {
+ log_debug(gc)("Safepoint verification of remembered set at update ref");
+ } else if (remembered == _verify_remembered_after_full_gc) {
+ log_debug(gc)("Safepoint verification of remembered set after full gc");
+ }
+
+ if (remembered == _verify_remembered_for_marking) {
+ _heap->verify_rem_set_at_mark();
+ } else if (remembered == _verify_remembered_for_updating_references) {
+ _heap->verify_rem_set_at_update_ref();
+ } else if (remembered == _verify_remembered_after_full_gc) {
+ _heap->verify_rem_set_after_full_gc();
+ }
+
+ ShenandoahGenerationStatsClosure cl;
+ _heap->heap_region_iterate(&cl);
+
+ if (LogTarget(Debug, gc)::is_enabled()) {
+ ShenandoahGenerationStatsClosure::log_usage(_heap->old_generation(), cl.old);
+ ShenandoahGenerationStatsClosure::log_usage(_heap->young_generation(), cl.young);
+ ShenandoahGenerationStatsClosure::log_usage(_heap->global_generation(), cl.global);
+ }
+
+ ShenandoahGenerationStatsClosure::validate_usage(label, _heap->old_generation(), cl.old);
+ ShenandoahGenerationStatsClosure::validate_usage(label, _heap->young_generation(), cl.young);
+ ShenandoahGenerationStatsClosure::validate_usage(label, _heap->global_generation(), cl.global);
+ }
+
+ log_debug(gc)("Safepoint verification finished remembered set verification");
+
// Internal heap region checks
if (ShenandoahVerifyLevel >= 1) {
ShenandoahVerifyHeapRegionClosure cl(label, regions);
! if (generation != nullptr) {
+ generation->heap_region_iterate(&cl);
+ } else {
+ _heap->heap_region_iterate(&cl);
+ }
}
+ log_debug(gc)("Safepoint verification finished heap region closure verification");
+
OrderAccess::fence();
if (UseTLAB) {
_heap->labs_make_parsable();
}
ShenandoahVerifierReachableTask task(_verification_bit_map, ld, label, options);
_heap->workers()->run_task(&task);
count_reachable = task.processed();
}
+ log_debug(gc)("Safepoint verification finished getting initial reachable set");
+
// Step 3. Walk marked objects. Marked objects might be unreachable. This verifies what collector,
// not the application, can see during the region scans. There is no reason to process the objects
// that were already verified, e.g. those marked in verification bitmap. There is interaction with TAMS:
// before TAMS, we verify the bitmaps, if available; after TAMS, we walk until the top(). It mimics
// what marked_object_iterate is doing, without calling into that optimized (and possibly incorrect)
count_marked = task.processed();
} else {
guarantee(ShenandoahVerifyLevel < 4 || marked == _verify_marked_incomplete || marked == _verify_marked_disable, "Should be");
}
+ log_debug(gc)("Safepoint verification finished walking marked objects");
+
// Step 4. Verify accumulated liveness data, if needed. Only reliable if verification level includes
// marked objects.
if (ShenandoahVerifyLevel >= 4 && marked == _verify_marked_complete && liveness == _verify_liveness_complete) {
for (size_t i = 0; i < _heap->num_regions(); i++) {
ShenandoahHeapRegion* r = _heap->get_region(i);
+ if (generation != nullptr && !generation->contains(r)) {
+ continue;
+ }
juint verf_live = 0;
if (r->is_humongous()) {
// For humongous objects, test if start region is marked live, and if so,
// all humongous regions in that chain have live data equal to their "used".
label, reg_live, verf_live, ss.freeze());
}
}
}
+ log_debug(gc)("Safepoint verification finished accumulation of liveness data");
+
+
log_info(gc)("Verify %s, Level " INTX_FORMAT " (" SIZE_FORMAT " reachable, " SIZE_FORMAT " marked)",
label, ShenandoahVerifyLevel, count_reachable, count_marked);
FREE_C_HEAP_ARRAY(ShenandoahLivenessData, ld);
}
void ShenandoahVerifier::verify_generic(VerifyOption vo) {
verify_at_safepoint(
"Generic Verification",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // conservatively allow forwarded
_verify_marked_disable, // do not verify marked: lots ot time wasted checking dead allocations
_verify_cset_disable, // cset may be inconsistent
_verify_liveness_disable, // no reliable liveness data
_verify_regions_disable, // no reliable region data
}
void ShenandoahVerifier::verify_before_concmark() {
verify_at_safepoint(
"Before Mark",
+ _verify_remembered_for_marking, // verify read-only remembered set from bottom() to top()
_verify_forwarded_none, // UR should have fixed up
_verify_marked_disable, // do not verify marked: lots ot time wasted checking dead allocations
_verify_cset_none, // UR should have fixed this
_verify_liveness_disable, // no reliable liveness data
_verify_regions_notrash, // no trash regions
}
void ShenandoahVerifier::verify_after_concmark() {
verify_at_safepoint(
"After Mark",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
_verify_marked_complete_except_references, // bitmaps as precise as we can get, except dangling j.l.r.Refs
_verify_cset_none, // no references to cset anymore
_verify_liveness_complete, // liveness data must be complete here
_verify_regions_disable, // trash regions not yet recycled
}
void ShenandoahVerifier::verify_before_evacuation() {
verify_at_safepoint(
"Before Evacuation",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
_verify_marked_complete_except_references, // walk over marked objects too
_verify_cset_disable, // non-forwarded references to cset expected
_verify_liveness_complete, // liveness data must be complete here
_verify_regions_disable, // trash regions not yet recycled
}
void ShenandoahVerifier::verify_during_evacuation() {
verify_at_safepoint(
"During Evacuation",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // some forwarded references are allowed
_verify_marked_disable, // walk only roots
_verify_cset_disable, // some cset references are not forwarded yet
_verify_liveness_disable, // liveness data might be already stale after pre-evacs
_verify_regions_disable, // trash regions not yet recycled
}
void ShenandoahVerifier::verify_after_evacuation() {
verify_at_safepoint(
"After Evacuation",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // objects are still forwarded
_verify_marked_complete, // bitmaps might be stale, but alloc-after-mark should be well
_verify_cset_forwarded, // all cset refs are fully forwarded
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_notrash, // trash regions have been recycled already
}
void ShenandoahVerifier::verify_before_updaterefs() {
verify_at_safepoint(
"Before Updating References",
! _verify_forwarded_allow, // forwarded references allowed
! _verify_marked_complete, // bitmaps might be stale, but alloc-after-mark should be well
! _verify_cset_forwarded, // all cset refs are fully forwarded
! _verify_liveness_disable, // no reliable liveness data anymore
! _verify_regions_notrash, // trash regions have been recycled already
! _verify_gcstate_forwarded // evacuation should have produced some forwarded objects
);
}
void ShenandoahVerifier::verify_after_updaterefs() {
verify_at_safepoint(
"After Updating References",
_verify_forwarded_none, // no forwarded references
_verify_marked_complete, // bitmaps might be stale, but alloc-after-mark should be well
_verify_cset_none, // no cset references, all updated
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_nocset, // no cset regions, trash regions have appeared
}
void ShenandoahVerifier::verify_before_updaterefs() {
verify_at_safepoint(
"Before Updating References",
! _verify_remembered_for_updating_references, // verify read-write remembered set
! _verify_forwarded_allow, // forwarded references allowed
! _verify_marked_complete, // bitmaps might be stale, but alloc-after-mark should be well
! _verify_cset_forwarded, // all cset refs are fully forwarded
! _verify_liveness_disable, // no reliable liveness data anymore
! _verify_regions_notrash, // trash regions have been recycled already
+ _verify_gcstate_updating // evacuation should have produced some forwarded objects
);
}
void ShenandoahVerifier::verify_after_updaterefs() {
verify_at_safepoint(
"After Updating References",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
_verify_marked_complete, // bitmaps might be stale, but alloc-after-mark should be well
_verify_cset_none, // no cset references, all updated
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_nocset, // no cset regions, trash regions have appeared
}
void ShenandoahVerifier::verify_after_degenerated() {
verify_at_safepoint(
"After Degenerated GC",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // all objects are non-forwarded
_verify_marked_complete, // all objects are marked in complete bitmap
_verify_cset_none, // no cset references
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_notrash_nocset, // no trash, no cset
}
void ShenandoahVerifier::verify_before_fullgc() {
verify_at_safepoint(
"Before Full GC",
_verify_forwarded_allow, // can have forwarded objects
_verify_marked_disable, // do not verify marked: lots ot time wasted checking dead allocations
_verify_cset_disable, // cset might be foobared
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_disable, // no reliable region data here
_verify_gcstate_disable // no reliable gcstate data
);
}
void ShenandoahVerifier::verify_after_fullgc() {
verify_at_safepoint(
"After Full GC",
_verify_forwarded_none, // all objects are non-forwarded
_verify_marked_complete, // all objects are marked in complete bitmap
_verify_cset_none, // no cset references
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_notrash_nocset, // no trash, no cset
_verify_gcstate_stable // full gc cleaned up everything
);
}
! class ShenandoahVerifyNoForwared : public OopClosure {
private:
template <class T>
void do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
}
void ShenandoahVerifier::verify_before_fullgc() {
verify_at_safepoint(
"Before Full GC",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // can have forwarded objects
_verify_marked_disable, // do not verify marked: lots ot time wasted checking dead allocations
_verify_cset_disable, // cset might be foobared
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_disable, // no reliable region data here
_verify_gcstate_disable // no reliable gcstate data
);
}
+ void ShenandoahVerifier::verify_after_generational_fullgc() {
+ verify_at_safepoint(
+ "After Full Generational GC",
+ _verify_remembered_after_full_gc, // verify read-write remembered set
+ _verify_forwarded_none, // all objects are non-forwarded
+ _verify_marked_complete, // all objects are marked in complete bitmap
+ _verify_cset_none, // no cset references
+ _verify_liveness_disable, // no reliable liveness data anymore
+ _verify_regions_notrash_nocset, // no trash, no cset
+ _verify_gcstate_stable // full gc cleaned up everything
+ );
+ }
+
void ShenandoahVerifier::verify_after_fullgc() {
verify_at_safepoint(
"After Full GC",
+ _verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // all objects are non-forwarded
_verify_marked_complete, // all objects are marked in complete bitmap
_verify_cset_none, // no cset references
_verify_liveness_disable, // no reliable liveness data anymore
_verify_regions_notrash_nocset, // no trash, no cset
_verify_gcstate_stable // full gc cleaned up everything
);
}
! class ShenandoahVerifyNoForwared : public BasicOopIterateClosure {
private:
template <class T>
void do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
public:
void do_oop(narrowOop* p) { do_oop_work(p); }
void do_oop(oop* p) { do_oop_work(p); }
};
! class ShenandoahVerifyInToSpaceClosure : public OopClosure {
private:
template <class T>
void do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o);
ShenandoahHeap* heap = ShenandoahHeap::heap();
! if (!heap->marking_context()->is_marked(obj)) {
ShenandoahAsserts::print_failure(ShenandoahAsserts::_safe_all, obj, p, nullptr,
"Verify Roots In To-Space", "Should be marked", __FILE__, __LINE__);
}
if (heap->in_collection_set(obj)) {
public:
void do_oop(narrowOop* p) { do_oop_work(p); }
void do_oop(oop* p) { do_oop_work(p); }
};
! class ShenandoahVerifyInToSpaceClosure : public BasicOopIterateClosure {
private:
template <class T>
void do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o);
ShenandoahHeap* heap = ShenandoahHeap::heap();
! if (!heap->marking_context()->is_marked_or_old(obj)) {
ShenandoahAsserts::print_failure(ShenandoahAsserts::_safe_all, obj, p, nullptr,
"Verify Roots In To-Space", "Should be marked", __FILE__, __LINE__);
}
if (heap->in_collection_set(obj)) {
< prev index next >