hotspot/src/share/vm/classfile/symbolTable.hpp
author jcoomes
Mon, 21 Mar 2011 18:38:00 -0700
changeset 8727 1642a45f024f
parent 8076 96d498ec7ae1
child 8885 eed0ba1d011b
permissions -rw-r--r--
6962930: make the string table size configurable Reviewed-by: never, phh, stefank, kamg, dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, 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;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    45
// 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
    46
// 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
    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
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    52
 public:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    53
  TempNewSymbol() : _temp(NULL) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
  // 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
    55
  TempNewSymbol(Symbol *s) : _temp(s) {}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
  // Operator= increments reference count.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
  void operator=(const TempNewSymbol &s) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    59
    _temp = s._temp;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    60
    if (_temp !=NULL) _temp->increment_refcount();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
  }
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
  // Decrement reference counter so it can go away if it's unique
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    64
  ~TempNewSymbol() { if (_temp != NULL) _temp->decrement_refcount(); }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    65
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    66
  // Operators so they can be used like Symbols
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    67
  Symbol* operator -> () const                   { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    68
  bool    operator == (Symbol* o) const          { return _temp == o; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    69
  // Sneaky conversion function
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
  operator Symbol*()                             { return _temp; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    71
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    72
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    73
class SymbolTable : public Hashtable<Symbol*> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  friend class VMStructs;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    75
  friend class ClassFileParser;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static SymbolTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    81
  // For statistics
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
  static int symbols_removed;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    83
  static int symbols_counted;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    85
  Symbol* allocate_symbol(const u1* name, int len, TRAPS);   // Assumes no characters larger than 0x7F
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
  bool allocate_symbols(int names_count, const u1** names, int* lengths, Symbol** syms, TRAPS);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    87
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Adding elements
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
  Symbol* basic_add(int index, u1* name, int len,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                      unsigned int hashValue, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  bool basic_add(constantPoolHandle cp, int names_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                 const char** names, int* lengths, int* cp_indices,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                 unsigned int* hashValues, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    95
  static void new_symbols(constantPoolHandle cp, int names_count,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    96
                          const char** name, int* lengths,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    97
                          int* cp_indices, unsigned int* hashValues,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    98
                          TRAPS) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    99
    add(cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   100
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   101
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   102
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Table size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    symbol_table_size = 20011
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   108
  Symbol* lookup(int index, const char* name, int len, unsigned int hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  SymbolTable()
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   111
    : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>)) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  SymbolTable(HashtableBucket* t, int number_of_entries)
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   114
    : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
                number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    symbol_alloc_batch_size = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static SymbolTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    _the_table = new SymbolTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void create_table(HashtableBucket* t, int length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                           int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    assert(length == symbol_table_size * sizeof(HashtableBucket),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
           "bad shared symbol size.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    _the_table = new SymbolTable(t, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   139
  static Symbol* lookup(const char* name, int len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // 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
   141
  static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // 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
   143
  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
   144
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   145
  static void release(Symbol* sym);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   147
  // jchar (utf16) version of lookups
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   148
  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
   149
  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
   150
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  static void add(constantPoolHandle cp, int names_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
                  const char** names, int* lengths, int* cp_indices,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                  unsigned int* hashValues, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   155
  // Release any dead symbols
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   156
  static void unlink();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   157
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   158
  // iterate over symbols
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   159
  static void symbols_do(SymbolClosure *cl);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   160
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   161
  // Symbol creation
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   162
  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
   163
    assert(utf8_buffer != NULL, "just checking");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   164
    return lookup(utf8_buffer, length, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   166
  static Symbol*       new_symbol(const char* name, TRAPS) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   167
    return new_symbol(name, (int)strlen(name), THREAD);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   168
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   169
  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
   170
    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
   171
    return lookup(sym, begin, end, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Symbol lookup
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   175
  static Symbol* lookup(int index, const char* name, int len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Needed for preloading classes in signatures when compiling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // Returns the symbol is already present in symbol table, otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // NULL.  NO ALLOCATION IS GUARANTEED!
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   180
  static Symbol* probe(const char* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   181
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   182
    return lookup_only(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   183
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   184
  static Symbol* probe_unicode(const jchar* name, int len) {
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   185
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   186
    return lookup_only_unicode(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   187
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // Histogram
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  static void print_histogram()     PRODUCT_RETURN;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   191
  static void print()     PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  static void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  static void copy_buckets(char** top, char*end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   198
    the_table()->Hashtable<Symbol*>::copy_buckets(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  static void copy_table(char** top, char*end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   201
    the_table()->Hashtable<Symbol*>::copy_table(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  static void reverse(void* boundary = NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   204
    the_table()->Hashtable<Symbol*>::reverse(boundary);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   208
class StringTable : public Hashtable<oop> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  static StringTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  oop basic_add(int index, Handle string_or_null, jchar* name, int len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                unsigned int hashValue, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
8727
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   221
  StringTable() : Hashtable<oop>((int)StringTableSize,
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   222
                                 sizeof (HashtableEntry<oop>)) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  StringTable(HashtableBucket* t, int number_of_entries)
8727
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   225
    : Hashtable<oop>((int)StringTableSize, sizeof (HashtableEntry<oop>), t,
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   226
                     number_of_entries) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  static StringTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    assert(_the_table == NULL, "One string table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    _the_table = new StringTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  static void create_table(HashtableBucket* t, int length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
                           int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    assert(_the_table == NULL, "One string table allowed.");
8727
1642a45f024f 6962930: make the string table size configurable
jcoomes
parents: 8076
diff changeset
   240
    assert((size_t)length == StringTableSize * sizeof(HashtableBucket),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
           "bad shared string size.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    _the_table = new StringTable(t, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  static int hash_string(jchar* s, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  //   Delete pointers to otherwise-unreachable objects.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   249
  static void unlink(BoolObjectClosure* cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // 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
   252
  static void oops_do(OopClosure* f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // Probing
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   255
  static oop lookup(Symbol* symbol);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // Interning
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   258
  static oop intern(Symbol* symbol, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  static oop intern(oop string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  static oop intern(const char *utf8_string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  static void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  static void copy_buckets(char** top, char*end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   267
    the_table()->Hashtable<oop>::copy_buckets(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  static void copy_table(char** top, char*end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   270
    the_table()->Hashtable<oop>::copy_table(top, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  static void reverse() {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   273
    the_table()->Hashtable<oop>::reverse();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   276
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   277
#endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP