hotspot/src/share/vm/utilities/hashtable.hpp
author stefank
Tue, 23 Nov 2010 13:22:55 -0800
changeset 7397 5b173b4ca846
parent 5547 f4b087cbb361
child 8076 96d498ec7ae1
permissions -rw-r--r--
6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_HASHTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_HASHTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/symbolOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// This is a generic hashtable, designed to be used for the symbol
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// and string tables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//  - TableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class BasicHashtableEntry : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  unsigned int         _hash;           // 32-bit hash for item
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Link to next element in the linked list for this bucket.  EXCEPT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // bit 0 set indicates that this entry is shared and must not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // unlinked from the table. Bit 0 is set during the dumping of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // archive. Since shared entries are immutable, _next fields in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // shared entries will not change.  New entries will always be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // unshared and since pointers are align, bit 0 will always remain 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // with no extra effort.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  BasicHashtableEntry* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Windows IA64 compiler requires subclasses to be able to access these
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Entry objects should not be created, they should be taken from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // free list with BasicHashtable.new_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Entry objects should not be destroyed.  They should be placed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // the free list instead with BasicHashtable.free_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  ~BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  unsigned int hash() const             { return _hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  void set_hash(unsigned int hash)      { _hash = hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  unsigned int* hash_addr()             { return &_hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static BasicHashtableEntry* make_ptr(BasicHashtableEntry* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return (BasicHashtableEntry*)((intptr_t)p & -2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  BasicHashtableEntry* next() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return make_ptr(_next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void set_next(BasicHashtableEntry* next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    _next = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  BasicHashtableEntry** next_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return &_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  bool is_shared() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    return ((intptr_t)_next & 1) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void set_shared() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _next = (BasicHashtableEntry*)((intptr_t)_next | 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
class HashtableEntry : public BasicHashtableEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  oop               _literal;          // ref to item in table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // Literal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  oop literal() const                   { return _literal; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  oop* literal_addr()                   { return &_literal; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  void set_literal(oop s)               { _literal = s; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  HashtableEntry* next() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return (HashtableEntry*)BasicHashtableEntry::next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  HashtableEntry** next_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return (HashtableEntry**)BasicHashtableEntry::next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
class HashtableBucket : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // Instance variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  BasicHashtableEntry*       _entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Accessing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void clear()                        { _entry = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // The following methods use order access methods to avoid race
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // conditions in multiprocessor systems.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  BasicHashtableEntry* get_entry() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void set_entry(BasicHashtableEntry* l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  BasicHashtableEntry** entry_addr()  { return &_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
class BasicHashtable : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  BasicHashtable(int table_size, int entry_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  BasicHashtable(int table_size, int entry_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                 HashtableBucket* buckets, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Sharing support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void copy_buckets(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void copy_table(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Bucket handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  int hash_to_index(unsigned int full_hash) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    int h = full_hash % _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    assert(h >= 0 && h < _table_size, "Illegal hash value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Reverse the order of elements in each of the buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  void reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Instance variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  int               _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  HashtableBucket*  _buckets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  BasicHashtableEntry* _free_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  char*             _first_free_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  char*             _end_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  int               _entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  int               _number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  int               _lookup_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  int               _lookup_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  void verify_lookup_length(double load);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void initialize(int table_size, int entry_size, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Accessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  int entry_size() const { return _entry_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  int table_size() { return _table_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // The following method is MT-safe and may be used with caution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  BasicHashtableEntry* bucket(int i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  BasicHashtableEntry** bucket_addr(int i) { return _buckets[i].entry_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // Table entry management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  BasicHashtableEntry* new_entry(unsigned int hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  void set_entry(int index, BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  void add_entry(int index, BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  void free_entry(BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  int number_of_entries() { return _number_of_entries; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
class Hashtable : public BasicHashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  Hashtable(int table_size, int entry_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    : BasicHashtable(table_size, entry_size) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  Hashtable(int table_size, int entry_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                   HashtableBucket* buckets, int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    : BasicHashtable(table_size, entry_size, buckets, number_of_entries) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // Invoke "f->do_oop" on the locations of all oops in the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  void print()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  //   Delete pointers to otherwise-unreachable objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  void unlink(BoolObjectClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Reverse the order of elements in each of the buckets. Hashtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // entries which refer to objects at a lower address than 'boundary'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // are separated from those which refer to objects at higher
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // addresses, and appear first in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void reverse(void* boundary = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  static unsigned int hash_symbol(const char* s, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  unsigned int compute_hash(symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return (unsigned int) name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  int index_for(symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    return hash_to_index(compute_hash(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Table entry management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  HashtableEntry* new_entry(unsigned int hashValue, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // The following method is MT-safe and may be used with caution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  HashtableEntry* bucket(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    return (HashtableEntry*)BasicHashtable::bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  HashtableEntry** bucket_addr(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    return (HashtableEntry**)BasicHashtable::bucket_addr(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
//  Verions of hashtable where two handles are used to compute the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
class TwoOopHashtable : public Hashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  TwoOopHashtable(int table_size, int entry_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    : Hashtable(table_size, entry_size) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  TwoOopHashtable(int table_size, int entry_size, HashtableBucket* t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
                  int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    : Hashtable(table_size, entry_size, t, number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  unsigned int compute_hash(symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    // Be careful with identity_hash(), it can safepoint and if this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    // were one expression, the compiler could choose to unhandle each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    // oop before calling identity_hash() for either of them.  If the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    // causes a GC, the next would fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    unsigned int name_hash = name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    return name_hash ^ loader_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  int index_for(symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    return hash_to_index(compute_hash(name, loader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   289
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   290
#endif // SHARE_VM_UTILITIES_HASHTABLE_HPP