Mercurial > hg > graal-compiler
annotate src/share/vm/utilities/hashtable.cpp @ 4911:d903bf750e9f
7129514: time warp warnings after 7117303
Summary: Replace calls to os::javaTimeMillis() that are used to update the milliseconds since the last GC to an equivalent that uses a monotonically non-decreasing time source.
Reviewed-by: ysr, jmasa
author | johnc |
---|---|
date | Wed, 18 Jan 2012 09:50:16 -0800 |
parents | 436b4a3231bf |
children | e9140bf80b4a |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 2003, 2011, 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" | |
27 #include "memory/resourceArea.hpp" | |
28 #include "oops/oop.inline.hpp" | |
29 #include "runtime/safepoint.hpp" | |
30 #include "utilities/dtrace.hpp" | |
31 #include "utilities/hashtable.hpp" | |
32 #include "utilities/hashtable.inline.hpp" | |
0 | 33 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
34 |
4006 | 35 #ifndef USDT2 |
0 | 36 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
|
37 void*, unsigned int, void*, void*); |
4006 | 38 #endif /* !USDT2 */ |
0 | 39 |
40 // This is a generic hashtable, designed to be used for the symbol | |
41 // and string tables. | |
42 // | |
43 // It is implemented as an open hash table with a fixed number of buckets. | |
44 // | |
45 // %note: | |
46 // - HashtableEntrys are allocated in blocks to reduce the space overhead. | |
47 | |
48 BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) { | |
49 BasicHashtableEntry* entry; | |
50 | |
51 if (_free_list) { | |
52 entry = _free_list; | |
53 _free_list = _free_list->next(); | |
54 } else { | |
432 | 55 if (_first_free_entry + _entry_size >= _end_block) { |
56 int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries)); | |
0 | 57 int len = _entry_size * block_size; |
432 | 58 len = 1 << log2_intptr(len); // round down to power of 2 |
59 assert(len >= _entry_size, ""); | |
0 | 60 _first_free_entry = NEW_C_HEAP_ARRAY(char, len); |
61 _end_block = _first_free_entry + len; | |
62 } | |
63 entry = (BasicHashtableEntry*)_first_free_entry; | |
64 _first_free_entry += _entry_size; | |
65 } | |
66 | |
432 | 67 assert(_entry_size % HeapWordSize == 0, ""); |
0 | 68 entry->set_hash(hashValue); |
69 return entry; | |
70 } | |
71 | |
72 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
73 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
|
74 HashtableEntry<T>* entry; |
0 | 75 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
76 entry = (HashtableEntry<T>*)BasicHashtable::new_entry(hashValue); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
77 entry->set_literal(obj); |
4006 | 78 #ifndef USDT2 |
0 | 79 HS_DTRACE_PROBE4(hs_private, hashtable__new_entry, |
80 this, hashValue, obj, entry); | |
4006 | 81 #else /* USDT2 */ |
82 HS_PRIVATE_HASHTABLE_NEW_ENTRY( | |
83 this, hashValue, (uintptr_t) obj, entry); | |
84 #endif /* USDT2 */ | |
0 | 85 return entry; |
86 } | |
87 | |
88 | |
89 // Reverse the order of elements in the hash buckets. | |
90 | |
91 void BasicHashtable::reverse() { | |
92 | |
93 for (int i = 0; i < _table_size; ++i) { | |
94 BasicHashtableEntry* new_list = NULL; | |
95 BasicHashtableEntry* p = bucket(i); | |
96 while (p != NULL) { | |
97 BasicHashtableEntry* next = p->next(); | |
98 p->set_next(new_list); | |
99 new_list = p; | |
100 p = next; | |
101 } | |
102 *bucket_addr(i) = new_list; | |
103 } | |
104 } | |
105 | |
106 | |
107 // Copy the table to the shared space. | |
108 | |
109 void BasicHashtable::copy_table(char** top, char* end) { | |
110 | |
111 // Dump the hash table entries. | |
112 | |
113 intptr_t *plen = (intptr_t*)(*top); | |
114 *top += sizeof(*plen); | |
115 | |
116 int i; | |
117 for (i = 0; i < _table_size; ++i) { | |
118 for (BasicHashtableEntry** p = _buckets[i].entry_addr(); | |
119 *p != NULL; | |
120 p = (*p)->next_addr()) { | |
121 if (*top + entry_size() > end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
122 report_out_of_shared_space(SharedMiscData); |
0 | 123 } |
124 *p = (BasicHashtableEntry*)memcpy(*top, *p, entry_size()); | |
125 *top += entry_size(); | |
126 } | |
127 } | |
128 *plen = (char*)(*top) - (char*)plen - sizeof(*plen); | |
129 | |
130 // Set the shared bit. | |
131 | |
132 for (i = 0; i < _table_size; ++i) { | |
133 for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) { | |
134 p->set_shared(); | |
135 } | |
136 } | |
137 } | |
138 | |
139 | |
140 | |
141 // Reverse the order of elements in the hash buckets. | |
142 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
143 template <class T> void Hashtable<T>::reverse(void* boundary) { |
0 | 144 |
145 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
|
146 HashtableEntry<T>* high_list = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
147 HashtableEntry<T>* low_list = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
148 HashtableEntry<T>* last_low_entry = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
149 HashtableEntry<T>* p = bucket(i); |
0 | 150 while (p != NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
151 HashtableEntry<T>* next = p->next(); |
0 | 152 if ((void*)p->literal() >= boundary) { |
153 p->set_next(high_list); | |
154 high_list = p; | |
155 } else { | |
156 p->set_next(low_list); | |
157 low_list = p; | |
158 if (last_low_entry == NULL) { | |
159 last_low_entry = p; | |
160 } | |
161 } | |
162 p = next; | |
163 } | |
164 if (low_list != NULL) { | |
165 *bucket_addr(i) = low_list; | |
166 last_low_entry->set_next(high_list); | |
167 } else { | |
168 *bucket_addr(i) = high_list; | |
169 } | |
170 } | |
171 } | |
172 | |
173 | |
174 // Dump the hash table buckets. | |
175 | |
176 void BasicHashtable::copy_buckets(char** top, char* end) { | |
177 intptr_t len = _table_size * sizeof(HashtableBucket); | |
178 *(intptr_t*)(*top) = len; | |
179 *top += sizeof(intptr_t); | |
180 | |
181 *(intptr_t*)(*top) = _number_of_entries; | |
182 *top += sizeof(intptr_t); | |
183 | |
184 if (*top + len > end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
185 report_out_of_shared_space(SharedMiscData); |
0 | 186 } |
187 _buckets = (HashtableBucket*)memcpy(*top, _buckets, len); | |
188 *top += len; | |
189 } | |
190 | |
191 | |
192 #ifndef PRODUCT | |
193 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
194 template <class T> void Hashtable<T>::print() { |
0 | 195 ResourceMark rm; |
196 | |
197 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
|
198 HashtableEntry<T>* entry = bucket(i); |
0 | 199 while(entry != NULL) { |
200 tty->print("%d : ", i); | |
201 entry->literal()->print(); | |
202 tty->cr(); | |
203 entry = entry->next(); | |
204 } | |
205 } | |
206 } | |
207 | |
208 | |
209 void BasicHashtable::verify() { | |
210 int count = 0; | |
211 for (int i = 0; i < table_size(); i++) { | |
212 for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) { | |
213 ++count; | |
214 } | |
215 } | |
216 assert(count == number_of_entries(), "number of hashtable entries incorrect"); | |
217 } | |
218 | |
219 | |
220 #endif // PRODUCT | |
221 | |
222 | |
223 #ifdef ASSERT | |
224 | |
225 void BasicHashtable::verify_lookup_length(double load) { | |
226 if ((double)_lookup_length / (double)_lookup_count > load * 2.0) { | |
227 warning("Performance bug: SystemDictionary lookup_count=%d " | |
228 "lookup_length=%d average=%lf load=%f", | |
229 _lookup_count, _lookup_length, | |
230 (double) _lookup_length / _lookup_count, load); | |
231 } | |
232 } | |
233 | |
234 #endif | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
235 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
236 // Explicitly instantiate these types |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
237 template class Hashtable<constantPoolOop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
238 template class Hashtable<Symbol*>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
239 template class Hashtable<klassOop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
240 template class Hashtable<oop>; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
241 |