Skip to content

Commit d34ef19

Browse files
committed
8370198: Test gc/arguments/TestShrinkHeapInSteps.java crashed: assert(left >= right) failed: avoid underflow
Reviewed-by: stefank, tschatzl
1 parent 811591c commit d34ef19

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5379,7 +5379,6 @@ void MacroAssembler::set_narrow_klass(Register dst, Klass* k) {
53795379
assert (UseCompressedClassPointers, "should only be used for compressed headers");
53805380
assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
53815381
int index = oop_recorder()->find_index(k);
5382-
assert(! Universe::heap()->is_in(k), "should not be an oop");
53835382

53845383
InstructionMark im(this);
53855384
RelocationHolder rspec = metadata_Relocation::spec(index);

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5187,7 +5187,6 @@ void MacroAssembler::set_narrow_klass(Register dst, Klass* k) {
51875187
assert (UseCompressedClassPointers, "should only be used for compressed headers");
51885188
assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
51895189
int index = oop_recorder()->find_index(k);
5190-
assert(!Universe::heap()->is_in(k), "should not be an oop");
51915190

51925191
narrowKlass nk = CompressedKlassPointers::encode(k);
51935192
relocate(metadata_Relocation::spec(index), [&] {

src/hotspot/share/gc/serial/serialHeap.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@ bool SerialHeap::requires_barriers(stackChunkOop obj) const {
630630

631631
// Returns "TRUE" iff "p" points into the committed areas of the heap.
632632
bool SerialHeap::is_in(const void* p) const {
633+
// precondition
634+
verify_not_in_native_if_java_thread();
635+
636+
if (!is_in_reserved(p)) {
637+
// If it's not even in reserved.
638+
return false;
639+
}
640+
633641
return _young_gen->is_in(p) || _old_gen->is_in(p);
634642
}
635643

@@ -797,3 +805,12 @@ void SerialHeap::gc_epilogue(bool full) {
797805

798806
MetaspaceCounters::update_performance_counters();
799807
};
808+
809+
#ifdef ASSERT
810+
void SerialHeap::verify_not_in_native_if_java_thread() {
811+
if (Thread::current()->is_Java_thread()) {
812+
JavaThread* thread = JavaThread::current();
813+
assert(thread->thread_state() != _thread_in_native, "precondition");
814+
}
815+
}
816+
#endif

src/hotspot/share/gc/serial/serialHeap.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class SerialHeap : public CollectedHeap {
111111
void print_tracing_info() const override;
112112
void stop() override {};
113113

114+
static void verify_not_in_native_if_java_thread() NOT_DEBUG_RETURN;
115+
114116
public:
115117
// Returns JNI_OK on success
116118
jint initialize() override;

0 commit comments

Comments
 (0)