Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit f33f25f

Browse files
committed
8278965: crash in SymbolTable::do_lookup
Reviewed-by: fparain Backport-of: 582b943439488a0f43482b67c0bc0d4975bf4023
1 parent 7cfbfc6 commit f33f25f

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed

src/hotspot/share/classfile/placeholders.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
#ifndef SHARE_CLASSFILE_PLACEHOLDERS_HPP
2626
#define SHARE_CLASSFILE_PLACEHOLDERS_HPP
2727

28+
#include "oops/symbol.hpp"
29+
2830
class PlaceholderEntry;
2931
class Thread;
3032
class ClassLoaderData;
31-
class Symbol;
3233

3334
// Placeholder objects. These represent classes currently
3435
// being loaded, as well as arrays of primitives.

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
663663
ObjectLocker ol(lockObject, THREAD);
664664

665665
bool super_load_in_progress = false;
666-
InstanceKlass* loaded_class = NULL;
667-
Symbol* superclassname = NULL;
666+
InstanceKlass* loaded_class = nullptr;
667+
SymbolHandle superclassname; // Keep alive while loading in parallel thread.
668668

669669
assert(THREAD->can_call_java(),
670670
"can not load classes with compiler thread: class=%s, classloader=%s",
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
#include "precompiled.hpp"
25+
#include "classfile/classLoaderData.hpp"
26+
#include "classfile/placeholders.hpp"
27+
#include "classfile/symbolTable.hpp"
28+
#include "oops/symbol.hpp"
29+
#include "runtime/interfaceSupport.inline.hpp"
30+
#include "runtime/mutexLocker.hpp"
31+
#include "threadHelper.inline.hpp"
32+
#include "unittest.hpp"
33+
34+
// Test that multiple threads calling handle_parallel_super_load don't underflow supername refcount.
35+
TEST_VM(PlaceholderTable, supername) {
36+
JavaThread* THREAD = JavaThread::current();
37+
JavaThread* T2 = THREAD;
38+
// the thread should be in vm to use locks
39+
ThreadInVMfromNative tivfn(THREAD);
40+
41+
// Assert messages assume these symbols are unique, and the refcounts start at one.
42+
TempNewSymbol A = SymbolTable::new_symbol("abc2_8_2023_class");
43+
TempNewSymbol D = SymbolTable::new_symbol("def2_8_2023_class");
44+
Symbol* super = SymbolTable::new_symbol("super2_8_2023_supername");
45+
TempNewSymbol interf = SymbolTable::new_symbol("interface2_8_2023_supername");
46+
47+
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
48+
49+
{
50+
MutexLocker ml(THREAD, SystemDictionary_lock);
51+
52+
PlaceholderTable::classloadAction super_action = PlaceholderTable::LOAD_SUPER;
53+
PlaceholderTable::classloadAction define_action = PlaceholderTable::DEFINE_CLASS;
54+
55+
// DefineClass A and D
56+
PlaceholderTable::find_and_add(A, loader_data, define_action, nullptr, THREAD);
57+
PlaceholderTable::find_and_add(D, loader_data, define_action, nullptr, T2);
58+
59+
// Load interfaces first to get supername replaced
60+
PlaceholderTable::find_and_add(A, loader_data, super_action, interf, THREAD);
61+
PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
62+
63+
PlaceholderTable::find_and_add(D, loader_data, super_action, interf, T2);
64+
PlaceholderTable::find_and_remove(D, loader_data, super_action, T2);
65+
66+
ASSERT_EQ(interf->refcount(), 3) << "supername isn't replaced until super set";
67+
68+
// Add placeholder to the table for loading A and super, and D also loading super
69+
PlaceholderTable::find_and_add(A, loader_data, super_action, super, THREAD);
70+
PlaceholderTable::find_and_add(D, loader_data, super_action, super, T2);
71+
72+
ASSERT_EQ(interf->refcount(), 1) << "now should be one";
73+
74+
// Another thread comes in and finds A loading Super
75+
PlaceholderEntry* placeholder = PlaceholderTable::get_entry(A, loader_data);
76+
SymbolHandle supername = placeholder->supername();
77+
78+
// Other thread is done before handle_parallel_super_load
79+
PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
80+
81+
// if THREAD drops reference to supername (loading failed or class unloaded), we're left with
82+
// a supername without refcount
83+
super->decrement_refcount();
84+
85+
// handle_parallel_super_load (same thread doesn't assert)
86+
PlaceholderTable::find_and_add(A, loader_data, super_action, supername, T2);
87+
88+
// Refcount should be 3: one in table for class A, one in table for class D
89+
// and one locally with SymbolHandle keeping it alive
90+
placeholder = PlaceholderTable::get_entry(A, loader_data);
91+
supername = placeholder->supername();
92+
EXPECT_EQ(super->refcount(), 3) << "super class name refcount should be 3";
93+
94+
// Second thread's done too
95+
PlaceholderTable::find_and_remove(D, loader_data, super_action, T2);
96+
97+
// Other threads are done.
98+
PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
99+
100+
// Remove A and D define_class placeholder
101+
PlaceholderTable::find_and_remove(A, loader_data, define_action, THREAD);
102+
PlaceholderTable::find_and_remove(D, loader_data, define_action, T2);
103+
104+
placeholder = PlaceholderTable::get_entry(A, loader_data);
105+
ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
106+
placeholder = PlaceholderTable::get_entry(D, loader_data);
107+
ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
108+
109+
EXPECT_EQ(super->refcount(), 1) << "super class name refcount should be 1 - kept alive in this scope";
110+
}
111+
112+
EXPECT_EQ(A->refcount(), 1) << "first lass name refcount should be 1";
113+
EXPECT_EQ(D->refcount(), 1) << "second class name refcount should be 1";
114+
EXPECT_EQ(super->refcount(), 0) << "super class name refcount should be 0 - was unloaded.";
115+
}

0 commit comments

Comments
 (0)