src/share/vm/utilities/hashtable.inline.hpp

Wed, 13 Jun 2012 19:52:59 -0400

author
coleenp
date
Wed, 13 Jun 2012 19:52:59 -0400
changeset 3865
e9140bf80b4a
parent 2708
1d1603768966
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

7158800: Improve storage of symbol tables
Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance
Reviewed-by: pbk, kamg, dlong, kvn, fparain

duke@435 1 /*
coleenp@3865 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.inline.hpp"
stefank@2314 29 #include "utilities/hashtable.hpp"
stefank@2314 30
duke@435 31 // Inline function definitions for hashtable.hpp.
duke@435 32
duke@435 33 // --------------------------------------------------------------------------
duke@435 34
duke@435 35 // Initialize a table.
duke@435 36
duke@435 37 inline BasicHashtable::BasicHashtable(int table_size, int entry_size) {
duke@435 38 // Called on startup, no locking needed
duke@435 39 initialize(table_size, entry_size, 0);
duke@435 40 _buckets = NEW_C_HEAP_ARRAY(HashtableBucket, table_size);
duke@435 41 for (int index = 0; index < _table_size; index++) {
duke@435 42 _buckets[index].clear();
duke@435 43 }
duke@435 44 }
duke@435 45
duke@435 46
duke@435 47 inline BasicHashtable::BasicHashtable(int table_size, int entry_size,
duke@435 48 HashtableBucket* buckets,
duke@435 49 int number_of_entries) {
duke@435 50 // Called on startup, no locking needed
duke@435 51 initialize(table_size, entry_size, number_of_entries);
duke@435 52 _buckets = buckets;
duke@435 53 }
duke@435 54
duke@435 55
duke@435 56 inline void BasicHashtable::initialize(int table_size, int entry_size,
duke@435 57 int number_of_entries) {
duke@435 58 // Called on startup, no locking needed
duke@435 59 _table_size = table_size;
duke@435 60 _entry_size = entry_size;
duke@435 61 _free_list = NULL;
duke@435 62 _first_free_entry = NULL;
duke@435 63 _end_block = NULL;
duke@435 64 _number_of_entries = number_of_entries;
duke@435 65 #ifdef ASSERT
duke@435 66 _lookup_count = 0;
duke@435 67 _lookup_length = 0;
duke@435 68 #endif
duke@435 69 }
duke@435 70
duke@435 71
duke@435 72 // The following method is MT-safe and may be used with caution.
duke@435 73 inline BasicHashtableEntry* BasicHashtable::bucket(int i) {
duke@435 74 return _buckets[i].get_entry();
duke@435 75 }
duke@435 76
duke@435 77
duke@435 78 inline void HashtableBucket::set_entry(BasicHashtableEntry* l) {
duke@435 79 // Warning: Preserve store ordering. The SystemDictionary is read
duke@435 80 // without locks. The new SystemDictionaryEntry must be
duke@435 81 // complete before other threads can be allowed to see it
duke@435 82 // via a store to _buckets[index].
duke@435 83 OrderAccess::release_store_ptr(&_entry, l);
duke@435 84 }
duke@435 85
duke@435 86
duke@435 87 inline BasicHashtableEntry* HashtableBucket::get_entry() const {
duke@435 88 // Warning: Preserve load ordering. The SystemDictionary is read
duke@435 89 // without locks. The new SystemDictionaryEntry must be
duke@435 90 // complete before other threads can be allowed to see it
duke@435 91 // via a store to _buckets[index].
duke@435 92 return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry);
duke@435 93 }
duke@435 94
duke@435 95
duke@435 96 inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) {
duke@435 97 _buckets[index].set_entry(entry);
duke@435 98 }
duke@435 99
duke@435 100
duke@435 101 inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) {
duke@435 102 entry->set_next(bucket(index));
duke@435 103 _buckets[index].set_entry(entry);
duke@435 104 ++_number_of_entries;
duke@435 105 }
duke@435 106
duke@435 107 inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) {
duke@435 108 entry->set_next(_free_list);
duke@435 109 _free_list = entry;
duke@435 110 --_number_of_entries;
duke@435 111 }
stefank@2314 112
stefank@2314 113 #endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP

mercurial