src/hotspot/share/utilities/hashtable.inline.hpp
author stefank
Mon, 25 Nov 2019 12:22:13 +0100
changeset 59247 56bf71d64d51
parent 54764 865ec913f916
child 59290 97d13893ec3c
permissions -rw-r--r--
8234562: Move OrderAccess::release_store*/load_acquire to Atomic Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
     2
 * Copyright (c) 2003, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
    25
#ifndef SHARE_UTILITIES_HASHTABLE_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
    26
#define SHARE_UTILITIES_HASHTABLE_INLINE_HPP
7397
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.inline.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 47634
diff changeset
    29
#include "runtime/orderAccess.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/hashtable.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    31
#include "utilities/dtrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Inline function definitions for hashtable.hpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// --------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Initialize a table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    39
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Called on startup, no locking needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  initialize(table_size, entry_size, 0);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    42
  _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  for (int index = 0; index < _table_size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    _buckets[index].clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
    46
  _stats_rate = TableRateStatistics();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    50
template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    51
                                      HashtableBucket<F>* buckets,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                                      int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Called on startup, no locking needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  initialize(table_size, entry_size, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _buckets = buckets;
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
    56
  _stats_rate = TableRateStatistics();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    59
template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() {
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    60
  for (int i = 0; i < _entry_blocks->length(); i++) {
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    61
    FREE_C_HEAP_ARRAY(char, _entry_blocks->at(i));
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    62
  }
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    63
  delete _entry_blocks;
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    64
  free_buckets();
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    65
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    67
template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                                       int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Called on startup, no locking needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _table_size = table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _entry_size = entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _free_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _first_free_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  _end_block = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  _number_of_entries = number_of_entries;
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 50429
diff changeset
    76
  _entry_blocks = new(ResourceObj::C_HEAP, F) GrowableArray<char*>(4, true, F);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// The following method is MT-safe and may be used with caution.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 24351
diff changeset
    81
template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return _buckets[i].get_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    86
template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39982
diff changeset
    87
  // Warning: Preserve store ordering.  The PackageEntryTable, ModuleEntryTable and
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39982
diff changeset
    88
  //          SystemDictionary are read without locks.  The new entry must be
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //          complete before other threads can be allowed to see it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  //          via a store to _buckets[index].
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54764
diff changeset
    91
  Atomic::release_store(&_entry, l);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
    95
template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39982
diff changeset
    96
  // Warning: Preserve load ordering.  The PackageEntryTable, ModuleEntryTable and
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39982
diff changeset
    97
  //          SystemDictionary are read without locks.  The new entry must be
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  //          complete before other threads can be allowed to see it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //          via a store to _buckets[index].
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54764
diff changeset
   100
  return Atomic::load_acquire(&_entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
   104
template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  _buckets[index].set_entry(entry);
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   106
  if (entry != NULL) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   107
    JFR_ONLY(_stats_rate.add();)
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   108
  } else {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   109
    JFR_ONLY(_stats_rate.remove();)
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   110
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13087
diff changeset
   114
template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  entry->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  _buckets[index].set_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  ++_number_of_entries;
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   118
  JFR_ONLY(_stats_rate.add();)
1
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: 13087
diff changeset
   121
template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  entry->set_next(_free_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  _free_list = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  --_number_of_entries;
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53244
diff changeset
   125
  JFR_ONLY(_stats_rate.remove();)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   127
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
   128
#endif // SHARE_UTILITIES_HASHTABLE_INLINE_HPP