1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
32 // one, but code does not rely on this. |
32 // one, but code does not rely on this. |
33 JavaThread* THREAD = JavaThread::current(); |
33 JavaThread* THREAD = JavaThread::current(); |
34 // the thread should be in vm to use locks |
34 // the thread should be in vm to use locks |
35 ThreadInVMfromNative ThreadInVMfromNative(THREAD); |
35 ThreadInVMfromNative ThreadInVMfromNative(THREAD); |
36 |
36 |
37 Symbol* abc = SymbolTable::new_symbol("abc", CATCH); |
37 Symbol* abc = SymbolTable::new_symbol("abc"); |
38 int abccount = abc->refcount(); |
38 int abccount = abc->refcount(); |
39 TempNewSymbol ss = abc; |
39 TempNewSymbol ss = abc; |
40 ASSERT_EQ(ss->refcount(), abccount) << "only one abc"; |
40 ASSERT_EQ(ss->refcount(), abccount) << "only one abc"; |
41 ASSERT_EQ(ss->refcount(), abc->refcount()) << "should match TempNewSymbol"; |
41 ASSERT_EQ(ss->refcount(), abc->refcount()) << "should match TempNewSymbol"; |
42 |
42 |
43 Symbol* efg = SymbolTable::new_symbol("efg", CATCH); |
43 Symbol* efg = SymbolTable::new_symbol("efg"); |
44 Symbol* hij = SymbolTable::new_symbol("hij", CATCH); |
44 Symbol* hij = SymbolTable::new_symbol("hij"); |
45 int efgcount = efg->refcount(); |
45 int efgcount = efg->refcount(); |
46 int hijcount = hij->refcount(); |
46 int hijcount = hij->refcount(); |
47 |
47 |
48 TempNewSymbol s1 = efg; |
48 TempNewSymbol s1 = efg; |
49 TempNewSymbol s2 = hij; |
49 TempNewSymbol s2 = hij; |
61 |
61 |
62 s1 = s1; // self assignment |
62 s1 = s1; // self assignment |
63 ASSERT_EQ(s1->refcount(), abccount + 1) << "should still be two abc (s1 and ss)"; |
63 ASSERT_EQ(s1->refcount(), abccount + 1) << "should still be two abc (s1 and ss)"; |
64 |
64 |
65 TempNewSymbol s3; |
65 TempNewSymbol s3; |
66 Symbol* klm = SymbolTable::new_symbol("klm", CATCH); |
66 Symbol* klm = SymbolTable::new_symbol("klm"); |
67 int klmcount = klm->refcount(); |
67 int klmcount = klm->refcount(); |
68 s3 = klm; // assignment |
68 s3 = klm; // assignment |
69 ASSERT_EQ(s3->refcount(), klmcount) << "only one klm now"; |
69 ASSERT_EQ(s3->refcount(), klmcount) << "only one klm now"; |
70 |
70 |
71 Symbol* xyz = SymbolTable::new_symbol("xyz", CATCH); |
71 Symbol* xyz = SymbolTable::new_symbol("xyz"); |
72 int xyzcount = xyz->refcount(); |
72 int xyzcount = xyz->refcount(); |
73 { // inner scope |
73 { // inner scope |
74 TempNewSymbol s_inner = xyz; |
74 TempNewSymbol s_inner = xyz; |
75 } |
75 } |
76 ASSERT_EQ(xyz->refcount(), xyzcount - 1) |
76 ASSERT_EQ(xyz->refcount(), xyzcount - 1) |
77 << "Should have been decremented by dtor in inner scope"; |
77 << "Should have been decremented by dtor in inner scope"; |
78 |
78 |
79 // Test overflowing refcount making symbol permanent |
79 // Test overflowing refcount making symbol permanent |
80 Symbol* bigsym = SymbolTable::new_symbol("bigsym", CATCH); |
80 Symbol* bigsym = SymbolTable::new_symbol("bigsym"); |
81 for (int i = 0; i < PERM_REFCOUNT + 100; i++) { |
81 for (int i = 0; i < PERM_REFCOUNT + 100; i++) { |
82 bigsym->increment_refcount(); |
82 bigsym->increment_refcount(); |
83 } |
83 } |
84 ASSERT_EQ(bigsym->refcount(), PERM_REFCOUNT) << "should not have overflowed"; |
84 ASSERT_EQ(bigsym->refcount(), PERM_REFCOUNT) << "should not have overflowed"; |
85 |
85 |
99 class SymbolThread : public JavaTestThread { |
99 class SymbolThread : public JavaTestThread { |
100 public: |
100 public: |
101 SymbolThread(Semaphore* post) : JavaTestThread(post) {} |
101 SymbolThread(Semaphore* post) : JavaTestThread(post) {} |
102 virtual ~SymbolThread() {} |
102 virtual ~SymbolThread() {} |
103 void main_run() { |
103 void main_run() { |
104 Thread* THREAD = Thread::current(); |
|
105 for (int i = 0; i < 1000; i++) { |
104 for (int i = 0; i < 1000; i++) { |
106 TempNewSymbol sym = SymbolTable::new_symbol(symbol_name, CATCH); |
105 TempNewSymbol sym = SymbolTable::new_symbol(symbol_name); |
107 // Create and destroy new symbol |
106 // Create and destroy new symbol |
108 EXPECT_TRUE(sym->refcount() != 0) << "Symbol refcount unexpectedly zeroed"; |
107 EXPECT_TRUE(sym->refcount() != 0) << "Symbol refcount unexpectedly zeroed"; |
109 } |
108 } |
110 } |
109 } |
111 }; |
110 }; |
119 virtual ~DriverSymbolThread(){} |
118 virtual ~DriverSymbolThread(){} |
120 |
119 |
121 void main_run() { |
120 void main_run() { |
122 Semaphore done(0); |
121 Semaphore done(0); |
123 |
122 |
124 Thread* THREAD = Thread::current(); |
|
125 |
|
126 // Find a symbol where there will probably be only one instance. |
123 // Find a symbol where there will probably be only one instance. |
127 for (int i = 0; i < 100; i++) { |
124 for (int i = 0; i < 100; i++) { |
128 os::snprintf(symbol_name, SYM_NAME_LENGTH, "some_symbol%d", i); |
125 os::snprintf(symbol_name, SYM_NAME_LENGTH, "some_symbol%d", i); |
129 TempNewSymbol ts = SymbolTable::new_symbol(symbol_name, CATCH); |
126 TempNewSymbol ts = SymbolTable::new_symbol(symbol_name); |
130 if (ts->refcount() == 1) { |
127 if (ts->refcount() == 1) { |
131 EXPECT_TRUE(ts->refcount() == 1) << "Symbol is just created"; |
128 EXPECT_TRUE(ts->refcount() == 1) << "Symbol is just created"; |
132 break; // found a unique symbol |
129 break; // found a unique symbol |
133 } |
130 } |
134 } |
131 } |