src/hotspot/share/classfile/symbolTable.hpp
author gziemski
Tue, 14 Aug 2018 18:42:14 -0500
changeset 51405 8b23aa7cef47
parent 48157 7c4d43c26352
child 51823 2a51125b2794
permissions -rw-r--r--
8195100: Use a low latency hashtable for SymbolTable Summary: Used concurrentHashTable, similar to stringTable Reviewed-by: coleenp, kbarrett, iklam, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
     2
 * Copyright (c) 1997, 2018, 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
#ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
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
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    34
// 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
    35
// 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
    36
// 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
    37
// 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
    38
// Symbol* temporarily in scope.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    39
//
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    40
// 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
    41
// 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
    42
// 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
    43
//
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    44
// In SymbolTable, new_symbol() and lookup() 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
    45
// 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
    46
// 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
    47
class TempNewSymbol : public StackObj {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
  Symbol* _temp;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    49
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    50
public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    51
  TempNewSymbol() : _temp(NULL) {}
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    52
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    53
  // Conversion from a Symbol* to a TempNewSymbol.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    54
  // Does not increment the current reference count.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    55
  TempNewSymbol(Symbol *s) : _temp(s) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    57
  // Copy constructor increments reference count.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    58
  TempNewSymbol(const TempNewSymbol& rhs) : _temp(rhs._temp) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    59
    if (_temp != NULL) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    60
      _temp->increment_refcount();
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    61
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    62
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    63
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    64
  // 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
    65
  // 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
    66
  // 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
    67
  // decrement upon destruction.
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    68
  void operator=(TempNewSymbol rhs) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    69
    Symbol* tmp = rhs._temp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    70
    rhs._temp = _temp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    71
    _temp = tmp;
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    72
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    73
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    74
  // 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
    75
  ~TempNewSymbol() {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    76
    if (_temp != NULL) {
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    77
      _temp->decrement_refcount();
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    78
    }
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    79
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    80
35497
94c7c07d0161 8145940: TempNewSymbol should have correct copy and assignment functions
coleenp
parents: 34237
diff changeset
    81
  // Symbol* conversion operators
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
  Symbol* operator -> () const                   { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    83
  bool    operator == (Symbol* o) const          { return _temp == o; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
  operator Symbol*()                             { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    85
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
    87
template <class T, class N> class CompactHashtable;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    88
class CompactSymbolTableWriter;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    89
class SerializeClosure;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
    90
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    91
class SymbolTableConfig;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    92
typedef ConcurrentHashTable<Symbol*,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    93
                              SymbolTableConfig, mtSymbol> SymbolTableHash;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    94
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    95
class SymbolTableCreateEntry;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    96
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    97
class SymbolTable : public CHeapObj<mtSymbol> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  friend class VMStructs;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
    99
  friend class Symbol;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   100
  friend class ClassFileParser;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   101
  friend class SymbolTableConfig;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   102
  friend class SymbolTableCreateEntry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
private:
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   105
  static void delete_symbol(Symbol* sym);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   106
  void grow(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   107
  void clean_dead_entries(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   108
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  static SymbolTable* _the_table;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   111
  // Shared symbol table.
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   112
  static CompactHashtable<Symbol*, char> _shared_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   113
  static volatile bool _lookup_shared_first;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   114
  static volatile bool _alt_hash;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   115
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   116
  // For statistics
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   117
  volatile size_t _symbols_removed;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   118
  volatile size_t _symbols_counted;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   119
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   120
  SymbolTableHash* _local_table;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   121
  size_t _current_size;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   122
  volatile bool _has_work;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   123
  // 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
   124
  volatile bool _needs_rehashing;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   125
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   126
  volatile size_t _items_count;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   127
  volatile size_t _uncleaned_items_count;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   128
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   129
  double get_load_factor();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   130
  double get_dead_factor();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   131
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   132
  void check_concurrent_work();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   133
  void trigger_concurrent_work();
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
   134
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   135
  static void item_added();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   136
  static void item_removed();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   137
  static void set_item_clean_count(size_t ncl);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   138
  static void mark_item_clean_count();
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
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   142
  Symbol* allocate_symbol(const char* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
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);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   144
  Symbol* do_add_if_needed(const char* name, int len, uintx hash, bool heap, TRAPS);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   145
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // Adding elements
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   147
  static void add(ClassLoaderData* loader_data,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   148
                  const constantPoolHandle& cp, int names_count,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   149
                  const char** names, int* lengths, int* cp_indices,
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   150
                  unsigned int* hashValues, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   152
  static void new_symbols(ClassLoaderData* loader_data,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28363
diff changeset
   153
                          const constantPoolHandle& cp, int names_count,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   154
                          const char** name, int* lengths,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   155
                          int* cp_indices, unsigned int* hashValues,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   156
                          TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   157
    add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   158
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   159
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 26421
diff changeset
   160
  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
   161
  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
   162
  Symbol* lookup_common(const char* name, int len, unsigned int hash);
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
  // 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
   165
  static Arena*  _arena;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   166
  static Arena* arena() { return _arena; }  // called for statistics
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   168
  static void initialize_symbols(int arena_alloc_size = 0);
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   169
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   170
  void concurrent_work(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   171
  void print_table_statistics(outputStream* st, const char* table_name);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   172
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   173
  void try_rehash_table();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   174
  bool do_rehash();
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   175
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
public:
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   177
  // The symbol table
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   178
  static SymbolTable* the_table() { return _the_table; }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   179
  size_t table_size();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   180
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  enum {
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   182
    symbol_alloc_batch_size = 8,
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   183
    // Pick initial size based on java -version size measurements
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   184
    symbol_alloc_arena_size = 360*K // TODO (revisit)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    _the_table = new SymbolTable();
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   190
    initialize_symbols(symbol_alloc_arena_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   193
  static void unlink() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   194
    do_check_concurrent_work();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   195
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   196
  static void do_check_concurrent_work();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   197
  static void do_concurrent_work(JavaThread* jt);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   198
  static bool has_work() { return the_table()->_has_work; }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   199
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   200
  // Probing
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   201
  static Symbol* lookup(const char* name, int len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // lookup only, won't add. Also calculate hash.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   203
  static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   204
  // adds new symbol if not found
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   205
  static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 28363
diff changeset
   206
  // jchar (UTF16) version of lookups
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   207
  static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   208
  static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // Needed for preloading classes in signatures when compiling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  // Returns the symbol is already present in symbol table, otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // NULL.  NO ALLOCATION IS GUARANTEED!
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   212
  static Symbol* probe(const char* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   213
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   214
    return lookup_only(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   215
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   216
  static Symbol* probe_unicode(const jchar* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   217
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   218
    return lookup_only_unicode(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   219
  }
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
  // Symbol creation
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   222
  static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   223
    assert(utf8_buffer != NULL, "just checking");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   224
    return lookup(utf8_buffer, length, THREAD);
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
  static Symbol* new_symbol(const char* name, TRAPS) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   227
    return new_symbol(name, (int)strlen(name), THREAD);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   228
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   229
  static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   230
    assert(begin <= end && end <= sym->utf8_length(), "just checking");
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   231
    return lookup(sym, begin, end, THREAD);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   232
  }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   233
  // Create a symbol in the arena for symbols that are not deleted
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   234
  static Symbol* new_permanent_symbol(const char* name, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   236
  // Rehash the string table if it gets out of balance
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   237
  static void rehash_table();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   238
  static bool needs_rehashing()
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   239
    { return SymbolTable::the_table()->_needs_rehashing; }
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   240
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   241
  // Heap dumper and CDS
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   242
  static void symbols_do(SymbolClosure *cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Sharing
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   245
private:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   246
  static void copy_shared_symbol_table(CompactSymbolTableWriter* ch_table);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   247
public:
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   248
  static void write_to_archive() NOT_CDS_RETURN;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   249
  static void serialize(SerializeClosure* soc) NOT_CDS_RETURN;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   250
  static void metaspace_pointers_do(MetaspaceClosure* it);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   251
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   252
  // Jcmd
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   253
  static void dump(outputStream* st, bool verbose=false);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   254
  // Debugging
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   255
  static void verify();
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   256
  static void read(const char* filename, TRAPS);
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   257
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   258
  // Histogram
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 48157
diff changeset
   259
  static void print_histogram() PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   262
#endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP