Mercurial > hg > graal-compiler
annotate src/share/vm/classfile/symbolTable.hpp @ 6162:e9140bf80b4a
7158800: Improve storage of symbol tables
Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance
Reviewed-by: pbk, kamg, dlong, kvn, fparain
author | coleenp |
---|---|
date | Wed, 13 Jun 2012 19:52:59 -0400 |
parents | fc9d8850ab8b |
children | 246d977b51f2 |
rev | line source |
---|---|
0 | 1 /* |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
2 * Copyright (c) 1997, 2012, 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) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
60 _temp = s._temp; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
61 if (_temp !=NULL) _temp->increment_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
62 } |
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 // Decrement reference counter so it can go away if it's unique |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
65 ~TempNewSymbol() { if (_temp != NULL) _temp->decrement_refcount(); } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
66 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
67 // Operators so they can be used like Symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
68 Symbol* operator -> () const { return _temp; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
69 bool operator == (Symbol* o) const { return _temp == o; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
70 // Sneaky conversion function |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
71 operator Symbol*() { return _temp; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
72 }; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
73 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
74 class SymbolTable : public Hashtable<Symbol*> { |
0 | 75 friend class VMStructs; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
76 friend class ClassFileParser; |
0 | 77 |
78 private: | |
79 // The symbol table | |
80 static SymbolTable* _the_table; | |
81 | |
6162 | 82 // Set if one bucket is out of balance due to hash algorithm deficiency |
83 static bool _needs_rehashing; | |
84 static jint _seed; | |
85 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
86 // For statistics |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
87 static int symbols_removed; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
88 static int symbols_counted; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
89 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
90 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
|
91 |
0 | 92 // Adding elements |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
93 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
|
94 bool c_heap, TRAPS); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
95 |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
96 bool basic_add(Handle class_loader, constantPoolHandle cp, int names_count, |
0 | 97 const char** names, int* lengths, int* cp_indices, |
98 unsigned int* hashValues, TRAPS); | |
99 | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
100 static void new_symbols(Handle class_loader, constantPoolHandle cp, |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
101 int names_count, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
102 const char** name, int* lengths, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
103 int* cp_indices, unsigned int* hashValues, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
104 TRAPS) { |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
105 add(class_loader, 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
|
106 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
107 |
0 | 108 // Table size |
109 enum { | |
110 symbol_table_size = 20011 | |
111 }; | |
112 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
113 Symbol* lookup(int index, const char* name, int len, unsigned int hash); |
0 | 114 |
115 SymbolTable() | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
116 : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>)) {} |
0 | 117 |
118 SymbolTable(HashtableBucket* t, int number_of_entries) | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
119 : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t, |
0 | 120 number_of_entries) {} |
121 | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
122 // 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
|
123 static Arena* _arena; |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
124 static Arena* arena() { return _arena; } // called for statistics |
0 | 125 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
126 static void initialize_symbols(int arena_alloc_size = 0); |
6162 | 127 |
128 static bool use_alternate_hashcode() { return _seed != 0; } | |
129 static jint seed() { return _seed; } | |
130 | |
131 unsigned int new_hash(Symbol* sym); | |
0 | 132 public: |
133 enum { | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
134 symbol_alloc_batch_size = 8, |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
135 // 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
|
136 symbol_alloc_arena_size = 360*K |
0 | 137 }; |
138 | |
139 // The symbol table | |
140 static SymbolTable* the_table() { return _the_table; } | |
141 | |
142 static void create_table() { | |
143 assert(_the_table == NULL, "One symbol table allowed."); | |
144 _the_table = new SymbolTable(); | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
145 initialize_symbols(symbol_alloc_arena_size); |
0 | 146 } |
147 | |
148 static void create_table(HashtableBucket* t, int length, | |
149 int number_of_entries) { | |
150 assert(_the_table == NULL, "One symbol table allowed."); | |
151 assert(length == symbol_table_size * sizeof(HashtableBucket), | |
152 "bad shared symbol size."); | |
153 _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
|
154 // 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
|
155 // 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
|
156 initialize_symbols(); |
0 | 157 } |
158 | |
6162 | 159 static unsigned int hash_symbol(const char* s, int len, unsigned int hashValue = 0); |
160 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
161 static Symbol* lookup(const char* name, int len, TRAPS); |
0 | 162 // 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
|
163 static Symbol* lookup_only(const char* name, int len, unsigned int& hash); |
0 | 164 // 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
|
165 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
|
166 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
167 static void release(Symbol* sym); |
0 | 168 |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
2418
diff
changeset
|
169 // 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
|
170 static Symbol** lookup_symbol_addr(Symbol* sym); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
2418
diff
changeset
|
171 |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
172 // jchar (utf16) version of lookups |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
173 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
|
174 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
|
175 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
176 static void add(Handle class_loader, constantPoolHandle cp, int names_count, |
0 | 177 const char** names, int* lengths, int* cp_indices, |
178 unsigned int* hashValues, TRAPS); | |
179 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
180 // Release any dead symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
181 static void unlink(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
182 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
183 // iterate over symbols |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
184 static void symbols_do(SymbolClosure *cl); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
185 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
186 // Symbol creation |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
187 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
|
188 assert(utf8_buffer != NULL, "just checking"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
189 return lookup(utf8_buffer, length, THREAD); |
0 | 190 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
191 static Symbol* new_symbol(const char* name, TRAPS) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
192 return new_symbol(name, (int)strlen(name), THREAD); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
193 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
194 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
|
195 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
|
196 return lookup(sym, begin, end, THREAD); |
0 | 197 } |
198 | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
4800
diff
changeset
|
199 // 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
|
200 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
|
201 |
0 | 202 // Symbol lookup |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
203 static Symbol* lookup(int index, const char* name, int len, TRAPS); |
0 | 204 |
205 // Needed for preloading classes in signatures when compiling. | |
206 // Returns the symbol is already present in symbol table, otherwise | |
207 // NULL. NO ALLOCATION IS GUARANTEED! | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
208 static Symbol* probe(const char* name, int len) { |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
209 unsigned int ignore_hash; |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
210 return lookup_only(name, len, ignore_hash); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
211 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
212 static Symbol* probe_unicode(const jchar* name, int len) { |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
213 unsigned int ignore_hash; |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
214 return lookup_only_unicode(name, len, ignore_hash); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
0
diff
changeset
|
215 } |
0 | 216 |
217 // Histogram | |
218 static void print_histogram() PRODUCT_RETURN; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
219 static void print() PRODUCT_RETURN; |
0 | 220 |
221 // Debugging | |
222 static void verify(); | |
6162 | 223 static void dump(outputStream* st); |
0 | 224 |
225 // Sharing | |
226 static void copy_buckets(char** top, char*end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
227 the_table()->Hashtable<Symbol*>::copy_buckets(top, end); |
0 | 228 } |
229 static void copy_table(char** top, char*end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
230 the_table()->Hashtable<Symbol*>::copy_table(top, end); |
0 | 231 } |
232 static void reverse(void* boundary = NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
233 the_table()->Hashtable<Symbol*>::reverse(boundary); |
0 | 234 } |
6162 | 235 |
236 // Rehash the symbol table if it gets out of balance | |
237 static void rehash_table(); | |
238 static bool needs_rehashing() { return _needs_rehashing; } | |
0 | 239 }; |
240 | |
6162 | 241 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
242 class StringTable : public Hashtable<oop> { |
0 | 243 friend class VMStructs; |
244 | |
245 private: | |
246 // The string table | |
247 static StringTable* _the_table; | |
248 | |
6162 | 249 // Set if one bucket is out of balance due to hash algorithm deficiency |
250 static bool _needs_rehashing; | |
251 static jint _seed; | |
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 | |
2378 | 259 StringTable() : Hashtable<oop>((int)StringTableSize, |
260 sizeof (HashtableEntry<oop>)) {} | |
0 | 261 |
262 StringTable(HashtableBucket* t, int number_of_entries) | |
2378 | 263 : Hashtable<oop>((int)StringTableSize, sizeof (HashtableEntry<oop>), t, |
264 number_of_entries) {} | |
0 | 265 |
6162 | 266 static bool use_alternate_hashcode() { return _seed != 0; } |
267 static jint seed() { return _seed; } | |
268 | |
269 unsigned int new_hash(oop s); | |
0 | 270 public: |
271 // The string table | |
272 static StringTable* the_table() { return _the_table; } | |
273 | |
274 static void create_table() { | |
275 assert(_the_table == NULL, "One string table allowed."); | |
276 _the_table = new StringTable(); | |
277 } | |
278 | |
279 static void create_table(HashtableBucket* t, int length, | |
280 int number_of_entries) { | |
281 assert(_the_table == NULL, "One string table allowed."); | |
2378 | 282 assert((size_t)length == StringTableSize * sizeof(HashtableBucket), |
0 | 283 "bad shared string size."); |
284 _the_table = new StringTable(t, number_of_entries); | |
285 } | |
286 | |
287 // GC support | |
288 // Delete pointers to otherwise-unreachable objects. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
289 static void unlink(BoolObjectClosure* cl); |
0 | 290 |
291 // 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
|
292 static void oops_do(OopClosure* f); |
0 | 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. | |
297 static unsigned int hash_string(const jchar* s, int len, unsigned int hashValue = 0); | |
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); |
0 | 304 |
305 // Interning | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
306 static oop intern(Symbol* symbol, TRAPS); |
0 | 307 static oop intern(oop string, TRAPS); |
308 static oop intern(const char *utf8_string, TRAPS); | |
309 | |
310 // Debugging | |
311 static void verify(); | |
6162 | 312 static void dump(outputStream* st); |
0 | 313 |
314 // Sharing | |
315 static void copy_buckets(char** top, char*end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
316 the_table()->Hashtable<oop>::copy_buckets(top, end); |
0 | 317 } |
318 static void copy_table(char** top, char*end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
319 the_table()->Hashtable<oop>::copy_table(top, end); |
0 | 320 } |
321 static void reverse() { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
322 the_table()->Hashtable<oop>::reverse(); |
0 | 323 } |
6162 | 324 |
325 // Rehash the symbol table if it gets out of balance | |
326 static void rehash_table(); | |
327 static bool needs_rehashing() { return _needs_rehashing; } | |
0 | 328 }; |
1972 | 329 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP |