hotspot/src/share/vm/utilities/hashtable.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2003, 2005, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// This is a generic hashtable, designed to be used for the symbol
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// and string tables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//  - TableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class BasicHashtableEntry : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  unsigned int         _hash;           // 32-bit hash for item
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Link to next element in the linked list for this bucket.  EXCEPT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // bit 0 set indicates that this entry is shared and must not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // unlinked from the table. Bit 0 is set during the dumping of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // archive. Since shared entries are immutable, _next fields in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // shared entries will not change.  New entries will always be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // unshared and since pointers are align, bit 0 will always remain 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // with no extra effort.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  BasicHashtableEntry* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Windows IA64 compiler requires subclasses to be able to access these
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Entry objects should not be created, they should be taken from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // free list with BasicHashtable.new_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // Entry objects should not be destroyed.  They should be placed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // the free list instead with BasicHashtable.free_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  ~BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  unsigned int hash() const             { return _hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void set_hash(unsigned int hash)      { _hash = hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  unsigned int* hash_addr()             { return &_hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static BasicHashtableEntry* make_ptr(BasicHashtableEntry* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    return (BasicHashtableEntry*)((intptr_t)p & -2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  BasicHashtableEntry* next() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    return make_ptr(_next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void set_next(BasicHashtableEntry* next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _next = next;
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_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return &_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
  bool is_shared() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    return ((intptr_t)_next & 1) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void set_shared() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _next = (BasicHashtableEntry*)((intptr_t)_next | 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
class HashtableEntry : public BasicHashtableEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  oop               _literal;          // ref to item in table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Literal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  oop literal() const                   { return _literal; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  oop* literal_addr()                   { return &_literal; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void set_literal(oop s)               { _literal = s; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  HashtableEntry* next() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return (HashtableEntry*)BasicHashtableEntry::next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  HashtableEntry** next_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return (HashtableEntry**)BasicHashtableEntry::next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
class HashtableBucket : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Instance variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  BasicHashtableEntry*       _entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Accessing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void clear()                        { _entry = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // The following methods use order access methods to avoid race
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // conditions in multiprocessor systems.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  BasicHashtableEntry* get_entry() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void set_entry(BasicHashtableEntry* l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  BasicHashtableEntry** entry_addr()  { return &_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
class BasicHashtable : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  BasicHashtable(int table_size, int entry_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  BasicHashtable(int table_size, int entry_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
                 HashtableBucket* buckets, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Sharing support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  void copy_buckets(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void copy_table(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Bucket handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int hash_to_index(unsigned int full_hash) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    int h = full_hash % _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    assert(h >= 0 && h < _table_size, "Illegal hash value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Reverse the order of elements in each of the buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  void reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // Instance variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  int               _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  HashtableBucket*  _buckets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  BasicHashtableEntry* _free_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  char*             _first_free_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  char*             _end_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  int               _entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  int               _number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  int               _lookup_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  int               _lookup_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  void verify_lookup_length(double load);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  void initialize(int table_size, int entry_size, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Accessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  int entry_size() const { return _entry_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  int table_size() { return _table_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // The following method is MT-safe and may be used with caution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  BasicHashtableEntry* bucket(int i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  BasicHashtableEntry** bucket_addr(int i) { return _buckets[i].entry_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // Table entry management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  BasicHashtableEntry* new_entry(unsigned int hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  void set_entry(int index, BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  void add_entry(int index, BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  void free_entry(BasicHashtableEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  int number_of_entries() { return _number_of_entries; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
class Hashtable : public BasicHashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  Hashtable(int table_size, int entry_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    : BasicHashtable(table_size, entry_size) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  Hashtable(int table_size, int entry_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                   HashtableBucket* buckets, int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    : BasicHashtable(table_size, entry_size, buckets, number_of_entries) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Invoke "f->do_oop" on the locations of all oops in the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  void print()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  //   Delete pointers to otherwise-unreachable objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  void unlink(BoolObjectClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // Reverse the order of elements in each of the buckets. Hashtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // entries which refer to objects at a lower address than 'boundary'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // are separated from those which refer to objects at higher
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // addresses, and appear first in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  void reverse(void* boundary = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  static unsigned int hash_symbol(const char* s, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  unsigned int compute_hash(symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return (unsigned int) name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  int index_for(symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    return hash_to_index(compute_hash(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Table entry management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  HashtableEntry* new_entry(unsigned int hashValue, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // The following method is MT-safe and may be used with caution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  HashtableEntry* bucket(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    return (HashtableEntry*)BasicHashtable::bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  HashtableEntry** bucket_addr(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    return (HashtableEntry**)BasicHashtable::bucket_addr(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
//  Verions of hashtable where two handles are used to compute the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
class TwoOopHashtable : public Hashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  TwoOopHashtable(int table_size, int entry_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    : Hashtable(table_size, entry_size) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  TwoOopHashtable(int table_size, int entry_size, HashtableBucket* t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                  int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    : Hashtable(table_size, entry_size, t, number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  unsigned int compute_hash(symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    // Be careful with identity_hash(), it can safepoint and if this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    // were one expression, the compiler could choose to unhandle each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // oop before calling identity_hash() for either of them.  If the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    // causes a GC, the next would fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    unsigned int name_hash = name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return name_hash ^ loader_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  int index_for(symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    return hash_to_index(compute_hash(name, loader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
};