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

Print this page


   1 /*
   2  * Copyright (c) 2003, 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  *
  23  */
  24 






  25 // Inline function definitions for hashtable.hpp.
  26 
  27 
  28 // --------------------------------------------------------------------------
  29 // Hash function
  30 
  31 // We originally used hashpjw, but hash P(31) gives just as good results
  32 // and is slighly faster. We would like a hash function that looks at every
  33 // character, since package names have large common prefixes, and also because
  34 // hash_or_fail does error checking while iterating.
  35 
  36 // hash P(31) from Kernighan & Ritchie
  37 
  38 inline unsigned int Hashtable::hash_symbol(const char* s, int len) {
  39   unsigned int h = 0;
  40   while (len-- > 0) {
  41     h = 31*h + (unsigned) *s;
  42     s++;
  43   }
  44   return h;


 107   return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry);
 108 }
 109 
 110 
 111 inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) {
 112   _buckets[index].set_entry(entry);
 113 }
 114 
 115 
 116 inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) {
 117   entry->set_next(bucket(index));
 118   _buckets[index].set_entry(entry);
 119   ++_number_of_entries;
 120 }
 121 
 122 inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) {
 123   entry->set_next(_free_list);
 124   _free_list = entry;
 125   --_number_of_entries;
 126 }


   1 /*
   2  * Copyright (c) 2003, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
  26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "utilities/hashtable.hpp"
  30 
  31 // Inline function definitions for hashtable.hpp.
  32 
  33 
  34 // --------------------------------------------------------------------------
  35 // Hash function
  36 
  37 // We originally used hashpjw, but hash P(31) gives just as good results
  38 // and is slighly faster. We would like a hash function that looks at every
  39 // character, since package names have large common prefixes, and also because
  40 // hash_or_fail does error checking while iterating.
  41 
  42 // hash P(31) from Kernighan & Ritchie
  43 
  44 inline unsigned int Hashtable::hash_symbol(const char* s, int len) {
  45   unsigned int h = 0;
  46   while (len-- > 0) {
  47     h = 31*h + (unsigned) *s;
  48     s++;
  49   }
  50   return h;


 113   return (BasicHashtableEntry*) OrderAccess::load_ptr_acquire(&_entry);
 114 }
 115 
 116 
 117 inline void BasicHashtable::set_entry(int index, BasicHashtableEntry* entry) {
 118   _buckets[index].set_entry(entry);
 119 }
 120 
 121 
 122 inline void BasicHashtable::add_entry(int index, BasicHashtableEntry* entry) {
 123   entry->set_next(bucket(index));
 124   _buckets[index].set_entry(entry);
 125   ++_number_of_entries;
 126 }
 127 
 128 inline void BasicHashtable::free_entry(BasicHashtableEntry* entry) {
 129   entry->set_next(_free_list);
 130   _free_list = entry;
 131   --_number_of_entries;
 132 }
 133 
 134 #endif // SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP