Skip to content

Commit

Permalink
8301123: Enable Symbol refcounting underflow checks in PRODUCT
Browse files Browse the repository at this point in the history
Reviewed-by: fparain, iklam
  • Loading branch information
coleenp committed Jan 27, 2023
1 parent e4252bb commit fccf818
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/hotspot/share/oops/symbol.cpp
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion test/hotspot/gtest/classfile/test_symbolTable.cpp
@@ -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
Expand Down Expand Up @@ -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
}

1 comment on commit fccf818

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.