annotate src/share/vm/utilities/hashtable.inline.hpp @ 20197:ce8f6bb717c9

8042195: Introduce umbrella header orderAccess.inline.hpp. Reviewed-by: dholmes, kvn, stefank, twisti
author goetz
date Tue, 29 Apr 2014 15:17:27 +0200
parents d2a62e0f25eb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6162
e9140bf80b4a 7158800: Improve storage of symbol tables
coleenp
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_INLINE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_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.inline.hpp"
20197
ce8f6bb717c9 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 6197
diff changeset
29 #include "runtime/orderAccess.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "utilities/hashtable.hpp"
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
31 #include "utilities/dtrace.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Inline function definitions for hashtable.hpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // --------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Initialize a table.
a61af66fc99e Initial load
duke
parents:
diff changeset
38
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
39 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Called on startup, no locking needed
a61af66fc99e Initial load
duke
parents:
diff changeset
41 initialize(table_size, entry_size, 0);
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
42 _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 for (int index = 0; index < _table_size; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _buckets[index].clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
49 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
50 HashtableBucket<F>* buckets,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Called on startup, no locking needed
a61af66fc99e Initial load
duke
parents:
diff changeset
53 initialize(table_size, entry_size, number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _buckets = buckets;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
58 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59 int number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Called on startup, no locking needed
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _table_size = table_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _entry_size = entry_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _free_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _first_free_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _end_block = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _number_of_entries = number_of_entries;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _lookup_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _lookup_length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // The following method is MT-safe and may be used with caution.
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
75 template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return _buckets[i].get_entry();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
80 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Warning: Preserve store ordering. The SystemDictionary is read
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // without locks. The new SystemDictionaryEntry must be
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // complete before other threads can be allowed to see it
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // via a store to _buckets[index].
a61af66fc99e Initial load
duke
parents:
diff changeset
85 OrderAccess::release_store_ptr(&_entry, l);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
89 template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Warning: Preserve load ordering. The SystemDictionary is read
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // without locks. The new SystemDictionaryEntry must be
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // complete before other threads can be allowed to see it
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // via a store to _buckets[index].
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
94 return (BasicHashtableEntry<F>*) OrderAccess::load_ptr_acquire(&_entry);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
98 template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _buckets[index].set_entry(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
103 template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104 entry->set_next(bucket(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _buckets[index].set_entry(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 ++_number_of_entries;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6162
diff changeset
109 template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 entry->set_next(_free_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _free_list = entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 --_number_of_entries;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
114
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
115 #endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP