< prev index next >

test/hotspot/gtest/classfile/test_placeholders.cpp

Print this page

 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 

 93     PlaceholderTable::find_and_remove(D, loader_data, super_action, T2);
 94 
 95     // Other threads are done.
 96     PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
 97 
 98     // Remove A and D define_class placeholder
 99     PlaceholderTable::find_and_remove(A, loader_data, define_action, THREAD);
100     PlaceholderTable::find_and_remove(D, loader_data, define_action, T2);
101 
102     placeholder = PlaceholderTable::get_entry(A, loader_data);
103     ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
104     placeholder = PlaceholderTable::get_entry(D, loader_data);
105     ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
106 
107     EXPECT_EQ(super->refcount(), 1) << "super class name refcount should be 1 - kept alive in this scope";
108   }
109 
110   EXPECT_EQ(A->refcount(), 1) << "first lass name refcount should be 1";
111   EXPECT_EQ(D->refcount(), 1) << "second class name refcount should be 1";
112   EXPECT_EQ(super->refcount(), 0) << "super class name refcount should be 0 - was unloaded.";





113 }

 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   Symbol* A = SymbolTable::new_symbol("abc2_8_2023_class");
 43   Symbol* D = SymbolTable::new_symbol("def2_8_2023_class");
 44   Symbol* super = SymbolTable::new_symbol("super2_8_2023_supername");
 45   Symbol* 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 

 93     PlaceholderTable::find_and_remove(D, loader_data, super_action, T2);
 94 
 95     // Other threads are done.
 96     PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
 97 
 98     // Remove A and D define_class placeholder
 99     PlaceholderTable::find_and_remove(A, loader_data, define_action, THREAD);
100     PlaceholderTable::find_and_remove(D, loader_data, define_action, T2);
101 
102     placeholder = PlaceholderTable::get_entry(A, loader_data);
103     ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
104     placeholder = PlaceholderTable::get_entry(D, loader_data);
105     ASSERT_TRUE(placeholder == nullptr) << "placeholder should be removed";
106 
107     EXPECT_EQ(super->refcount(), 1) << "super class name refcount should be 1 - kept alive in this scope";
108   }
109 
110   EXPECT_EQ(A->refcount(), 1) << "first lass name refcount should be 1";
111   EXPECT_EQ(D->refcount(), 1) << "second class name refcount should be 1";
112   EXPECT_EQ(super->refcount(), 0) << "super class name refcount should be 0 - was unloaded.";
113 
114   // clean up temporary symbols
115   A->decrement_refcount();
116   D->decrement_refcount();
117   interf->decrement_refcount();
118 }
< prev index next >