author | coleenp |
Thu, 27 Jan 2011 16:11:27 -0800 | |
changeset 8076 | 96d498ec7ae1 |
parent 7397 | 5b173b4ca846 |
child 8921 | 14bfe81f2a9d |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 2003, 2010, 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_INLINE_HPP |
26 |
#define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |
|
27 |
||
28 |
#include "memory/allocation.inline.hpp" |
|
29 |
#include "utilities/hashtable.hpp" |
|
30 |
||
1 | 31 |
// Inline function definitions for hashtable.hpp. |
32 |
||
33 |
||
34 |
// -------------------------------------------------------------------------- |
|
35 |
// Hash function |
|
36 |
||
37 |
// We originally used hashpjw, but hash P(31) gives just as good results |
|
38 |
// and is slighly faster. We would like a hash function that looks at every |
|
39 |
// character, since package names have large common prefixes, and also because |
|
40 |
// hash_or_fail does error checking while iterating. |
|
41 |
||
42 |
// hash P(31) from Kernighan & Ritchie |
|
43 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
44 |
inline unsigned int BasicHashtable::hash_symbol(const char* s, int len) { |
1 | 45 |
unsigned int h = 0; |
46 |
while (len-- > 0) { |
|
47 |
h = 31*h + (unsigned) *s; |
|
48 |
s++; |
|
49 |
} |
|
50 |
return h; |
|
51 |
} |
|
52 |
||
53 |
||
54 |
// -------------------------------------------------------------------------- |
|
55 |
||
56 |
// Initialize a table. |
|
57 |
||
58 |
inline BasicHashtable::BasicHashtable(int table_size, int entry_size) { |
|
59 |
// Called on startup, no locking needed |
|
60 |
initialize(table_size, entry_size, 0); |
|
61 |
_buckets = NEW_C_HEAP_ARRAY(HashtableBucket, table_size); |
|
62 |
for (int index = 0; index < _table_size; index++) { |
|
63 |
_buckets[index].clear(); |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
||
68 |
inline BasicHashtable::BasicHashtable(int table_size, int entry_size, |
|
69 |
HashtableBucket* buckets, |
|
70 |
int number_of_entries) { |
|
71 |
// Called on startup, no locking needed |
|
72 |
initialize(table_size, entry_size, number_of_entries); |
|
73 |
_buckets = buckets; |
|
74 |
} |
|
75 |
||
76 |
||
77 |
inline void BasicHashtable::initialize(int table_size, int entry_size, |
|
78 |
int number_of_entries) { |
|
79 |
// Called on startup, no locking needed |
|
80 |
_table_size = table_size; |
|
81 |
_entry_size = entry_size; |
|
82 |
_free_list = NULL; |
|
83 |
_first_free_entry = NULL; |
|
84 |
_end_block = NULL; |
|
85 |
_number_of_entries = number_of_entries; |
|
86 |
#ifdef ASSERT |
|
87 |
_lookup_count = 0; |
|
88 |
_lookup_length = 0; |
|
89 |
#endif |
|
90 |
} |
|
91 |
||
92 |
||
93 |
// The following method is MT-safe and may be used with caution. |
|
94 |
inline BasicHashtableEntry* BasicHashtable::bucket(int i) { |
|
95 |
return _buckets[i].get_entry(); |
|
96 |
} |
|
97 |
||
98 |
||
99 |
inline void HashtableBucket::set_entry(BasicHashtableEntry* l) { |
|
100 |
// Warning: Preserve store ordering. The SystemDictionary is read |
|
101 |
// without locks. The new SystemDictionaryEntry must be |
|
102 |
// complete before other threads can be allowed to see it |
|
103 |
// via a store to _buckets[index]. |
|
104 |
OrderAccess::release_store_ptr(&_entry, l); |
|
105 |
} |
|
106 |
||
107 |
||
108 |
inline BasicHashtableEntry* HashtableBucket::get_entry() const { |
|
109 |
// Warning: Preserve load ordering. The SystemDictionary is read |
|
110 |
// without locks. The new SystemDictionaryEntry must be |
|
111 |
// complete before other threads can be allowed to see it |
|
112 |
// via a store to _buckets[index]. |
|
113 |
return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry); |
|
114 |
} |
|
115 |
||
116 |
||
117 |
inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) { |
|
118 |
_buckets[index].set_entry(entry); |
|
119 |
} |
|
120 |
||
121 |
||
122 |
inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) { |
|
123 |
entry->set_next(bucket(index)); |
|
124 |
_buckets[index].set_entry(entry); |
|
125 |
++_number_of_entries; |
|
126 |
} |
|
127 |
||
128 |
inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) { |
|
129 |
entry->set_next(_free_list); |
|
130 |
_free_list = entry; |
|
131 |
--_number_of_entries; |
|
132 |
} |
|
7397 | 133 |
|
134 |
#endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |