Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/hashtable.inline.hpp
32285 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP25#define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP2627#include "memory/allocation.inline.hpp"28#include "runtime/orderAccess.inline.hpp"29#include "utilities/hashtable.hpp"30#include "utilities/dtrace.hpp"3132// Inline function definitions for hashtable.hpp.3334// --------------------------------------------------------------------------3536// Initialize a table.3738template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {39// Called on startup, no locking needed40initialize(table_size, entry_size, 0);41_buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);42for (int index = 0; index < _table_size; index++) {43_buckets[index].clear();44}45}464748template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,49HashtableBucket<F>* buckets,50int number_of_entries) {51// Called on startup, no locking needed52initialize(table_size, entry_size, number_of_entries);53_buckets = buckets;54}555657template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,58int number_of_entries) {59// Called on startup, no locking needed60_table_size = table_size;61_entry_size = entry_size;62_free_list = NULL;63_first_free_entry = NULL;64_end_block = NULL;65_number_of_entries = number_of_entries;66#ifdef ASSERT67_lookup_count = 0;68_lookup_length = 0;69#endif70}717273// The following method is MT-safe and may be used with caution.74template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) {75return _buckets[i].get_entry();76}777879template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {80// Warning: Preserve store ordering. The SystemDictionary is read81// without locks. The new SystemDictionaryEntry must be82// complete before other threads can be allowed to see it83// via a store to _buckets[index].84OrderAccess::release_store_ptr(&_entry, l);85}868788template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {89// Warning: Preserve load ordering. The SystemDictionary is read90// without locks. The new SystemDictionaryEntry must be91// complete before other threads can be allowed to see it92// via a store to _buckets[index].93return (BasicHashtableEntry<F>*) OrderAccess::load_ptr_acquire(&_entry);94}959697template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {98_buckets[index].set_entry(entry);99}100101102template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {103entry->set_next(bucket(index));104_buckets[index].set_entry(entry);105++_number_of_entries;106}107108template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {109entry->set_next(_free_list);110_free_list = entry;111--_number_of_entries;112}113114#endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP115116117