Mercurial > hg > graal-compiler
annotate src/share/vm/classfile/symbolTable.hpp @ 14189:1a899ea6b7ed
8031305: (hotspot) com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
Reviewed-by: jbachorik, mchung, dholmes
author | sla |
---|---|
date | Tue, 07 Jan 2014 12:32:57 +0100 |
parents | c90e76575b03 |
children | 893ce66f7473 |
rev | line source |
---|---|
0 | 1 /* |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
665
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
665
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
665
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP |
26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP | |
27 | |
28 #include "memory/allocation.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
29 #include "oops/symbol.hpp" |
1972 | 30 #include "utilities/hashtable.hpp" |
31 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
32 // The symbol table holds all Symbol*s and corresponding interned strings. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
33 // Symbol*s and literal strings should be canonicalized. |
0 | 34 // |
35 // The interned strings are created lazily. | |
36 // | |
37 // It is implemented as an open hash table with a fixed number of buckets. | |
38 // | |
39 // %note: | |
40 // - symbolTableEntrys are allocated in blocks to reduce the space overhead. | |
41 | |
42 class BoolObjectClosure; | |
6162 | 43 class outputStream; |
0 | 44 |
45 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
46 // Class to hold a newly created or referenced Symbol* temporarily in scope. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
47 // new_symbol() and lookup() will create a Symbol* if not already in the |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
48 // symbol table and add to the symbol's reference count. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
49 // probe() and lookup_only() will increment the refcount if symbol is found. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
50 class TempNewSymbol : public StackObj { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
51 Symbol* _temp; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
52 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
53 public: |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
54 TempNewSymbol() : _temp(NULL) {} |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
55 // Creating or looking up a symbol increments the symbol's reference count |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
56 TempNewSymbol(Symbol *s) : _temp(s) {} |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
57 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
58 // Operator= increments reference count. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
59 void operator=(const TempNewSymbol &s) { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6201
diff
changeset
|
60 //clear(); //FIXME |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
61 _temp = s._temp; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
62 if (_temp !=NULL) _temp->increment_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
63 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
64 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
65 // Decrement reference counter so it can go away if it's unique |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6201
diff
changeset
|
66 void clear() { if (_temp != NULL) _temp->decrement_refcount(); _temp = NULL; } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6201
diff
changeset
|
67 |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6201
diff
changeset
|
68 ~TempNewSymbol() { clear(); } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
69 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
70 // Operators so they can be used like Symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
71 Symbol* operator -> () const { return _temp; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
72 bool operator == (Symbol* o) const { return _temp == o; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
73 // Sneaky conversion function |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
74 operator Symbol*() { return _temp; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
75 }; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
76 |
6197 | 77 class SymbolTable : public Hashtable<Symbol*, mtSymbol> { |
0 | 78 friend class VMStructs; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
79 friend class ClassFileParser; |
0 | 80 |
81 private: | |
82 // The symbol table | |
83 static SymbolTable* _the_table; | |
84 | |
6162 | 85 // Set if one bucket is out of balance due to hash algorithm deficiency |
86 static bool _needs_rehashing; | |
87 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
88 // For statistics |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
89 static int symbols_removed; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
90 static int symbols_counted; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
91 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
92 Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
93 |
0 | 94 // Adding elements |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
95 Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue, |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
96 bool c_heap, TRAPS); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
97 bool basic_add(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
98 constantPoolHandle cp, int names_count, |
0 | 99 const char** names, int* lengths, int* cp_indices, |
100 unsigned int* hashValues, TRAPS); | |
101 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
102 static void new_symbols(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
103 constantPoolHandle cp, int names_count, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
104 const char** name, int* lengths, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
105 int* cp_indices, unsigned int* hashValues, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
106 TRAPS) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
107 add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
108 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
109 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
110 Symbol* lookup(int index, const char* name, int len, unsigned int hash); |
0 | 111 |
112 SymbolTable() | |
12825
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
113 : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {} |
0 | 114 |
6197 | 115 SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries) |
12825
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
116 : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t, |
0 | 117 number_of_entries) {} |
118 | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
119 // Arena for permanent symbols (null class loader) that are never unloaded |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
120 static Arena* _arena; |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
121 static Arena* arena() { return _arena; } // called for statistics |
0 | 122 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
123 static void initialize_symbols(int arena_alloc_size = 0); |
0 | 124 public: |
125 enum { | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
126 symbol_alloc_batch_size = 8, |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
127 // Pick initial size based on java -version size measurements |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
128 symbol_alloc_arena_size = 360*K |
0 | 129 }; |
130 | |
131 // The symbol table | |
132 static SymbolTable* the_table() { return _the_table; } | |
133 | |
12825
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
134 // Size of one bucket in the string table. Used when checking for rollover. |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
135 static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); } |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
136 |
0 | 137 static void create_table() { |
138 assert(_the_table == NULL, "One symbol table allowed."); | |
139 _the_table = new SymbolTable(); | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
140 initialize_symbols(symbol_alloc_arena_size); |
0 | 141 } |
142 | |
6197 | 143 static void create_table(HashtableBucket<mtSymbol>* t, int length, |
0 | 144 int number_of_entries) { |
145 assert(_the_table == NULL, "One symbol table allowed."); | |
12825
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
146 |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
147 // If CDS archive used a different symbol table size, use that size instead |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
148 // which is better than giving an error. |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
149 SymbolTableSize = length/bucket_size(); |
c90e76575b03
8019375: Internal symbol table size should be tunable.
kevinw
parents:
12275
diff
changeset
|
150 |
0 | 151 _the_table = new SymbolTable(t, number_of_entries); |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
152 // if CDS give symbol table a default arena size since most symbols |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
153 // are already allocated in the shared misc section. |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
154 initialize_symbols(); |
0 | 155 } |
156 | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
157 static unsigned int hash_symbol(const char* s, int len); |
6162 | 158 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
159 static Symbol* lookup(const char* name, int len, TRAPS); |
0 | 160 // lookup only, won't add. Also calculate hash. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
161 static Symbol* lookup_only(const char* name, int len, unsigned int& hash); |
0 | 162 // Only copy to C string to be added if lookup failed. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
163 static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
164 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
165 static void release(Symbol* sym); |
0 | 166 |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
2418
diff
changeset
|
167 // Look up the address of the literal in the SymbolTable for this Symbol* |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
2418
diff
changeset
|
168 static Symbol** lookup_symbol_addr(Symbol* sym); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
2418
diff
changeset
|
169 |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
170 // jchar (utf16) version of lookups |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
171 static Symbol* lookup_unicode(const jchar* name, int len, TRAPS); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
172 static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash); |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
173 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
174 static void add(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
175 constantPoolHandle cp, int names_count, |
0 | 176 const char** names, int* lengths, int* cp_indices, |
177 unsigned int* hashValues, TRAPS); | |
178 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
179 // Release any dead symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
180 static void unlink(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
181 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
182 // iterate over symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
183 static void symbols_do(SymbolClosure *cl); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
184 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
185 // Symbol creation |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
186 static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
187 assert(utf8_buffer != NULL, "just checking"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
188 return lookup(utf8_buffer, length, THREAD); |
0 | 189 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
190 static Symbol* new_symbol(const char* name, TRAPS) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
191 return new_symbol(name, (int)strlen(name), THREAD); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
192 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
193 static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
194 assert(begin <= end && end <= sym->utf8_length(), "just checking"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
195 return lookup(sym, begin, end, THREAD); |
0 | 196 } |
197 | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
198 // Create a symbol in the arena for symbols that are not deleted |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
199 static Symbol* new_permanent_symbol(const char* name, TRAPS); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
200 |
0 | 201 // Symbol lookup |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
202 static Symbol* lookup(int index, const char* name, int len, TRAPS); |
0 | 203 |
204 // Needed for preloading classes in signatures when compiling. | |
205 // Returns the symbol is already present in symbol table, otherwise | |
206 // NULL. NO ALLOCATION IS GUARANTEED! | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
207 static Symbol* probe(const char* name, int len) { |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
208 unsigned int ignore_hash; |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
209 return lookup_only(name, len, ignore_hash); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
210 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
211 static Symbol* probe_unicode(const jchar* name, int len) { |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
212 unsigned int ignore_hash; |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
213 return lookup_only_unicode(name, len, ignore_hash); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
214 } |
0 | 215 |
216 // Histogram | |
217 static void print_histogram() PRODUCT_RETURN; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
218 static void print() PRODUCT_RETURN; |
0 | 219 |
220 // Debugging | |
221 static void verify(); | |
6162 | 222 static void dump(outputStream* st); |
0 | 223 |
224 // Sharing | |
225 static void copy_buckets(char** top, char*end) { | |
6197 | 226 the_table()->Hashtable<Symbol*, mtSymbol>::copy_buckets(top, end); |
0 | 227 } |
228 static void copy_table(char** top, char*end) { | |
6197 | 229 the_table()->Hashtable<Symbol*, mtSymbol>::copy_table(top, end); |
0 | 230 } |
231 static void reverse(void* boundary = NULL) { | |
6197 | 232 the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary); |
0 | 233 } |
6162 | 234 |
235 // Rehash the symbol table if it gets out of balance | |
236 static void rehash_table(); | |
237 static bool needs_rehashing() { return _needs_rehashing; } | |
0 | 238 }; |
239 | |
6197 | 240 class StringTable : public Hashtable<oop, mtSymbol> { |
0 | 241 friend class VMStructs; |
242 | |
243 private: | |
244 // The string table | |
245 static StringTable* _the_table; | |
246 | |
6162 | 247 // Set if one bucket is out of balance due to hash algorithm deficiency |
248 static bool _needs_rehashing; | |
249 | |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
250 // Claimed high water mark for parallel chunked scanning |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
251 static volatile int _parallel_claimed_idx; |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
252 |
0 | 253 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS); |
254 oop basic_add(int index, Handle string_or_null, jchar* name, int len, | |
255 unsigned int hashValue, TRAPS); | |
256 | |
257 oop lookup(int index, jchar* chars, int length, unsigned int hashValue); | |
258 | |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
259 // Apply the give oop closure to the entries to the buckets |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
260 // in the range [start_idx, end_idx). |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
261 static void buckets_do(OopClosure* f, int start_idx, int end_idx); |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
262 |
6197 | 263 StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize, |
264 sizeof (HashtableEntry<oop, mtSymbol>)) {} | |
0 | 265 |
6197 | 266 StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries) |
267 : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t, | |
2378 | 268 number_of_entries) {} |
0 | 269 public: |
270 // The string table | |
271 static StringTable* the_table() { return _the_table; } | |
272 | |
6982
e4f764ddb06a
7122219: Passed StringTableSize value not verified
hseigel
parents:
6725
diff
changeset
|
273 // Size of one bucket in the string table. Used when checking for rollover. |
e4f764ddb06a
7122219: Passed StringTableSize value not verified
hseigel
parents:
6725
diff
changeset
|
274 static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); } |
e4f764ddb06a
7122219: Passed StringTableSize value not verified
hseigel
parents:
6725
diff
changeset
|
275 |
0 | 276 static void create_table() { |
277 assert(_the_table == NULL, "One string table allowed."); | |
278 _the_table = new StringTable(); | |
279 } | |
280 | |
281 // GC support | |
282 // Delete pointers to otherwise-unreachable objects. | |
10363
8dbc025ff709
8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents:
8850
diff
changeset
|
283 static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f); |
8dbc025ff709
8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents:
8850
diff
changeset
|
284 static void unlink(BoolObjectClosure* cl) { |
8dbc025ff709
8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents:
8850
diff
changeset
|
285 unlink_or_oops_do(cl, NULL); |
8dbc025ff709
8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents:
8850
diff
changeset
|
286 } |
0 | 287 |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
288 // Serially invoke "f->do_oop" on the locations of all oops in the table. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
289 static void oops_do(OopClosure* f); |
0 | 290 |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
291 // Possibly parallel version of the above |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
292 static void possibly_parallel_oops_do(OopClosure* f); |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
293 |
6162 | 294 // Hashing algorithm, used as the hash value used by the |
295 // StringTable for bucket selection and comparison (stored in the | |
296 // HashtableEntry structures). This is used in the String.intern() method. | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
297 static unsigned int hash_string(const jchar* s, int len); |
6162 | 298 |
299 // Internal test. | |
300 static void test_alt_hash() PRODUCT_RETURN; | |
301 | |
0 | 302 // Probing |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
303 static oop lookup(Symbol* symbol); |
8850 | 304 static oop lookup(jchar* chars, int length); |
0 | 305 |
306 // Interning | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
307 static oop intern(Symbol* symbol, TRAPS); |
0 | 308 static oop intern(oop string, TRAPS); |
309 static oop intern(const char *utf8_string, TRAPS); | |
310 | |
311 // Debugging | |
312 static void verify(); | |
6162 | 313 static void dump(outputStream* st); |
0 | 314 |
12275
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
315 enum VerifyMesgModes { |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
316 _verify_quietly = 0, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
317 _verify_with_mesgs = 1 |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
318 }; |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
319 |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
320 enum VerifyRetTypes { |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
321 _verify_pass = 0, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
322 _verify_fail_continue = 1, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
323 _verify_fail_done = 2 |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
324 }; |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
325 |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
326 static VerifyRetTypes compare_entries(int bkt1, int e_cnt1, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
327 HashtableEntry<oop, mtSymbol>* e_ptr1, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
328 int bkt2, int e_cnt2, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
329 HashtableEntry<oop, mtSymbol>* e_ptr2); |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
330 static VerifyRetTypes verify_entry(int bkt, int e_cnt, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
331 HashtableEntry<oop, mtSymbol>* e_ptr, |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
332 VerifyMesgModes mesg_mode); |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
333 static int verify_and_compare_entries(); |
63147986a428
8019835: Strings interned in different threads equal but does not ==
dcubed
parents:
10991
diff
changeset
|
334 |
0 | 335 // Sharing |
336 static void copy_buckets(char** top, char*end) { | |
6197 | 337 the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end); |
0 | 338 } |
339 static void copy_table(char** top, char*end) { | |
6197 | 340 the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end); |
0 | 341 } |
342 static void reverse() { | |
6197 | 343 the_table()->Hashtable<oop, mtSymbol>::reverse(); |
0 | 344 } |
6162 | 345 |
346 // Rehash the symbol table if it gets out of balance | |
347 static void rehash_table(); | |
348 static bool needs_rehashing() { return _needs_rehashing; } | |
10991
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
349 |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
350 // Parallel chunked scanning |
01522ca68fc7
8015237: Parallelize string table scanning during strong root processing
johnc
parents:
10363
diff
changeset
|
351 static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; } |
0 | 352 }; |
1972 | 353 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP |