author | coleenp |
Fri, 04 Jan 2019 15:06:01 -0500 | |
changeset 53149 | 259c36ef27df |
parent 52631 | 3009ca99de32 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
47634
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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" |
|
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 |
} |
|
46 |
} |
|
47 |
||
48 |
||
13195 | 49 |
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size, |
50 |
HashtableBucket<F>* buckets, |
|
1 | 51 |
int number_of_entries) { |
52 |
// Called on startup, no locking needed |
|
53 |
initialize(table_size, entry_size, number_of_entries); |
|
54 |
_buckets = buckets; |
|
55 |
} |
|
56 |
||
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
57 |
template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
61 |
delete _entry_blocks; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
62 |
free_buckets(); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
63 |
} |
1 | 64 |
|
13195 | 65 |
template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size, |
1 | 66 |
int number_of_entries) { |
67 |
// Called on startup, no locking needed |
|
68 |
_table_size = table_size; |
|
69 |
_entry_size = entry_size; |
|
70 |
_free_list = NULL; |
|
71 |
_first_free_entry = NULL; |
|
72 |
_end_block = NULL; |
|
73 |
_number_of_entries = number_of_entries; |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
50429
diff
changeset
|
74 |
_entry_blocks = new(ResourceObj::C_HEAP, F) GrowableArray<char*>(4, true, F); |
1 | 75 |
} |
76 |
||
77 |
||
78 |
// The following method is MT-safe and may be used with caution. |
|
34666 | 79 |
template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) const { |
1 | 80 |
return _buckets[i].get_entry(); |
81 |
} |
|
82 |
||
83 |
||
13195 | 84 |
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
|
85 |
// 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
|
86 |
// SystemDictionary are read without locks. The new entry must be |
1 | 87 |
// complete before other threads can be allowed to see it |
88 |
// via a store to _buckets[index]. |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
89 |
OrderAccess::release_store(&_entry, l); |
1 | 90 |
} |
91 |
||
92 |
||
13195 | 93 |
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
|
94 |
// 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
|
95 |
// SystemDictionary are read without locks. The new entry must be |
1 | 96 |
// complete before other threads can be allowed to see it |
97 |
// via a store to _buckets[index]. |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
98 |
return OrderAccess::load_acquire(&_entry); |
1 | 99 |
} |
100 |
||
101 |
||
13195 | 102 |
template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) { |
1 | 103 |
_buckets[index].set_entry(entry); |
104 |
} |
|
105 |
||
106 |
||
13195 | 107 |
template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) { |
1 | 108 |
entry->set_next(bucket(index)); |
109 |
_buckets[index].set_entry(entry); |
|
110 |
++_number_of_entries; |
|
111 |
} |
|
112 |
||
13195 | 113 |
template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) { |
1 | 114 |
entry->set_next(_free_list); |
115 |
_free_list = entry; |
|
116 |
--_number_of_entries; |
|
117 |
} |
|
7397 | 118 |
|
119 |
#endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |