8267935: Replace BasicHashtable and Hashtable
Reviewed-by: coleenp, rehn, tschatzl
This commit is contained in:
parent
a74ebd048a
commit
f4592b1471
@ -28,7 +28,6 @@
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "oops/weakHandle.hpp"
|
||||
#include "utilities/hashtable.hpp"
|
||||
#include "utilities/resizeableResourceHash.hpp"
|
||||
|
||||
class JvmtiEnv;
|
||||
|
@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "classfile/dictionary.hpp"
|
||||
#include "classfile/javaClasses.inline.hpp"
|
||||
#include "classfile/vmClasses.hpp"
|
||||
#include "code/nmethod.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "memory/allocation.inline.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "oops/symbol.hpp"
|
||||
#include "oops/weakHandle.inline.hpp"
|
||||
#include "prims/jvmtiTagMapTable.hpp"
|
||||
#include "runtime/safepoint.hpp"
|
||||
#include "utilities/dtrace.hpp"
|
||||
#include "utilities/hashtable.hpp"
|
||||
#include "utilities/hashtable.inline.hpp"
|
||||
#include "utilities/numberSeq.hpp"
|
||||
|
||||
// This hashtable is implemented as an open hash table with a fixed number of buckets.
|
||||
|
||||
// Hashtable entry allocates in the C heap directly.
|
||||
|
||||
template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry(unsigned int hashValue) {
|
||||
BasicHashtableEntry<F>* entry = ::new (NEW_C_HEAP_ARRAY(char, this->entry_size(), F))
|
||||
BasicHashtableEntry<F>(hashValue);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
template <class T, MEMFLAGS F> HashtableEntry<T, F>* Hashtable<T, F>::new_entry(unsigned int hashValue, T obj) {
|
||||
HashtableEntry<T, F>* entry = ::new (NEW_C_HEAP_ARRAY(char, this->entry_size(), F))
|
||||
HashtableEntry<T, F>(hashValue, obj);
|
||||
return entry;
|
||||
}
|
||||
|
||||
template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {
|
||||
// Unlink from the Hashtable prior to freeing
|
||||
unlink_entry(entry);
|
||||
FREE_C_HEAP_ARRAY(char, entry);
|
||||
JFR_ONLY(_stats_rate.remove();)
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
|
||||
FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
|
||||
_buckets = nullptr;
|
||||
}
|
||||
|
||||
// Default overload, for types that are uninteresting.
|
||||
template<typename T> static size_t literal_size(T) { return 0; }
|
||||
|
||||
static size_t literal_size(oop obj) {
|
||||
if (obj == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t word_size = obj->size();
|
||||
|
||||
if (obj->klass() == vmClasses::String_klass()) {
|
||||
// This may overcount if String.value arrays are shared.
|
||||
word_size += java_lang_String::value(obj)->size();
|
||||
}
|
||||
|
||||
return word_size * HeapWordSize;
|
||||
}
|
||||
|
||||
static size_t literal_size(WeakHandle v) {
|
||||
return literal_size(v.peek());
|
||||
}
|
||||
|
||||
const double _resize_factor = 2.0; // by how much we will resize using current number of entries
|
||||
const int _small_table_sizes[] = { 107, 1009, 2017, 4049, 5051, 10103, 20201, 40423 } ;
|
||||
const int _small_array_size = sizeof(_small_table_sizes)/sizeof(int);
|
||||
|
||||
// possible hashmap sizes - odd primes that roughly double in size.
|
||||
// To avoid excessive resizing the odd primes from 4801-76831 and
|
||||
// 76831-307261 have been removed.
|
||||
const int _large_table_sizes[] = { 4801, 76831, 307261, 614563, 1228891,
|
||||
2457733, 4915219, 9830479, 19660831, 39321619, 78643219 };
|
||||
const int _large_array_size = sizeof(_large_table_sizes)/sizeof(int);
|
||||
|
||||
// Calculate next "good" hashtable size based on requested count
|
||||
template <MEMFLAGS F> int BasicHashtable<F>::calculate_resize(bool use_large_table_sizes) const {
|
||||
int requested = (int)(_resize_factor*number_of_entries());
|
||||
const int* primelist = use_large_table_sizes ? _large_table_sizes : _small_table_sizes;
|
||||
int arraysize = use_large_table_sizes ? _large_array_size : _small_array_size;
|
||||
int newsize;
|
||||
for (int i = 0; i < arraysize; i++) {
|
||||
newsize = primelist[i];
|
||||
if (newsize >= requested)
|
||||
break;
|
||||
}
|
||||
return newsize;
|
||||
}
|
||||
|
||||
template <MEMFLAGS F> bool BasicHashtable<F>::resize(int new_size) {
|
||||
|
||||
// Allocate new buckets
|
||||
HashtableBucket<F>* buckets_new = NEW_C_HEAP_ARRAY2_RETURN_NULL(HashtableBucket<F>, new_size, F, CURRENT_PC);
|
||||
if (buckets_new == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear the new buckets
|
||||
for (int i = 0; i < new_size; i++) {
|
||||
buckets_new[i].clear();
|
||||
}
|
||||
|
||||
int table_size_old = _table_size;
|
||||
// hash_to_index() uses _table_size, so switch the sizes now
|
||||
_table_size = new_size;
|
||||
|
||||
// Move entries from the old table to a new table
|
||||
for (int index_old = 0; index_old < table_size_old; index_old++) {
|
||||
for (BasicHashtableEntry<F>* p = _buckets[index_old].get_entry(); p != nullptr; ) {
|
||||
BasicHashtableEntry<F>* next = p->next();
|
||||
int index_new = hash_to_index(p->hash());
|
||||
|
||||
p->set_next(buckets_new[index_new].get_entry());
|
||||
buckets_new[index_new].set_entry(p);
|
||||
p = next;
|
||||
}
|
||||
}
|
||||
|
||||
// The old backets now can be released
|
||||
BasicHashtable<F>::free_buckets();
|
||||
|
||||
// Switch to the new storage
|
||||
_buckets = buckets_new;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <MEMFLAGS F> bool BasicHashtable<F>::maybe_grow(int max_size, int load_factor) {
|
||||
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
|
||||
|
||||
if (table_size() >= max_size) {
|
||||
return false;
|
||||
}
|
||||
if (number_of_entries() / table_size() > load_factor) {
|
||||
resize(MIN2<int>(table_size() * 2, max_size));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, MEMFLAGS F> TableStatistics Hashtable<T, F>::statistics_calculate(T (*literal_load_barrier)(HashtableEntry<T, F>*)) {
|
||||
NumberSeq summary;
|
||||
size_t literal_bytes = 0;
|
||||
for (int i = 0; i < this->table_size(); ++i) {
|
||||
int count = 0;
|
||||
for (HashtableEntry<T, F>* e = this->bucket(i);
|
||||
e != nullptr; e = e->next()) {
|
||||
count++;
|
||||
T l = (literal_load_barrier != nullptr) ? literal_load_barrier(e) : e->literal();
|
||||
literal_bytes += literal_size(l);
|
||||
}
|
||||
summary.add((double)count);
|
||||
}
|
||||
return TableStatistics(this->_stats_rate, summary, literal_bytes, sizeof(HashtableBucket<F>), sizeof(HashtableEntry<T, F>));
|
||||
}
|
||||
|
||||
// Dump footprint and bucket length statistics
|
||||
template <class T, MEMFLAGS F> void Hashtable<T, F>::print_table_statistics(outputStream* st,
|
||||
const char *table_name,
|
||||
T (*literal_load_barrier)(HashtableEntry<T, F>*)) {
|
||||
TableStatistics ts = statistics_calculate(literal_load_barrier);
|
||||
ts.print(st, table_name);
|
||||
}
|
||||
|
||||
#ifndef PRODUCT
|
||||
template <class T> static void print_literal(T const& l) { l.print(); }
|
||||
template <class T> static void print_literal(T* l) { print_literal(*l); }
|
||||
|
||||
template <class T, MEMFLAGS F> void Hashtable<T, F>::print() {
|
||||
ResourceMark rm;
|
||||
|
||||
for (int i = 0; i < BasicHashtable<F>::table_size(); i++) {
|
||||
HashtableEntry<T, F>* entry = bucket(i);
|
||||
while(entry != nullptr) {
|
||||
tty->print("%d : ", i);
|
||||
print_literal(entry->literal());
|
||||
tty->cr();
|
||||
entry = entry->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <MEMFLAGS F>
|
||||
template <class T> void BasicHashtable<F>::verify_table(const char* table_name) {
|
||||
int element_count = 0;
|
||||
int max_bucket_count = 0;
|
||||
int max_bucket_number = 0;
|
||||
for (int index = 0; index < table_size(); index++) {
|
||||
int bucket_count = 0;
|
||||
for (T* probe = (T*)bucket(index); probe != nullptr; probe = probe->next()) {
|
||||
probe->verify();
|
||||
bucket_count++;
|
||||
}
|
||||
element_count += bucket_count;
|
||||
if (bucket_count > max_bucket_count) {
|
||||
max_bucket_count = bucket_count;
|
||||
max_bucket_number = index;
|
||||
}
|
||||
}
|
||||
guarantee(number_of_entries() == element_count,
|
||||
"Verify of %s failed", table_name);
|
||||
|
||||
// Log some statistics about the hashtable
|
||||
log_info(hashtables)("%s max bucket size %d bucket %d element count %d table size %d", table_name,
|
||||
max_bucket_count, max_bucket_number, _number_of_entries, _table_size);
|
||||
if (_number_of_entries > 0 && log_is_enabled(Debug, hashtables)) {
|
||||
for (int index = 0; index < table_size(); index++) {
|
||||
int bucket_count = 0;
|
||||
for (T* probe = (T*)bucket(index); probe != nullptr; probe = probe->next()) {
|
||||
log_debug(hashtables)("bucket %d hash " INTPTR_FORMAT, index, (intptr_t)probe->hash());
|
||||
bucket_count++;
|
||||
}
|
||||
if (bucket_count > 0) {
|
||||
log_debug(hashtables)("bucket %d count %d", index, bucket_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PRODUCT
|
||||
|
||||
// Explicitly instantiate these types
|
||||
template class BasicHashtable<mtGC>;
|
||||
template class BasicHashtable<mtServiceability>;
|
||||
|
||||
template class Hashtable<nmethod*, mtGC>;
|
||||
template class Hashtable<WeakHandle, mtServiceability>;
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_UTILITIES_HASHTABLE_HPP
|
||||
#define SHARE_UTILITIES_HASHTABLE_HPP
|
||||
|
||||
#include "memory/allocation.hpp"
|
||||
#include "oops/symbol.hpp"
|
||||
#include "runtime/handles.hpp"
|
||||
#include "utilities/tableStatistics.hpp"
|
||||
|
||||
// This is a generic hashtable which is implemented as an open hash table with
|
||||
// a fixed number of buckets.
|
||||
|
||||
template <MEMFLAGS F> class BasicHashtableEntry {
|
||||
friend class VMStructs;
|
||||
private:
|
||||
unsigned int _hash; // 32-bit hash for item
|
||||
|
||||
// Link to next element in the linked list for this bucket.
|
||||
BasicHashtableEntry<F>* _next;
|
||||
|
||||
public:
|
||||
BasicHashtableEntry(unsigned int hashValue) : _hash(hashValue), _next(nullptr) {}
|
||||
// Still should not call this. Entries are placement new allocated, so are
|
||||
// deleted with free_entry.
|
||||
~BasicHashtableEntry() { ShouldNotReachHere(); }
|
||||
|
||||
unsigned int hash() const { return _hash; }
|
||||
void set_hash(unsigned int hash) { _hash = hash; }
|
||||
unsigned int* hash_addr() { return &_hash; }
|
||||
|
||||
BasicHashtableEntry<F>* next() const {
|
||||
return _next;
|
||||
}
|
||||
|
||||
void set_next(BasicHashtableEntry<F>* next) {
|
||||
_next = next;
|
||||
}
|
||||
|
||||
BasicHashtableEntry<F>** next_addr() {
|
||||
return &_next;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class T, MEMFLAGS F> class HashtableEntry : public BasicHashtableEntry<F> {
|
||||
friend class VMStructs;
|
||||
private:
|
||||
T _literal; // ref to item in table.
|
||||
|
||||
public:
|
||||
HashtableEntry(unsigned int hashValue, T value) : BasicHashtableEntry<F>(hashValue), _literal(value) {}
|
||||
|
||||
// Literal
|
||||
T literal() const { return _literal; }
|
||||
T* literal_addr() { return &_literal; }
|
||||
void set_literal(T s) { _literal = s; }
|
||||
|
||||
HashtableEntry* next() const {
|
||||
return (HashtableEntry*)BasicHashtableEntry<F>::next();
|
||||
}
|
||||
HashtableEntry** next_addr() {
|
||||
return (HashtableEntry**)BasicHashtableEntry<F>::next_addr();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <MEMFLAGS F> class HashtableBucket : public CHeapObj<F> {
|
||||
friend class VMStructs;
|
||||
private:
|
||||
// Instance variable
|
||||
BasicHashtableEntry<F>* _entry;
|
||||
|
||||
public:
|
||||
// Accessing
|
||||
void clear() { _entry = nullptr; }
|
||||
|
||||
// The following methods use order access methods to avoid race
|
||||
// conditions in multiprocessor systems.
|
||||
BasicHashtableEntry<F>* get_entry() const;
|
||||
void set_entry(BasicHashtableEntry<F>* l);
|
||||
|
||||
// The following method is not MT-safe and must be done under lock.
|
||||
BasicHashtableEntry<F>** entry_addr() { return &_entry; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <MEMFLAGS F> class BasicHashtable : public CHeapObj<F> {
|
||||
friend class VMStructs;
|
||||
|
||||
public:
|
||||
BasicHashtable(int table_size, int entry_size);
|
||||
BasicHashtable(int table_size, int entry_size,
|
||||
HashtableBucket<F>* buckets, int number_of_entries);
|
||||
~BasicHashtable();
|
||||
|
||||
// Bucket handling
|
||||
int hash_to_index(unsigned int full_hash) const {
|
||||
int h = full_hash % _table_size;
|
||||
assert(h >= 0 && h < _table_size, "Illegal hash value");
|
||||
return h;
|
||||
}
|
||||
|
||||
private:
|
||||
// Instance variables
|
||||
int _table_size;
|
||||
HashtableBucket<F>* _buckets;
|
||||
int _entry_size;
|
||||
volatile int _number_of_entries;
|
||||
|
||||
protected:
|
||||
|
||||
TableRateStatistics _stats_rate;
|
||||
|
||||
void initialize(int table_size, int entry_size, int number_of_entries);
|
||||
|
||||
// Accessor
|
||||
int entry_size() const { return _entry_size; }
|
||||
|
||||
// The following method is MT-safe and may be used with caution.
|
||||
BasicHashtableEntry<F>* bucket(int i) const;
|
||||
|
||||
// The following method is not MT-safe and must be done under lock.
|
||||
BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); }
|
||||
|
||||
// Table entry management
|
||||
BasicHashtableEntry<F>* new_entry(unsigned int hashValue);
|
||||
|
||||
// Used when moving the entry to another table or deleting entry.
|
||||
// Clean up links.
|
||||
void unlink_entry(BasicHashtableEntry<F>* entry) {
|
||||
entry->set_next(nullptr);
|
||||
--_number_of_entries;
|
||||
}
|
||||
|
||||
// Free the buckets in this hashtable
|
||||
void free_buckets();
|
||||
public:
|
||||
int table_size() const { return _table_size; }
|
||||
void set_entry(int index, BasicHashtableEntry<F>* entry);
|
||||
|
||||
void add_entry(int index, BasicHashtableEntry<F>* entry);
|
||||
|
||||
void free_entry(BasicHashtableEntry<F>* entry);
|
||||
|
||||
int number_of_entries() const { return _number_of_entries; }
|
||||
|
||||
int calculate_resize(bool use_large_table_sizes) const;
|
||||
bool resize(int new_size);
|
||||
|
||||
// Grow the number of buckets if the average entries per bucket is over the load_factor
|
||||
bool maybe_grow(int max_size, int load_factor = 8);
|
||||
|
||||
template <class T> void verify_table(const char* table_name) PRODUCT_RETURN;
|
||||
};
|
||||
|
||||
|
||||
template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
|
||||
friend class VMStructs;
|
||||
|
||||
public:
|
||||
Hashtable(int table_size, int entry_size)
|
||||
: BasicHashtable<F>(table_size, entry_size) { }
|
||||
|
||||
Hashtable(int table_size, int entry_size,
|
||||
HashtableBucket<F>* buckets, int number_of_entries)
|
||||
: BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
|
||||
|
||||
// Debugging
|
||||
void print() PRODUCT_RETURN;
|
||||
|
||||
unsigned int compute_hash(const Symbol* name) const {
|
||||
return (unsigned int) name->identity_hash();
|
||||
}
|
||||
|
||||
int index_for(const Symbol* name) const {
|
||||
return this->hash_to_index(compute_hash(name));
|
||||
}
|
||||
|
||||
TableStatistics statistics_calculate(T (*literal_load_barrier)(HashtableEntry<T, F>*) = nullptr);
|
||||
void print_table_statistics(outputStream* st, const char *table_name, T (*literal_load_barrier)(HashtableEntry<T, F>*) = nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);
|
||||
|
||||
// The following method is MT-safe and may be used with caution.
|
||||
HashtableEntry<T, F>* bucket(int i) const {
|
||||
return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
|
||||
}
|
||||
|
||||
// The following method is not MT-safe and must be done under lock.
|
||||
HashtableEntry<T, F>** bucket_addr(int i) {
|
||||
return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SHARE_UTILITIES_HASHTABLE_HPP
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_UTILITIES_HASHTABLE_INLINE_HPP
|
||||
#define SHARE_UTILITIES_HASHTABLE_INLINE_HPP
|
||||
|
||||
#include "utilities/hashtable.hpp"
|
||||
|
||||
#include "memory/allocation.inline.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "services/memTracker.hpp"
|
||||
|
||||
// Inline function definitions for hashtable.hpp.
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Initialize a table.
|
||||
|
||||
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {
|
||||
// Called on startup, no locking needed
|
||||
initialize(table_size, entry_size, 0);
|
||||
_buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
|
||||
for (int index = 0; index < _table_size; index++) {
|
||||
_buckets[index].clear();
|
||||
}
|
||||
_stats_rate = TableRateStatistics();
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
|
||||
HashtableBucket<F>* buckets,
|
||||
int number_of_entries) {
|
||||
|
||||
// Called on startup, no locking needed
|
||||
initialize(table_size, entry_size, number_of_entries);
|
||||
_buckets = buckets;
|
||||
_stats_rate = TableRateStatistics();
|
||||
}
|
||||
|
||||
template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() {
|
||||
free_buckets();
|
||||
}
|
||||
|
||||
template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
|
||||
int number_of_entries) {
|
||||
// Called on startup, no locking needed
|
||||
_table_size = table_size;
|
||||
_entry_size = entry_size;
|
||||
_number_of_entries = number_of_entries;
|
||||
}
|
||||
|
||||
|
||||
// The following method is MT-safe and may be used with caution.
|
||||
template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) const {
|
||||
return _buckets[i].get_entry();
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
|
||||
// Warning: Preserve store ordering. The PackageEntryTable, ModuleEntryTable and
|
||||
// SystemDictionary are read without locks. The new entry must be
|
||||
// complete before other threads can be allowed to see it
|
||||
// via a store to _buckets[index].
|
||||
Atomic::release_store(&_entry, l);
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {
|
||||
// Warning: Preserve load ordering. The PackageEntryTable, ModuleEntryTable and
|
||||
// SystemDictionary are read without locks. The new entry must be
|
||||
// complete before other threads can be allowed to see it
|
||||
// via a store to _buckets[index].
|
||||
return Atomic::load_acquire(&_entry);
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {
|
||||
_buckets[index].set_entry(entry);
|
||||
if (entry != nullptr) {
|
||||
JFR_ONLY(_stats_rate.add();)
|
||||
} else {
|
||||
JFR_ONLY(_stats_rate.remove();)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {
|
||||
entry->set_next(bucket(index));
|
||||
_buckets[index].set_entry(entry);
|
||||
++_number_of_entries;
|
||||
JFR_ONLY(_stats_rate.add();)
|
||||
}
|
||||
|
||||
#endif // SHARE_UTILITIES_HASHTABLE_INLINE_HPP
|
Loading…
x
Reference in New Issue
Block a user