annotate src/share/vm/classfile/symbolTable.hpp @ 6201:ace99a6ffc83

7181200: JVM new hashing code breaks SA in product mode Summary: Made new_hash() overloaded rather than a virtual function so SA code doesn't need to be changed. Reviewed-by: kvn, acorn, dholmes, fparain
author coleenp
date Wed, 04 Jul 2012 15:55:45 -0400
parents d2a62e0f25eb
children 1d7922586cf6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
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
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "utilities/hashtable.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // The interned strings are created lazily.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 //
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // It is implemented as an open hash table with a fixed number of buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // %note:
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // - symbolTableEntrys are allocated in blocks to reduce the space overhead.
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class BoolObjectClosure;
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
43 class outputStream;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
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
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
74 class SymbolTable : public Hashtable<Symbol*, mtSymbol> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static SymbolTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
81
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
82 // Set if one bucket is out of balance due to hash algorithm deficiency
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
83 static bool _needs_rehashing;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
84
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
85 // For statistics
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
86 static int symbols_removed;
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
87 static int symbols_counted;
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
88
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
89 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
90
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Adding elements
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
92 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
93 bool c_heap, TRAPS);
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
94
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
95 bool basic_add(Handle class_loader, constantPoolHandle cp, int names_count,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
97 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
99 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
100 int names_count,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
101 const char** name, int* lengths,
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
102 int* cp_indices, unsigned int* hashValues,
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
103 TRAPS) {
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
104 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
105 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
106
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
108 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 symbol_table_size = 20011
a61af66fc99e Initial load
duke
parents:
diff changeset
110 };
a61af66fc99e Initial load
duke
parents:
diff changeset
111
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
112 Symbol* lookup(int index, const char* name, int len, unsigned int hash);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 SymbolTable()
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
115 : Hashtable<Symbol*, mtSymbol>(symbol_table_size, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
116
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
117 SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
118 : Hashtable<Symbol*, mtSymbol>(symbol_table_size, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
119 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
120
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
121 // 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
122 static Arena* _arena;
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
123 static Arena* arena() { return _arena; } // called for statistics
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
125 static void initialize_symbols(int arena_alloc_size = 0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 enum {
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
128 symbol_alloc_batch_size = 8,
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
129 // 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
130 symbol_alloc_arena_size = 360*K
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 };
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
134 static SymbolTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert(_the_table == NULL, "One symbol table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _the_table = new SymbolTable();
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
139 initialize_symbols(symbol_alloc_arena_size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
142 static void create_table(HashtableBucket<mtSymbol>* t, int length,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 assert(_the_table == NULL, "One symbol table allowed.");
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
145 assert(length == symbol_table_size * sizeof(HashtableBucket<mtSymbol>),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 "bad shared symbol size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 _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
148 // 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
149 // 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
150 initialize_symbols();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
6172
246d977b51f2 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 6162
diff changeset
153 static unsigned int hash_symbol(const char* s, int len);
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
154
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
155 static Symbol* lookup(const char* name, int len, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // 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
157 static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // 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
159 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
160
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
161 static void release(Symbol* sym);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162
4800
94ec88ca68e2 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 2418
diff changeset
163 // 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
164 static Symbol** lookup_symbol_addr(Symbol* sym);
94ec88ca68e2 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 2418
diff changeset
165
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
166 // jchar (utf16) version of lookups
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
167 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
168 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
169
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
170 static void add(Handle class_loader, constantPoolHandle cp, int names_count,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
171 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
172 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
173
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
174 // Release any dead symbols
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
175 static void unlink();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
176
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
177 // iterate over symbols
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
178 static void symbols_do(SymbolClosure *cl);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
179
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
180 // Symbol creation
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
181 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
182 assert(utf8_buffer != NULL, "just checking");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
183 return lookup(utf8_buffer, length, THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
185 static Symbol* new_symbol(const char* name, TRAPS) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
186 return new_symbol(name, (int)strlen(name), THREAD);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
187 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
188 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
189 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
190 return lookup(sym, begin, end, THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
5979
fc9d8850ab8b 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 4800
diff changeset
193 // 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
194 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
195
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // Symbol lookup
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
197 static Symbol* lookup(int index, const char* name, int len, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Needed for preloading classes in signatures when compiling.
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Returns the symbol is already present in symbol table, otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // NULL. NO ALLOCATION IS GUARANTEED!
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
202 static Symbol* probe(const char* name, int len) {
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
203 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
204 return lookup_only(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
205 }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
206 static Symbol* probe_unicode(const jchar* name, int len) {
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
207 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
208 return lookup_only_unicode(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
209 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // Histogram
a61af66fc99e Initial load
duke
parents:
diff changeset
212 static void print_histogram() PRODUCT_RETURN;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
213 static void print() PRODUCT_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
216 static void verify();
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
217 static void dump(outputStream* st);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
220 static void copy_buckets(char** top, char*end) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
221 the_table()->Hashtable<Symbol*, mtSymbol>::copy_buckets(top, end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 static void copy_table(char** top, char*end) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
224 the_table()->Hashtable<Symbol*, mtSymbol>::copy_table(top, end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 static void reverse(void* boundary = NULL) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
227 the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
229
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
230 // Rehash the symbol table if it gets out of balance
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
231 static void rehash_table();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
232 static bool needs_rehashing() { return _needs_rehashing; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
233 };
a61af66fc99e Initial load
duke
parents:
diff changeset
234
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
235 class StringTable : public Hashtable<oop, mtSymbol> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
236 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
240 static StringTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
241
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
242 // Set if one bucket is out of balance due to hash algorithm deficiency
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
243 static bool _needs_rehashing;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
244
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
247 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
250
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
251 StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
252 sizeof (HashtableEntry<oop, mtSymbol>)) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
253
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
254 StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
255 : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
2378
924777755fad 6962930: make the string table size configurable
jcoomes
parents: 2177
diff changeset
256 number_of_entries) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
259 static StringTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 _the_table = new StringTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
266 static void create_table(HashtableBucket<mtSymbol>* t, int length,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
267 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 assert(_the_table == NULL, "One string table allowed.");
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
269 assert((size_t)length == StringTableSize * sizeof(HashtableBucket<mtSymbol>),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 "bad shared string size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 _the_table = new StringTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Delete pointers to otherwise-unreachable objects.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
276 static void unlink(BoolObjectClosure* cl);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // 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
279 static void oops_do(OopClosure* f);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
280
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
281 // Hashing algorithm, used as the hash value used by the
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
282 // StringTable for bucket selection and comparison (stored in the
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
283 // 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
284 static unsigned int hash_string(const jchar* s, int len);
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
285
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
286 // Internal test.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
287 static void test_alt_hash() PRODUCT_RETURN;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
288
0
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // Probing
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
290 static oop lookup(Symbol* symbol);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // Interning
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
293 static oop intern(Symbol* symbol, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
294 static oop intern(oop string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
295 static oop intern(const char *utf8_string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
298 static void verify();
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
299 static void dump(outputStream* st);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
302 static void copy_buckets(char** top, char*end) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
303 the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 static void copy_table(char** top, char*end) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
306 the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 static void reverse() {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6172
diff changeset
309 the_table()->Hashtable<oop, mtSymbol>::reverse();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
311
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
312 // Rehash the symbol table if it gets out of balance
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
313 static void rehash_table();
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 5979
diff changeset
314 static bool needs_rehashing() { return _needs_rehashing; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
315 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
316 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP