hotspot/src/share/vm/classfile/symbolTable.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 2332 5c7b6f4ce0a1
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
     2
 * Copyright (c) 1997, 2009, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// The symbol table holds all symbolOops and corresponding interned strings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// symbolOops and literal strings should be canonicalized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// The interned strings are created lazily.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//  - symbolTableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class BoolObjectClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class SymbolTable : public Hashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static SymbolTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Adding elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  symbolOop basic_add(int index, u1* name, int len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                      unsigned int hashValue, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  bool basic_add(constantPoolHandle cp, int names_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                 const char** names, int* lengths, int* cp_indices,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                 unsigned int* hashValues, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // Table size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    symbol_table_size = 20011
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  symbolOop lookup(int index, const char* name, int len, unsigned int hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  SymbolTable()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  SymbolTable(HashtableBucket* t, int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
                number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    symbol_alloc_batch_size = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // The symbol table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static SymbolTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    _the_table = new SymbolTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  static void create_table(HashtableBucket* t, int length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                           int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    assert(_the_table == NULL, "One symbol table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    assert(length == symbol_table_size * sizeof(HashtableBucket),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
           "bad shared symbol size.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _the_table = new SymbolTable(t, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  static symbolOop lookup(const char* name, int len, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // lookup only, won't add. Also calculate hash.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Only copy to C string to be added if lookup failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
    94
  // jchar (utf16) version of lookups
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
    95
  static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
    96
  static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
    97
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static void add(constantPoolHandle cp, int names_count,
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  //   Delete pointers to otherwise-unreachable objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  static void unlink(BoolObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    the_table()->Hashtable::unlink(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Invoke "f->do_oop" on the locations of all oops in the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    the_table()->Hashtable::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // Symbol lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static symbolOop lookup(int index, const char* name, int len, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Needed for preloading classes in signatures when compiling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Returns the symbol is already present in symbol table, otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // NULL.  NO ALLOCATION IS GUARANTEED!
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   119
  static symbolOop probe(const char* name, int len) {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   120
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   121
    return lookup_only(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   122
  }
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   123
  static symbolOop probe_unicode(const jchar* name, int len) {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   124
    unsigned int ignore_hash;
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   125
    return lookup_only_unicode(name, len, ignore_hash);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   126
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Histogram
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static void print_histogram()     PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static void copy_buckets(char** top, char*end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    the_table()->Hashtable::copy_buckets(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static void copy_table(char** top, char*end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    the_table()->Hashtable::copy_table(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static void reverse(void* boundary = NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    ((Hashtable*)the_table())->reverse(boundary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
class StringTable : public Hashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static StringTable* _the_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  oop basic_add(int index, Handle string_or_null, jchar* name, int len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
                unsigned int hashValue, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Table size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    string_table_size = 1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  StringTable(HashtableBucket* t, int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    : Hashtable(string_table_size, sizeof (HashtableEntry), t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                number_of_entries) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // The string table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  static StringTable* the_table() { return _the_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  static void create_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    assert(_the_table == NULL, "One string table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    _the_table = new StringTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  static void create_table(HashtableBucket* t, int length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                           int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    assert(_the_table == NULL, "One string table allowed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    assert(length == string_table_size * sizeof(HashtableBucket),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
           "bad shared string size.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    _the_table = new StringTable(t, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  static int hash_string(jchar* s, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  //   Delete pointers to otherwise-unreachable objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  static void unlink(BoolObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    the_table()->Hashtable::unlink(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Invoke "f->do_oop" on the locations of all oops in the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  static void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    the_table()->Hashtable::oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // Probing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  static oop lookup(symbolOop symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // Interning
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  static oop intern(symbolOop symbol, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  static oop intern(oop string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  static oop intern(const char *utf8_string, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  static void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Sharing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  static void copy_buckets(char** top, char*end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    the_table()->Hashtable::copy_buckets(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  static void copy_table(char** top, char*end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    the_table()->Hashtable::copy_table(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  static void reverse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    ((BasicHashtable*)the_table())->reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
};