src/hotspot/share/classfile/symbolTable.hpp
author coleenp
Tue, 14 May 2019 11:29:18 -0400
changeset 54847 59ea39bb2809
parent 54764 865ec913f916
child 54896 ea619918de95
permissions -rw-r--r--
8223657: Remove unused THREAD argument from SymbolTable functions Summary: also made lookup and lookup_only functions private to SymbolTable. External callers use new_symbol or probe. Reviewed-by: dholmes, gziemski
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    25
#ifndef SHARE_CLASSFILE_SYMBOLTABLE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    26
#define SHARE_CLASSFILE_SYMBOLTABLE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
    28
#include "memory/allocation.hpp"
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    29
#include "memory/padded.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    30
#include "oops/symbol.hpp"
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    31
#include "utilities/concurrentHashTable.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/hashtable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 52951
diff changeset
    34
class JavaThread;
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 52951
diff changeset
    35
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    36
// TempNewSymbol acts as a handle class in a handle/body idiom and is
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    37
// responsible for proper resource management of the body (which is a Symbol*).
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    38
// The body is resource managed by a reference counting scheme.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    39
// TempNewSymbol can therefore be used to properly hold a newly created or referenced
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    40
// Symbol* temporarily in scope.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    41
//
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    42
// Routines in SymbolTable will initialize the reference count of a Symbol* before
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    43
// it becomes "managed" by TempNewSymbol instances. As a handle class, TempNewSymbol
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    44
// needs to maintain proper reference counting in context of copy semantics.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    45
//
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
    46
// In SymbolTable, new_symbol() will create a Symbol* if not already in the
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    47
// symbol table and add to the symbol's reference count.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
// probe() and lookup_only() will increment the refcount if symbol is found.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    49
class TempNewSymbol : public StackObj {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    50
  Symbol* _temp;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    51
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    52
public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    53
  TempNewSymbol() : _temp(NULL) {}
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    54
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    55
  // Conversion from a Symbol* to a TempNewSymbol.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    56
  // Does not increment the current reference count.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
  TempNewSymbol(Symbol *s) : _temp(s) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    59
  // Copy constructor increments reference count.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    60
  TempNewSymbol(const TempNewSymbol& rhs) : _temp(rhs._temp) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    61
    if (_temp != NULL) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    62
      _temp->increment_refcount();
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    63
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    64
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    65
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    66
  // Assignment operator uses a c++ trick called copy and swap idiom.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    67
  // rhs is passed by value so within the scope of this method it is a copy.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    68
  // At method exit it contains the former value of _temp, triggering the correct refcount
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    69
  // decrement upon destruction.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    70
  void operator=(TempNewSymbol rhs) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    71
    Symbol* tmp = rhs._temp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    72
    rhs._temp = _temp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    73
    _temp = tmp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    74
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    75
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    76
  // Decrement reference counter so it can go away if it's unused
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    77
  ~TempNewSymbol() {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    78
    if (_temp != NULL) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    79
      _temp->decrement_refcount();
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    80
    }
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    81
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    83
  // Symbol* conversion operators
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
  Symbol* operator -> () const                   { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    85
  bool    operator == (Symbol* o) const          { return _temp == o; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
  operator Symbol*()                             { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    87
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
    89
class CompactHashtableWriter;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    90
class SerializeClosure;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
    91
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    92
class SymbolTableConfig;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    93
typedef ConcurrentHashTable<Symbol*,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    94
                              SymbolTableConfig, mtSymbol> SymbolTableHash;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    95
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    96
class SymbolTableCreateEntry;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    97
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    98
class SymbolTable : public CHeapObj<mtSymbol> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  friend class VMStructs;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   100
  friend class Symbol;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   101
  friend class ClassFileParser;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   102
  friend class SymbolTableConfig;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   103
  friend class SymbolTableCreateEntry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
private:
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   106
  static void delete_symbol(Symbol* sym);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   107
  void grow(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   108
  void clean_dead_entries(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   109
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  static SymbolTable* _the_table;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   112
  static volatile bool _lookup_shared_first;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   113
  static volatile bool _alt_hash;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   114
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   115
  // For statistics
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   116
  volatile size_t _symbols_removed;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   117
  volatile size_t _symbols_counted;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   118
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   119
  SymbolTableHash* _local_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   120
  size_t _current_size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   121
  volatile bool _has_work;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   122
  // Set if one bucket is out of balance due to hash algorithm deficiency
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   123
  volatile bool _needs_rehashing;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   124
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   125
  volatile size_t _items_count;
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   126
  volatile bool   _has_items_to_clean;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   127
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52047
diff changeset
   128
  double get_load_factor() const;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   129
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   130
  void check_concurrent_work();
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
   131
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   132
  static void item_added();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   133
  static void item_removed();
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   134
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   135
  // For cleaning
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   136
  void reset_has_items_to_clean();
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   137
  void mark_has_items_to_clean();
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   138
  bool has_items_to_clean() const;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   139
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   140
  SymbolTable();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   141
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   142
  Symbol* allocate_symbol(const char* name, int len, bool c_heap); // Assumes no characters larger than 0x7F
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   143
  Symbol* do_lookup(const char* name, int len, uintx hash);
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   144
  Symbol* 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
   145
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   146
  // lookup only, won't add. Also calculate hash. Used by the ClassfileParser.
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   147
  static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   148
  static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   149
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Adding elements
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   151
  static void new_symbols(ClassLoaderData* loader_data,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28363
diff changeset
   152
                          const constantPoolHandle& cp, int names_count,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   153
                          const char** name, int* lengths,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   154
                          int* cp_indices, unsigned int* hashValues);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   155
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
   156
  static Symbol* lookup_shared(const char* name, int len, unsigned int hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   157
  Symbol* lookup_dynamic(const char* name, int len, unsigned int hash);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   158
  Symbol* lookup_common(const char* name, int len, unsigned int hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   160
  // Arena for permanent symbols (null class loader) that are never unloaded
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   161
  static Arena*  _arena;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   162
  static Arena* arena() { return _arena; }  // called for statistics
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   164
  static void initialize_symbols(int arena_alloc_size = 0);
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   165
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   166
  void concurrent_work(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   167
  void print_table_statistics(outputStream* st, const char* table_name);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   168
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   169
  void try_rehash_table();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   170
  bool do_rehash();
52951
722eaae2a785 8214310: SymbolTable: Use get and insert
gziemski
parents: 52931
diff changeset
   171
  inline void update_needs_rehash(bool rehash);
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   172
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
public:
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   174
  // The symbol table
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   175
  static SymbolTable* the_table() { return _the_table; }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   176
  size_t table_size();
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 53898
diff changeset
   177
  TableStatistics get_table_statistics();
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   178
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  enum {
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   180
    symbol_alloc_batch_size = 8,
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   181
    // Pick initial size based on java -version size measurements
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   182
    symbol_alloc_arena_size = 360*K // TODO (revisit)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    _the_table = new SymbolTable();
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   188
    initialize_symbols(symbol_alloc_arena_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   191
  static void do_concurrent_work(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   192
  static bool has_work() { return the_table()->_has_work; }
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53244
diff changeset
   193
  static void trigger_cleanup();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   194
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   195
  // Probing
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Needed for preloading classes in signatures when compiling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // Returns the symbol is already present in symbol table, otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // NULL.  NO ALLOCATION IS GUARANTEED!
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   199
  static Symbol* probe(const char* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   200
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   201
    return lookup_only(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   202
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   203
  static Symbol* probe_unicode(const jchar* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   204
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   205
    return lookup_only_unicode(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   206
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   208
  // Symbol lookup and create if not found.
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   209
  // jchar (UTF16) version of lookup
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   210
  static Symbol* new_symbol(const jchar* name, int len);
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   211
  // char (UTF8) versions
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   212
  static Symbol* new_symbol(const Symbol* sym, int begin, int end);
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   213
  static Symbol* new_symbol(const char* utf8_buffer, int length);
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   214
  static Symbol* new_symbol(const char* name) {
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   215
    return new_symbol(name, (int)strlen(name));
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   216
  }
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   217
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   218
  // Create a symbol in the arena for symbols that are not deleted
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54764
diff changeset
   219
  static Symbol* new_permanent_symbol(const char* name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   221
  // Rehash the string table if it gets out of balance
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   222
  static void rehash_table();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   223
  static bool needs_rehashing()
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   224
    { return SymbolTable::the_table()->_needs_rehashing; }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   225
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   226
  // Heap dumper and CDS
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   227
  static void symbols_do(SymbolClosure *cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Sharing
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   230
private:
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   231
  static void copy_shared_symbol_table(CompactHashtableWriter* ch_table);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   232
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   233
  static void write_to_archive() NOT_CDS_RETURN;
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   234
  static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   235
  static void metaspace_pointers_do(MetaspaceClosure* it);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   236
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   237
  // Jcmd
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   238
  static void dump(outputStream* st, bool verbose=false);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   239
  // Debugging
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   240
  static void verify();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   241
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   242
  // Histogram
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   243
  static void print_histogram() PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
   246
#endif // SHARE_CLASSFILE_SYMBOLTABLE_HPP