src/share/vm/classfile/symbolTable.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 435
a61af66fc99e
child 1100
c89f86385056
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 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
duke@435 94 static void add(constantPoolHandle cp, int names_count,
duke@435 95 const char** names, int* lengths, int* cp_indices,
duke@435 96 unsigned int* hashValues, TRAPS);
duke@435 97
duke@435 98 // GC support
duke@435 99 // Delete pointers to otherwise-unreachable objects.
duke@435 100 static void unlink(BoolObjectClosure* cl) {
duke@435 101 the_table()->Hashtable::unlink(cl);
duke@435 102 }
duke@435 103
duke@435 104 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 105 static void oops_do(OopClosure* f) {
duke@435 106 the_table()->Hashtable::oops_do(f);
duke@435 107 }
duke@435 108
duke@435 109 // Symbol lookup
duke@435 110 static symbolOop lookup(int index, const char* name, int len, TRAPS);
duke@435 111
duke@435 112 // Needed for preloading classes in signatures when compiling.
duke@435 113 // Returns the symbol is already present in symbol table, otherwise
duke@435 114 // NULL. NO ALLOCATION IS GUARANTEED!
duke@435 115 static symbolOop probe(const char* name, int len);
duke@435 116
duke@435 117 // Histogram
duke@435 118 static void print_histogram() PRODUCT_RETURN;
duke@435 119
duke@435 120 // Debugging
duke@435 121 static void verify();
duke@435 122
duke@435 123 // Sharing
duke@435 124 static void copy_buckets(char** top, char*end) {
duke@435 125 the_table()->Hashtable::copy_buckets(top, end);
duke@435 126 }
duke@435 127 static void copy_table(char** top, char*end) {
duke@435 128 the_table()->Hashtable::copy_table(top, end);
duke@435 129 }
duke@435 130 static void reverse(void* boundary = NULL) {
duke@435 131 ((Hashtable*)the_table())->reverse(boundary);
duke@435 132 }
duke@435 133 };
duke@435 134
duke@435 135
duke@435 136 class StringTable : public Hashtable {
duke@435 137 friend class VMStructs;
duke@435 138
duke@435 139 private:
duke@435 140 // The string table
duke@435 141 static StringTable* _the_table;
duke@435 142
duke@435 143 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
duke@435 144 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
duke@435 145 unsigned int hashValue, TRAPS);
duke@435 146
duke@435 147 // Table size
duke@435 148 enum {
duke@435 149 string_table_size = 1009
duke@435 150 };
duke@435 151
duke@435 152 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
duke@435 153
duke@435 154 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
duke@435 155
duke@435 156 StringTable(HashtableBucket* t, int number_of_entries)
duke@435 157 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
duke@435 158 number_of_entries) {}
duke@435 159
duke@435 160 public:
duke@435 161 // The string table
duke@435 162 static StringTable* the_table() { return _the_table; }
duke@435 163
duke@435 164 static void create_table() {
duke@435 165 assert(_the_table == NULL, "One string table allowed.");
duke@435 166 _the_table = new StringTable();
duke@435 167 }
duke@435 168
duke@435 169 static void create_table(HashtableBucket* t, int length,
duke@435 170 int number_of_entries) {
duke@435 171 assert(_the_table == NULL, "One string table allowed.");
duke@435 172 assert(length == string_table_size * sizeof(HashtableBucket),
duke@435 173 "bad shared string size.");
duke@435 174 _the_table = new StringTable(t, number_of_entries);
duke@435 175 }
duke@435 176
duke@435 177
duke@435 178 static int hash_string(jchar* s, int len);
duke@435 179
duke@435 180
duke@435 181 // GC support
duke@435 182 // Delete pointers to otherwise-unreachable objects.
duke@435 183 static void unlink(BoolObjectClosure* cl) {
duke@435 184 the_table()->Hashtable::unlink(cl);
duke@435 185 }
duke@435 186
duke@435 187 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 188 static void oops_do(OopClosure* f) {
duke@435 189 the_table()->Hashtable::oops_do(f);
duke@435 190 }
duke@435 191
duke@435 192 // Probing
duke@435 193 static oop lookup(symbolOop symbol);
duke@435 194
duke@435 195 // Interning
duke@435 196 static oop intern(symbolOop symbol, TRAPS);
duke@435 197 static oop intern(oop string, TRAPS);
duke@435 198 static oop intern(const char *utf8_string, TRAPS);
duke@435 199
duke@435 200 // Debugging
duke@435 201 static void verify();
duke@435 202
duke@435 203 // Sharing
duke@435 204 static void copy_buckets(char** top, char*end) {
duke@435 205 the_table()->Hashtable::copy_buckets(top, end);
duke@435 206 }
duke@435 207 static void copy_table(char** top, char*end) {
duke@435 208 the_table()->Hashtable::copy_table(top, end);
duke@435 209 }
duke@435 210 static void reverse() {
duke@435 211 ((BasicHashtable*)the_table())->reverse();
duke@435 212 }
duke@435 213 };

mercurial