< prev index next >

test/hotspot/gtest/classfile/test_placeholders.cpp

Print this page

 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(), 1) << "supername is replaced with null";
 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     // Another thread comes in and finds A loading Super
 73     PlaceholderEntry* placeholder = PlaceholderTable::get_entry(A, loader_data);
 74     SymbolHandle supername = placeholder->supername();
 75 
 76     // Other thread is done before handle_parallel_super_load
 77     PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
 78 
 79     // if THREAD drops reference to supername (loading failed or class unloaded), we're left with
 80     // a supername without refcount
 81     super->decrement_refcount();
 82 
 83     // handle_parallel_super_load (same thread doesn't assert)
 84     PlaceholderTable::find_and_add(A, loader_data, super_action, supername, T2);
 85 
 86     // Refcount should be 3: one in table for class A, one in table for class D
 87     // and one locally with SymbolHandle keeping it alive
 88     placeholder = PlaceholderTable::get_entry(A, loader_data);
 89     supername = placeholder->supername();
 90     EXPECT_EQ(super->refcount(), 3) << "super class name refcount should be 3";
 91 
 92     // Second thread's done too
 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 

 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::DETECT_CIRCULARITY;
 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(), 1) << "supername is replaced with null";
 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     // Another thread comes in and finds A loading Super
 73     PlaceholderEntry* placeholder = PlaceholderTable::get_entry(A, loader_data);
 74     SymbolHandle supername = placeholder->next_klass_name();
 75 
 76     // Other thread is done before handle_parallel_super_load
 77     PlaceholderTable::find_and_remove(A, loader_data, super_action, THREAD);
 78 
 79     // if THREAD drops reference to supername (loading failed or class unloaded), we're left with
 80     // a supername without refcount
 81     super->decrement_refcount();
 82 
 83     // handle_parallel_super_load (same thread doesn't assert)
 84     PlaceholderTable::find_and_add(A, loader_data, super_action, supername, T2);
 85 
 86     // Refcount should be 3: one in table for class A, one in table for class D
 87     // and one locally with SymbolHandle keeping it alive
 88     placeholder = PlaceholderTable::get_entry(A, loader_data);
 89     supername = placeholder->next_klass_name();
 90     EXPECT_EQ(super->refcount(), 3) << "super class name refcount should be 3";
 91 
 92     // Second thread's done too
 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 
< prev index next >