annotate src/share/vm/classfile/symbolTable.hpp @ 1972:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents c18cbe5936b8
children 3582bf76420e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, 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"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "oops/symbolOop.hpp"
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
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // The symbol table holds all symbolOops and corresponding interned strings.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // symbolOops and literal strings should be canonicalized.
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;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 class SymbolTable : public Hashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
50 static SymbolTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Adding elements
a61af66fc99e Initial load
duke
parents:
diff changeset
53 symbolOop basic_add(int index, u1* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 bool basic_add(constantPoolHandle cp, int names_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
56 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
57 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
60 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 symbol_table_size = 20011
a61af66fc99e Initial load
duke
parents:
diff changeset
62 };
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 symbolOop lookup(int index, const char* name, int len, unsigned int hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 SymbolTable()
a61af66fc99e Initial load
duke
parents:
diff changeset
67 : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 SymbolTable(HashtableBucket* t, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
70 : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
a61af66fc99e Initial load
duke
parents:
diff changeset
71 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 symbol_alloc_batch_size = 8
a61af66fc99e Initial load
duke
parents:
diff changeset
77 };
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // The symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static SymbolTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 assert(_the_table == NULL, "One symbol table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _the_table = new SymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 static void create_table(HashtableBucket* t, int length,
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 assert(_the_table == NULL, "One symbol table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
90 assert(length == symbol_table_size * sizeof(HashtableBucket),
a61af66fc99e Initial load
duke
parents:
diff changeset
91 "bad shared symbol size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _the_table = new SymbolTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static symbolOop lookup(const char* name, int len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // lookup only, won't add. Also calculate hash.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Only copy to C string to be added if lookup failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
100
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
101 // jchar (utf16) version of lookups
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
102 static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
103 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
104
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 static void add(constantPoolHandle cp, int names_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
106 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
107 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Symbol lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
121 static symbolOop lookup(int index, const char* name, int len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Needed for preloading classes in signatures when compiling.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Returns the symbol is already present in symbol table, otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // NULL. NO ALLOCATION IS GUARANTEED!
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
126 static symbolOop probe(const char* name, int len) {
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
127 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
128 return lookup_only(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
129 }
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
130 static symbolOop probe_unicode(const jchar* name, int len) {
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
131 unsigned int ignore_hash;
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
132 return lookup_only_unicode(name, len, ignore_hash);
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
133 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Histogram
a61af66fc99e Initial load
duke
parents:
diff changeset
136 static void print_histogram() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
139 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
142 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 static void reverse(void* boundary = NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ((Hashtable*)the_table())->reverse(boundary);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 };
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 class StringTable : public Hashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
159 static StringTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
163 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
166 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 string_table_size = 1009
a61af66fc99e Initial load
duke
parents:
diff changeset
168 };
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 StringTable(HashtableBucket* t, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
175 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
a61af66fc99e Initial load
duke
parents:
diff changeset
176 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
180 static StringTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 _the_table = new StringTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 static void create_table(HashtableBucket* t, int length,
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 assert(length == string_table_size * sizeof(HashtableBucket),
a61af66fc99e Initial load
duke
parents:
diff changeset
191 "bad shared string size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 _the_table = new StringTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 static int hash_string(jchar* s, int len);
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
201 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
206 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Probing
a61af66fc99e Initial load
duke
parents:
diff changeset
211 static oop lookup(symbolOop symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // Interning
a61af66fc99e Initial load
duke
parents:
diff changeset
214 static oop intern(symbolOop symbol, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 static oop intern(oop string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 static oop intern(const char *utf8_string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
219 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
222 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 static void reverse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 ((BasicHashtable*)the_table())->reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
232
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
233 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP