annotate src/share/vm/utilities/hashtable.hpp @ 6162:e9140bf80b4a

7158800: Improve storage of symbol tables Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance Reviewed-by: pbk, kamg, dlong, kvn, fparain
author coleenp
date Wed, 13 Jun 2012 19:52:59 -0400
parents b2cd0ee8f778
children 246d977b51f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
4864
b2cd0ee8f778 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 2426
diff changeset
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_UTILITIES_HASHTABLE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "oops/oop.hpp"
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
30 #include "oops/symbol.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/handles.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // This is a generic hashtable, designed to be used for the symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // and string tables.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // It is implemented as an open hash table with a fixed number of buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 //
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // %note:
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // - TableEntrys are allocated in blocks to reduce the space overhead.
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class BasicHashtableEntry : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
46 unsigned int _hash; // 32-bit hash for item
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Link to next element in the linked list for this bucket. EXCEPT
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // bit 0 set indicates that this entry is shared and must not be
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // unlinked from the table. Bit 0 is set during the dumping of the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // archive. Since shared entries are immutable, _next fields in the
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // shared entries will not change. New entries will always be
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // unshared and since pointers are align, bit 0 will always remain 0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // with no extra effort.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 BasicHashtableEntry* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Windows IA64 compiler requires subclasses to be able to access these
a61af66fc99e Initial load
duke
parents:
diff changeset
58 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Entry objects should not be created, they should be taken from the
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // free list with BasicHashtable.new_entry().
a61af66fc99e Initial load
duke
parents:
diff changeset
61 BasicHashtableEntry() { ShouldNotReachHere(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Entry objects should not be destroyed. They should be placed on
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // the free list instead with BasicHashtable.free_entry().
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ~BasicHashtableEntry() { ShouldNotReachHere(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 unsigned int hash() const { return _hash; }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void set_hash(unsigned int hash) { _hash = hash; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 unsigned int* hash_addr() { return &_hash; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 static BasicHashtableEntry* make_ptr(BasicHashtableEntry* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return (BasicHashtableEntry*)((intptr_t)p & -2);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 BasicHashtableEntry* next() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return make_ptr(_next);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void set_next(BasicHashtableEntry* next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _next = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 BasicHashtableEntry** next_addr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return &_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 bool is_shared() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return ((intptr_t)_next & 1) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void set_shared() {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _next = (BasicHashtableEntry*)((intptr_t)_next | 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 };
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
99 template <class T> class HashtableEntry : public BasicHashtableEntry {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
100 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 private:
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
102 T _literal; // ref to item in table.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Literal
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
106 T literal() const { return _literal; }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
107 T* literal_addr() { return &_literal; }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
108 void set_literal(T s) { _literal = s; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 HashtableEntry* next() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return (HashtableEntry*)BasicHashtableEntry::next();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 HashtableEntry** next_addr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return (HashtableEntry**)BasicHashtableEntry::next_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 };
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 class HashtableBucket : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Instance variable
a61af66fc99e Initial load
duke
parents:
diff changeset
124 BasicHashtableEntry* _entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Accessing
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void clear() { _entry = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // The following methods use order access methods to avoid race
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // conditions in multiprocessor systems.
a61af66fc99e Initial load
duke
parents:
diff changeset
132 BasicHashtableEntry* get_entry() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 void set_entry(BasicHashtableEntry* l);
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // The following method is not MT-safe and must be done under lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 BasicHashtableEntry** entry_addr() { return &_entry; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 };
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 class BasicHashtable : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
144 BasicHashtable(int table_size, int entry_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 BasicHashtable(int table_size, int entry_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
146 HashtableBucket* buckets, int number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Sharing support.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void copy_buckets(char** top, char* end);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void copy_table(char** top, char* end);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Bucket handling
a61af66fc99e Initial load
duke
parents:
diff changeset
153 int hash_to_index(unsigned int full_hash) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int h = full_hash % _table_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 assert(h >= 0 && h < _table_size, "Illegal hash value");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return h;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Reverse the order of elements in each of the buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 void reverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Instance variables
a61af66fc99e Initial load
duke
parents:
diff changeset
164 int _table_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 HashtableBucket* _buckets;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 BasicHashtableEntry* _free_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 char* _first_free_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 char* _end_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int _entry_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int _number_of_entries;
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
175 int _lookup_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int _lookup_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 void verify_lookup_length(double load);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
179
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
180 enum {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
181 rehash_count = 100,
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
182 rehash_multiple = 60
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
183 };
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
184
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 void initialize(int table_size, int entry_size, int number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Accessor
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int entry_size() const { return _entry_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // The following method is MT-safe and may be used with caution.
a61af66fc99e Initial load
duke
parents:
diff changeset
191 BasicHashtableEntry* bucket(int i);
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // The following method is not MT-safe and must be done under lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 BasicHashtableEntry** bucket_addr(int i) { return _buckets[i].entry_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // Table entry management
a61af66fc99e Initial load
duke
parents:
diff changeset
197 BasicHashtableEntry* new_entry(unsigned int hashValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
199 // Check that the table is unbalanced
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
200 bool check_rehash_table(int count);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
201
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
202 // Used when moving the entry to another table
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
203 // Clean up links, but do not add to free_list
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
204 void unlink_entry(BasicHashtableEntry* entry) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
205 entry->set_next(NULL);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
206 --_number_of_entries;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
207 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
208
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
209 // Move over freelist and free block for allocation
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
210 void copy_freelist(BasicHashtable* src) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
211 _free_list = src->_free_list;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
212 src->_free_list = NULL;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
213 _first_free_entry = src->_first_free_entry;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
214 src->_first_free_entry = NULL;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
215 _end_block = src->_end_block;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
216 src->_end_block = NULL;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
217 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
218
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
219 // Free the buckets in this hashtable
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
220 void free_buckets() {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
221 if (NULL != _buckets) {
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
222 FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
223 _buckets = NULL;
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
224 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
225 }
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
226
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227 public:
4864
b2cd0ee8f778 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 2426
diff changeset
228 int table_size() { return _table_size; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void set_entry(int index, BasicHashtableEntry* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 void add_entry(int index, BasicHashtableEntry* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 void free_entry(BasicHashtableEntry* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 int number_of_entries() { return _number_of_entries; }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 void verify() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 };
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
241 template <class T> class Hashtable : public BasicHashtable {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
242 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
245 Hashtable(int table_size, int entry_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
246 : BasicHashtable(table_size, entry_size) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 Hashtable(int table_size, int entry_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
249 HashtableBucket* buckets, int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
250 : BasicHashtable(table_size, entry_size, buckets, number_of_entries) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void print() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // Reverse the order of elements in each of the buckets. Hashtable
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // entries which refer to objects at a lower address than 'boundary'
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // are separated from those which refer to objects at higher
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // addresses, and appear first in the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 void reverse(void* boundary = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
262
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
263 unsigned int compute_hash(Symbol* name) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return (unsigned int) name->identity_hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
267 int index_for(Symbol* name) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return hash_to_index(compute_hash(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Table entry management
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
272 HashtableEntry<T>* new_entry(unsigned int hashValue, T obj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // The following method is MT-safe and may be used with caution.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
275 HashtableEntry<T>* bucket(int i) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
276 return (HashtableEntry<T>*)BasicHashtable::bucket(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // The following method is not MT-safe and must be done under lock.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
280 HashtableEntry<T>** bucket_addr(int i) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
281 return (HashtableEntry<T>**)BasicHashtable::bucket_addr(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
283
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
284 // Function to move these elements into the new table.
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
285 void move_to(Hashtable<T>* new_table);
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
parents: 4864
diff changeset
286 virtual unsigned int new_hash(T) { ShouldNotReachHere(); return 0; } // should be overridden
0
a61af66fc99e Initial load
duke
parents:
diff changeset
287 };
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Verions of hashtable where two handles are used to compute the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
291
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
292 template <class T> class TwoOopHashtable : public Hashtable<T> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
293 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
295 TwoOopHashtable(int table_size, int entry_size)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
296 : Hashtable<T>(table_size, entry_size) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 TwoOopHashtable(int table_size, int entry_size, HashtableBucket* t,
a61af66fc99e Initial load
duke
parents:
diff changeset
299 int number_of_entries)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
300 : Hashtable<T>(table_size, entry_size, t, number_of_entries) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 public:
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
303 unsigned int compute_hash(Symbol* name, Handle loader) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Be careful with identity_hash(), it can safepoint and if this
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // were one expression, the compiler could choose to unhandle each
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // oop before calling identity_hash() for either of them. If the first
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // causes a GC, the next would fail.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 unsigned int name_hash = name->identity_hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return name_hash ^ loader_hash;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
313 int index_for(Symbol* name, Handle loader) {
2240
3adec115d40d 7019689: Non-dependent name is found in dependent base class although it should be rejected
coleenp
parents: 2177
diff changeset
314 return this->hash_to_index(compute_hash(name, loader));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
317
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
318 #endif // SHARE_VM_UTILITIES_HASHTABLE_HPP