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