1 /*
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
66
67 template <typename T>
68 class JfrBasicHashtable : public CHeapObj<mtTracing> {
69 private:
70 typedef JfrHashtableBucket<T> Bucket;
71 typedef JfrBasicHashtableEntry<T> TableEntry;
72 Bucket* _buckets;
73 uintptr_t _table_size;
74 const size_t _entry_size;
75 size_t _number_of_entries;
76
77 protected:
78 JfrBasicHashtable(uintptr_t table_size, size_t entry_size) :
79 _buckets(NULL), _table_size(table_size), _entry_size(entry_size), _number_of_entries(0) {
80 _buckets = NEW_C_HEAP_ARRAY2(Bucket, table_size, mtTracing, CURRENT_PC);
81 memset((void*)_buckets, 0, table_size * sizeof(Bucket));
82 }
83
84 size_t hash_to_index(uintptr_t full_hash) const {
85 const uintptr_t h = full_hash % _table_size;
86 assert(h >= 0 && h < _table_size, "Illegal hash value");
87 return (size_t)h;
88 }
89 size_t entry_size() const { return _entry_size; }
90 void unlink_entry(TableEntry* entry) {
91 entry->set_next(NULL);
92 --_number_of_entries;
93 }
94 void free_buckets() {
95 FREE_C_HEAP_ARRAY(Bucket, _buckets);
96 }
97 TableEntry* bucket(size_t i) { return _buckets[i].get_entry();}
98 TableEntry** bucket_addr(size_t i) { return _buckets[i].entry_addr(); }
99 uintptr_t table_size() const { return _table_size; }
100 size_t number_of_entries() const { return _number_of_entries; }
101 void add_entry(size_t index, TableEntry* entry) {
102 assert(entry != NULL, "invariant");
103 entry->set_next(bucket(index));
104 _buckets[index].set_entry(entry);
105 ++_number_of_entries;
106 }
|
1 /*
2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
66
67 template <typename T>
68 class JfrBasicHashtable : public CHeapObj<mtTracing> {
69 private:
70 typedef JfrHashtableBucket<T> Bucket;
71 typedef JfrBasicHashtableEntry<T> TableEntry;
72 Bucket* _buckets;
73 uintptr_t _table_size;
74 const size_t _entry_size;
75 size_t _number_of_entries;
76
77 protected:
78 JfrBasicHashtable(uintptr_t table_size, size_t entry_size) :
79 _buckets(NULL), _table_size(table_size), _entry_size(entry_size), _number_of_entries(0) {
80 _buckets = NEW_C_HEAP_ARRAY2(Bucket, table_size, mtTracing, CURRENT_PC);
81 memset((void*)_buckets, 0, table_size * sizeof(Bucket));
82 }
83
84 size_t hash_to_index(uintptr_t full_hash) const {
85 const uintptr_t h = full_hash % _table_size;
86 assert(h < _table_size, "Illegal hash value");
87 return (size_t)h;
88 }
89 size_t entry_size() const { return _entry_size; }
90 void unlink_entry(TableEntry* entry) {
91 entry->set_next(NULL);
92 --_number_of_entries;
93 }
94 void free_buckets() {
95 FREE_C_HEAP_ARRAY(Bucket, _buckets);
96 }
97 TableEntry* bucket(size_t i) { return _buckets[i].get_entry();}
98 TableEntry** bucket_addr(size_t i) { return _buckets[i].entry_addr(); }
99 uintptr_t table_size() const { return _table_size; }
100 size_t number_of_entries() const { return _number_of_entries; }
101 void add_entry(size_t index, TableEntry* entry) {
102 assert(entry != NULL, "invariant");
103 entry->set_next(bucket(index));
104 _buckets[index].set_entry(entry);
105 ++_number_of_entries;
106 }
|