hotspot/src/share/vm/utilities/hashtable.hpp
author coleenp
Wed, 04 Jul 2012 15:55:45 -0400
changeset 13199 025b0984feea
parent 13195 be27e1b6a4b9
child 13342 76a5de64aa62
permissions -rw-r--r--
7181200: JVM new hashing code breaks SA in product mode Summary: Made new_hash() overloaded rather than a virtual function so SA code doesn't need to be changed. Reviewed-by: kvn, acorn, dholmes, fparain
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11628
13155c0c00b4 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 8921
diff changeset
     2
 * Copyright (c) 2003, 2012, 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"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    30
#include "oops/symbol.hpp"
7397
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    43
template <MEMFLAGS F> class BasicHashtableEntry : public CHeapObj<F> {
1
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.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    55
  BasicHashtableEntry<F>* _next;
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    72
  static BasicHashtableEntry<F>* make_ptr(BasicHashtableEntry<F>* p) {
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    76
  BasicHashtableEntry<F>* next() const {
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    80
  void set_next(BasicHashtableEntry<F>* next) {
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    84
  BasicHashtableEntry<F>** next_addr() {
1
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() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    93
    _next = (BasicHashtableEntry<F>*)((intptr_t)_next | 1);
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    99
template <class T, MEMFLAGS F> class HashtableEntry : public BasicHashtableEntry<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
private:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   102
  T               _literal;          // ref to item in table.
1
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
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   106
  T literal() const                   { return _literal; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   107
  T* literal_addr()                   { return &_literal; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   108
  void set_literal(T s)               { _literal = s; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  HashtableEntry* next() const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   111
    return (HashtableEntry*)BasicHashtableEntry<F>::next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  HashtableEntry** next_addr() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   114
    return (HashtableEntry**)BasicHashtableEntry<F>::next_addr();
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   120
template <MEMFLAGS F> class HashtableBucket : public CHeapObj<F> {
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   124
  BasicHashtableEntry<F>*       _entry;
1
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.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   132
  BasicHashtableEntry<F>* get_entry() const;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   133
  void set_entry(BasicHashtableEntry<F>* l);
1
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.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   136
  BasicHashtableEntry<F>** entry_addr()  { return &_entry; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   140
template <MEMFLAGS F> class BasicHashtable : public CHeapObj<F> {
1
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,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   146
                 HashtableBucket<F>* buckets, int number_of_entries);
1
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;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   165
  HashtableBucket<F>*     _buckets;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   166
  BasicHashtableEntry<F>* _free_list;
1
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
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   180
  enum {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   181
    rehash_count = 100,
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   182
    rehash_multiple = 60
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   183
  };
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   184
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  void initialize(int table_size, int entry_size, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // Accessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  int entry_size() const { return _entry_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // The following method is MT-safe and may be used with caution.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   191
  BasicHashtableEntry<F>* bucket(int i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // The following method is not MT-safe and must be done under lock.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   194
  BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   197
  BasicHashtableEntry<F>* new_entry(unsigned int hashValue);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   199
  // Check that the table is unbalanced
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   200
  bool check_rehash_table(int count);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   201
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   202
  // Used when moving the entry to another table
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   203
  // Clean up links, but do not add to free_list
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   204
  void unlink_entry(BasicHashtableEntry<F>* entry) {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   205
    entry->set_next(NULL);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   206
    --_number_of_entries;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   207
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   208
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   209
  // Move over freelist and free block for allocation
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   210
  void copy_freelist(BasicHashtable* src) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   211
    _free_list = src->_free_list;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   212
    src->_free_list = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   213
    _first_free_entry = src->_first_free_entry;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   214
    src->_first_free_entry = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   215
    _end_block = src->_end_block;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   216
    src->_end_block = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   217
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   218
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   219
  // Free the buckets in this hashtable
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   220
  void free_buckets();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   221
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
public:
11628
13155c0c00b4 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 8921
diff changeset
   223
  int table_size() { return _table_size; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   224
  void set_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   226
  void add_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   228
  void free_entry(BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  int number_of_entries() { return _number_of_entries; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   236
template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  Hashtable(int table_size, int entry_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   241
    : BasicHashtable<F>(table_size, entry_size) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  Hashtable(int table_size, int entry_size,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   244
                   HashtableBucket<F>* buckets, int number_of_entries)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   245
    : BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  void print()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // Reverse the order of elements in each of the buckets. Hashtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // entries which refer to objects at a lower address than 'boundary'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // are separated from those which refer to objects at higher
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // addresses, and appear first in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  void reverse(void* boundary = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   258
  unsigned int compute_hash(Symbol* name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    return (unsigned int) name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   262
  int index_for(Symbol* name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    return hash_to_index(compute_hash(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   267
  HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // The following method is MT-safe and may be used with caution.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   270
  HashtableEntry<T, F>* bucket(int i) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   271
    return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // The following method is not MT-safe and must be done under lock.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   275
  HashtableEntry<T, F>** bucket_addr(int i) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   276
    return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   278
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   279
  // Function to move these elements into the new table.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   280
  void move_to(Hashtable<T, F>* new_table);
13199
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   281
  static bool use_alternate_hashcode()  { return _seed != 0; }
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   282
  static jint seed()                    { return _seed; }
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   283
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   284
 private:
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   285
  static jint _seed;
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   286
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   287
  unsigned int new_hash(Symbol* s);
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   288
  unsigned int new_hash(oop string);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
//  Verions of hashtable where two handles are used to compute the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   294
template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  TwoOopHashtable(int table_size, int entry_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   298
    : Hashtable<T, F>(table_size, entry_size) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   300
  TwoOopHashtable(int table_size, int entry_size, HashtableBucket<F>* t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
                  int number_of_entries)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   302
    : Hashtable<T, F>(table_size, entry_size, t, number_of_entries) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   305
  unsigned int compute_hash(Symbol* name, Handle loader) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // Be careful with identity_hash(), it can safepoint and if this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // were one expression, the compiler could choose to unhandle each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // oop before calling identity_hash() for either of them.  If the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    // causes a GC, the next would fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    unsigned int name_hash = name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    unsigned int loader_hash = loader.is_null() ? 0 : loader->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    return name_hash ^ loader_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   315
  int index_for(Symbol* name, Handle loader) {
8310
d7c285113f48 7019689: Non-dependent name is found in dependent base class although it should be rejected
coleenp
parents: 8076
diff changeset
   316
    return this->hash_to_index(compute_hash(name, loader));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   319
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   320
#endif // SHARE_VM_UTILITIES_HASHTABLE_HPP