From fccf818972f15bc4f69ce9566b5cd4b7e7777107 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Fri, 27 Jan 2023 14:56:29 +0000 Subject: [PATCH] 8301123: Enable Symbol refcounting underflow checks in PRODUCT Reviewed-by: fparain, iklam --- src/hotspot/share/oops/symbol.cpp | 6 ------ test/hotspot/gtest/classfile/test_symbolTable.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/oops/symbol.cpp b/src/hotspot/share/oops/symbol.cpp index c2f00f6f035f3..cd4c827adb1cd 100644 --- a/src/hotspot/share/oops/symbol.cpp +++ b/src/hotspot/share/oops/symbol.cpp @@ -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); diff --git a/test/hotspot/gtest/classfile/test_symbolTable.cpp b/test/hotspot/gtest/classfile/test_symbolTable.cpp index a10a9e9ff217c..77d076ec21327 100644 --- a/test/hotspot/gtest/classfile/test_symbolTable.cpp +++ b/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 @@ -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 +}