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

Mon, 03 Jan 2011 14:09:11 -0500

author
coleenp
date
Mon, 03 Jan 2011 14:09:11 -0500
changeset 2418
36c186bcc085
parent 2314
f95d63e2154a
child 2497
3582bf76420e
permissions
-rw-r--r--

6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
Summary: enhance the error reporting mechanism to help user to fix the problem rather than making it look like a VM error.
Reviewed-by: kvn, kamg

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, 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 // Hash function
duke@435 36
duke@435 37 // We originally used hashpjw, but hash P(31) gives just as good results
duke@435 38 // and is slighly faster. We would like a hash function that looks at every
duke@435 39 // character, since package names have large common prefixes, and also because
duke@435 40 // hash_or_fail does error checking while iterating.
duke@435 41
duke@435 42 // hash P(31) from Kernighan & Ritchie
duke@435 43
duke@435 44 inline unsigned int Hashtable::hash_symbol(const char* s, int len) {
duke@435 45 unsigned int h = 0;
duke@435 46 while (len-- > 0) {
duke@435 47 h = 31*h + (unsigned) *s;
duke@435 48 s++;
duke@435 49 }
duke@435 50 return h;
duke@435 51 }
duke@435 52
duke@435 53
duke@435 54 // --------------------------------------------------------------------------
duke@435 55
duke@435 56 // Initialize a table.
duke@435 57
duke@435 58 inline BasicHashtable::BasicHashtable(int table_size, int entry_size) {
duke@435 59 // Called on startup, no locking needed
duke@435 60 initialize(table_size, entry_size, 0);
duke@435 61 _buckets = NEW_C_HEAP_ARRAY(HashtableBucket, table_size);
duke@435 62 for (int index = 0; index < _table_size; index++) {
duke@435 63 _buckets[index].clear();
duke@435 64 }
duke@435 65 }
duke@435 66
duke@435 67
duke@435 68 inline BasicHashtable::BasicHashtable(int table_size, int entry_size,
duke@435 69 HashtableBucket* buckets,
duke@435 70 int number_of_entries) {
duke@435 71 // Called on startup, no locking needed
duke@435 72 initialize(table_size, entry_size, number_of_entries);
duke@435 73 _buckets = buckets;
duke@435 74 }
duke@435 75
duke@435 76
duke@435 77 inline void BasicHashtable::initialize(int table_size, int entry_size,
duke@435 78 int number_of_entries) {
duke@435 79 // Called on startup, no locking needed
duke@435 80 _table_size = table_size;
duke@435 81 _entry_size = entry_size;
duke@435 82 _free_list = NULL;
duke@435 83 _first_free_entry = NULL;
duke@435 84 _end_block = NULL;
duke@435 85 _number_of_entries = number_of_entries;
duke@435 86 #ifdef ASSERT
duke@435 87 _lookup_count = 0;
duke@435 88 _lookup_length = 0;
duke@435 89 #endif
duke@435 90 }
duke@435 91
duke@435 92
duke@435 93 // The following method is MT-safe and may be used with caution.
duke@435 94 inline BasicHashtableEntry* BasicHashtable::bucket(int i) {
duke@435 95 return _buckets[i].get_entry();
duke@435 96 }
duke@435 97
duke@435 98
duke@435 99 inline void HashtableBucket::set_entry(BasicHashtableEntry* l) {
duke@435 100 // Warning: Preserve store ordering. The SystemDictionary is read
duke@435 101 // without locks. The new SystemDictionaryEntry must be
duke@435 102 // complete before other threads can be allowed to see it
duke@435 103 // via a store to _buckets[index].
duke@435 104 OrderAccess::release_store_ptr(&_entry, l);
duke@435 105 }
duke@435 106
duke@435 107
duke@435 108 inline BasicHashtableEntry* HashtableBucket::get_entry() const {
duke@435 109 // Warning: Preserve load ordering. The SystemDictionary is read
duke@435 110 // without locks. The new SystemDictionaryEntry must be
duke@435 111 // complete before other threads can be allowed to see it
duke@435 112 // via a store to _buckets[index].
duke@435 113 return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry);
duke@435 114 }
duke@435 115
duke@435 116
duke@435 117 inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) {
duke@435 118 _buckets[index].set_entry(entry);
duke@435 119 }
duke@435 120
duke@435 121
duke@435 122 inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) {
duke@435 123 entry->set_next(bucket(index));
duke@435 124 _buckets[index].set_entry(entry);
duke@435 125 ++_number_of_entries;
duke@435 126 }
duke@435 127
duke@435 128 inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) {
duke@435 129 entry->set_next(_free_list);
duke@435 130 _free_list = entry;
duke@435 131 --_number_of_entries;
duke@435 132 }
stefank@2314 133
stefank@2314 134 #endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP

mercurial