8301123: Enable Symbol refcounting underflow checks in PRODUCT

Reviewed-by: fparain, iklam
This commit is contained in:
Coleen Phillimore 2023-01-27 14:56:29 +00:00
parent e4252bb914
commit fccf818972
2 changed files with 8 additions and 7 deletions

View File

@ -340,10 +340,8 @@ bool Symbol::try_increment_refcount() {
// this caller.
void Symbol::increment_refcount() {
if (!try_increment_refcount()) {
#ifdef ASSERT
print();
fatal("refcount has gone to zero");
#endif
}
#ifndef PRODUCT
if (refcount() != PERM_REFCOUNT) { // not a permanent symbol
@ -363,10 +361,8 @@ void Symbol::decrement_refcount() {
if (refc == PERM_REFCOUNT) {
return; // refcount is permanent, permanent is sticky
} else if (refc == 0) {
#ifdef ASSERT
print();
fatal("refcount underflow");
#endif
return;
} else {
found = Atomic::cmpxchg(&_hash_and_refcount, old_value, old_value - 1);
@ -386,10 +382,8 @@ void Symbol::make_permanent() {
if (refc == PERM_REFCOUNT) {
return; // refcount is permanent, permanent is sticky
} else if (refc == 0) {
#ifdef ASSERT
print();
fatal("refcount underflow");
#endif
return;
} else {
int hash = extract_hash(old_value);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -118,3 +118,10 @@ TEST_VM(SymbolTable, test_symbol_refcount_parallel) {
ttg.doit();
ttg.join();
}
TEST_VM_FATAL_ERROR_MSG(SymbolTable, test_symbol_underflow, ".*refcount has gone to zero.*") {
Symbol* my_symbol = SymbolTable::new_symbol("my_symbol2023");
EXPECT_TRUE(my_symbol->refcount() == 1) << "Symbol refcount just created is 1";
my_symbol->decrement_refcount();
my_symbol->increment_refcount(); // Should crash even in PRODUCT mode
}