src/hotspot/share/utilities/hashtable.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46746 hotspot/src/share/vm/utilities/hashtable.hpp@ea379ebb9447
child 47774 69c081ca110a
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
44897
1d9f4d0c9927 8030750: SA: Alternate hashing not implemented
sballal
parents: 42073
diff changeset
     2
 * Copyright (c) 2003, 2017, 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
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46435
diff changeset
   129
  void clear()                        { _entry = NULL; }
1
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; }
39982
1a3808e3f4d9 8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents: 34666
diff changeset
   138
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   142
template <MEMFLAGS F> class BasicHashtable : public CHeapObj<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  BasicHashtable(int table_size, int entry_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  BasicHashtable(int table_size, int entry_size,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   148
                 HashtableBucket<F>* buckets, int number_of_entries);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Sharing support.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   151
  size_t count_bytes_for_buckets();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   152
  size_t count_bytes_for_table();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   153
  void copy_buckets(char* top, char* end);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   154
  void copy_table(char* top, char* end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // Bucket handling
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26421
diff changeset
   157
  int hash_to_index(unsigned int full_hash) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    int h = full_hash % _table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    assert(h >= 0 && h < _table_size, "Illegal hash value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
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;
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   167
  BasicHashtableEntry<F>* volatile _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;
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   171
  volatile int      _number_of_entries;
1
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
  void initialize(int table_size, int entry_size, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Accessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  int entry_size() const { return _entry_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // The following method is MT-safe and may be used with caution.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26421
diff changeset
   181
  BasicHashtableEntry<F>* bucket(int i) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // 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
   184
  BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   186
  // Attempt to get an entry from the free list
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   187
  BasicHashtableEntry<F>* new_entry_free_list();
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   188
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   190
  BasicHashtableEntry<F>* new_entry(unsigned int hashValue);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   192
  // Used when moving the entry to another table
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   193
  // Clean up links, but do not add to free_list
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   194
  void unlink_entry(BasicHashtableEntry<F>* entry) {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   195
    entry->set_next(NULL);
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   196
    --_number_of_entries;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   197
  }
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   198
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   199
  // Move over freelist and free block for allocation
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   200
  void copy_freelist(BasicHashtable* src) {
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   201
    _free_list = src->_free_list;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   202
    src->_free_list = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   203
    _first_free_entry = src->_first_free_entry;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   204
    src->_first_free_entry = NULL;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   205
    _end_block = src->_end_block;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   206
    src->_end_block = NULL;
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
  // Free the buckets in this hashtable
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   210
  void free_buckets();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   211
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   212
  // Helper data structure containing context for the bucket entry unlink process,
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   213
  // storing the unlinked buckets in a linked list.
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   214
  // Also avoids the need to pass around these four members as parameters everywhere.
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   215
  struct BucketUnlinkContext {
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   216
    int _num_processed;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   217
    int _num_removed;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   218
    // Head and tail pointers for the linked list of removed entries.
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   219
    BasicHashtableEntry<F>* _removed_head;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   220
    BasicHashtableEntry<F>* _removed_tail;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   221
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   222
    BucketUnlinkContext() : _num_processed(0), _num_removed(0), _removed_head(NULL), _removed_tail(NULL) {
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   223
    }
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   224
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   225
    void free_entry(BasicHashtableEntry<F>* entry);
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   226
  };
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   227
  // Add of bucket entries linked together in the given context to the global free list. This method
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   228
  // is mt-safe wrt. to other calls of this method.
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 42073
diff changeset
   229
  void bulk_free_entries(BucketUnlinkContext* context);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
public:
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   231
  int table_size() const { return _table_size; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   232
  void set_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   234
  void add_entry(int index, BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   236
  void free_entry(BasicHashtableEntry<F>* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   238
  int number_of_entries() const { return _number_of_entries; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46435
diff changeset
   240
  template <class T> void verify_table(const char* table_name) PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   244
template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  Hashtable(int table_size, int entry_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   249
    : BasicHashtable<F>(table_size, entry_size) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  Hashtable(int table_size, int entry_size,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   252
                   HashtableBucket<F>* buckets, int number_of_entries)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   253
    : BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  void print()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46630
diff changeset
   258
  unsigned int compute_hash(const Symbol* name) const {
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
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46630
diff changeset
   262
  int index_for(const Symbol* name) const {
13342
76a5de64aa62 7186278: Build error after CR#6995781 / 7151532 with GCC 4.7.0
andrew
parents: 13199
diff changeset
   263
    return this->hash_to_index(compute_hash(name));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   266
  void print_table_statistics(outputStream* st, const char *table_name);
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   267
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   268
 protected:
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46630
diff changeset
   269
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // Table entry management
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   271
  HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46630
diff changeset
   272
  // Don't create and use freelist of HashtableEntry.
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46630
diff changeset
   273
  HashtableEntry<T, F>* allocate_new_entry(unsigned int hashValue, T obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // The following method is MT-safe and may be used with caution.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26421
diff changeset
   276
  HashtableEntry<T, F>* bucket(int i) const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   277
    return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // 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
   281
  HashtableEntry<T, F>** bucket_addr(int i) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   282
    return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   284
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   285
};
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   286
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   287
template <class T, MEMFLAGS F> class RehashableHashtable : public Hashtable<T, F> {
44897
1d9f4d0c9927 8030750: SA: Alternate hashing not implemented
sballal
parents: 42073
diff changeset
   288
 friend class VMStructs;
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   289
 protected:
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   290
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   291
  enum {
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   292
    rehash_count = 100,
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   293
    rehash_multiple = 60
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   294
  };
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   295
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   296
  // Check that the table is unbalanced
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   297
  bool check_rehash_table(int count);
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   298
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   299
 public:
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   300
  RehashableHashtable(int table_size, int entry_size)
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   301
    : Hashtable<T, F>(table_size, entry_size) { }
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   302
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   303
  RehashableHashtable(int table_size, int entry_size,
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   304
                   HashtableBucket<F>* buckets, int number_of_entries)
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   305
    : Hashtable<T, F>(table_size, entry_size, buckets, number_of_entries) { }
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   306
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   307
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 11628
diff changeset
   308
  // Function to move these elements into the new table.
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 23187
diff changeset
   309
  void move_to(RehashableHashtable<T, F>* new_table);
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46545
diff changeset
   310
  static bool use_alternate_hashcode();
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46545
diff changeset
   311
  static juint seed();
13199
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   312
025b0984feea 7181200: JVM new hashing code breaks SA in product mode
coleenp
parents: 13195
diff changeset
   313
 private:
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 22234
diff changeset
   314
  static juint _seed;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46545
diff changeset
   317
template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::_seed = 0;
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46545
diff changeset
   318
template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::seed() { return _seed; };
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46545
diff changeset
   319
template <class T, MEMFLAGS F> bool  RehashableHashtable<T, F>::use_alternate_hashcode() { return _seed != 0; };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   321
#endif // SHARE_VM_UTILITIES_HASHTABLE_HPP