src/hotspot/share/classfile/stringTable.hpp
author coleenp
Thu, 16 May 2019 07:09:17 -0400
changeset 54896 ea619918de95
parent 54764 865ec913f916
child 57828 35db8fba55f9
permissions -rw-r--r--
8223956: Make SymbolTable and StringTable AllStatic Summary: Removed superfluous and confusing _the_table pointer. Reviewed-by: gziemski, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52931
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     4
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     8
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    13
 * accompanied this code).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    14
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    18
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    21
 * questions.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    22
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    23
 */
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52931
diff changeset
    25
#ifndef SHARE_CLASSFILE_STRINGTABLE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52931
diff changeset
    26
#define SHARE_CLASSFILE_STRINGTABLE_HPP
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    27
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    28
#include "gc/shared/oopStorage.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    29
#include "memory/allocation.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    30
#include "memory/padded.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    31
#include "oops/oop.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    32
#include "oops/weakHandle.hpp"
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    33
#include "utilities/tableStatistics.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    34
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
    35
class CompactHashtableWriter;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37172
diff changeset
    36
class SerializeClosure;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28363
diff changeset
    37
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    38
class StringTable;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    39
class StringTableConfig;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    40
class StringTableCreateEntry;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    41
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    42
class StringTable : public CHeapObj<mtSymbol>{
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    43
  friend class VMStructs;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    44
  friend class Symbol;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    45
  friend class StringTableConfig;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    46
  friend class StringTableCreateEntry;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    47
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    48
  static volatile bool _has_work;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    49
  static volatile size_t _uncleaned_items_count;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    50
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 50676
diff changeset
    51
  // Set if one bucket is out of balance due to hash algorithm deficiency
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    52
  static volatile bool _needs_rehashing;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    53
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    54
  static OopStorage* _weak_handles;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    55
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    56
  static void grow(JavaThread* jt);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    57
  static void clean_dead_entries(JavaThread* jt);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    58
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    59
  static double get_load_factor();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    60
  static double get_dead_factor();
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
    61
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    62
  static void check_concurrent_work();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    63
  static void trigger_concurrent_work();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    64
50676
8c0a5b51559b 8203030: Zero s390 31 bit size_t type conflicts in shared code
chrisphi
parents: 50556
diff changeset
    65
  static size_t item_added();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    66
  static void item_removed();
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    67
  static size_t add_items_to_clean(size_t ndead);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 37995
diff changeset
    68
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51537
diff changeset
    69
  static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    70
  static oop do_intern(Handle string_or_null, const jchar* name, int len, uintx hash, TRAPS);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    71
  static oop do_lookup(const jchar* name, int len, uintx hash);
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 48157
diff changeset
    72
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    73
  static void print_table_statistics(outputStream* st, const char* table_name);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    74
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    75
  static bool do_rehash();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    76
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    77
 public:
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    78
  static size_t table_size();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    79
  static TableStatistics get_table_statistics();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    81
  static OopStorage* weak_storage() { return _weak_handles; }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    82
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    83
  static void create_table();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    84
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    85
  static void do_concurrent_work(JavaThread* jt);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    86
  static bool has_work() { return _has_work; }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    87
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    88
  // GC support
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    89
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    90
  // Must be called before a parallel walk where strings might die.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    91
  static void reset_dead_counter() { _uncleaned_items_count = 0; }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    92
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    93
  // After the parallel walk this method must be called to trigger
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    94
  // cleaning. Note it might trigger a resize instead.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    95
  static void finish_dead_counter() { check_concurrent_work(); }
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    96
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    97
  // If GC uses ParState directly it should add the number of cleared
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    98
  // strings to this method.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    99
  static void inc_dead_counter(size_t ndead) { add_items_to_clean(ndead); }
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   100
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   101
  // Serially invoke "f->do_oop" on the locations of all oops in the table.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   102
  // Used by JFR leak profiler.  TODO: it should find these oops through
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   103
  // the WeakProcessor.
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   104
  static void oops_do(OopClosure* f);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   105
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   106
  // Probing
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   107
  static oop lookup(Symbol* symbol);
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51537
diff changeset
   108
  static oop lookup(const jchar* chars, int length);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   109
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   110
  // Interning
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   111
  static oop intern(Symbol* symbol, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   112
  static oop intern(oop string, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   113
  static oop intern(const char *utf8_string, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   114
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   115
  // Rehash the string table if it gets out of balance
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   116
  static void rehash_table();
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   117
  static bool needs_rehashing() { return _needs_rehashing; }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   118
  static inline void update_needs_rehash(bool rehash) {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   119
    if (rehash) {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   120
      _needs_rehashing = true;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   121
    }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   122
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   123
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   124
  // Sharing
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   125
 private:
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   126
  static oop lookup_shared(const jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   127
  static void copy_shared_string_table(CompactHashtableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   128
 public:
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   129
  static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   130
  static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   131
  static void write_to_archive() NOT_CDS_JAVA_HEAP_RETURN;
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   132
  static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   133
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   134
  // Jcmd
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   135
  static void dump(outputStream* st, bool verbose=false);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   136
  // Debugging
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   137
  static size_t verify_and_compare_entries();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   138
  static void verify();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   139
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   140
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52931
diff changeset
   141
#endif // SHARE_CLASSFILE_STRINGTABLE_HPP