Skip to content

Commit d7a83ce

Browse files
committedJan 26, 2022
Fix derived pointers assertions and debugging
1 parent a416710 commit d7a83ce

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed
 

‎src/hotspot/share/compiler/oopMap.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ void ImmutableOopMap::oops_do(const frame *fr, const RegisterMap *reg_map,
498498
derived_cl = &process_cl;
499499
break;
500500
case DerivedPointerIterationMode::_with_table:
501+
// if (has_derived_oops()) { tty->print_cr(">>> ImmutableOopMap::oops_do derived table"); fr->print_on(tty); }
501502
derived_cl = &add_cl;
502503
break;
503504
case DerivedPointerIterationMode::_ignore:
@@ -1011,6 +1012,8 @@ void DerivedPointerTable::update_pointers() {
10111012
*derived_loc = derived_base + offset;
10121013
assert(*derived_loc - derived_base == offset, "sanity check");
10131014

1015+
// assert (offset >= 0 && offset <= (intptr_t)(base->size() << LogHeapWordSize), "offset: %ld base->size: %zu relative: %d", offset, base->size() << LogHeapWordSize, *(intptr_t*)derived_loc <= 0);
1016+
10141017
if (TraceDerivedPointers) {
10151018
tty->print_cr("Updating derived pointer@" INTPTR_FORMAT
10161019
" - Derived: " INTPTR_FORMAT " Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")",

‎src/hotspot/share/compiler/oopMap.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void OopMapDo<OopFnT, DerivedOopFnT, ValueFilterT>::iterate_oops_do(const frame
7171

7272
address loc = fr->oopmapreg_to_location(omv.reg(), reg_map);
7373

74-
DEBUG_ONLY(if (reg_map->should_skip_missing()) continue;)
74+
DEBUG_ONLY(if (loc == NULL && reg_map->should_skip_missing()) continue;)
7575
guarantee(loc != NULL, "missing saved register");
7676
derived_pointer* derived_loc = (derived_pointer*)loc;
7777
oop* base_loc = fr->oopmapreg_to_oop_location(omv.content_reg(), reg_map);

‎src/hotspot/share/oops/instanceStackChunkKlass.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ class RelativizeDerivedPointers : public DerivedOopClosure {
273273

274274
OrderAccess::loadload();
275275
intptr_t derived_int_val = Atomic::load((intptr_t*)derived_loc); // *derived_loc;
276-
if (derived_int_val <= 0) { // an offset of 0 was observed on AArch64
276+
if (derived_int_val <= 0) {
277277
return;
278278
}
279279

280280
// at this point, we've seen a non-offset value *after* we've read the base, but we write the offset *before* fixing the base,
281281
// so we are guaranteed that the value in derived_loc is consistent with base (i.e. points into the object).
282282
intptr_t offset = derived_int_val - cast_from_oop<intptr_t>(base);
283-
assert (offset >= 0, "Derived pointer offset is %ld", offset); // an offset of 0 was observed on AArch64
283+
assert (offset >= 0, "Derived pointer offset is %ld", offset);
284284
// assert (offset >= 0 && offset <= (base->size() << LogHeapWordSize), "offset: %ld size: %d", offset, (base->size() << LogHeapWordSize)); -- base might be invalid at this point
285285
Atomic::store((intptr_t*)derived_loc, -offset); // there could be a benign race here; we write a negative offset to let the sign bit signify it's an offset rather than an address
286286
} else {
@@ -304,17 +304,11 @@ class DerelativizeDerivedPointers : public DerivedOopClosure {
304304

305305
// at this point, we've seen a non-offset value *after* we've read the base, but we write the offset *before* fixing the base,
306306
// so we are guaranteed that the value in derived_loc is consistent with base (i.e. points into the object).
307-
if (offset <= 0) { // an offset of 0 was observed on AArch64
307+
if (offset <= 0) {
308308
offset = -offset;
309309
assert (offset >= 0 && (size_t)offset <= (base->size() << LogHeapWordSize), "");
310310
Atomic::store((intptr_t*)derived_loc, cast_from_oop<intptr_t>(base) + offset);
311311
}
312-
#ifdef ASSERT
313-
else {
314-
offset = offset - cast_from_oop<intptr_t>(base);
315-
assert (offset >= 0 && (size_t)offset <= (base->size() << LogHeapWordSize), "offset: " PTR_FORMAT " size: %zu", offset, (base->size() << LogHeapWordSize));
316-
}
317-
#endif
318312
}
319313
}
320314
};
@@ -744,10 +738,10 @@ class StackChunkVerifyBitmapClosure : public BitMapClosure {
744738

745739
class StackChunkVerifyOopsClosure : public OopClosure {
746740
stackChunkOop _chunk;
747-
intptr_t* _sp;
741+
intptr_t* _unextended_sp;
748742
int _count;
749743
public:
750-
StackChunkVerifyOopsClosure(stackChunkOop chunk, intptr_t* sp) : _chunk(chunk), _sp(sp), _count(0) {}
744+
StackChunkVerifyOopsClosure(stackChunkOop chunk, intptr_t* unextended_sp) : _chunk(chunk), _unextended_sp(unextended_sp), _count(0) {}
751745
int count() { return _count; }
752746
void do_oop(oop* p) override { (_chunk->has_bitmap() && UseCompressedOops) ? do_oop_work((narrowOop*)p) : do_oop_work(p); }
753747
void do_oop(narrowOop* p) override { do_oop_work(p); }
@@ -768,8 +762,10 @@ class StackChunkVerifyOopsClosure : public OopClosure {
768762

769763
class StackChunkVerifyDerivedPointersClosure : public DerivedOopClosure {
770764
stackChunkOop _chunk;
765+
intptr_t* _unextended_sp;
771766
public:
772-
StackChunkVerifyDerivedPointersClosure(stackChunkOop chunk) : _chunk(chunk) {}
767+
768+
StackChunkVerifyDerivedPointersClosure(stackChunkOop chunk, intptr_t* unextended_sp) : _chunk(chunk), _unextended_sp(unextended_sp) {}
773769

774770
virtual void do_derived_oop(oop* base_loc, derived_pointer* derived_loc) override {
775771
log_develop_trace(jvmcont)("debug_verify_stack_chunk base: " INTPTR_FORMAT " derived: " INTPTR_FORMAT, p2i(base_loc), p2i(derived_loc));
@@ -784,11 +780,12 @@ class StackChunkVerifyDerivedPointersClosure : public DerivedOopClosure {
784780
ZGC_ONLY(assert (!UseZGC || ZAddress::is_good(cast_from_oop<uintptr_t>(base)), "");)
785781
OrderAccess::loadload();
786782
intptr_t offset = Atomic::load((intptr_t*)derived_loc);
787-
offset = offset <= 0 // an offset of 0 was observed on AArch64
783+
offset = offset <= 0
788784
? -offset
789785
: offset - cast_from_oop<intptr_t>(base);
790786

791787
// Has been seen to fail on AArch64 for some reason
788+
// It looks as if a derived pointer appears live in the oopMap but isn't used.
792789
// assert (offset >= 0 && offset <= (intptr_t)(base->size() << LogHeapWordSize), "offset: %ld base->size: %zu relative: %d", offset, base->size() << LogHeapWordSize, *(intptr_t*)derived_loc <= 0);
793790
} else {
794791
assert (*derived_loc == derived_pointer(0), "");
@@ -850,11 +847,11 @@ class VerifyStackClosure {
850847
// }
851848
// }
852849

853-
StackChunkVerifyOopsClosure oops_closure(_chunk, f.sp());
850+
StackChunkVerifyOopsClosure oops_closure(_chunk, f.unextended_sp());
854851
f.iterate_oops(&oops_closure, map);
855852
assert (oops_closure.count() == num_oops, "oops: %d oopmap->num_oops(): %d", oops_closure.count(), num_oops);
856853

857-
StackChunkVerifyDerivedPointersClosure derived_oops_closure(_chunk);
854+
StackChunkVerifyDerivedPointersClosure derived_oops_closure(_chunk, f.unextended_sp());
858855
f.iterate_derived_pointers(&derived_oops_closure, map);
859856

860857
_callee_interpreted = f.is_interpreted();

‎src/hotspot/share/runtime/frame.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,15 @@ class FrameValuesOopClosure: public OopClosure, public DerivedOopClosure {
13171317
values.describe(frame_no, (intptr_t*)derived, err_msg("derived pointer (base: " INTPTR_FORMAT ") for #%d", p2i(base), frame_no));
13181318
}
13191319
}
1320-
virtual void do_oop(oop* p) { _oops->push(p); }
1321-
virtual void do_oop(narrowOop* p) { _narrow_oops->push(p); }
1322-
virtual void do_derived_oop(oop* base, derived_pointer* derived) {
1323-
_base->push(base);
1324-
_derived->push(derived);
1320+
virtual void do_oop(oop* p) override { _oops->push(p); }
1321+
virtual void do_oop(narrowOop* p) override { _narrow_oops->push(p); }
1322+
virtual void do_derived_oop(oop* base_loc, derived_pointer* derived_loc) override {
1323+
// oop base = *base_loc;
1324+
// intptr_t offset = *(intptr_t*)derived_loc - cast_from_oop<intptr_t>(base);
1325+
// assert (offset >= 0 && offset <= (intptr_t)(base->size() << LogHeapWordSize), "offset: %ld base->size: %zu relative: %d", offset, base->size() << LogHeapWordSize, *(intptr_t*)derived_loc <= 0);
1326+
1327+
_base->push(base_loc);
1328+
_derived->push(derived_loc);
13251329
}
13261330
};
13271331

@@ -1335,7 +1339,7 @@ class FrameValuesOopMapClosure: public OopMapClosure {
13351339
FrameValuesOopMapClosure(const frame* fr, const RegisterMap* reg_map, FrameValues& values, int frame_no)
13361340
: _fr(fr), _reg_map(reg_map), _values(values), _frame_no(frame_no) {}
13371341

1338-
virtual void do_value(VMReg reg, OopMapValue::oop_types type) {
1342+
virtual void do_value(VMReg reg, OopMapValue::oop_types type) override {
13391343
intptr_t* p = (intptr_t*)_fr->oopmapreg_to_location(reg, _reg_map);
13401344
if (p != NULL && (((intptr_t)p & WordAlignmentMask) == 0)) {
13411345
const char* type_name = NULL;

0 commit comments

Comments
 (0)
Please sign in to comment.