src/share/vm/utilities/hashtable.hpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2005, 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 // This is a generic hashtable, designed to be used for the symbol
  26 // and string tables.
  27 //
  28 // It is implemented as an open hash table with a fixed number of buckets.
  29 //
  30 // %note:
  31 //  - TableEntrys are allocated in blocks to reduce the space overhead.
  32 
  33 
  34 
  35 class BasicHashtableEntry : public CHeapObj {
  36   friend class VMStructs;
  37 private:
  38   unsigned int         _hash;           // 32-bit hash for item
  39 
  40   // Link to next element in the linked list for this bucket.  EXCEPT
  41   // bit 0 set indicates that this entry is shared and must not be
  42   // unlinked from the table. Bit 0 is set during the dumping of the
  43   // archive. Since shared entries are immutable, _next fields in the
  44   // shared entries will not change.  New entries will always be


 261 
 262   TwoOopHashtable(int table_size, int entry_size, HashtableBucket* t,
 263                   int number_of_entries)
 264     : Hashtable(table_size, entry_size, t, number_of_entries) {}
 265 
 266 public:
 267   unsigned int compute_hash(symbolHandle name, Handle loader) {
 268     // Be careful with identity_hash(), it can safepoint and if this
 269     // were one expression, the compiler could choose to unhandle each
 270     // oop before calling identity_hash() for either of them.  If the first
 271     // causes a GC, the next would fail.
 272     unsigned int name_hash = name->identity_hash();
 273     unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
 274     return name_hash ^ loader_hash;
 275   }
 276 
 277   int index_for(symbolHandle name, Handle loader) {
 278     return hash_to_index(compute_hash(name, loader));
 279   }
 280 };


   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_HPP
  26 #define SHARE_VM_UTILITIES_HASHTABLE_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "oops/oop.hpp"
  30 #include "oops/symbolOop.hpp"
  31 #include "runtime/handles.hpp"
  32 
  33 // This is a generic hashtable, designed to be used for the symbol
  34 // and string tables.
  35 //
  36 // It is implemented as an open hash table with a fixed number of buckets.
  37 //
  38 // %note:
  39 //  - TableEntrys are allocated in blocks to reduce the space overhead.
  40 
  41 
  42 
  43 class BasicHashtableEntry : public CHeapObj {
  44   friend class VMStructs;
  45 private:
  46   unsigned int         _hash;           // 32-bit hash for item
  47 
  48   // Link to next element in the linked list for this bucket.  EXCEPT
  49   // bit 0 set indicates that this entry is shared and must not be
  50   // unlinked from the table. Bit 0 is set during the dumping of the
  51   // archive. Since shared entries are immutable, _next fields in the
  52   // shared entries will not change.  New entries will always be


 269 
 270   TwoOopHashtable(int table_size, int entry_size, HashtableBucket* t,
 271                   int number_of_entries)
 272     : Hashtable(table_size, entry_size, t, number_of_entries) {}
 273 
 274 public:
 275   unsigned int compute_hash(symbolHandle name, Handle loader) {
 276     // Be careful with identity_hash(), it can safepoint and if this
 277     // were one expression, the compiler could choose to unhandle each
 278     // oop before calling identity_hash() for either of them.  If the first
 279     // causes a GC, the next would fail.
 280     unsigned int name_hash = name->identity_hash();
 281     unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
 282     return name_hash ^ loader_hash;
 283   }
 284 
 285   int index_for(symbolHandle name, Handle loader) {
 286     return hash_to_index(compute_hash(name, loader));
 287   }
 288 };
 289 
 290 #endif // SHARE_VM_UTILITIES_HASHTABLE_HPP