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