duke@435: /* coleenp@3865: * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP stefank@2314: #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP stefank@2314: stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "utilities/hashtable.hpp" zgu@3900: #include "utilities/dtrace.hpp" stefank@2314: duke@435: // Inline function definitions for hashtable.hpp. duke@435: duke@435: // -------------------------------------------------------------------------- duke@435: duke@435: // Initialize a table. duke@435: zgu@3900: template inline BasicHashtable::BasicHashtable(int table_size, int entry_size) { duke@435: // Called on startup, no locking needed duke@435: initialize(table_size, entry_size, 0); zgu@3900: _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket, table_size, F, CURRENT_PC); duke@435: for (int index = 0; index < _table_size; index++) { duke@435: _buckets[index].clear(); duke@435: } duke@435: } duke@435: duke@435: zgu@3900: template inline BasicHashtable::BasicHashtable(int table_size, int entry_size, zgu@3900: HashtableBucket* buckets, duke@435: int number_of_entries) { duke@435: // Called on startup, no locking needed duke@435: initialize(table_size, entry_size, number_of_entries); duke@435: _buckets = buckets; duke@435: } duke@435: duke@435: zgu@3900: template inline void BasicHashtable::initialize(int table_size, int entry_size, duke@435: int number_of_entries) { duke@435: // Called on startup, no locking needed duke@435: _table_size = table_size; duke@435: _entry_size = entry_size; duke@435: _free_list = NULL; duke@435: _first_free_entry = NULL; duke@435: _end_block = NULL; duke@435: _number_of_entries = number_of_entries; duke@435: #ifdef ASSERT duke@435: _lookup_count = 0; duke@435: _lookup_length = 0; duke@435: #endif duke@435: } duke@435: duke@435: duke@435: // The following method is MT-safe and may be used with caution. zgu@3900: template inline BasicHashtableEntry* BasicHashtable::bucket(int i) { duke@435: return _buckets[i].get_entry(); duke@435: } duke@435: duke@435: zgu@3900: template inline void HashtableBucket::set_entry(BasicHashtableEntry* l) { duke@435: // Warning: Preserve store ordering. The SystemDictionary is read duke@435: // without locks. The new SystemDictionaryEntry must be duke@435: // complete before other threads can be allowed to see it duke@435: // via a store to _buckets[index]. duke@435: OrderAccess::release_store_ptr(&_entry, l); duke@435: } duke@435: duke@435: zgu@3900: template inline BasicHashtableEntry* HashtableBucket::get_entry() const { duke@435: // Warning: Preserve load ordering. The SystemDictionary is read duke@435: // without locks. The new SystemDictionaryEntry must be duke@435: // complete before other threads can be allowed to see it duke@435: // via a store to _buckets[index]. zgu@3900: return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry); duke@435: } duke@435: duke@435: zgu@3900: template inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) { duke@435: _buckets[index].set_entry(entry); duke@435: } duke@435: duke@435: zgu@3900: template inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) { duke@435: entry->set_next(bucket(index)); duke@435: _buckets[index].set_entry(entry); duke@435: ++_number_of_entries; duke@435: } duke@435: zgu@3900: template inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) { duke@435: entry->set_next(_free_list); duke@435: _free_list = entry; duke@435: --_number_of_entries; duke@435: } stefank@2314: stefank@2314: #endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP