annotate src/share/vm/classfile/symbolTable.hpp @ 973:ad6585fd4087

6830542: Performance: JVM_DefineClass already verified. Reviewed-by: kamg, phh
author acorn
date Fri, 04 Sep 2009 12:53:02 -0400
parents c89f86385056
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // The symbol table holds all symbolOops and corresponding interned strings.
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // symbolOops and literal strings should be canonicalized.
a61af66fc99e Initial load
duke
parents:
diff changeset
27 //
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // The interned strings are created lazily.
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // It is implemented as an open hash table with a fixed number of buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // %note:
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // - symbolTableEntrys are allocated in blocks to reduce the space overhead.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class BoolObjectClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class SymbolTable : public Hashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static SymbolTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Adding elements
a61af66fc99e Initial load
duke
parents:
diff changeset
46 symbolOop basic_add(int index, u1* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 bool basic_add(constantPoolHandle cp, int names_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
53 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 symbol_table_size = 20011
a61af66fc99e Initial load
duke
parents:
diff changeset
55 };
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 symbolOop lookup(int index, const char* name, int len, unsigned int hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 SymbolTable()
a61af66fc99e Initial load
duke
parents:
diff changeset
60 : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 SymbolTable(HashtableBucket* t, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
63 : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
a61af66fc99e Initial load
duke
parents:
diff changeset
64 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
68 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 symbol_alloc_batch_size = 8
a61af66fc99e Initial load
duke
parents:
diff changeset
70 };
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
73 static SymbolTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(_the_table == NULL, "One symbol table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _the_table = new SymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static void create_table(HashtableBucket* t, int length,
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 assert(_the_table == NULL, "One symbol table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 assert(length == symbol_table_size * sizeof(HashtableBucket),
a61af66fc99e Initial load
duke
parents:
diff changeset
84 "bad shared symbol size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _the_table = new SymbolTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 static symbolOop lookup(const char* name, int len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // lookup only, won't add. Also calculate hash.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Only copy to C string to be added if lookup failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
93
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
94 // jchar (utf16) version of lookups
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
95 static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
96 static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
97
0
a61af66fc99e Initial load
duke
parents:
diff changeset
98 static void add(constantPoolHandle cp, int names_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
99 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
100 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Symbol lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
114 static symbolOop lookup(int index, const char* name, int len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Needed for preloading classes in signatures when compiling.
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Returns the symbol is already present in symbol table, otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // NULL. NO ALLOCATION IS GUARANTEED!
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
119 static symbolOop probe(const char* name, int len) {
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
120 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
121 return lookup_only(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
122 }
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
123 static symbolOop probe_unicode(const jchar* name, int len) {
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
124 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
125 return lookup_only_unicode(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
126 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Histogram
a61af66fc99e Initial load
duke
parents:
diff changeset
129 static void print_histogram() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
132 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
135 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 static void reverse(void* boundary = NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 ((Hashtable*)the_table())->reverse(boundary);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 };
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 class StringTable : public Hashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
152 static StringTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
156 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
159 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 string_table_size = 1009
a61af66fc99e Initial load
duke
parents:
diff changeset
161 };
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 StringTable(HashtableBucket* t, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
168 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
a61af66fc99e Initial load
duke
parents:
diff changeset
169 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
173 static StringTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _the_table = new StringTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 static void create_table(HashtableBucket* t, int length,
a61af66fc99e Initial load
duke
parents:
diff changeset
181 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(length == string_table_size * sizeof(HashtableBucket),
a61af66fc99e Initial load
duke
parents:
diff changeset
184 "bad shared string size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 _the_table = new StringTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 static int hash_string(jchar* s, int len);
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Probing
a61af66fc99e Initial load
duke
parents:
diff changeset
204 static oop lookup(symbolOop symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // Interning
a61af66fc99e Initial load
duke
parents:
diff changeset
207 static oop intern(symbolOop symbol, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 static oop intern(oop string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 static oop intern(const char *utf8_string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
212 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
215 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 static void reverse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 ((BasicHashtable*)the_table())->reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 };