author | stefank |
Mon, 25 Nov 2019 12:22:13 +0100 | |
changeset 59247 | 56bf71d64d51 |
parent 54764 | 865ec913f916 |
child 59290 | 97d13893ec3c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52631
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52631
diff
changeset
|
25 |
#ifndef SHARE_UTILITIES_HASHTABLE_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52631
diff
changeset
|
26 |
#define SHARE_UTILITIES_HASHTABLE_INLINE_HPP |
7397 | 27 |
|
28 |
#include "memory/allocation.inline.hpp" |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
47634
diff
changeset
|
29 |
#include "runtime/orderAccess.hpp" |
7397 | 30 |
#include "utilities/hashtable.hpp" |
13195 | 31 |
#include "utilities/dtrace.hpp" |
7397 | 32 |
|
1 | 33 |
// Inline function definitions for hashtable.hpp. |
34 |
||
35 |
// -------------------------------------------------------------------------- |
|
36 |
||
37 |
// Initialize a table. |
|
38 |
||
13195 | 39 |
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) { |
1 | 40 |
// Called on startup, no locking needed |
41 |
initialize(table_size, entry_size, 0); |
|
13195 | 42 |
_buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC); |
1 | 43 |
for (int index = 0; index < _table_size; index++) { |
44 |
_buckets[index].clear(); |
|
45 |
} |
|
54764 | 46 |
_stats_rate = TableRateStatistics(); |
1 | 47 |
} |
48 |
||
49 |
||
13195 | 50 |
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size, |
51 |
HashtableBucket<F>* buckets, |
|
1 | 52 |
int number_of_entries) { |
53 |
// Called on startup, no locking needed |
|
54 |
initialize(table_size, entry_size, number_of_entries); |
|
55 |
_buckets = buckets; |
|
54764 | 56 |
_stats_rate = TableRateStatistics(); |
1 | 57 |
} |
58 |
||
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
59 |
template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
60 |
for (int i = 0; i < _entry_blocks->length(); i++) { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
61 |
FREE_C_HEAP_ARRAY(char, _entry_blocks->at(i)); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
62 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
63 |
delete _entry_blocks; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
64 |
free_buckets(); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
65 |
} |
1 | 66 |
|
13195 | 67 |
template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size, |
1 | 68 |
int number_of_entries) { |
69 |
// Called on startup, no locking needed |
|
70 |
_table_size = table_size; |
|
71 |
_entry_size = entry_size; |
|
72 |
_free_list = NULL; |
|
73 |
_first_free_entry = NULL; |
|
74 |
_end_block = NULL; |
|
75 |
_number_of_entries = number_of_entries; |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
76 |
_entry_blocks = new(ResourceObj::C_HEAP, F) GrowableArray<char*>(4, true, F); |
1 | 77 |
} |
78 |
||
79 |
||
80 |
// The following method is MT-safe and may be used with caution. |
|
34666 | 81 |
template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) const { |
1 | 82 |
return _buckets[i].get_entry(); |
83 |
} |
|
84 |
||
85 |
||
13195 | 86 |
template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) { |
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39982
diff
changeset
|
87 |
// Warning: Preserve store ordering. The PackageEntryTable, ModuleEntryTable and |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39982
diff
changeset
|
88 |
// SystemDictionary are read without locks. The new entry must be |
1 | 89 |
// complete before other threads can be allowed to see it |
90 |
// via a store to _buckets[index]. |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54764
diff
changeset
|
91 |
Atomic::release_store(&_entry, l); |
1 | 92 |
} |
93 |
||
94 |
||
13195 | 95 |
template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const { |
41183
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39982
diff
changeset
|
96 |
// Warning: Preserve load ordering. The PackageEntryTable, ModuleEntryTable and |
207b92e69457
8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents:
39982
diff
changeset
|
97 |
// SystemDictionary are read without locks. The new entry must be |
1 | 98 |
// complete before other threads can be allowed to see it |
99 |
// via a store to _buckets[index]. |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54764
diff
changeset
|
100 |
return Atomic::load_acquire(&_entry); |
1 | 101 |
} |
102 |
||
103 |
||
13195 | 104 |
template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) { |
1 | 105 |
_buckets[index].set_entry(entry); |
54764 | 106 |
if (entry != NULL) { |
107 |
JFR_ONLY(_stats_rate.add();) |
|
108 |
} else { |
|
109 |
JFR_ONLY(_stats_rate.remove();) |
|
110 |
} |
|
1 | 111 |
} |
112 |
||
113 |
||
13195 | 114 |
template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) { |
1 | 115 |
entry->set_next(bucket(index)); |
116 |
_buckets[index].set_entry(entry); |
|
117 |
++_number_of_entries; |
|
54764 | 118 |
JFR_ONLY(_stats_rate.add();) |
1 | 119 |
} |
120 |
||
13195 | 121 |
template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) { |
1 | 122 |
entry->set_next(_free_list); |
123 |
_free_list = entry; |
|
124 |
--_number_of_entries; |
|
54764 | 125 |
JFR_ONLY(_stats_rate.remove();) |
1 | 126 |
} |
7397 | 127 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52631
diff
changeset
|
128 |
#endif // SHARE_UTILITIES_HASHTABLE_INLINE_HPP |