src/hotspot/share/classfile/stringTable.hpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 57828 35db8fba55f9
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:
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 "memory/allocation.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    29
#include "memory/padded.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    30
#include "oops/oop.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    31
#include "oops/weakHandle.hpp"
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    32
#include "utilities/tableStatistics.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    33
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
    34
class CompactHashtableWriter;
57828
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents: 54896
diff changeset
    35
class JavaThread;
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 void grow(JavaThread* jt);
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    55
  static void clean_dead_entries(JavaThread* jt);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    56
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    57
  static double get_load_factor();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    58
  static double get_dead_factor();
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
    59
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    60
  static void check_concurrent_work();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    61
  static void trigger_concurrent_work();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    62
50676
8c0a5b51559b 8203030: Zero s390 31 bit size_t type conflicts in shared code
chrisphi
parents: 50556
diff changeset
    63
  static size_t item_added();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    64
  static void item_removed();
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    65
  static size_t add_items_to_clean(size_t ndead);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 37995
diff changeset
    66
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51537
diff changeset
    67
  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
    68
  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
    69
  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
    70
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    71
  static void print_table_statistics(outputStream* st, const char* table_name);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    72
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    73
  static bool do_rehash();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    74
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    75
 public:
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    76
  static size_t table_size();
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    77
  static TableStatistics get_table_statistics();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    78
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    79
  static void create_table();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    81
  static void do_concurrent_work(JavaThread* jt);
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    82
  static bool has_work() { return _has_work; }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
    83
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    84
  // GC support
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    85
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    86
  // Must be called before a parallel walk where strings might die.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    87
  static void reset_dead_counter() { _uncleaned_items_count = 0; }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    88
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    89
  // 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
    90
  // cleaning. Note it might trigger a resize instead.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    91
  static void finish_dead_counter() { check_concurrent_work(); }
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    92
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
    93
  // 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
    94
  // strings to this method.
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    95
  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
    96
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    97
  // 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
    98
  // Used by JFR leak profiler.  TODO: it should find these oops through
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
    99
  // the WeakProcessor.
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   100
  static void oops_do(OopClosure* f);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   101
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   102
  // Probing
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   103
  static oop lookup(Symbol* symbol);
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51537
diff changeset
   104
  static oop lookup(const jchar* chars, int length);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   105
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   106
  // Interning
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   107
  static oop intern(Symbol* symbol, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   108
  static oop intern(oop string, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   109
  static oop intern(const char *utf8_string, TRAPS);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   110
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   111
  // 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
   112
  static void rehash_table();
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   113
  static bool needs_rehashing() { return _needs_rehashing; }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   114
  static inline void update_needs_rehash(bool rehash) {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   115
    if (rehash) {
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   116
      _needs_rehashing = true;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   117
    }
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   118
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   119
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   120
  // Sharing
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   121
 private:
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54764
diff changeset
   122
  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
   123
  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
   124
 public:
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   125
  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
   126
  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
   127
  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
   128
  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
   129
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   130
  // Jcmd
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   131
  static void dump(outputStream* st, bool verbose=false);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   132
  // Debugging
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   133
  static size_t verify_and_compare_entries();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   134
  static void verify();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 49621
diff changeset
   135
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   136
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52931
diff changeset
   137
#endif // SHARE_CLASSFILE_STRINGTABLE_HPP