src/share/vm/classfile/symbolTable.hpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

duke@435 1 /*
jrose@1100 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // The symbol table holds all symbolOops and corresponding interned strings.
duke@435 26 // symbolOops and literal strings should be canonicalized.
duke@435 27 //
duke@435 28 // The interned strings are created lazily.
duke@435 29 //
duke@435 30 // It is implemented as an open hash table with a fixed number of buckets.
duke@435 31 //
duke@435 32 // %note:
duke@435 33 // - symbolTableEntrys are allocated in blocks to reduce the space overhead.
duke@435 34
duke@435 35 class BoolObjectClosure;
duke@435 36
duke@435 37
duke@435 38 class SymbolTable : public Hashtable {
duke@435 39 friend class VMStructs;
duke@435 40
duke@435 41 private:
duke@435 42 // The symbol table
duke@435 43 static SymbolTable* _the_table;
duke@435 44
duke@435 45 // Adding elements
duke@435 46 symbolOop basic_add(int index, u1* name, int len,
duke@435 47 unsigned int hashValue, TRAPS);
duke@435 48 bool basic_add(constantPoolHandle cp, int names_count,
duke@435 49 const char** names, int* lengths, int* cp_indices,
duke@435 50 unsigned int* hashValues, TRAPS);
duke@435 51
duke@435 52 // Table size
duke@435 53 enum {
duke@435 54 symbol_table_size = 20011
duke@435 55 };
duke@435 56
duke@435 57 symbolOop lookup(int index, const char* name, int len, unsigned int hash);
duke@435 58
duke@435 59 SymbolTable()
duke@435 60 : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
duke@435 61
duke@435 62 SymbolTable(HashtableBucket* t, int number_of_entries)
duke@435 63 : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
duke@435 64 number_of_entries) {}
duke@435 65
duke@435 66
duke@435 67 public:
duke@435 68 enum {
duke@435 69 symbol_alloc_batch_size = 8
duke@435 70 };
duke@435 71
duke@435 72 // The symbol table
duke@435 73 static SymbolTable* the_table() { return _the_table; }
duke@435 74
duke@435 75 static void create_table() {
duke@435 76 assert(_the_table == NULL, "One symbol table allowed.");
duke@435 77 _the_table = new SymbolTable();
duke@435 78 }
duke@435 79
duke@435 80 static void create_table(HashtableBucket* t, int length,
duke@435 81 int number_of_entries) {
duke@435 82 assert(_the_table == NULL, "One symbol table allowed.");
duke@435 83 assert(length == symbol_table_size * sizeof(HashtableBucket),
duke@435 84 "bad shared symbol size.");
duke@435 85 _the_table = new SymbolTable(t, number_of_entries);
duke@435 86 }
duke@435 87
duke@435 88 static symbolOop lookup(const char* name, int len, TRAPS);
duke@435 89 // lookup only, won't add. Also calculate hash.
duke@435 90 static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
duke@435 91 // Only copy to C string to be added if lookup failed.
duke@435 92 static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
duke@435 93
jrose@1100 94 // jchar (utf16) version of lookups
jrose@1100 95 static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
jrose@1100 96 static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
jrose@1100 97
duke@435 98 static void add(constantPoolHandle cp, int names_count,
duke@435 99 const char** names, int* lengths, int* cp_indices,
duke@435 100 unsigned int* hashValues, TRAPS);
duke@435 101
duke@435 102 // GC support
duke@435 103 // Delete pointers to otherwise-unreachable objects.
duke@435 104 static void unlink(BoolObjectClosure* cl) {
duke@435 105 the_table()->Hashtable::unlink(cl);
duke@435 106 }
duke@435 107
duke@435 108 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 109 static void oops_do(OopClosure* f) {
duke@435 110 the_table()->Hashtable::oops_do(f);
duke@435 111 }
duke@435 112
duke@435 113 // Symbol lookup
duke@435 114 static symbolOop lookup(int index, const char* name, int len, TRAPS);
duke@435 115
duke@435 116 // Needed for preloading classes in signatures when compiling.
duke@435 117 // Returns the symbol is already present in symbol table, otherwise
duke@435 118 // NULL. NO ALLOCATION IS GUARANTEED!
jrose@1100 119 static symbolOop probe(const char* name, int len) {
jrose@1100 120 unsigned int ignore_hash;
jrose@1100 121 return lookup_only(name, len, ignore_hash);
jrose@1100 122 }
jrose@1100 123 static symbolOop probe_unicode(const jchar* name, int len) {
jrose@1100 124 unsigned int ignore_hash;
jrose@1100 125 return lookup_only_unicode(name, len, ignore_hash);
jrose@1100 126 }
duke@435 127
duke@435 128 // Histogram
duke@435 129 static void print_histogram() PRODUCT_RETURN;
duke@435 130
duke@435 131 // Debugging
duke@435 132 static void verify();
duke@435 133
duke@435 134 // Sharing
duke@435 135 static void copy_buckets(char** top, char*end) {
duke@435 136 the_table()->Hashtable::copy_buckets(top, end);
duke@435 137 }
duke@435 138 static void copy_table(char** top, char*end) {
duke@435 139 the_table()->Hashtable::copy_table(top, end);
duke@435 140 }
duke@435 141 static void reverse(void* boundary = NULL) {
duke@435 142 ((Hashtable*)the_table())->reverse(boundary);
duke@435 143 }
duke@435 144 };
duke@435 145
duke@435 146
duke@435 147 class StringTable : public Hashtable {
duke@435 148 friend class VMStructs;
duke@435 149
duke@435 150 private:
duke@435 151 // The string table
duke@435 152 static StringTable* _the_table;
duke@435 153
duke@435 154 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
duke@435 155 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
duke@435 156 unsigned int hashValue, TRAPS);
duke@435 157
duke@435 158 // Table size
duke@435 159 enum {
duke@435 160 string_table_size = 1009
duke@435 161 };
duke@435 162
duke@435 163 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
duke@435 164
duke@435 165 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
duke@435 166
duke@435 167 StringTable(HashtableBucket* t, int number_of_entries)
duke@435 168 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
duke@435 169 number_of_entries) {}
duke@435 170
duke@435 171 public:
duke@435 172 // The string table
duke@435 173 static StringTable* the_table() { return _the_table; }
duke@435 174
duke@435 175 static void create_table() {
duke@435 176 assert(_the_table == NULL, "One string table allowed.");
duke@435 177 _the_table = new StringTable();
duke@435 178 }
duke@435 179
duke@435 180 static void create_table(HashtableBucket* t, int length,
duke@435 181 int number_of_entries) {
duke@435 182 assert(_the_table == NULL, "One string table allowed.");
duke@435 183 assert(length == string_table_size * sizeof(HashtableBucket),
duke@435 184 "bad shared string size.");
duke@435 185 _the_table = new StringTable(t, number_of_entries);
duke@435 186 }
duke@435 187
duke@435 188
duke@435 189 static int hash_string(jchar* s, int len);
duke@435 190
duke@435 191
duke@435 192 // GC support
duke@435 193 // Delete pointers to otherwise-unreachable objects.
duke@435 194 static void unlink(BoolObjectClosure* cl) {
duke@435 195 the_table()->Hashtable::unlink(cl);
duke@435 196 }
duke@435 197
duke@435 198 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 199 static void oops_do(OopClosure* f) {
duke@435 200 the_table()->Hashtable::oops_do(f);
duke@435 201 }
duke@435 202
duke@435 203 // Probing
duke@435 204 static oop lookup(symbolOop symbol);
duke@435 205
duke@435 206 // Interning
duke@435 207 static oop intern(symbolOop symbol, TRAPS);
duke@435 208 static oop intern(oop string, TRAPS);
duke@435 209 static oop intern(const char *utf8_string, TRAPS);
duke@435 210
duke@435 211 // Debugging
duke@435 212 static void verify();
duke@435 213
duke@435 214 // Sharing
duke@435 215 static void copy_buckets(char** top, char*end) {
duke@435 216 the_table()->Hashtable::copy_buckets(top, end);
duke@435 217 }
duke@435 218 static void copy_table(char** top, char*end) {
duke@435 219 the_table()->Hashtable::copy_table(top, end);
duke@435 220 }
duke@435 221 static void reverse() {
duke@435 222 ((BasicHashtable*)the_table())->reverse();
duke@435 223 }
duke@435 224 };

mercurial