duke@0
|
1 /*
|
duke@0
|
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
duke@0
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
duke@0
|
4 *
|
duke@0
|
5 * This code is free software; you can redistribute it and/or modify it
|
duke@0
|
6 * under the terms of the GNU General Public License version 2 only, as
|
duke@0
|
7 * published by the Free Software Foundation.
|
duke@0
|
8 *
|
duke@0
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
duke@0
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
duke@0
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
duke@0
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
duke@0
|
13 * accompanied this code).
|
duke@0
|
14 *
|
duke@0
|
15 * You should have received a copy of the GNU General Public License version
|
duke@0
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
duke@0
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
duke@0
|
18 *
|
duke@0
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
duke@0
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
duke@0
|
21 * have any questions.
|
duke@0
|
22 *
|
duke@0
|
23 */
|
duke@0
|
24
|
duke@0
|
25 // The symbol table holds all symbolOops and corresponding interned strings.
|
duke@0
|
26 // symbolOops and literal strings should be canonicalized.
|
duke@0
|
27 //
|
duke@0
|
28 // The interned strings are created lazily.
|
duke@0
|
29 //
|
duke@0
|
30 // It is implemented as an open hash table with a fixed number of buckets.
|
duke@0
|
31 //
|
duke@0
|
32 // %note:
|
duke@0
|
33 // - symbolTableEntrys are allocated in blocks to reduce the space overhead.
|
duke@0
|
34
|
duke@0
|
35 class BoolObjectClosure;
|
duke@0
|
36
|
duke@0
|
37
|
duke@0
|
38 class SymbolTable : public Hashtable {
|
duke@0
|
39 friend class VMStructs;
|
duke@0
|
40
|
duke@0
|
41 private:
|
duke@0
|
42 // The symbol table
|
duke@0
|
43 static SymbolTable* _the_table;
|
duke@0
|
44
|
duke@0
|
45 // Adding elements
|
duke@0
|
46 symbolOop basic_add(int index, u1* name, int len,
|
duke@0
|
47 unsigned int hashValue, TRAPS);
|
duke@0
|
48 bool basic_add(constantPoolHandle cp, int names_count,
|
duke@0
|
49 const char** names, int* lengths, int* cp_indices,
|
duke@0
|
50 unsigned int* hashValues, TRAPS);
|
duke@0
|
51
|
duke@0
|
52 // Table size
|
duke@0
|
53 enum {
|
duke@0
|
54 symbol_table_size = 20011
|
duke@0
|
55 };
|
duke@0
|
56
|
duke@0
|
57 symbolOop lookup(int index, const char* name, int len, unsigned int hash);
|
duke@0
|
58
|
duke@0
|
59 SymbolTable()
|
duke@0
|
60 : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
|
duke@0
|
61
|
duke@0
|
62 SymbolTable(HashtableBucket* t, int number_of_entries)
|
duke@0
|
63 : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
|
duke@0
|
64 number_of_entries) {}
|
duke@0
|
65
|
duke@0
|
66
|
duke@0
|
67 public:
|
duke@0
|
68 enum {
|
duke@0
|
69 symbol_alloc_batch_size = 8
|
duke@0
|
70 };
|
duke@0
|
71
|
duke@0
|
72 // The symbol table
|
duke@0
|
73 static SymbolTable* the_table() { return _the_table; }
|
duke@0
|
74
|
duke@0
|
75 static void create_table() {
|
duke@0
|
76 assert(_the_table == NULL, "One symbol table allowed.");
|
duke@0
|
77 _the_table = new SymbolTable();
|
duke@0
|
78 }
|
duke@0
|
79
|
duke@0
|
80 static void create_table(HashtableBucket* t, int length,
|
duke@0
|
81 int number_of_entries) {
|
duke@0
|
82 assert(_the_table == NULL, "One symbol table allowed.");
|
duke@0
|
83 assert(length == symbol_table_size * sizeof(HashtableBucket),
|
duke@0
|
84 "bad shared symbol size.");
|
duke@0
|
85 _the_table = new SymbolTable(t, number_of_entries);
|
duke@0
|
86 }
|
duke@0
|
87
|
duke@0
|
88 static symbolOop lookup(const char* name, int len, TRAPS);
|
duke@0
|
89 // lookup only, won't add. Also calculate hash.
|
duke@0
|
90 static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
|
duke@0
|
91 // Only copy to C string to be added if lookup failed.
|
duke@0
|
92 static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
|
duke@0
|
93
|
duke@0
|
94 static void add(constantPoolHandle cp, int names_count,
|
duke@0
|
95 const char** names, int* lengths, int* cp_indices,
|
duke@0
|
96 unsigned int* hashValues, TRAPS);
|
duke@0
|
97
|
duke@0
|
98 // GC support
|
duke@0
|
99 // Delete pointers to otherwise-unreachable objects.
|
duke@0
|
100 static void unlink(BoolObjectClosure* cl) {
|
duke@0
|
101 the_table()->Hashtable::unlink(cl);
|
duke@0
|
102 }
|
duke@0
|
103
|
duke@0
|
104 // Invoke "f->do_oop" on the locations of all oops in the table.
|
duke@0
|
105 static void oops_do(OopClosure* f) {
|
duke@0
|
106 the_table()->Hashtable::oops_do(f);
|
duke@0
|
107 }
|
duke@0
|
108
|
duke@0
|
109 // Symbol lookup
|
duke@0
|
110 static symbolOop lookup(int index, const char* name, int len, TRAPS);
|
duke@0
|
111
|
duke@0
|
112 // Needed for preloading classes in signatures when compiling.
|
duke@0
|
113 // Returns the symbol is already present in symbol table, otherwise
|
duke@0
|
114 // NULL. NO ALLOCATION IS GUARANTEED!
|
duke@0
|
115 static symbolOop probe(const char* name, int len);
|
duke@0
|
116
|
duke@0
|
117 // Histogram
|
duke@0
|
118 static void print_histogram() PRODUCT_RETURN;
|
duke@0
|
119
|
duke@0
|
120 // Debugging
|
duke@0
|
121 static void verify();
|
duke@0
|
122
|
duke@0
|
123 // Sharing
|
duke@0
|
124 static void copy_buckets(char** top, char*end) {
|
duke@0
|
125 the_table()->Hashtable::copy_buckets(top, end);
|
duke@0
|
126 }
|
duke@0
|
127 static void copy_table(char** top, char*end) {
|
duke@0
|
128 the_table()->Hashtable::copy_table(top, end);
|
duke@0
|
129 }
|
duke@0
|
130 static void reverse(void* boundary = NULL) {
|
duke@0
|
131 ((Hashtable*)the_table())->reverse(boundary);
|
duke@0
|
132 }
|
duke@0
|
133 };
|
duke@0
|
134
|
duke@0
|
135
|
duke@0
|
136 class StringTable : public Hashtable {
|
duke@0
|
137 friend class VMStructs;
|
duke@0
|
138
|
duke@0
|
139 private:
|
duke@0
|
140 // The string table
|
duke@0
|
141 static StringTable* _the_table;
|
duke@0
|
142
|
duke@0
|
143 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
|
duke@0
|
144 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
|
duke@0
|
145 unsigned int hashValue, TRAPS);
|
duke@0
|
146
|
duke@0
|
147 // Table size
|
duke@0
|
148 enum {
|
duke@0
|
149 string_table_size = 1009
|
duke@0
|
150 };
|
duke@0
|
151
|
duke@0
|
152 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
|
duke@0
|
153
|
duke@0
|
154 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
|
duke@0
|
155
|
duke@0
|
156 StringTable(HashtableBucket* t, int number_of_entries)
|
duke@0
|
157 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
|
duke@0
|
158 number_of_entries) {}
|
duke@0
|
159
|
duke@0
|
160 public:
|
duke@0
|
161 // The string table
|
duke@0
|
162 static StringTable* the_table() { return _the_table; }
|
duke@0
|
163
|
duke@0
|
164 static void create_table() {
|
duke@0
|
165 assert(_the_table == NULL, "One string table allowed.");
|
duke@0
|
166 _the_table = new StringTable();
|
duke@0
|
167 }
|
duke@0
|
168
|
duke@0
|
169 static void create_table(HashtableBucket* t, int length,
|
duke@0
|
170 int number_of_entries) {
|
duke@0
|
171 assert(_the_table == NULL, "One string table allowed.");
|
duke@0
|
172 assert(length == string_table_size * sizeof(HashtableBucket),
|
duke@0
|
173 "bad shared string size.");
|
duke@0
|
174 _the_table = new StringTable(t, number_of_entries);
|
duke@0
|
175 }
|
duke@0
|
176
|
duke@0
|
177
|
duke@0
|
178 static int hash_string(jchar* s, int len);
|
duke@0
|
179
|
duke@0
|
180
|
duke@0
|
181 // GC support
|
duke@0
|
182 // Delete pointers to otherwise-unreachable objects.
|
duke@0
|
183 static void unlink(BoolObjectClosure* cl) {
|
duke@0
|
184 the_table()->Hashtable::unlink(cl);
|
duke@0
|
185 }
|
duke@0
|
186
|
duke@0
|
187 // Invoke "f->do_oop" on the locations of all oops in the table.
|
duke@0
|
188 static void oops_do(OopClosure* f) {
|
duke@0
|
189 the_table()->Hashtable::oops_do(f);
|
duke@0
|
190 }
|
duke@0
|
191
|
duke@0
|
192 // Probing
|
duke@0
|
193 static oop lookup(symbolOop symbol);
|
duke@0
|
194
|
duke@0
|
195 // Interning
|
duke@0
|
196 static oop intern(symbolOop symbol, TRAPS);
|
duke@0
|
197 static oop intern(oop string, TRAPS);
|
duke@0
|
198 static oop intern(const char *utf8_string, TRAPS);
|
duke@0
|
199
|
duke@0
|
200 // Debugging
|
duke@0
|
201 static void verify();
|
duke@0
|
202
|
duke@0
|
203 // Sharing
|
duke@0
|
204 static void copy_buckets(char** top, char*end) {
|
duke@0
|
205 the_table()->Hashtable::copy_buckets(top, end);
|
duke@0
|
206 }
|
duke@0
|
207 static void copy_table(char** top, char*end) {
|
duke@0
|
208 the_table()->Hashtable::copy_table(top, end);
|
duke@0
|
209 }
|
duke@0
|
210 static void reverse() {
|
duke@0
|
211 ((BasicHashtable*)the_table())->reverse();
|
duke@0
|
212 }
|
duke@0
|
213 };
|