hotspot/src/share/vm/utilities/hashtable.hpp
author anoll
Wed, 26 Feb 2014 11:29:47 +0100
changeset 22921 ee35d5c0b1dc
parent 22757 b2cbb3680b4f
child 23187 0f438571f278
permissions -rw-r--r--
8034839: jvm hangs with gc/gctests/LoadUnloadGC test Summary: Provide fast lookup of checked dependencies via hashmap Reviewed-by: kvn, roland
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 22234
diff changeset
     2
 * Copyright (c) 2003, 2014, 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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
    28
#include "classfile/classLoaderData.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/oop.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    31
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// This is a generic hashtable, designed to be used for the symbol
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// and string tables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//  - TableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    44
template <MEMFLAGS F> class BasicHashtableEntry : public CHeapObj<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  unsigned int         _hash;           // 32-bit hash for item
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Link to next element in the linked list for this bucket.  EXCEPT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // bit 0 set indicates that this entry is shared and must not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // unlinked from the table. Bit 0 is set during the dumping of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // archive. Since shared entries are immutable, _next fields in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // shared entries will not change.  New entries will always be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // unshared and since pointers are align, bit 0 will always remain 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // with no extra effort.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    56
  BasicHashtableEntry<F>* _next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Windows IA64 compiler requires subclasses to be able to access these
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Entry objects should not be created, they should be taken from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // free list with BasicHashtable.new_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Entry objects should not be destroyed.  They should be placed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // the free list instead with BasicHashtable.free_entry().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  ~BasicHashtableEntry() { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  unsigned int hash() const             { return _hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void set_hash(unsigned int hash)      { _hash = hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  unsigned int* hash_addr()             { return &_hash; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    73
  static BasicHashtableEntry<F>* make_ptr(BasicHashtableEntry<F>* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return (BasicHashtableEntry*)((intptr_t)p & -2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    77
  BasicHashtableEntry<F>* next() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    return make_ptr(_next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    81
  void set_next(BasicHashtableEntry<F>* next) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    _next = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    85
  BasicHashtableEntry<F>** next_addr() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return &_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  bool is_shared() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return ((intptr_t)_next & 1) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void set_shared() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    94
    _next = (BasicHashtableEntry<F>*)((intptr_t)_next | 1);
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   100
template <class T, MEMFLAGS F> class HashtableEntry : public BasicHashtableEntry<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
private:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   103
  T               _literal;          // ref to item in table.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Literal
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   107
  T literal() const                   { return _literal; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   108
  T* literal_addr()                   { return &_literal; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   109
  void set_literal(T s)               { _literal = s; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  HashtableEntry* next() const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   112
    return (HashtableEntry*)BasicHashtableEntry<F>::next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  HashtableEntry** next_addr() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   115
    return (HashtableEntry**)BasicHashtableEntry<F>::next_addr();
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   121
template <MEMFLAGS F> class HashtableBucket : public CHeapObj<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // Instance variable
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   125
  BasicHashtableEntry<F>*       _entry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Accessing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  void clear()                        { _entry = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // The following methods use order access methods to avoid race
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // conditions in multiprocessor systems.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   133
  BasicHashtableEntry<F>* get_entry() const;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   134
  void set_entry(BasicHashtableEntry<F>* l);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // 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
   137
  BasicHashtableEntry<F>** entry_addr()  { return &_entry; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   141
template <MEMFLAGS F> class BasicHashtable : public CHeapObj<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  BasicHashtable(int table_size, int entry_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  BasicHashtable(int table_size, int entry_size,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   147
                 HashtableBucket<F>* buckets, int number_of_entries);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // Sharing support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void copy_buckets(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void copy_table(char** top, char* end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Bucket handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  int hash_to_index(unsigned int full_hash) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    int h = full_hash % _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    assert(h >= 0 && h < _table_size, "Illegal hash value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Reverse the order of elements in each of the buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // Instance variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  int               _table_size;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   166
  HashtableBucket<F>*     _buckets;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   167
  BasicHashtableEntry<F>* _free_list;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  char*             _first_free_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  char*             _end_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  int               _entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  int               _number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  int               _lookup_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  int               _lookup_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  void verify_lookup_length(double load);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   181
  enum {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   182
    rehash_count = 100,
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   183
    rehash_multiple = 60
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   184
  };
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   185
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  void initialize(int table_size, int entry_size, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Accessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  int entry_size() const { return _entry_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // 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
   192
  BasicHashtableEntry<F>* bucket(int i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // 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
   195
  BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   198
  BasicHashtableEntry<F>* new_entry(unsigned int hashValue);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   200
  // Check that the table is unbalanced
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   201
  bool check_rehash_table(int count);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   202
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   203
  // Used when moving the entry to another table
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   204
  // Clean up links, but do not add to free_list
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   205
  void unlink_entry(BasicHashtableEntry<F>* entry) {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   206
    entry->set_next(NULL);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   207
    --_number_of_entries;
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
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   210
  // Move over freelist and free block for allocation
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   211
  void copy_freelist(BasicHashtable* src) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   212
    _free_list = src->_free_list;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   213
    src->_free_list = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   214
    _first_free_entry = src->_first_free_entry;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   215
    src->_first_free_entry = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   216
    _end_block = src->_end_block;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   217
    src->_end_block = NULL;
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
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   220
  // Free the buckets in this hashtable
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   221
  void free_buckets();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   222
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
public:
11628
13155c0c00b4 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 8921
diff changeset
   224
  int table_size() { return _table_size; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   225
  void set_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   227
  void add_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   229
  void free_entry(BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  int number_of_entries() { return _number_of_entries; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   237
template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  Hashtable(int table_size, int entry_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   242
    : BasicHashtable<F>(table_size, entry_size) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  Hashtable(int table_size, int entry_size,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   245
                   HashtableBucket<F>* buckets, int number_of_entries)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   246
    : BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  void print()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // Reverse the order of elements in each of the buckets. Hashtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // entries which refer to objects at a lower address than 'boundary'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // are separated from those which refer to objects at higher
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // addresses, and appear first in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  void reverse(void* boundary = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   259
  unsigned int compute_hash(Symbol* name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    return (unsigned int) name->identity_hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   263
  int index_for(Symbol* name) {
13342
76a5de64aa62 7186278: Build error after CR#6995781 / 7151532 with GCC 4.7.0
andrew
parents: 13199
diff changeset
   264
    return this->hash_to_index(compute_hash(name));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   268
  HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // 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
   271
  HashtableEntry<T, F>* bucket(int i) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   272
    return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // 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
   276
  HashtableEntry<T, F>** bucket_addr(int i) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   277
    return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   279
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   280
  // Function to move these elements into the new table.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   281
  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
   282
  static bool use_alternate_hashcode()  { return _seed != 0; }
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 22234
diff changeset
   283
  static juint seed()                    { return _seed; }
13199
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   284
17610
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   285
  static int literal_size(Symbol *symbol);
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   286
  static int literal_size(oop oop);
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   287
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   288
  // The following two are currently not used, but are needed anyway because some
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   289
  // C++ compilers (MacOS and Solaris) force the instantiation of
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   290
  // Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   291
  // in the VM code.
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   292
  static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;}
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   293
  static int literal_size(Klass *k)         {Unimplemented(); return 0;}
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   294
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   295
public:
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   296
  void dump_table(outputStream* st, const char *table_name);
c6857feaac47 8014262: PrintStringTableStatistics should include more footprint info
iklam
parents: 13728
diff changeset
   297
13199
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   298
 private:
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 22234
diff changeset
   299
  static juint _seed;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
22921
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   303
// Versions of hashtable where two handles are used to compute the index.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   305
template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  TwoOopHashtable(int table_size, int entry_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   309
    : Hashtable<T, F>(table_size, entry_size) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   311
  TwoOopHashtable(int table_size, int entry_size, HashtableBucket<F>* t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                  int number_of_entries)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   313
    : Hashtable<T, F>(table_size, entry_size, t, number_of_entries) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   316
  unsigned int compute_hash(Symbol* name, ClassLoaderData* loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    unsigned int name_hash = name->identity_hash();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   318
    // loader is null with CDS
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   319
    assert(loader_data != NULL || UseSharedSpaces || DumpSharedSpaces,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   320
           "only allowed with shared spaces");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   321
    unsigned int loader_hash = loader_data == NULL ? 0 : loader_data->identity_hash();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    return name_hash ^ loader_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   325
  int index_for(Symbol* name, ClassLoaderData* loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13342
diff changeset
   326
    return this->hash_to_index(compute_hash(name, loader_data));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   329
22921
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   330
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   331
/*
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   332
 * Usage of GenericHashtable:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   333
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   334
 * class X : public GenericHashtableEntry<X, ResourceObj> {
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   335
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   336
 *   // Implement virtual functions in class X
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   337
 *   bool      equals(X* sig) const;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   338
 *   uintptr_t hash()         const;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   339
 * };
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   340
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   341
 * void foo() {
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   342
 *   GenericHashtable<X, ResourceObj>* table = new GenericHashtable<X, ResourceObj>(11027, false);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   343
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   344
 *   X* elem = new X();
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   345
 *   table->add(elem);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   346
 *   table->contains(elem);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   347
 * }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   348
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   349
 * You can choose other allocation types as well. For example, to store the hashtable to a
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   350
 * particular region (CHeapObj<type>) simply replace ResourceObj with the desired type:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   351
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   352
 * class X : public GenericHashtableEntry<X, CHeapObj<mtCode> > { ... };
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   353
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   354
 * To make the destructor (and remove) of the hashtable work:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   355
 * 1) override the delete operator of X
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   356
 * 2) provide a destructor of the X
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   357
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   358
 * You may also find it convenient to override the new operator.
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   359
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   360
 * If you use this templates do not forget to add an explicit initialization
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   361
 * (at the end of hashtable.cpp).
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   362
 *
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   363
 *  template class GenericHashtable<X, ResourceObj>;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   364
 */
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   365
template <class T, class M> class GenericHashtableEntry : public M {
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   366
 private:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   367
  T* _next;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   368
  T* _prev;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   369
 public:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   370
  // Must be implemented by subclass.
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   371
  virtual uintptr_t key()            const = 0;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   372
  virtual bool      equals(T* other) const = 0;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   373
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   374
  T* next() const        { return _next; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   375
  T* prev() const        { return _prev; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   376
  void set_next(T* item) { _next = item; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   377
  void set_prev(T* item) { _prev = item; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   378
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   379
  // Constructor and destructor
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   380
  GenericHashtableEntry() : _next(NULL), _prev(NULL) { };
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   381
  virtual ~GenericHashtableEntry() {};
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   382
};
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   383
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   384
template <class T, class M> class GenericHashtable : public M {
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   385
 private:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   386
  T**      _items;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   387
  int      _size;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   388
  bool     _C_heap;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   389
  MEMFLAGS _memflag;
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   390
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   391
  // Accessor methods
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   392
  T*   head    (int idx) const    { return _items[idx]; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   393
  void set_head(T* item, int idx) { _items[idx] = item; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   394
  int  index   (T* item)          { assert(item != NULL, "missing null check"); return item->key() % size(); }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   395
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   396
  // Helper function
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   397
  T* contains_impl(T* item, int idx);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   398
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   399
  DEBUG_ONLY(int _num_items;)
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   400
 public:
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   401
  GenericHashtable(int size, bool C_heap = false, MEMFLAGS memflag = mtNone);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   402
  ~GenericHashtable();
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   403
  T*   contains(T* match_item);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   404
  T*   remove  (T* match_item);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   405
  bool add     (T* item);
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   406
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   407
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   408
  bool on_C_heap() const { return _C_heap; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   409
  int  size()      const { return _size; }
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   410
};
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22757
diff changeset
   411
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   412
#endif // SHARE_VM_UTILITIES_HASHTABLE_HPP