hotspot/src/share/vm/classfile/symbolTable.hpp
author ehelin
Tue, 25 Feb 2014 11:02:11 +0100
changeset 22905 4b1549d69106
parent 22545 b93a7f0e9b9d
child 24426 0a69c8cdfca9
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
     2
 * Copyright (c) 1997, 2013, 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
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    29
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/hashtable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    32
// The symbol table holds all Symbol*s and corresponding interned strings.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    33
// Symbol*s and literal strings should be canonicalized.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// The interned strings are created lazily.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//  - symbolTableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class BoolObjectClosure;
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
    43
class outputStream;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    46
// Class to hold a newly created or referenced Symbol* temporarily in scope.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    47
// new_symbol() and lookup() will create a Symbol* if not already in the
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
// 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
    49
// 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
    50
class TempNewSymbol : public StackObj {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    51
  Symbol* _temp;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    52
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    53
 public:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
  TempNewSymbol() : _temp(NULL) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    55
  // Creating or looking up a symbol increments the symbol's reference count
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
  TempNewSymbol(Symbol *s) : _temp(s) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
  // Operator= increments reference count.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    59
  void operator=(const TempNewSymbol &s) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    60
    //clear();  //FIXME
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
    _temp = s._temp;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    62
    if (_temp !=NULL) _temp->increment_refcount();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    63
  }
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
  // Decrement reference counter so it can go away if it's unique
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    66
  void clear() { if (_temp != NULL)  _temp->decrement_refcount();  _temp = NULL; }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    67
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13199
diff changeset
    68
  ~TempNewSymbol() { clear(); }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    69
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
  // Operators so they can be used like Symbols
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    71
  Symbol* operator -> () const                   { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    72
  bool    operator == (Symbol* o) const          { return _temp == o; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    73
  // Sneaky conversion function
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    74
  operator Symbol*()                             { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    75
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    76
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
    77
class SymbolTable : public Hashtable<Symbol*, mtSymbol> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  friend class VMStructs;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    79
  friend class ClassFileParser;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static SymbolTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
    85
  // Set if one bucket is out of balance due to hash algorithm deficiency
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
    86
  static bool _needs_rehashing;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
    87
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
  // For statistics
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
    89
  static int _symbols_removed;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
    90
  static int _symbols_counted;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    91
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    92
  Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    93
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Adding elements
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    95
  Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue,
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
    96
                    bool c_heap, TRAPS);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    97
  bool basic_add(ClassLoaderData* loader_data,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    98
                 constantPoolHandle cp, int names_count,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                 const char** names, int* lengths, int* cp_indices,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                 unsigned int* hashValues, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   102
  static void new_symbols(ClassLoaderData* loader_data,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   103
                          constantPoolHandle cp, int names_count,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   104
                          const char** name, int* lengths,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   105
                          int* cp_indices, unsigned int* hashValues,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   106
                          TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   107
    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
   108
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   109
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   110
  Symbol* lookup(int index, const char* name, int len, unsigned int hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  SymbolTable()
20393
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   113
    : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   115
  SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
20393
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   116
    : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
                number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   119
  // 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
   120
  static Arena*  _arena;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   121
  static Arena* arena() { return _arena; }  // called for statistics
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   123
  static void initialize_symbols(int arena_alloc_size = 0);
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   124
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   125
  static volatile int _parallel_claimed_idx;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   126
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   127
  // Release any dead symbols
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   128
  static void buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  enum {
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   131
    symbol_alloc_batch_size = 8,
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   132
    // Pick initial size based on java -version size measurements
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   133
    symbol_alloc_arena_size = 360*K
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  static SymbolTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
20393
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   139
  // Size of one bucket in the string table.  Used when checking for rollover.
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   140
  static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   141
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    _the_table = new SymbolTable();
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   145
    initialize_symbols(symbol_alloc_arena_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   148
  static void create_table(HashtableBucket<mtSymbol>* t, int length,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                           int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    assert(_the_table == NULL, "One symbol table allowed.");
20393
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   151
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   152
    // If CDS archive used a different symbol table size, use that size instead
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   153
    // which is better than giving an error.
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   154
    SymbolTableSize = length/bucket_size();
0675c0224a5a 8019375: Internal symbol table size should be tunable.
kevinw
parents: 20053
diff changeset
   155
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    _the_table = new SymbolTable(t, number_of_entries);
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   157
    // if CDS give symbol table a default arena size since most symbols
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   158
    // are already allocated in the shared misc section.
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   159
    initialize_symbols();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   162
  static unsigned int hash_symbol(const char* s, int len);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   163
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   164
  static Symbol* lookup(const char* name, int len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // 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
   166
  static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Only copy to C string to be added if lookup failed.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   168
  static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   169
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   170
  static void release(Symbol* sym);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
11480
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 8885
diff changeset
   172
  // Look up the address of the literal in the SymbolTable for this Symbol*
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 8885
diff changeset
   173
  static Symbol** lookup_symbol_addr(Symbol* sym);
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 8885
diff changeset
   174
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   175
  // jchar (utf16) version of lookups
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   176
  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
   177
  static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   178
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   179
  static void add(ClassLoaderData* loader_data,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   180
                  constantPoolHandle cp, int names_count,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                  const char** names, int* lengths, int* cp_indices,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                  unsigned int* hashValues, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   184
  // Release any dead symbols
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   185
  static void unlink() {
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   186
    int processed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   187
    int removed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   188
    unlink(&processed, &removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   189
  }
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   190
  static void unlink(int* processed, int* removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   191
  // Release any dead symbols, possibly parallel version
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   192
  static void possibly_parallel_unlink(int* processed, int* removed);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   193
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   194
  // iterate over symbols
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   195
  static void symbols_do(SymbolClosure *cl);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   196
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   197
  // Symbol creation
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   198
  static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   199
    assert(utf8_buffer != NULL, "just checking");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   200
    return lookup(utf8_buffer, length, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   202
  static Symbol*       new_symbol(const char* name, TRAPS) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   203
    return new_symbol(name, (int)strlen(name), THREAD);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   204
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   205
  static Symbol*       new_symbol(const Symbol* sym, int begin, int end, TRAPS) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   206
    assert(begin <= end && end <= sym->utf8_length(), "just checking");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   207
    return lookup(sym, begin, end, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   210
  // Create a symbol in the arena for symbols that are not deleted
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   211
  static Symbol* new_permanent_symbol(const char* name, TRAPS);
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11480
diff changeset
   212
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // Symbol lookup
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   214
  static Symbol* lookup(int index, const char* name, int len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Needed for preloading classes in signatures when compiling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Returns the symbol is already present in symbol table, otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // NULL.  NO ALLOCATION IS GUARANTEED!
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   219
  static Symbol* probe(const char* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   220
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   221
    return lookup_only(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   222
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   223
  static Symbol* probe_unicode(const jchar* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   224
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   225
    return lookup_only_unicode(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   226
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // Histogram
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  static void print_histogram()     PRODUCT_RETURN;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   230
  static void print()     PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  static void verify();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   234
  static void dump(outputStream* st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  static void copy_buckets(char** top, char*end) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   238
    the_table()->Hashtable<Symbol*, mtSymbol>::copy_buckets(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  static void copy_table(char** top, char*end) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   241
    the_table()->Hashtable<Symbol*, mtSymbol>::copy_table(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  static void reverse(void* boundary = NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   244
    the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   246
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   247
  // Rehash the symbol table if it gets out of balance
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   248
  static void rehash_table();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   249
  static bool needs_rehashing()         { return _needs_rehashing; }
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   250
  // Parallel chunked scanning
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   251
  static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   252
  static int parallel_claimed_index()        { return _parallel_claimed_idx; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   255
class StringTable : public Hashtable<oop, mtSymbol> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  static StringTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   262
  // Set if one bucket is out of balance due to hash algorithm deficiency
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   263
  static bool _needs_rehashing;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   264
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   265
  // Claimed high water mark for parallel chunked scanning
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   266
  static volatile int _parallel_claimed_idx;
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   267
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  oop basic_add(int index, Handle string_or_null, jchar* name, int len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
                unsigned int hashValue, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   274
  // Apply the give oop closure to the entries to the buckets
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   275
  // in the range [start_idx, end_idx).
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   276
  static void buckets_oops_do(OopClosure* f, int start_idx, int end_idx);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   277
  // Unlink or apply the give oop closure to the entries to the buckets
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   278
  // in the range [start_idx, end_idx).
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   279
  static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed);
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   280
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   281
  StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   282
                              sizeof (HashtableEntry<oop, mtSymbol>)) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   284
  StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   285
    : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
8727
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   286
                     number_of_entries) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  static StringTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
14487
9a40ad461ee9 7122219: Passed StringTableSize value not verified
hseigel
parents: 13728
diff changeset
   291
  // Size of one bucket in the string table.  Used when checking for rollover.
9a40ad461ee9 7122219: Passed StringTableSize value not verified
hseigel
parents: 13728
diff changeset
   292
  static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
9a40ad461ee9 7122219: Passed StringTableSize value not verified
hseigel
parents: 13728
diff changeset
   293
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    assert(_the_table == NULL, "One string table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    _the_table = new StringTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  //   Delete pointers to otherwise-unreachable objects.
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   301
  static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f) {
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   302
    int processed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   303
    int removed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   304
    unlink_or_oops_do(cl, f, &processed, &removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   305
  }
17846
68ef5934c097 8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents: 16601
diff changeset
   306
  static void unlink(BoolObjectClosure* cl) {
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   307
    int processed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   308
    int removed = 0;
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   309
    unlink_or_oops_do(cl, NULL, &processed, &removed);
17846
68ef5934c097 8015422: Large performance hit when the StringTable is walked twice in Parallel Scavenge
stefank
parents: 16601
diff changeset
   310
  }
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   311
  static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   312
  static void unlink(BoolObjectClosure* cl, int* processed, int* removed) {
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   313
    unlink_or_oops_do(cl, NULL, processed, removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   314
  }
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   315
  // Serially invoke "f->do_oop" on the locations of all oops in the table.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   316
  static void oops_do(OopClosure* f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   318
  // Possibly parallel versions of the above
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   319
  static void possibly_parallel_unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   320
  static void possibly_parallel_unlink(BoolObjectClosure* cl, int* processed, int* removed) {
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   321
    possibly_parallel_unlink_or_oops_do(cl, NULL, processed, removed);
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   322
  }
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   323
  static void possibly_parallel_oops_do(OopClosure* f);
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   324
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   325
  // Hashing algorithm, used as the hash value used by the
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   326
  //     StringTable for bucket selection and comparison (stored in the
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   327
  //     HashtableEntry structures).  This is used in the String.intern() method.
13097
c146b608d91f 7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents: 13087
diff changeset
   328
  static unsigned int hash_string(const jchar* s, int len);
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   329
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   330
  // Internal test.
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   331
  static void test_alt_hash() PRODUCT_RETURN;
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   332
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // Probing
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   334
  static oop lookup(Symbol* symbol);
16601
7c6db0c8952f 8009763: Add WB test for String.intern()
mgerdin
parents: 14487
diff changeset
   335
  static oop lookup(jchar* chars, int length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // Interning
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   338
  static oop intern(Symbol* symbol, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  static oop intern(oop string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  static oop intern(const char *utf8_string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  static void verify();
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   344
  static void dump(outputStream* st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
20053
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   346
  enum VerifyMesgModes {
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   347
    _verify_quietly    = 0,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   348
    _verify_with_mesgs = 1
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   349
  };
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   350
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   351
  enum VerifyRetTypes {
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   352
    _verify_pass          = 0,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   353
    _verify_fail_continue = 1,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   354
    _verify_fail_done     = 2
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   355
  };
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   356
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   357
  static VerifyRetTypes compare_entries(int bkt1, int e_cnt1,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   358
                                        HashtableEntry<oop, mtSymbol>* e_ptr1,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   359
                                        int bkt2, int e_cnt2,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   360
                                        HashtableEntry<oop, mtSymbol>* e_ptr2);
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   361
  static VerifyRetTypes verify_entry(int bkt, int e_cnt,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   362
                                     HashtableEntry<oop, mtSymbol>* e_ptr,
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   363
                                     VerifyMesgModes mesg_mode);
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   364
  static int verify_and_compare_entries();
a12bd7991794 8019835: Strings interned in different threads equal but does not ==
dcubed
parents: 18091
diff changeset
   365
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  static void copy_buckets(char** top, char*end) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   368
    the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  static void copy_table(char** top, char*end) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   371
    the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  static void reverse() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13097
diff changeset
   374
    the_table()->Hashtable<oop, mtSymbol>::reverse();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  }
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   376
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   377
  // Rehash the symbol table if it gets out of balance
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   378
  static void rehash_table();
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12263
diff changeset
   379
  static bool needs_rehashing() { return _needs_rehashing; }
18091
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   380
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   381
  // Parallel chunked scanning
ddde9f0f414d 8015237: Parallelize string table scanning during strong root processing
johnc
parents: 17846
diff changeset
   382
  static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
22545
b93a7f0e9b9d 8027476: Improve performance of Stringtable unlink
tschatzl
parents: 20393
diff changeset
   383
  static int parallel_claimed_index() { return _parallel_claimed_idx; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   385
#endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP