25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |
25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |
26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |
26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP |
27 |
27 |
28 #include "memory/allocation.inline.hpp" |
28 #include "memory/allocation.inline.hpp" |
29 #include "utilities/hashtable.hpp" |
29 #include "utilities/hashtable.hpp" |
|
30 #include "utilities/dtrace.hpp" |
30 |
31 |
31 // Inline function definitions for hashtable.hpp. |
32 // Inline function definitions for hashtable.hpp. |
32 |
33 |
33 // -------------------------------------------------------------------------- |
34 // -------------------------------------------------------------------------- |
34 |
35 |
35 // Initialize a table. |
36 // Initialize a table. |
36 |
37 |
37 inline BasicHashtable::BasicHashtable(int table_size, int entry_size) { |
38 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) { |
38 // Called on startup, no locking needed |
39 // Called on startup, no locking needed |
39 initialize(table_size, entry_size, 0); |
40 initialize(table_size, entry_size, 0); |
40 _buckets = NEW_C_HEAP_ARRAY(HashtableBucket, table_size); |
41 _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC); |
41 for (int index = 0; index < _table_size; index++) { |
42 for (int index = 0; index < _table_size; index++) { |
42 _buckets[index].clear(); |
43 _buckets[index].clear(); |
43 } |
44 } |
44 } |
45 } |
45 |
46 |
46 |
47 |
47 inline BasicHashtable::BasicHashtable(int table_size, int entry_size, |
48 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size, |
48 HashtableBucket* buckets, |
49 HashtableBucket<F>* buckets, |
49 int number_of_entries) { |
50 int number_of_entries) { |
50 // Called on startup, no locking needed |
51 // Called on startup, no locking needed |
51 initialize(table_size, entry_size, number_of_entries); |
52 initialize(table_size, entry_size, number_of_entries); |
52 _buckets = buckets; |
53 _buckets = buckets; |
53 } |
54 } |
54 |
55 |
55 |
56 |
56 inline void BasicHashtable::initialize(int table_size, int entry_size, |
57 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size, |
57 int number_of_entries) { |
58 int number_of_entries) { |
58 // Called on startup, no locking needed |
59 // Called on startup, no locking needed |
59 _table_size = table_size; |
60 _table_size = table_size; |
60 _entry_size = entry_size; |
61 _entry_size = entry_size; |
61 _free_list = NULL; |
62 _free_list = NULL; |
68 #endif |
69 #endif |
69 } |
70 } |
70 |
71 |
71 |
72 |
72 // The following method is MT-safe and may be used with caution. |
73 // The following method is MT-safe and may be used with caution. |
73 inline BasicHashtableEntry* BasicHashtable::bucket(int i) { |
74 template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) { |
74 return _buckets[i].get_entry(); |
75 return _buckets[i].get_entry(); |
75 } |
76 } |
76 |
77 |
77 |
78 |
78 inline void HashtableBucket::set_entry(BasicHashtableEntry* l) { |
79 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) { |
79 // Warning: Preserve store ordering. The SystemDictionary is read |
80 // Warning: Preserve store ordering. The SystemDictionary is read |
80 // without locks. The new SystemDictionaryEntry must be |
81 // without locks. The new SystemDictionaryEntry must be |
81 // complete before other threads can be allowed to see it |
82 // complete before other threads can be allowed to see it |
82 // via a store to _buckets[index]. |
83 // via a store to _buckets[index]. |
83 OrderAccess::release_store_ptr(&_entry, l); |
84 OrderAccess::release_store_ptr(&_entry, l); |
84 } |
85 } |
85 |
86 |
86 |
87 |
87 inline BasicHashtableEntry* HashtableBucket::get_entry() const { |
88 template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const { |
88 // Warning: Preserve load ordering. The SystemDictionary is read |
89 // Warning: Preserve load ordering. The SystemDictionary is read |
89 // without locks. The new SystemDictionaryEntry must be |
90 // without locks. The new SystemDictionaryEntry must be |
90 // complete before other threads can be allowed to see it |
91 // complete before other threads can be allowed to see it |
91 // via a store to _buckets[index]. |
92 // via a store to _buckets[index]. |
92 return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry); |
93 return (BasicHashtableEntry<F>*) OrderAccess::load_ptr_acquire(&_entry); |
93 } |
94 } |
94 |
95 |
95 |
96 |
96 inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) { |
97 template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) { |
97 _buckets[index].set_entry(entry); |
98 _buckets[index].set_entry(entry); |
98 } |
99 } |
99 |
100 |
100 |
101 |
101 inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) { |
102 template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) { |
102 entry->set_next(bucket(index)); |
103 entry->set_next(bucket(index)); |
103 _buckets[index].set_entry(entry); |
104 _buckets[index].set_entry(entry); |
104 ++_number_of_entries; |
105 ++_number_of_entries; |
105 } |
106 } |
106 |
107 |
107 inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) { |
108 template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) { |
108 entry->set_next(_free_list); |
109 entry->set_next(_free_list); |
109 _free_list = entry; |
110 _free_list = entry; |
110 --_number_of_entries; |
111 --_number_of_entries; |
111 } |
112 } |
112 |
113 |