src/share/vm/classfile/symbolTable.hpp

Tue, 21 Dec 2010 04:37:30 -0800

author
twisti
date
Tue, 21 Dec 2010 04:37:30 -0800
changeset 2408
ef3c5db0b3ae
parent 2314
f95d63e2154a
child 2497
3582bf76420e
permissions
-rw-r--r--

7008165: Garbage in ClassFormatError message
Summary: When bootstrap_method_ref in BootstrapMethods attribute points to a wrong CP entry (non-MethodHandle), JVM throws ClassFormatError with a message, where method index and class file name is garbage.
Reviewed-by: iveresov

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
stefank@2314 26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.inline.hpp"
stefank@2314 29 #include "oops/symbolOop.hpp"
stefank@2314 30 #include "utilities/hashtable.hpp"
stefank@2314 31
duke@435 32 // The symbol table holds all symbolOops and corresponding interned strings.
duke@435 33 // symbolOops and literal strings should be canonicalized.
duke@435 34 //
duke@435 35 // The interned strings are created lazily.
duke@435 36 //
duke@435 37 // It is implemented as an open hash table with a fixed number of buckets.
duke@435 38 //
duke@435 39 // %note:
duke@435 40 // - symbolTableEntrys are allocated in blocks to reduce the space overhead.
duke@435 41
duke@435 42 class BoolObjectClosure;
duke@435 43
duke@435 44
duke@435 45 class SymbolTable : public Hashtable {
duke@435 46 friend class VMStructs;
duke@435 47
duke@435 48 private:
duke@435 49 // The symbol table
duke@435 50 static SymbolTable* _the_table;
duke@435 51
duke@435 52 // Adding elements
duke@435 53 symbolOop basic_add(int index, u1* name, int len,
duke@435 54 unsigned int hashValue, TRAPS);
duke@435 55 bool basic_add(constantPoolHandle cp, int names_count,
duke@435 56 const char** names, int* lengths, int* cp_indices,
duke@435 57 unsigned int* hashValues, TRAPS);
duke@435 58
duke@435 59 // Table size
duke@435 60 enum {
duke@435 61 symbol_table_size = 20011
duke@435 62 };
duke@435 63
duke@435 64 symbolOop lookup(int index, const char* name, int len, unsigned int hash);
duke@435 65
duke@435 66 SymbolTable()
duke@435 67 : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
duke@435 68
duke@435 69 SymbolTable(HashtableBucket* t, int number_of_entries)
duke@435 70 : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
duke@435 71 number_of_entries) {}
duke@435 72
duke@435 73
duke@435 74 public:
duke@435 75 enum {
duke@435 76 symbol_alloc_batch_size = 8
duke@435 77 };
duke@435 78
duke@435 79 // The symbol table
duke@435 80 static SymbolTable* the_table() { return _the_table; }
duke@435 81
duke@435 82 static void create_table() {
duke@435 83 assert(_the_table == NULL, "One symbol table allowed.");
duke@435 84 _the_table = new SymbolTable();
duke@435 85 }
duke@435 86
duke@435 87 static void create_table(HashtableBucket* t, int length,
duke@435 88 int number_of_entries) {
duke@435 89 assert(_the_table == NULL, "One symbol table allowed.");
duke@435 90 assert(length == symbol_table_size * sizeof(HashtableBucket),
duke@435 91 "bad shared symbol size.");
duke@435 92 _the_table = new SymbolTable(t, number_of_entries);
duke@435 93 }
duke@435 94
duke@435 95 static symbolOop lookup(const char* name, int len, TRAPS);
duke@435 96 // lookup only, won't add. Also calculate hash.
duke@435 97 static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
duke@435 98 // Only copy to C string to be added if lookup failed.
duke@435 99 static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
duke@435 100
jrose@1100 101 // jchar (utf16) version of lookups
jrose@1100 102 static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
jrose@1100 103 static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
jrose@1100 104
duke@435 105 static void add(constantPoolHandle cp, int names_count,
duke@435 106 const char** names, int* lengths, int* cp_indices,
duke@435 107 unsigned int* hashValues, TRAPS);
duke@435 108
duke@435 109 // GC support
duke@435 110 // Delete pointers to otherwise-unreachable objects.
duke@435 111 static void unlink(BoolObjectClosure* cl) {
duke@435 112 the_table()->Hashtable::unlink(cl);
duke@435 113 }
duke@435 114
duke@435 115 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 116 static void oops_do(OopClosure* f) {
duke@435 117 the_table()->Hashtable::oops_do(f);
duke@435 118 }
duke@435 119
duke@435 120 // Symbol lookup
duke@435 121 static symbolOop lookup(int index, const char* name, int len, TRAPS);
duke@435 122
duke@435 123 // Needed for preloading classes in signatures when compiling.
duke@435 124 // Returns the symbol is already present in symbol table, otherwise
duke@435 125 // NULL. NO ALLOCATION IS GUARANTEED!
jrose@1100 126 static symbolOop probe(const char* name, int len) {
jrose@1100 127 unsigned int ignore_hash;
jrose@1100 128 return lookup_only(name, len, ignore_hash);
jrose@1100 129 }
jrose@1100 130 static symbolOop probe_unicode(const jchar* name, int len) {
jrose@1100 131 unsigned int ignore_hash;
jrose@1100 132 return lookup_only_unicode(name, len, ignore_hash);
jrose@1100 133 }
duke@435 134
duke@435 135 // Histogram
duke@435 136 static void print_histogram() PRODUCT_RETURN;
duke@435 137
duke@435 138 // Debugging
duke@435 139 static void verify();
duke@435 140
duke@435 141 // Sharing
duke@435 142 static void copy_buckets(char** top, char*end) {
duke@435 143 the_table()->Hashtable::copy_buckets(top, end);
duke@435 144 }
duke@435 145 static void copy_table(char** top, char*end) {
duke@435 146 the_table()->Hashtable::copy_table(top, end);
duke@435 147 }
duke@435 148 static void reverse(void* boundary = NULL) {
duke@435 149 ((Hashtable*)the_table())->reverse(boundary);
duke@435 150 }
duke@435 151 };
duke@435 152
duke@435 153
duke@435 154 class StringTable : public Hashtable {
duke@435 155 friend class VMStructs;
duke@435 156
duke@435 157 private:
duke@435 158 // The string table
duke@435 159 static StringTable* _the_table;
duke@435 160
duke@435 161 static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
duke@435 162 oop basic_add(int index, Handle string_or_null, jchar* name, int len,
duke@435 163 unsigned int hashValue, TRAPS);
duke@435 164
duke@435 165 // Table size
duke@435 166 enum {
duke@435 167 string_table_size = 1009
duke@435 168 };
duke@435 169
duke@435 170 oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
duke@435 171
duke@435 172 StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
duke@435 173
duke@435 174 StringTable(HashtableBucket* t, int number_of_entries)
duke@435 175 : Hashtable(string_table_size, sizeof (HashtableEntry), t,
duke@435 176 number_of_entries) {}
duke@435 177
duke@435 178 public:
duke@435 179 // The string table
duke@435 180 static StringTable* the_table() { return _the_table; }
duke@435 181
duke@435 182 static void create_table() {
duke@435 183 assert(_the_table == NULL, "One string table allowed.");
duke@435 184 _the_table = new StringTable();
duke@435 185 }
duke@435 186
duke@435 187 static void create_table(HashtableBucket* t, int length,
duke@435 188 int number_of_entries) {
duke@435 189 assert(_the_table == NULL, "One string table allowed.");
duke@435 190 assert(length == string_table_size * sizeof(HashtableBucket),
duke@435 191 "bad shared string size.");
duke@435 192 _the_table = new StringTable(t, number_of_entries);
duke@435 193 }
duke@435 194
duke@435 195
duke@435 196 static int hash_string(jchar* s, int len);
duke@435 197
duke@435 198
duke@435 199 // GC support
duke@435 200 // Delete pointers to otherwise-unreachable objects.
duke@435 201 static void unlink(BoolObjectClosure* cl) {
duke@435 202 the_table()->Hashtable::unlink(cl);
duke@435 203 }
duke@435 204
duke@435 205 // Invoke "f->do_oop" on the locations of all oops in the table.
duke@435 206 static void oops_do(OopClosure* f) {
duke@435 207 the_table()->Hashtable::oops_do(f);
duke@435 208 }
duke@435 209
duke@435 210 // Probing
duke@435 211 static oop lookup(symbolOop symbol);
duke@435 212
duke@435 213 // Interning
duke@435 214 static oop intern(symbolOop symbol, TRAPS);
duke@435 215 static oop intern(oop string, TRAPS);
duke@435 216 static oop intern(const char *utf8_string, TRAPS);
duke@435 217
duke@435 218 // Debugging
duke@435 219 static void verify();
duke@435 220
duke@435 221 // Sharing
duke@435 222 static void copy_buckets(char** top, char*end) {
duke@435 223 the_table()->Hashtable::copy_buckets(top, end);
duke@435 224 }
duke@435 225 static void copy_table(char** top, char*end) {
duke@435 226 the_table()->Hashtable::copy_table(top, end);
duke@435 227 }
duke@435 228 static void reverse() {
duke@435 229 ((BasicHashtable*)the_table())->reverse();
duke@435 230 }
duke@435 231 };
stefank@2314 232
stefank@2314 233 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP

mercurial