Mercurial > hg > graal-compiler
annotate src/share/vm/utilities/hashtable.cpp @ 6216:161ae369407d
7181632: nsk classLoad001_14 failure and CompileTheWorld crash after 7178145.
Summary: Need to copy the inlined exception table to the new constMethodOop during method rewriting.
Reviewed-by: coleenp, dholmes
author | jiangli |
---|---|
date | Thu, 05 Jul 2012 20:54:45 -0400 |
parents | 246d977b51f2 |
children | d2a62e0f25eb |
rev | line source |
---|---|
0 | 1 /* |
6162 | 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
470
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
470
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:
470
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/allocation.inline.hpp" | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
27 #include "memory/filemap.hpp" |
1972 | 28 #include "memory/resourceArea.hpp" |
29 #include "oops/oop.inline.hpp" | |
30 #include "runtime/safepoint.hpp" | |
31 #include "utilities/dtrace.hpp" | |
32 #include "utilities/hashtable.hpp" | |
33 #include "utilities/hashtable.inline.hpp" | |
0 | 34 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
35 |
4006 | 36 #ifndef USDT2 |
0 | 37 HS_DTRACE_PROBE_DECL4(hs_private, hashtable__new_entry, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
38 void*, unsigned int, void*, void*); |
4006 | 39 #endif /* !USDT2 */ |
0 | 40 |
41 // This is a generic hashtable, designed to be used for the symbol | |
42 // and string tables. | |
43 // | |
44 // It is implemented as an open hash table with a fixed number of buckets. | |
45 // | |
46 // %note: | |
47 // - HashtableEntrys are allocated in blocks to reduce the space overhead. | |
48 | |
49 BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) { | |
50 BasicHashtableEntry* entry; | |
51 | |
52 if (_free_list) { | |
53 entry = _free_list; | |
54 _free_list = _free_list->next(); | |
55 } else { | |
432 | 56 if (_first_free_entry + _entry_size >= _end_block) { |
57 int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries)); | |
0 | 58 int len = _entry_size * block_size; |
432 | 59 len = 1 << log2_intptr(len); // round down to power of 2 |
60 assert(len >= _entry_size, ""); | |
0 | 61 _first_free_entry = NEW_C_HEAP_ARRAY(char, len); |
62 _end_block = _first_free_entry + len; | |
63 } | |
64 entry = (BasicHashtableEntry*)_first_free_entry; | |
65 _first_free_entry += _entry_size; | |
66 } | |
67 | |
432 | 68 assert(_entry_size % HeapWordSize == 0, ""); |
0 | 69 entry->set_hash(hashValue); |
70 return entry; | |
71 } | |
72 | |
73 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
74 template <class T> HashtableEntry<T>* Hashtable<T>::new_entry(unsigned int hashValue, T obj) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
75 HashtableEntry<T>* entry; |
0 | 76 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
77 entry = (HashtableEntry<T>*)BasicHashtable::new_entry(hashValue); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
78 entry->set_literal(obj); |
4006 | 79 #ifndef USDT2 |
0 | 80 HS_DTRACE_PROBE4(hs_private, hashtable__new_entry, |
81 this, hashValue, obj, entry); | |
4006 | 82 #else /* USDT2 */ |
83 HS_PRIVATE_HASHTABLE_NEW_ENTRY( | |
84 this, hashValue, (uintptr_t) obj, entry); | |
85 #endif /* USDT2 */ | |
0 | 86 return entry; |
87 } | |
88 | |
89 | |
6162 | 90 // Check to see if the hashtable is unbalanced. The caller set a flag to |
91 // rehash at the next safepoint. If this bucket is 60 times greater than the | |
92 // expected average bucket length, it's an unbalanced hashtable. | |
93 // This is somewhat an arbitrary heuristic but if one bucket gets to | |
94 // rehash_count which is currently 100, there's probably something wrong. | |
95 | |
96 bool BasicHashtable::check_rehash_table(int count) { | |
97 assert(table_size() != 0, "underflow"); | |
98 if (count > (((double)number_of_entries()/(double)table_size())*rehash_multiple)) { | |
99 // Set a flag for the next safepoint, which should be at some guaranteed | |
100 // safepoint interval. | |
101 return true; | |
102 } | |
103 return false; | |
104 } | |
105 | |
106 // Create a new table and using alternate hash code, populate the new table | |
107 // with the existing elements. This can be used to change the hash code | |
108 // and could in the future change the size of the table. | |
109 | |
110 template <class T> void Hashtable<T>::move_to(Hashtable<T>* new_table) { | |
111 int saved_entry_count = number_of_entries(); | |
112 | |
113 // Iterate through the table and create a new entry for the new table | |
114 for (int i = 0; i < new_table->table_size(); ++i) { | |
115 for (HashtableEntry<T>* p = bucket(i); p != NULL; ) { | |
116 HashtableEntry<T>* next = p->next(); | |
117 T string = p->literal(); | |
118 // Use alternate hashing algorithm on the symbol in the first table | |
119 unsigned int hashValue = new_hash(string); | |
120 // Get a new index relative to the new table (can also change size) | |
121 int index = new_table->hash_to_index(hashValue); | |
122 p->set_hash(hashValue); | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
123 // Keep the shared bit in the Hashtable entry to indicate that this entry |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
124 // can't be deleted. The shared bit is the LSB in the _next field so |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
125 // walking the hashtable past these entries requires |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
126 // BasicHashtableEntry::make_ptr() call. |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
127 bool keep_shared = p->is_shared(); |
6162 | 128 unlink_entry(p); |
129 new_table->add_entry(index, p); | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
130 if (keep_shared) { |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
131 p->set_shared(); |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
132 } |
6162 | 133 p = next; |
134 } | |
135 } | |
136 // give the new table the free list as well | |
137 new_table->copy_freelist(this); | |
138 assert(new_table->number_of_entries() == saved_entry_count, "lost entry on dictionary copy?"); | |
139 | |
140 // Destroy memory used by the buckets in the hashtable. The memory | |
141 // for the elements has been used in a new table and is not | |
142 // destroyed. The memory reuse will benefit resizing the SystemDictionary | |
143 // to avoid a memory allocation spike at safepoint. | |
144 free_buckets(); | |
145 } | |
146 | |
6172
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
147 void BasicHashtable::free_buckets() { |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
148 if (NULL != _buckets) { |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
149 // Don't delete the buckets in the shared space. They aren't |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
150 // allocated by os::malloc |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
151 if (!UseSharedSpaces || |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
152 !FileMapInfo::current_info()->is_in_shared_space(_buckets)) { |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
153 FREE_C_HEAP_ARRAY(HashtableBucket, _buckets); |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
154 } |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
155 _buckets = NULL; |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
156 } |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
157 } |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
158 |
246d977b51f2
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
6162
diff
changeset
|
159 |
0 | 160 // Reverse the order of elements in the hash buckets. |
161 | |
162 void BasicHashtable::reverse() { | |
163 | |
164 for (int i = 0; i < _table_size; ++i) { | |
165 BasicHashtableEntry* new_list = NULL; | |
166 BasicHashtableEntry* p = bucket(i); | |
167 while (p != NULL) { | |
168 BasicHashtableEntry* next = p->next(); | |
169 p->set_next(new_list); | |
170 new_list = p; | |
171 p = next; | |
172 } | |
173 *bucket_addr(i) = new_list; | |
174 } | |
175 } | |
176 | |
177 | |
178 // Copy the table to the shared space. | |
179 | |
180 void BasicHashtable::copy_table(char** top, char* end) { | |
181 | |
182 // Dump the hash table entries. | |
183 | |
184 intptr_t *plen = (intptr_t*)(*top); | |
185 *top += sizeof(*plen); | |
186 | |
187 int i; | |
188 for (i = 0; i < _table_size; ++i) { | |
189 for (BasicHashtableEntry** p = _buckets[i].entry_addr(); | |
190 *p != NULL; | |
191 p = (*p)->next_addr()) { | |
192 if (*top + entry_size() > end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
193 report_out_of_shared_space(SharedMiscData); |
0 | 194 } |
195 *p = (BasicHashtableEntry*)memcpy(*top, *p, entry_size()); | |
196 *top += entry_size(); | |
197 } | |
198 } | |
199 *plen = (char*)(*top) - (char*)plen - sizeof(*plen); | |
200 | |
201 // Set the shared bit. | |
202 | |
203 for (i = 0; i < _table_size; ++i) { | |
204 for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) { | |
205 p->set_shared(); | |
206 } | |
207 } | |
208 } | |
209 | |
210 | |
211 | |
212 // Reverse the order of elements in the hash buckets. | |
213 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
214 template <class T> void Hashtable<T>::reverse(void* boundary) { |
0 | 215 |
216 for (int i = 0; i < table_size(); ++i) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
217 HashtableEntry<T>* high_list = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
218 HashtableEntry<T>* low_list = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
219 HashtableEntry<T>* last_low_entry = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
220 HashtableEntry<T>* p = bucket(i); |
0 | 221 while (p != NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
222 HashtableEntry<T>* next = p->next(); |
0 | 223 if ((void*)p->literal() >= boundary) { |
224 p->set_next(high_list); | |
225 high_list = p; | |
226 } else { | |
227 p->set_next(low_list); | |
228 low_list = p; | |
229 if (last_low_entry == NULL) { | |
230 last_low_entry = p; | |
231 } | |
232 } | |
233 p = next; | |
234 } | |
235 if (low_list != NULL) { | |
236 *bucket_addr(i) = low_list; | |
237 last_low_entry->set_next(high_list); | |
238 } else { | |
239 *bucket_addr(i) = high_list; | |
240 } | |
241 } | |
242 } | |
243 | |
244 | |
245 // Dump the hash table buckets. | |
246 | |
247 void BasicHashtable::copy_buckets(char** top, char* end) { | |
248 intptr_t len = _table_size * sizeof(HashtableBucket); | |
249 *(intptr_t*)(*top) = len; | |
250 *top += sizeof(intptr_t); | |
251 | |
252 *(intptr_t*)(*top) = _number_of_entries; | |
253 *top += sizeof(intptr_t); | |
254 | |
255 if (*top + len > end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
256 report_out_of_shared_space(SharedMiscData); |
0 | 257 } |
258 _buckets = (HashtableBucket*)memcpy(*top, _buckets, len); | |
259 *top += len; | |
260 } | |
261 | |
262 | |
263 #ifndef PRODUCT | |
264 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
265 template <class T> void Hashtable<T>::print() { |
0 | 266 ResourceMark rm; |
267 | |
268 for (int i = 0; i < table_size(); i++) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
269 HashtableEntry<T>* entry = bucket(i); |
0 | 270 while(entry != NULL) { |
271 tty->print("%d : ", i); | |
272 entry->literal()->print(); | |
273 tty->cr(); | |
274 entry = entry->next(); | |
275 } | |
276 } | |
277 } | |
278 | |
279 | |
280 void BasicHashtable::verify() { | |
281 int count = 0; | |
282 for (int i = 0; i < table_size(); i++) { | |
283 for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) { | |
284 ++count; | |
285 } | |
286 } | |
287 assert(count == number_of_entries(), "number of hashtable entries incorrect"); | |
288 } | |
289 | |
290 | |
291 #endif // PRODUCT | |
292 | |
293 | |
294 #ifdef ASSERT | |
295 | |
296 void BasicHashtable::verify_lookup_length(double load) { | |
297 if ((double)_lookup_length / (double)_lookup_count > load * 2.0) { | |
298 warning("Performance bug: SystemDictionary lookup_count=%d " | |
299 "lookup_length=%d average=%lf load=%f", | |
300 _lookup_count, _lookup_length, | |
301 (double) _lookup_length / _lookup_count, load); | |
302 } | |
303 } | |
304 | |
305 #endif | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
306 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
307 // Explicitly instantiate these types |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
308 template class Hashtable<constantPoolOop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
309 template class Hashtable<Symbol*>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
310 template class Hashtable<klassOop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
311 template class Hashtable<oop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
312 |