src/hotspot/share/classfile/symbolTable.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 58447 319173c62caa
child 58679 9c3209ff7550
child 59248 e92153ed8bdc
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
     2
 * Copyright (c) 1997, 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: 2332
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
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: 2332
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
#include "precompiled.hpp"
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
    26
#include "classfile/altHashing.hpp"
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    27
#include "classfile/compactHashtable.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/symbolTable.hpp"
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    30
#include "memory/allocation.inline.hpp"
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    31
#include "memory/dynamicArchive.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    32
#include "memory/metaspaceClosure.hpp"
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    33
#include "memory/metaspaceShared.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37198
diff changeset
    34
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "oops/oop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39713
diff changeset
    36
#include "runtime/atomic.hpp"
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    37
#include "runtime/interfaceSupport.inline.hpp"
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    38
#include "runtime/timerTrace.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 45114
diff changeset
    39
#include "services/diagnosticCommand.hpp"
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    40
#include "utilities/concurrentHashTable.inline.hpp"
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    41
#include "utilities/concurrentHashTableTasks.inline.hpp"
54347
235883996bc7 8221698: Remove redundant includes from popular header files
iklam
parents: 54133
diff changeset
    42
#include "utilities/utf8.hpp"
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    43
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    44
// We used to not resize at all, so let's be conservative
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    45
// and not set it too short before we decide to resize,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    46
// to match previous startup behavior
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
    47
const double PREF_AVG_LIST_LEN = 8.0;
57593
f40a73b61b5e 8227123: Assertion failure when setting SymbolTableSize larger than 2^17 (131,072)
coleenp
parents: 55478
diff changeset
    48
// 2^24 is max size, like StringTable.
f40a73b61b5e 8227123: Assertion failure when setting SymbolTableSize larger than 2^17 (131,072)
coleenp
parents: 55478
diff changeset
    49
const size_t END_SIZE = 24;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    50
// If a chain gets to 100 something might be wrong
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
    51
const size_t REHASH_LEN = 100;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    52
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
    53
const size_t ON_STACK_BUFFER_LENGTH = 128;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// --------------------------------------------------------------------------
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    56
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    57
inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    58
  if (value->equals(key, len)) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    59
    assert(value->refcount() == PERM_REFCOUNT, "must be shared");
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    60
    return true;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    61
  } else {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    62
    return false;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    63
  }
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    64
}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    65
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52047
diff changeset
    66
static OffsetCompactHashtable<
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    67
  const char*, Symbol*,
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    68
  symbol_equals_compact_hashtable_entry
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    69
> _shared_table;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    70
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    71
static OffsetCompactHashtable<
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    72
  const char*, Symbol*,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    73
  symbol_equals_compact_hashtable_entry
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    74
> _dynamic_shared_table;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
    75
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
    76
// --------------------------------------------------------------------------
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    77
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
    78
typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    79
static SymbolTableHash* _local_table = NULL;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    80
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    81
volatile bool SymbolTable::_has_work = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    82
volatile bool SymbolTable::_needs_rehashing = false;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    83
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    84
// For statistics
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    85
static size_t _symbols_removed = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    86
static size_t _symbols_counted = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    87
static size_t _current_size = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    88
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    89
static volatile size_t _items_count = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    90
static volatile bool   _has_items_to_clean = false;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    91
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    92
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    93
static volatile bool _alt_hash = false;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    94
static volatile bool _lookup_shared_first = false;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
    95
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    96
// Static arena for symbols that are not deallocated
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    97
Arena* SymbolTable::_arena = NULL;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    98
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
    99
static juint murmur_seed = 0;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   100
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   101
static inline void log_trace_symboltable_helper(Symbol* sym, const char* msg) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   102
#ifndef PRODUCT
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   103
  ResourceMark rm;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   104
  log_trace(symboltable)("%s [%s]", msg, sym->as_quoted_ascii());
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   105
#endif // PRODUCT
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   106
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   107
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   108
// Pick hashing algorithm.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   109
static uintx hash_symbol(const char* s, int len, bool useAlt) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   110
  return useAlt ?
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   111
  AltHashing::murmur3_32(murmur_seed, (const jbyte*)s, len) :
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   112
  java_lang_String::hash_code((const jbyte*)s, len);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   113
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   114
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   115
#if INCLUDE_CDS
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   116
static uintx hash_shared_symbol(const char* s, int len) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   117
  return java_lang_String::hash_code((const jbyte*)s, len);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   118
}
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   119
#endif
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   120
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   121
class SymbolTableConfig : public AllStatic {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   122
private:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   123
public:
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   124
  typedef Symbol* Value;  // value of the Node in the hashtable
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   125
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   126
  static uintx get_hash(Value const& value, bool* is_dead) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   127
    *is_dead = (value->refcount() == 0);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   128
    if (*is_dead) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   129
      return 0;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   130
    } else {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   131
      return hash_symbol((const char*)value->bytes(), value->utf8_length(), _alt_hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   132
    }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   133
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   134
  // We use default allocation/deallocation but counted
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   135
  static void* allocate_node(size_t size, Value const& value) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   136
    SymbolTable::item_added();
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   137
    return AllocateHeap(size, mtSymbol);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   138
  }
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   139
  static void free_node(void* memory, Value const& value) {
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   140
    // We get here because #1 some threads lost a race to insert a newly created Symbol
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   141
    // or #2 we're cleaning up unused symbol.
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   142
    // If #1, then the symbol can be either permanent (refcount==PERM_REFCOUNT),
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   143
    // or regular newly created one (refcount==1)
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   144
    // If #2, then the symbol is dead (refcount==0)
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   145
    assert((value->refcount() == PERM_REFCOUNT) || (value->refcount() == 1) || (value->refcount() == 0),
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   146
           "refcount %d", value->refcount());
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   147
    if (value->refcount() == 1) {
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   148
      value->decrement_refcount();
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   149
      assert(value->refcount() == 0, "expected dead symbol");
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   150
    }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   151
    SymbolTable::delete_symbol(value);
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 55328
diff changeset
   152
    FreeHeap(memory);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   153
    SymbolTable::item_removed();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   154
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   155
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   156
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   157
static size_t ceil_log2(size_t value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   158
  size_t ret;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   159
  for (ret = 1; ((size_t)1 << ret) < value; ++ret);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   160
  return ret;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   161
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   162
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   163
void SymbolTable::create_table ()  {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   164
  size_t start_size_log_2 = ceil_log2(SymbolTableSize);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   165
  _current_size = ((size_t)1) << start_size_log_2;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   166
  log_trace(symboltable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   167
                         _current_size, start_size_log_2);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   168
  _local_table = new SymbolTableHash(start_size_log_2, END_SIZE, REHASH_LEN);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   169
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   170
  // Initialize the arena for global symbols, size passed in depends on CDS.
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   171
  if (symbol_alloc_arena_size == 0) {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   172
    _arena = new (mtSymbol) Arena(mtSymbol);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   173
  } else {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   174
    _arena = new (mtSymbol) Arena(mtSymbol, symbol_alloc_arena_size);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   175
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   176
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   177
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   178
void SymbolTable::delete_symbol(Symbol* sym) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   179
  if (sym->refcount() == PERM_REFCOUNT) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54347
diff changeset
   180
    MutexLocker ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag); // Protect arena
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   181
    // Deleting permanent symbol should not occur very often (insert race condition),
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   182
    // so log it.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   183
    log_trace_symboltable_helper(sym, "Freeing permanent symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   184
    if (!arena()->Afree(sym, sym->size())) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   185
      log_trace_symboltable_helper(sym, "Leaked permanent symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   186
    }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   187
  } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   188
    delete sym;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   189
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   190
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   191
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   192
void SymbolTable::reset_has_items_to_clean() { Atomic::store(false, &_has_items_to_clean); }
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   193
void SymbolTable::mark_has_items_to_clean()  { Atomic::store(true, &_has_items_to_clean); }
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   194
bool SymbolTable::has_items_to_clean()       { return Atomic::load(&_has_items_to_clean); }
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   195
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   196
void SymbolTable::item_added() {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   197
  Atomic::inc(&_items_count);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   198
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   200
void SymbolTable::item_removed() {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   201
  Atomic::inc(&(_symbols_removed));
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   202
  Atomic::dec(&_items_count);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   203
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   204
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   205
double SymbolTable::get_load_factor() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   206
  return (double)_items_count/_current_size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   207
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   208
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   209
size_t SymbolTable::table_size() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   210
  return ((size_t)1) << _local_table->get_size_log2(Thread::current());
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   211
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   212
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   213
void SymbolTable::trigger_cleanup() {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54347
diff changeset
   214
  MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   215
  _has_work = true;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   216
  Service_lock->notify_all();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   217
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   218
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   219
Symbol* SymbolTable::allocate_symbol(const char* name, int len, bool c_heap) {
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   220
  assert (len <= Symbol::max_length(), "should be checked by caller");
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   221
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   222
  Symbol* sym;
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 57593
diff changeset
   223
  if (Arguments::is_dumping_archive()) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   224
    c_heap = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   225
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   226
  if (c_heap) {
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   227
    // refcount starts as 1
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   228
    sym = new (len) Symbol((const u1*)name, len, 1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13199
diff changeset
   229
    assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13199
diff changeset
   230
  } else {
15934
104ff83451f1 8009829: CDS: JDK JPRT test fails crash in Symbol::equals()
coleenp
parents: 14742
diff changeset
   231
    // Allocate to global arena
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54347
diff changeset
   232
    MutexLocker ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag); // Protect arena
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   233
    sym = new (len, arena()) Symbol((const u1*)name, len, PERM_REFCOUNT);
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   234
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   235
  return sym;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   236
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   237
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   238
class SymbolsDo : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   239
  SymbolClosure *_cl;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   240
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   241
  SymbolsDo(SymbolClosure *cl) : _cl(cl) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   242
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   243
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   244
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   245
    _cl->do_symbol(value);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   246
    return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   247
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   248
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   249
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   250
class SharedSymbolIterator {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   251
  SymbolClosure* _symbol_closure;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   252
public:
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   253
  SharedSymbolIterator(SymbolClosure* f) : _symbol_closure(f) {}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   254
  void do_value(Symbol* symbol) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   255
    _symbol_closure->do_symbol(&symbol);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   256
  }
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   257
};
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   258
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   259
// Call function for all symbols in the symbol table.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   260
void SymbolTable::symbols_do(SymbolClosure *cl) {
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   261
  // all symbols from shared table
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   262
  SharedSymbolIterator iter(cl);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51520
diff changeset
   263
  _shared_table.iterate(&iter);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   264
  _dynamic_shared_table.iterate(&iter);
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   265
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   266
  // all symbols from the dynamic table
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   267
  SymbolsDo sd(cl);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   268
  if (!_local_table->try_scan(Thread::current(), sd)) {
55328
d9a157f6fd71 8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents: 55134
diff changeset
   269
    log_info(symboltable)("symbols_do unavailable at this moment");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   270
  }
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20283
diff changeset
   271
}
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20283
diff changeset
   272
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   273
class MetaspacePointersDo : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   274
  MetaspaceClosure *_it;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   275
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   276
  MetaspacePointersDo(MetaspaceClosure *it) : _it(it) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   277
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   278
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   279
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   280
    _it->push(value);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   281
    return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   282
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   283
};
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20283
diff changeset
   284
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   285
void SymbolTable::metaspace_pointers_do(MetaspaceClosure* it) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 57593
diff changeset
   286
  Arguments::assert_is_dumping_archive();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   287
  MetaspacePointersDo mpd(it);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   288
  _local_table->do_safepoint_scan(mpd);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   289
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   290
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   291
Symbol* SymbolTable::lookup_dynamic(const char* name,
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   292
                                    int len, unsigned int hash) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   293
  Symbol* sym = do_lookup(name, len, hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   294
  assert((sym == NULL) || sym->refcount() != 0, "refcount must not be zero");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   295
  return sym;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   298
#if INCLUDE_CDS
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   299
Symbol* SymbolTable::lookup_shared(const char* name,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   300
                                   int len, unsigned int hash) {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   301
  Symbol* sym = NULL;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   302
  if (!_shared_table.empty()) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   303
    if (_alt_hash) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   304
      // hash_code parameter may use alternate hashing algorithm but the shared table
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   305
      // always uses the same original hash code.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   306
      hash = hash_shared_symbol(name, len);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   307
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   308
    sym = _shared_table.lookup(name, hash, len);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   309
    if (sym == NULL && DynamicArchive::is_mapped()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   310
      sym = _dynamic_shared_table.lookup(name, hash, len);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   311
    }
37198
b96542d1afa1 8152380: Shared symbol table should never use alternate hashcode
iklam
parents: 35898
diff changeset
   312
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   313
  return sym;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   314
}
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   315
#endif
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   316
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   317
Symbol* SymbolTable::lookup_common(const char* name,
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   318
                            int len, unsigned int hash) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   319
  Symbol* sym;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   320
  if (_lookup_shared_first) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   321
    sym = lookup_shared(name, len, hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   322
    if (sym == NULL) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   323
      _lookup_shared_first = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   324
      sym = lookup_dynamic(name, len, hash);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   325
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   326
  } else {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   327
    sym = lookup_dynamic(name, len, hash);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   328
    if (sym == NULL) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   329
      sym = lookup_shared(name, len, hash);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   330
      if (sym != NULL) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   331
        _lookup_shared_first = true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   332
      }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   333
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   334
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   335
  return sym;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   336
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   337
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   338
Symbol* SymbolTable::new_symbol(const char* name, int len) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   339
  unsigned int hash = hash_symbol(name, len, _alt_hash);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   340
  Symbol* sym = lookup_common(name, len, hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   341
  if (sym == NULL) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   342
    sym = do_add_if_needed(name, len, hash, true);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   343
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   344
  assert(sym->refcount() != 0, "lookup should have incremented the count");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   345
  assert(sym->equals(name, len), "symbol must be properly initialized");
39713
29ece76096cb 8150752: Share Class Data
iklam
parents: 37995
diff changeset
   346
  return sym;
29ece76096cb 8150752: Share Class Data
iklam
parents: 37995
diff changeset
   347
}
29ece76096cb 8150752: Share Class Data
iklam
parents: 37995
diff changeset
   348
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   349
Symbol* SymbolTable::new_symbol(const Symbol* sym, int begin, int end) {
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   350
  assert(begin <= end && end <= sym->utf8_length(), "just checking");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   351
  assert(sym->refcount() != 0, "require a valid symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   352
  const char* name = (const char*)sym->base() + begin;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   353
  int len = end - begin;
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   354
  unsigned int hash = hash_symbol(name, len, _alt_hash);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   355
  Symbol* found = lookup_common(name, len, hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   356
  if (found == NULL) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   357
    found = do_add_if_needed(name, len, hash, true);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   358
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   359
  return found;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   362
class SymbolTableLookup : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   363
private:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   364
  Thread* _thread;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   365
  uintx _hash;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   366
  int _len;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   367
  const char* _str;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   368
public:
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   369
  SymbolTableLookup(const char* key, int len, uintx hash)
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   370
  : _hash(hash), _len(len), _str(key) {}
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   371
  uintx get_hash() const {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   372
    return _hash;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   374
  bool equals(Symbol** value, bool* is_dead) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   375
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   376
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   377
    Symbol *sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   378
    if (sym->equals(_str, _len)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   379
      if (sym->try_increment_refcount()) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   380
        // something is referencing this symbol now.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   381
        return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   382
      } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   383
        assert(sym->refcount() == 0, "expected dead symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   384
        *is_dead = true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   385
        return false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   386
      }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   387
    } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   388
      *is_dead = (sym->refcount() == 0);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   389
      return false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   390
    }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   391
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   392
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   394
class SymbolTableGet : public StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   395
  Symbol* _return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   396
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   397
  SymbolTableGet() : _return(NULL) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   398
  void operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   399
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   400
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   401
    _return = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   402
  }
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
   403
  Symbol* get_res_sym() const {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   404
    return _return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   406
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   407
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   408
Symbol* SymbolTable::do_lookup(const char* name, int len, uintx hash) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   409
  Thread* thread = Thread::current();
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   410
  SymbolTableLookup lookup(name, len, hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   411
  SymbolTableGet stg;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   412
  bool rehash_warning = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   413
  _local_table->get(thread, lookup, stg, &rehash_warning);
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   414
  update_needs_rehash(rehash_warning);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   415
  Symbol* sym = stg.get_res_sym();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   416
  assert((sym == NULL) || sym->refcount() != 0, "found dead symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   417
  return sym;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   420
Symbol* SymbolTable::lookup_only(const char* name, int len, unsigned int& hash) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   421
  hash = hash_symbol(name, len, _alt_hash);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   422
  return lookup_common(name, len, hash);
11480
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 8885
diff changeset
   423
}
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 8885
diff changeset
   424
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   425
// Suggestion: Push unicode-based lookup all the way into the hashing
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   426
// and probing logic, so there is no need for convert_to_utf8 until
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   427
// an actual new Symbol* is created.
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   428
Symbol* SymbolTable::new_symbol(const jchar* name, int utf16_length) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   429
  int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   430
  char stack_buf[ON_STACK_BUFFER_LENGTH];
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   431
  if (utf8_length < (int) sizeof(stack_buf)) {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   432
    char* chars = stack_buf;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   433
    UNICODE::convert_to_utf8(name, utf16_length, chars);
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   434
    return new_symbol(chars, utf8_length);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   435
  } else {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   436
    ResourceMark rm;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   437
    char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   438
    UNICODE::convert_to_utf8(name, utf16_length, chars);
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   439
    return new_symbol(chars, utf8_length);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   440
  }
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   441
}
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   442
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   443
Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   444
                                         unsigned int& hash) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   445
  int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   446
  char stack_buf[ON_STACK_BUFFER_LENGTH];
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   447
  if (utf8_length < (int) sizeof(stack_buf)) {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   448
    char* chars = stack_buf;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   449
    UNICODE::convert_to_utf8(name, utf16_length, chars);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   450
    return lookup_only(chars, utf8_length, hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   451
  } else {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   452
    ResourceMark rm;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   453
    char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   454
    UNICODE::convert_to_utf8(name, utf16_length, chars);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   455
    return lookup_only(chars, utf8_length, hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   456
  }
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   457
}
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2131
diff changeset
   458
53898
853b82a25d53 8219554: Redundant lookup_common in SymbolTable::add
redestad
parents: 53587
diff changeset
   459
void SymbolTable::new_symbols(ClassLoaderData* loader_data, const constantPoolHandle& cp,
853b82a25d53 8219554: Redundant lookup_common in SymbolTable::add
redestad
parents: 53587
diff changeset
   460
                              int names_count, const char** names, int* lengths,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   461
                              int* cp_indices, unsigned int* hashValues) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   462
  bool c_heap = !loader_data->is_the_null_class_loader_data();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   463
  for (int i = 0; i < names_count; i++) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   464
    const char *name = names[i];
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   465
    int len = lengths[i];
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   466
    unsigned int hash = hashValues[i];
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   467
    assert(lookup_shared(name, len, hash) == NULL, "must have checked already");
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   468
    Symbol* sym = do_add_if_needed(name, len, hash, c_heap);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   469
    assert(sym->refcount() != 0, "lookup should have incremented the count");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   470
    cp->symbol_at_put(cp_indices[i], sym);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   471
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   472
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   473
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   474
Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, bool heap) {
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   475
  SymbolTableLookup lookup(name, len, hash);
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   476
  SymbolTableGet stg;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   477
  bool clean_hint = false;
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   478
  bool rehash_warning = false;
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   479
  Symbol* sym = NULL;
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   480
  Thread* THREAD = Thread::current();
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   481
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   482
  do {
54942
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   483
    // Callers have looked up the symbol once, insert the symbol.
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   484
    sym = allocate_symbol(name, len, heap);
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   485
    if (_local_table->insert(THREAD, lookup, sym, &rehash_warning, &clean_hint)) {
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   486
      break;
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   487
    }
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   488
    // In case another thread did a concurrent add, return value already in the table.
2523496f5107 8221967: InternTest.java timed out
coleenp
parents: 54927
diff changeset
   489
    // This could fail if the symbol got deleted concurrently, so loop back until success.
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   490
    if (_local_table->get(THREAD, lookup, stg, &rehash_warning)) {
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   491
      sym = stg.get_res_sym();
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   492
      break;
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   493
    }
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   494
  } while(true);
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   495
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   496
  update_needs_rehash(rehash_warning);
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   497
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   498
  if (clean_hint) {
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   499
    mark_has_items_to_clean();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   500
    check_concurrent_work();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   501
  }
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   502
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   503
  assert((sym == NULL) || sym->refcount() != 0, "found dead symbol");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   504
  return sym;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   505
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   506
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   507
Symbol* SymbolTable::new_permanent_symbol(const char* name) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   508
  unsigned int hash = 0;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   509
  int len = (int)strlen(name);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   510
  Symbol* sym = SymbolTable::lookup_only(name, len, hash);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   511
  if (sym == NULL) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   512
    sym = do_add_if_needed(name, len, hash, false);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   513
  }
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53898
diff changeset
   514
  if (!sym->is_permanent()) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53898
diff changeset
   515
    sym->make_permanent();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   516
    log_trace_symboltable_helper(sym, "Asked for a permanent symbol, but got a regular one");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   517
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   518
  return sym;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   519
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   520
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   521
struct SizeFunc : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   522
  size_t operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   523
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   524
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   525
    return (*value)->size() * HeapWordSize;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   526
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   527
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   528
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   529
TableStatistics SymbolTable::get_table_statistics() {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   530
  static TableStatistics ts;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   531
  SizeFunc sz;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   532
  ts = _local_table->statistics_get(Thread::current(), sz, ts);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   533
  return ts;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   534
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54623
diff changeset
   535
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   536
void SymbolTable::print_table_statistics(outputStream* st,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   537
                                         const char* table_name) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   538
  SizeFunc sz;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   539
  _local_table->statistics_to(Thread::current(), sz, st, table_name);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   540
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   541
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   542
// Verification
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   543
class VerifySymbols : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   544
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   545
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   546
    guarantee(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   547
    guarantee(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   548
    Symbol* sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   549
    guarantee(sym->equals((const char*)sym->bytes(), sym->utf8_length()),
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   550
              "symbol must be internally consistent");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   551
    return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   552
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   553
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   554
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   555
void SymbolTable::verify() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   556
  Thread* thr = Thread::current();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   557
  VerifySymbols vs;
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   558
  if (!_local_table->try_scan(thr, vs)) {
55328
d9a157f6fd71 8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents: 55134
diff changeset
   559
    log_info(symboltable)("verify unavailable at this moment");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   560
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   561
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   562
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   563
// Dumping
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   564
class DumpSymbol : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   565
  Thread* _thr;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   566
  outputStream* _st;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   567
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   568
  DumpSymbol(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   569
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   570
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   571
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   572
    Symbol* sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   573
    const char* utf8_string = (const char*)sym->bytes();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   574
    int utf8_length = sym->utf8_length();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   575
    _st->print("%d %d: ", utf8_length, sym->refcount());
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   576
    HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   577
    _st->cr();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   578
    return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   579
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   580
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   581
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   582
void SymbolTable::dump(outputStream* st, bool verbose) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   583
  if (!verbose) {
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   584
    print_table_statistics(st, "SymbolTable");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   585
  } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   586
    Thread* thr = Thread::current();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   587
    ResourceMark rm(thr);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   588
    st->print_cr("VERSION: 1.1");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   589
    DumpSymbol ds(thr, st);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   590
    if (!_local_table->try_scan(thr, ds)) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   591
      log_info(symboltable)("dump unavailable at this moment");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   596
#if INCLUDE_CDS
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   597
struct CopyToArchive : StackObj {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   598
  CompactHashtableWriter* _writer;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   599
  CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   600
  bool operator()(Symbol** value) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   601
    assert(value != NULL, "expected valid value");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   602
    assert(*value != NULL, "value should point to a symbol");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   603
    Symbol* sym = *value;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   604
    unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   605
    assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   606
           "must not rehash during dumping");
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   607
    if (DynamicDumpSharedSpaces) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   608
      sym = DynamicArchive::original_to_target(sym);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   609
    }
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52047
diff changeset
   610
    _writer->add(fixed_hash, MetaspaceShared::object_delta_u4(sym));
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   611
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   613
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   615
void SymbolTable::copy_shared_symbol_table(CompactHashtableWriter* writer) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   616
  CopyToArchive copy(writer);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   617
  _local_table->do_safepoint_scan(copy);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   618
}
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   619
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   620
size_t SymbolTable::estimate_size_for_archive() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   621
  return CompactHashtableWriter::estimate_size(int(_items_count));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   622
}
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   623
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   624
void SymbolTable::write_to_archive(bool is_static_archive) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   625
  CompactHashtableWriter writer(int(_items_count),
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51997
diff changeset
   626
                                &MetaspaceShared::stats()->symbol);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   627
  copy_shared_symbol_table(&writer);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   628
  if (is_static_archive) {
55134
72474808e305 8224692: runtime/appcds tests crash in "HotSpotJVMCI::compute_offset" when running in Graal as JIT mode
iklam
parents: 54942
diff changeset
   629
    _shared_table.reset();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   630
    writer.dump(&_shared_table, "symbol");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   631
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   632
    // Verify table is correct
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   633
    Symbol* sym = vmSymbols::java_lang_Object();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   634
    const char* name = (const char*)sym->bytes();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   635
    int len = sym->utf8_length();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   636
    unsigned int hash = hash_symbol(name, len, _alt_hash);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   637
    assert(sym == _shared_table.lookup(name, hash, len), "sanity");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   638
  } else {
55134
72474808e305 8224692: runtime/appcds tests crash in "HotSpotJVMCI::compute_offset" when running in Graal as JIT mode
iklam
parents: 54942
diff changeset
   639
    _dynamic_shared_table.reset();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   640
    writer.dump(&_dynamic_shared_table, "symbol");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   641
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   642
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   643
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   644
void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   645
                                                bool is_static_archive) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   646
  OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   647
  if (is_static_archive) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   648
    table = &_shared_table;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   649
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   650
    table = &_dynamic_shared_table;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   651
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   652
  table->serialize_header(soc);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   653
  if (soc->writing()) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   654
    // Sanity. Make sure we don't use the shared table at dump time
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54896
diff changeset
   655
    table->reset();
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   656
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   657
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   658
#endif //INCLUDE_CDS
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   659
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   660
// Concurrent work
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   661
void SymbolTable::grow(JavaThread* jt) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   662
  SymbolTableHash::GrowTask gt(_local_table);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   663
  if (!gt.prepare(jt)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   664
    return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   665
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   666
  log_trace(symboltable)("Started to grow");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   667
  {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   668
    TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   669
    while (gt.do_task(jt)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   670
      gt.pause(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   671
      {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   672
        ThreadBlockInVM tbivm(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   673
      }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   674
      gt.cont(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   675
    }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   676
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   677
  gt.done(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   678
  _current_size = table_size();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   679
  log_debug(symboltable)("Grown to size:" SIZE_FORMAT, _current_size);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   680
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   681
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   682
struct SymbolTableDoDelete : StackObj {
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
   683
  size_t _deleted;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   684
  SymbolTableDoDelete() : _deleted(0) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   685
  void operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   686
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   687
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   688
    Symbol *sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   689
    assert(sym->refcount() == 0, "refcount");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   690
    _deleted++;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   691
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   692
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   693
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   694
struct SymbolTableDeleteCheck : StackObj {
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
   695
  size_t _processed;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   696
  SymbolTableDeleteCheck() : _processed(0) {}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   697
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   698
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   699
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   700
    _processed++;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   701
    Symbol *sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   702
    return (sym->refcount() == 0);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   703
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   704
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   705
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   706
void SymbolTable::clean_dead_entries(JavaThread* jt) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   707
  SymbolTableHash::BulkDeleteTask bdt(_local_table);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   708
  if (!bdt.prepare(jt)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   709
    return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   710
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   711
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   712
  SymbolTableDeleteCheck stdc;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   713
  SymbolTableDoDelete stdd;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   714
  {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   715
    TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf));
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   716
    while (bdt.do_task(jt, stdc, stdd)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   717
      bdt.pause(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   718
      {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   719
        ThreadBlockInVM tbivm(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   720
      }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   721
      bdt.cont(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   722
    }
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   723
    reset_has_items_to_clean();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   724
    bdt.done(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   725
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   726
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
   727
  Atomic::add(stdc._processed, &_symbols_counted);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   728
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52516
diff changeset
   729
  log_debug(symboltable)("Cleaned " SIZE_FORMAT " of " SIZE_FORMAT,
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   730
                         stdd._deleted, stdc._processed);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   731
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   732
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   733
void SymbolTable::check_concurrent_work() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   734
  if (_has_work) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   735
    return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   736
  }
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   737
  // We should clean/resize if we have
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   738
  // more items than preferred load factor or
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   739
  // more dead items than water mark.
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   740
  if (has_items_to_clean() || (get_load_factor() > PREF_AVG_LIST_LEN)) {
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   741
    log_debug(symboltable)("Concurrent work triggered, load factor: %f, items to clean: %s",
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   742
                           get_load_factor(), has_items_to_clean() ? "true" : "false");
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   743
    trigger_cleanup();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   744
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   745
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   746
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   747
void SymbolTable::do_concurrent_work(JavaThread* jt) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   748
  double load_factor = get_load_factor();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   749
  log_debug(symboltable, perf)("Concurrent work, live factor: %g", load_factor);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   750
  // We prefer growing, since that also removes dead items
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   751
  if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   752
    grow(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   753
  } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   754
    clean_dead_entries(jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   755
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   756
  _has_work = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   757
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   758
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   759
// Rehash
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   760
bool SymbolTable::do_rehash() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   761
  if (!_local_table->is_safepoint_safe()) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   762
    return false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   763
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   764
55328
d9a157f6fd71 8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents: 55134
diff changeset
   765
  // We use current size
d9a157f6fd71 8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents: 55134
diff changeset
   766
  size_t new_size = _local_table->get_size_log2(Thread::current());
d9a157f6fd71 8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents: 55134
diff changeset
   767
  SymbolTableHash* new_table = new SymbolTableHash(new_size, END_SIZE, REHASH_LEN);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   768
  // Use alt hash from now on
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   769
  _alt_hash = true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   770
  if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   771
    _alt_hash = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   772
    delete new_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   773
    return false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   774
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   775
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   776
  // free old table
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   777
  delete _local_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   778
  _local_table = new_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   779
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   780
  return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   781
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   782
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   783
void SymbolTable::rehash_table() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   784
  static bool rehashed = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   785
  log_debug(symboltable)("Table imbalanced, rehashing called.");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   786
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   787
  // Grow instead of rehash.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   788
  if (get_load_factor() > PREF_AVG_LIST_LEN &&
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   789
      !_local_table->is_max_size_reached()) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   790
    log_debug(symboltable)("Choosing growing over rehashing.");
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   791
    trigger_cleanup();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   792
    _needs_rehashing = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   793
    return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   794
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   795
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   796
  // Already rehashed.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   797
  if (rehashed) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   798
    log_warning(symboltable)("Rehashing already done, still long lists.");
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 52951
diff changeset
   799
    trigger_cleanup();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   800
    _needs_rehashing = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   801
    return;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   802
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   803
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   804
  murmur_seed = AltHashing::compute_seed();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   805
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   806
  if (do_rehash()) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   807
    rehashed = true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   808
  } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   809
    log_info(symboltable)("Resizes in progress rehashing skipped.");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   810
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   811
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   812
  _needs_rehashing = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   813
}
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   814
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
//---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   820
class HistogramIterator : StackObj {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   821
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   822
  static const size_t results_length = 100;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   823
  size_t counts[results_length];
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   824
  size_t sizes[results_length];
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   825
  size_t total_size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   826
  size_t total_count;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   827
  size_t total_length;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   828
  size_t max_length;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   829
  size_t out_of_range_count;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   830
  size_t out_of_range_size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   831
  HistogramIterator() : total_size(0), total_count(0), total_length(0),
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   832
                        max_length(0), out_of_range_count(0), out_of_range_size(0) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   833
    // initialize results to zero
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   834
    for (size_t i = 0; i < results_length; i++) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   835
      counts[i] = 0;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   836
      sizes[i] = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   839
  bool operator()(Symbol** value) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   840
    assert(value != NULL, "expected valid value");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   841
    assert(*value != NULL, "value should point to a symbol");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   842
    Symbol* sym = *value;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   843
    size_t size = sym->size();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   844
    size_t len = sym->utf8_length();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   845
    if (len < results_length) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   846
      counts[len]++;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   847
      sizes[len] += size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   848
    } else {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   849
      out_of_range_count++;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   850
      out_of_range_size += size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   851
    }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   852
    total_count++;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   853
    total_size += size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   854
    total_length += len;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   855
    max_length = MAX2(max_length, len);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   856
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   857
    return true;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   858
  };
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   859
};
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   860
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   861
void SymbolTable::print_histogram() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   862
  HistogramIterator hi;
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   863
  _local_table->do_scan(Thread::current(), hi);
26923
60c1555c25c5 8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents: 26421
diff changeset
   864
  tty->print_cr("Symbol Table Histogram:");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   865
  tty->print_cr("  Total number of symbols  " SIZE_FORMAT_W(7), hi.total_count);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   866
  tty->print_cr("  Total size in memory     " SIZE_FORMAT_W(7) "K",
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   867
          (hi.total_size * wordSize) / 1024);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   868
  tty->print_cr("  Total counted            " SIZE_FORMAT_W(7), _symbols_counted);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   869
  tty->print_cr("  Total removed            " SIZE_FORMAT_W(7), _symbols_removed);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   870
  if (_symbols_counted > 0) {
26923
60c1555c25c5 8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents: 26421
diff changeset
   871
    tty->print_cr("  Percent removed          %3.2f",
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54847
diff changeset
   872
          ((float)_symbols_removed / _symbols_counted) * 100);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   873
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   874
  tty->print_cr("  Reference counts         " SIZE_FORMAT_W(7), Symbol::_total_count);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   875
  tty->print_cr("  Symbol arena used        " SIZE_FORMAT_W(7) "K", arena()->used() / 1024);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   876
  tty->print_cr("  Symbol arena size        " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / 1024);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   877
  tty->print_cr("  Total symbol length      " SIZE_FORMAT_W(7), hi.total_length);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   878
  tty->print_cr("  Maximum symbol length    " SIZE_FORMAT_W(7), hi.max_length);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   879
  tty->print_cr("  Average symbol length    %7.2f", ((float)hi.total_length / hi.total_count));
26923
60c1555c25c5 8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents: 26421
diff changeset
   880
  tty->print_cr("  Symbol length histogram:");
60c1555c25c5 8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents: 26421
diff changeset
   881
  tty->print_cr("    %6s %10s %10s", "Length", "#Symbols", "Size");
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   882
  for (size_t i = 0; i < hi.results_length; i++) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   883
    if (hi.counts[i] > 0) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   884
      tty->print_cr("    " SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K",
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   885
                    i, hi.counts[i], (hi.sizes[i] * wordSize) / 1024);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  }
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   888
  tty->print_cr("  >=" SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K\n",
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   889
                hi.results_length, hi.out_of_range_count, (hi.out_of_range_size*wordSize) / 1024);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
#endif // PRODUCT
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   892
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   893
// Utility for dumping symbols
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   894
SymboltableDCmd::SymboltableDCmd(outputStream* output, bool heap) :
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   895
                                 DCmdWithParser(output, heap),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   896
  _verbose("-verbose", "Dump the content of each symbol in the table",
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   897
           "BOOLEAN", false, "false") {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   898
  _dcmdparser.add_dcmd_option(&_verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   899
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   900
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   901
void SymboltableDCmd::execute(DCmdSource source, TRAPS) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   902
  VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSymbols,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   903
                         _verbose.value());
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   904
  VMThread::execute(&dumper);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   905
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   906
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   907
int SymboltableDCmd::num_arguments() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   908
  ResourceMark rm;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   909
  SymboltableDCmd* dcmd = new SymboltableDCmd(NULL, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   910
  if (dcmd != NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   911
    DCmdMark mark(dcmd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   912
    return dcmd->_dcmdparser.num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   913
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   914
    return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   915
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27677
diff changeset
   916
}