author | kzhaldyb |
Mon, 15 Aug 2016 13:18:35 +0300 | |
changeset 40903 | efb9ac3b77ce |
parent 39982 | 1a3808e3f4d9 |
child 42073 | 89e056fd82cc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22757
b2cbb3680b4f
8033792: AltHashing used jint for imprecise bit shifting
minqi
parents:
22234
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_HASHTABLE_HPP |
26 |
#define SHARE_VM_UTILITIES_HASHTABLE_HPP |
|
27 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
28 |
#include "classfile/classLoaderData.hpp" |
7397 | 29 |
#include "memory/allocation.hpp" |
30 |
#include "oops/oop.hpp" |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
31 |
#include "oops/symbol.hpp" |
7397 | 32 |
#include "runtime/handles.hpp" |
33 |
||
1 | 34 |
// This is a generic hashtable, designed to be used for the symbol |
35 |
// and string tables. |
|
36 |
// |
|
37 |
// It is implemented as an open hash table with a fixed number of buckets. |
|
38 |
// |
|
39 |
// %note: |
|
40 |
// - TableEntrys are allocated in blocks to reduce the space overhead. |
|
41 |
||
42 |
||
43 |
||
13195 | 44 |
template <MEMFLAGS F> class BasicHashtableEntry : public CHeapObj<F> { |
1 | 45 |
friend class VMStructs; |
46 |
private: |
|
47 |
unsigned int _hash; // 32-bit hash for item |
|
48 |
||
49 |
// Link to next element in the linked list for this bucket. EXCEPT |
|
50 |
// bit 0 set indicates that this entry is shared and must not be |
|
51 |
// unlinked from the table. Bit 0 is set during the dumping of the |
|
52 |
// archive. Since shared entries are immutable, _next fields in the |
|
53 |
// shared entries will not change. New entries will always be |
|
54 |
// unshared and since pointers are align, bit 0 will always remain 0 |
|
55 |
// with no extra effort. |
|
13195 | 56 |
BasicHashtableEntry<F>* _next; |
1 | 57 |
|
58 |
// Windows IA64 compiler requires subclasses to be able to access these |
|
59 |
protected: |
|
60 |
// Entry objects should not be created, they should be taken from the |
|
61 |
// free list with BasicHashtable.new_entry(). |
|
62 |
BasicHashtableEntry() { ShouldNotReachHere(); } |
|
63 |
// Entry objects should not be destroyed. They should be placed on |
|
64 |
// the free list instead with BasicHashtable.free_entry(). |
|
65 |
~BasicHashtableEntry() { ShouldNotReachHere(); } |
|
66 |
||
67 |
public: |
|
68 |
||
69 |
unsigned int hash() const { return _hash; } |
|
70 |
void set_hash(unsigned int hash) { _hash = hash; } |
|
71 |
unsigned int* hash_addr() { return &_hash; } |
|
72 |
||
13195 | 73 |
static BasicHashtableEntry<F>* make_ptr(BasicHashtableEntry<F>* p) { |
1 | 74 |
return (BasicHashtableEntry*)((intptr_t)p & -2); |
75 |
} |
|
76 |
||
13195 | 77 |
BasicHashtableEntry<F>* next() const { |
1 | 78 |
return make_ptr(_next); |
79 |
} |
|
80 |
||
13195 | 81 |
void set_next(BasicHashtableEntry<F>* next) { |
1 | 82 |
_next = next; |
83 |
} |
|
84 |
||
13195 | 85 |
BasicHashtableEntry<F>** next_addr() { |
1 | 86 |
return &_next; |
87 |
} |
|
88 |
||
89 |
bool is_shared() const { |
|
90 |
return ((intptr_t)_next & 1) != 0; |
|
91 |
} |
|
92 |
||
93 |
void set_shared() { |
|
13195 | 94 |
_next = (BasicHashtableEntry<F>*)((intptr_t)_next | 1); |
1 | 95 |
} |
96 |
}; |
|
97 |
||
98 |
||
99 |
||
13195 | 100 |
template <class T, MEMFLAGS F> class HashtableEntry : public BasicHashtableEntry<F> { |
1 | 101 |
friend class VMStructs; |
102 |
private: |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
103 |
T _literal; // ref to item in table. |
1 | 104 |
|
105 |
public: |
|
106 |
// Literal |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
107 |
T literal() const { return _literal; } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
108 |
T* literal_addr() { return &_literal; } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
109 |
void set_literal(T s) { _literal = s; } |
1 | 110 |
|
111 |
HashtableEntry* next() const { |
|
13195 | 112 |
return (HashtableEntry*)BasicHashtableEntry<F>::next(); |
1 | 113 |
} |
114 |
HashtableEntry** next_addr() { |
|
13195 | 115 |
return (HashtableEntry**)BasicHashtableEntry<F>::next_addr(); |
1 | 116 |
} |
117 |
}; |
|
118 |
||
119 |
||
120 |
||
13195 | 121 |
template <MEMFLAGS F> class HashtableBucket : public CHeapObj<F> { |
1 | 122 |
friend class VMStructs; |
123 |
private: |
|
124 |
// Instance variable |
|
13195 | 125 |
BasicHashtableEntry<F>* _entry; |
1 | 126 |
|
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
127 |
#ifdef ASSERT |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
128 |
private: |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
129 |
unsigned _hits; |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
130 |
public: |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
131 |
unsigned hits() { return _hits; } |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
132 |
void count_hit() { _hits++; } |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
133 |
#endif |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
134 |
|
1 | 135 |
public: |
136 |
// Accessing |
|
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
137 |
void clear() { _entry = NULL; DEBUG_ONLY(_hits = 0); } |
1 | 138 |
|
139 |
// The following methods use order access methods to avoid race |
|
140 |
// conditions in multiprocessor systems. |
|
13195 | 141 |
BasicHashtableEntry<F>* get_entry() const; |
142 |
void set_entry(BasicHashtableEntry<F>* l); |
|
1 | 143 |
|
144 |
// The following method is not MT-safe and must be done under lock. |
|
13195 | 145 |
BasicHashtableEntry<F>** entry_addr() { return &_entry; } |
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
146 |
|
1 | 147 |
}; |
148 |
||
149 |
||
13195 | 150 |
template <MEMFLAGS F> class BasicHashtable : public CHeapObj<F> { |
1 | 151 |
friend class VMStructs; |
152 |
||
153 |
public: |
|
154 |
BasicHashtable(int table_size, int entry_size); |
|
155 |
BasicHashtable(int table_size, int entry_size, |
|
13195 | 156 |
HashtableBucket<F>* buckets, int number_of_entries); |
1 | 157 |
|
158 |
// Sharing support. |
|
159 |
void copy_buckets(char** top, char* end); |
|
160 |
void copy_table(char** top, char* end); |
|
161 |
||
162 |
// Bucket handling |
|
34666 | 163 |
int hash_to_index(unsigned int full_hash) const { |
1 | 164 |
int h = full_hash % _table_size; |
165 |
assert(h >= 0 && h < _table_size, "Illegal hash value"); |
|
166 |
return h; |
|
167 |
} |
|
168 |
||
169 |
// Reverse the order of elements in each of the buckets. |
|
170 |
void reverse(); |
|
171 |
||
172 |
private: |
|
173 |
// Instance variables |
|
174 |
int _table_size; |
|
13195 | 175 |
HashtableBucket<F>* _buckets; |
176 |
BasicHashtableEntry<F>* _free_list; |
|
1 | 177 |
char* _first_free_entry; |
178 |
char* _end_block; |
|
179 |
int _entry_size; |
|
180 |
int _number_of_entries; |
|
181 |
||
182 |
protected: |
|
183 |
||
184 |
#ifdef ASSERT |
|
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
185 |
bool _lookup_warning; |
34666 | 186 |
mutable int _lookup_count; |
187 |
mutable int _lookup_length; |
|
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
188 |
bool verify_lookup_length(double load); |
1 | 189 |
#endif |
190 |
||
191 |
void initialize(int table_size, int entry_size, int number_of_entries); |
|
192 |
||
193 |
// Accessor |
|
194 |
int entry_size() const { return _entry_size; } |
|
195 |
||
196 |
// The following method is MT-safe and may be used with caution. |
|
34666 | 197 |
BasicHashtableEntry<F>* bucket(int i) const; |
1 | 198 |
|
199 |
// The following method is not MT-safe and must be done under lock. |
|
13195 | 200 |
BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); } |
1 | 201 |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
202 |
// Attempt to get an entry from the free list |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
203 |
BasicHashtableEntry<F>* new_entry_free_list(); |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
204 |
|
1 | 205 |
// Table entry management |
13195 | 206 |
BasicHashtableEntry<F>* new_entry(unsigned int hashValue); |
1 | 207 |
|
13087 | 208 |
// Used when moving the entry to another table |
209 |
// Clean up links, but do not add to free_list |
|
13195 | 210 |
void unlink_entry(BasicHashtableEntry<F>* entry) { |
13087 | 211 |
entry->set_next(NULL); |
212 |
--_number_of_entries; |
|
213 |
} |
|
214 |
||
215 |
// Move over freelist and free block for allocation |
|
216 |
void copy_freelist(BasicHashtable* src) { |
|
217 |
_free_list = src->_free_list; |
|
218 |
src->_free_list = NULL; |
|
219 |
_first_free_entry = src->_first_free_entry; |
|
220 |
src->_first_free_entry = NULL; |
|
221 |
_end_block = src->_end_block; |
|
222 |
src->_end_block = NULL; |
|
223 |
} |
|
224 |
||
225 |
// Free the buckets in this hashtable |
|
13097
c146b608d91f
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
13087
diff
changeset
|
226 |
void free_buckets(); |
13087 | 227 |
|
1 | 228 |
public: |
11628
13155c0c00b4
7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents:
8921
diff
changeset
|
229 |
int table_size() { return _table_size; } |
13195 | 230 |
void set_entry(int index, BasicHashtableEntry<F>* entry); |
1 | 231 |
|
13195 | 232 |
void add_entry(int index, BasicHashtableEntry<F>* entry); |
1 | 233 |
|
13195 | 234 |
void free_entry(BasicHashtableEntry<F>* entry); |
1 | 235 |
|
236 |
int number_of_entries() { return _number_of_entries; } |
|
237 |
||
238 |
void verify() PRODUCT_RETURN; |
|
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
239 |
|
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
240 |
#ifdef ASSERT |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
241 |
void bucket_count_hit(int i) const { |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
242 |
_buckets[i].count_hit(); |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
243 |
} |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
244 |
unsigned bucket_hits(int i) const { |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
245 |
return _buckets[i].hits(); |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
246 |
} |
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
34666
diff
changeset
|
247 |
#endif |
1 | 248 |
}; |
249 |
||
250 |
||
13195 | 251 |
template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> { |
1 | 252 |
friend class VMStructs; |
253 |
||
254 |
public: |
|
255 |
Hashtable(int table_size, int entry_size) |
|
13195 | 256 |
: BasicHashtable<F>(table_size, entry_size) { } |
1 | 257 |
|
258 |
Hashtable(int table_size, int entry_size, |
|
13195 | 259 |
HashtableBucket<F>* buckets, int number_of_entries) |
260 |
: BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { } |
|
1 | 261 |
|
262 |
// Debugging |
|
263 |
void print() PRODUCT_RETURN; |
|
264 |
||
265 |
// Reverse the order of elements in each of the buckets. Hashtable |
|
266 |
// entries which refer to objects at a lower address than 'boundary' |
|
267 |
// are separated from those which refer to objects at higher |
|
268 |
// addresses, and appear first in the list. |
|
269 |
void reverse(void* boundary = NULL); |
|
270 |
||
271 |
protected: |
|
272 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
273 |
unsigned int compute_hash(Symbol* name) { |
1 | 274 |
return (unsigned int) name->identity_hash(); |
275 |
} |
|
276 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
277 |
int index_for(Symbol* name) { |
13342
76a5de64aa62
7186278: Build error after CR#6995781 / 7151532 with GCC 4.7.0
andrew
parents:
13199
diff
changeset
|
278 |
return this->hash_to_index(compute_hash(name)); |
1 | 279 |
} |
280 |
||
281 |
// Table entry management |
|
13195 | 282 |
HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj); |
1 | 283 |
|
284 |
// The following method is MT-safe and may be used with caution. |
|
34666 | 285 |
HashtableEntry<T, F>* bucket(int i) const { |
13195 | 286 |
return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i); |
1 | 287 |
} |
288 |
||
289 |
// The following method is not MT-safe and must be done under lock. |
|
13195 | 290 |
HashtableEntry<T, F>** bucket_addr(int i) { |
291 |
return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i); |
|
1 | 292 |
} |
13087 | 293 |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
294 |
}; |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
295 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
296 |
template <class T, MEMFLAGS F> class RehashableHashtable : public Hashtable<T, F> { |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
297 |
protected: |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
298 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
299 |
enum { |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
300 |
rehash_count = 100, |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
301 |
rehash_multiple = 60 |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
302 |
}; |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
303 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
304 |
// Check that the table is unbalanced |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
305 |
bool check_rehash_table(int count); |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
306 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
307 |
public: |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
308 |
RehashableHashtable(int table_size, int entry_size) |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
309 |
: Hashtable<T, F>(table_size, entry_size) { } |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
310 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
311 |
RehashableHashtable(int table_size, int entry_size, |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
312 |
HashtableBucket<F>* buckets, int number_of_entries) |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
313 |
: Hashtable<T, F>(table_size, entry_size, buckets, number_of_entries) { } |
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
314 |
|
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
315 |
|
13087 | 316 |
// Function to move these elements into the new table. |
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
23187
diff
changeset
|
317 |
void move_to(RehashableHashtable<T, F>* new_table); |
13199
025b0984feea
7181200: JVM new hashing code breaks SA in product mode
coleenp
parents:
13195
diff
changeset
|
318 |
static bool use_alternate_hashcode() { return _seed != 0; } |
22757
b2cbb3680b4f
8033792: AltHashing used jint for imprecise bit shifting
minqi
parents:
22234
diff
changeset
|
319 |
static juint seed() { return _seed; } |
13199
025b0984feea
7181200: JVM new hashing code breaks SA in product mode
coleenp
parents:
13195
diff
changeset
|
320 |
|
17610
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
321 |
static int literal_size(Symbol *symbol); |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
322 |
static int literal_size(oop oop); |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
323 |
|
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
324 |
// The following two are currently not used, but are needed anyway because some |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
325 |
// C++ compilers (MacOS and Solaris) force the instantiation of |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
326 |
// Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
327 |
// in the VM code. |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
328 |
static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;} |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
329 |
static int literal_size(Klass *k) {Unimplemented(); return 0;} |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
330 |
|
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
331 |
void dump_table(outputStream* st, const char *table_name); |
c6857feaac47
8014262: PrintStringTableStatistics should include more footprint info
iklam
parents:
13728
diff
changeset
|
332 |
|
13199
025b0984feea
7181200: JVM new hashing code breaks SA in product mode
coleenp
parents:
13195
diff
changeset
|
333 |
private: |
22757
b2cbb3680b4f
8033792: AltHashing used jint for imprecise bit shifting
minqi
parents:
22234
diff
changeset
|
334 |
static juint _seed; |
1 | 335 |
}; |
336 |
||
337 |
||
22921
ee35d5c0b1dc
8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents:
22757
diff
changeset
|
338 |
// Versions of hashtable where two handles are used to compute the index. |
1 | 339 |
|
13195 | 340 |
template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> { |
1 | 341 |
friend class VMStructs; |
342 |
protected: |
|
343 |
TwoOopHashtable(int table_size, int entry_size) |
|
13195 | 344 |
: Hashtable<T, F>(table_size, entry_size) {} |
1 | 345 |
|
13195 | 346 |
TwoOopHashtable(int table_size, int entry_size, HashtableBucket<F>* t, |
1 | 347 |
int number_of_entries) |
13195 | 348 |
: Hashtable<T, F>(table_size, entry_size, t, number_of_entries) {} |
1 | 349 |
|
350 |
public: |
|
34666 | 351 |
unsigned int compute_hash(const Symbol* name, const ClassLoaderData* loader_data) const { |
1 | 352 |
unsigned int name_hash = name->identity_hash(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
353 |
// loader is null with CDS |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
354 |
assert(loader_data != NULL || UseSharedSpaces || DumpSharedSpaces, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
355 |
"only allowed with shared spaces"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
356 |
unsigned int loader_hash = loader_data == NULL ? 0 : loader_data->identity_hash(); |
1 | 357 |
return name_hash ^ loader_hash; |
358 |
} |
|
359 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
360 |
int index_for(Symbol* name, ClassLoaderData* loader_data) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13342
diff
changeset
|
361 |
return this->hash_to_index(compute_hash(name, loader_data)); |
1 | 362 |
} |
363 |
}; |
|
7397 | 364 |
|
365 |
#endif // SHARE_VM_UTILITIES_HASHTABLE_HPP |