annotate src/share/vm/classfile/symbolTable.hpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children c89f86385056
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
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
a61af66fc99e Initial load
duke
parents:
diff changeset
94 static void add(constantPoolHandle cp, int names_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
95 const char** names, int* lengths, int* cp_indices,
a61af66fc99e Initial load
duke
parents:
diff changeset
96 unsigned int* hashValues, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
100 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Symbol lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static symbolOop lookup(int index, const char* name, int len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Needed for preloading classes in signatures when compiling.
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Returns the symbol is already present in symbol table, otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // NULL. NO ALLOCATION IS GUARANTEED!
a61af66fc99e Initial load
duke
parents:
diff changeset
115 static symbolOop probe(const char* name, int len);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Histogram
a61af66fc99e Initial load
duke
parents:
diff changeset
118 static void print_histogram() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
121 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
124 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 static void reverse(void* boundary = NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ((Hashtable*)the_table())->reverse(boundary);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 };
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 class StringTable : public Hashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
141 static StringTable* _the_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
a61af66fc99e Initial load
duke
parents:
diff changeset
145 unsigned int hashValue, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
148 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 string_table_size = 1009
a61af66fc99e Initial load
duke
parents:
diff changeset
150 };
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 StringTable(HashtableBucket* t, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
157 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
a61af66fc99e Initial load
duke
parents:
diff changeset
158 number_of_entries) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // The string table
a61af66fc99e Initial load
duke
parents:
diff changeset
162 static StringTable* the_table() { return _the_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 static void create_table() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _the_table = new StringTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 static void create_table(HashtableBucket* t, int length,
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 assert(_the_table == NULL, "One string table allowed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 assert(length == string_table_size * sizeof(HashtableBucket),
a61af66fc99e Initial load
duke
parents:
diff changeset
173 "bad shared string size.");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _the_table = new StringTable(t, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 static int hash_string(jchar* s, int len);
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Delete pointers to otherwise-unreachable objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
183 static void unlink(BoolObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 the_table()->Hashtable::unlink(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Invoke "f->do_oop" on the locations of all oops in the table.
a61af66fc99e Initial load
duke
parents:
diff changeset
188 static void oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 the_table()->Hashtable::oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Probing
a61af66fc99e Initial load
duke
parents:
diff changeset
193 static oop lookup(symbolOop symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Interning
a61af66fc99e Initial load
duke
parents:
diff changeset
196 static oop intern(symbolOop symbol, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 static oop intern(oop string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 static oop intern(const char *utf8_string, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
201 static void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Sharing
a61af66fc99e Initial load
duke
parents:
diff changeset
204 static void copy_buckets(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 the_table()->Hashtable::copy_buckets(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 static void copy_table(char** top, char*end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 the_table()->Hashtable::copy_table(top, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 static void reverse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ((BasicHashtable*)the_table())->reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 };