Wed, 01 Jun 2011 23:25:20 -0700
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
Summary: Delegate invokedynamic linkage errors to MethodHandleNatives.raiseException.
Reviewed-by: never
duke@435 | 1 | /* |
never@2700 | 2 | * Copyright (c) 1997, 2011, 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" |
coleenp@2497 | 29 | #include "oops/symbol.hpp" |
stefank@2314 | 30 | #include "utilities/hashtable.hpp" |
stefank@2314 | 31 | |
coleenp@2497 | 32 | // The symbol table holds all Symbol*s and corresponding interned strings. |
coleenp@2497 | 33 | // Symbol*s 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 | |
coleenp@2497 | 45 | // Class to hold a newly created or referenced Symbol* temporarily in scope. |
coleenp@2497 | 46 | // new_symbol() and lookup() will create a Symbol* if not already in the |
coleenp@2497 | 47 | // symbol table and add to the symbol's reference count. |
coleenp@2497 | 48 | // probe() and lookup_only() will increment the refcount if symbol is found. |
coleenp@2497 | 49 | class TempNewSymbol : public StackObj { |
coleenp@2497 | 50 | Symbol* _temp; |
coleenp@2497 | 51 | |
coleenp@2497 | 52 | public: |
coleenp@2497 | 53 | TempNewSymbol() : _temp(NULL) {} |
coleenp@2497 | 54 | // Creating or looking up a symbol increments the symbol's reference count |
coleenp@2497 | 55 | TempNewSymbol(Symbol *s) : _temp(s) {} |
coleenp@2497 | 56 | |
coleenp@2497 | 57 | // Operator= increments reference count. |
coleenp@2497 | 58 | void operator=(const TempNewSymbol &s) { |
coleenp@2497 | 59 | _temp = s._temp; |
coleenp@2497 | 60 | if (_temp !=NULL) _temp->increment_refcount(); |
coleenp@2497 | 61 | } |
coleenp@2497 | 62 | |
coleenp@2497 | 63 | // Decrement reference counter so it can go away if it's unique |
coleenp@2497 | 64 | ~TempNewSymbol() { if (_temp != NULL) _temp->decrement_refcount(); } |
coleenp@2497 | 65 | |
coleenp@2497 | 66 | // Operators so they can be used like Symbols |
coleenp@2497 | 67 | Symbol* operator -> () const { return _temp; } |
coleenp@2497 | 68 | bool operator == (Symbol* o) const { return _temp == o; } |
coleenp@2497 | 69 | // Sneaky conversion function |
coleenp@2497 | 70 | operator Symbol*() { return _temp; } |
coleenp@2497 | 71 | }; |
coleenp@2497 | 72 | |
coleenp@2497 | 73 | class SymbolTable : public Hashtable<Symbol*> { |
duke@435 | 74 | friend class VMStructs; |
coleenp@2497 | 75 | friend class ClassFileParser; |
duke@435 | 76 | |
duke@435 | 77 | private: |
duke@435 | 78 | // The symbol table |
duke@435 | 79 | static SymbolTable* _the_table; |
duke@435 | 80 | |
coleenp@2497 | 81 | // For statistics |
coleenp@2497 | 82 | static int symbols_removed; |
coleenp@2497 | 83 | static int symbols_counted; |
coleenp@2497 | 84 | |
coleenp@2497 | 85 | Symbol* allocate_symbol(const u1* name, int len, TRAPS); // Assumes no characters larger than 0x7F |
coleenp@2497 | 86 | bool allocate_symbols(int names_count, const u1** names, int* lengths, Symbol** syms, TRAPS); |
coleenp@2497 | 87 | |
duke@435 | 88 | // Adding elements |
coleenp@2497 | 89 | Symbol* basic_add(int index, u1* name, int len, |
duke@435 | 90 | unsigned int hashValue, TRAPS); |
duke@435 | 91 | bool basic_add(constantPoolHandle cp, int names_count, |
duke@435 | 92 | const char** names, int* lengths, int* cp_indices, |
duke@435 | 93 | unsigned int* hashValues, TRAPS); |
duke@435 | 94 | |
coleenp@2497 | 95 | static void new_symbols(constantPoolHandle cp, int names_count, |
coleenp@2497 | 96 | const char** name, int* lengths, |
coleenp@2497 | 97 | int* cp_indices, unsigned int* hashValues, |
coleenp@2497 | 98 | TRAPS) { |
coleenp@2497 | 99 | add(cp, names_count, name, lengths, cp_indices, hashValues, THREAD); |
coleenp@2497 | 100 | } |
coleenp@2497 | 101 | |
coleenp@2497 | 102 | |
duke@435 | 103 | // Table size |
duke@435 | 104 | enum { |
duke@435 | 105 | symbol_table_size = 20011 |
duke@435 | 106 | }; |
duke@435 | 107 | |
coleenp@2497 | 108 | Symbol* lookup(int index, const char* name, int len, unsigned int hash); |
duke@435 | 109 | |
duke@435 | 110 | SymbolTable() |
coleenp@2497 | 111 | : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>)) {} |
duke@435 | 112 | |
duke@435 | 113 | SymbolTable(HashtableBucket* t, int number_of_entries) |
coleenp@2497 | 114 | : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t, |
duke@435 | 115 | number_of_entries) {} |
duke@435 | 116 | |
duke@435 | 117 | |
duke@435 | 118 | public: |
duke@435 | 119 | enum { |
duke@435 | 120 | symbol_alloc_batch_size = 8 |
duke@435 | 121 | }; |
duke@435 | 122 | |
duke@435 | 123 | // The symbol table |
duke@435 | 124 | static SymbolTable* the_table() { return _the_table; } |
duke@435 | 125 | |
duke@435 | 126 | static void create_table() { |
duke@435 | 127 | assert(_the_table == NULL, "One symbol table allowed."); |
duke@435 | 128 | _the_table = new SymbolTable(); |
duke@435 | 129 | } |
duke@435 | 130 | |
duke@435 | 131 | static void create_table(HashtableBucket* t, int length, |
duke@435 | 132 | int number_of_entries) { |
duke@435 | 133 | assert(_the_table == NULL, "One symbol table allowed."); |
duke@435 | 134 | assert(length == symbol_table_size * sizeof(HashtableBucket), |
duke@435 | 135 | "bad shared symbol size."); |
duke@435 | 136 | _the_table = new SymbolTable(t, number_of_entries); |
duke@435 | 137 | } |
duke@435 | 138 | |
coleenp@2497 | 139 | static Symbol* lookup(const char* name, int len, TRAPS); |
duke@435 | 140 | // lookup only, won't add. Also calculate hash. |
coleenp@2497 | 141 | static Symbol* lookup_only(const char* name, int len, unsigned int& hash); |
duke@435 | 142 | // Only copy to C string to be added if lookup failed. |
coleenp@2497 | 143 | static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS); |
coleenp@2497 | 144 | |
coleenp@2497 | 145 | static void release(Symbol* sym); |
duke@435 | 146 | |
jrose@1100 | 147 | // jchar (utf16) version of lookups |
coleenp@2497 | 148 | static Symbol* lookup_unicode(const jchar* name, int len, TRAPS); |
coleenp@2497 | 149 | static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash); |
jrose@1100 | 150 | |
duke@435 | 151 | static void add(constantPoolHandle cp, int names_count, |
duke@435 | 152 | const char** names, int* lengths, int* cp_indices, |
duke@435 | 153 | unsigned int* hashValues, TRAPS); |
duke@435 | 154 | |
coleenp@2497 | 155 | // Release any dead symbols |
coleenp@2497 | 156 | static void unlink(); |
coleenp@2497 | 157 | |
coleenp@2497 | 158 | // iterate over symbols |
coleenp@2497 | 159 | static void symbols_do(SymbolClosure *cl); |
coleenp@2497 | 160 | |
coleenp@2497 | 161 | // Symbol creation |
coleenp@2497 | 162 | static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) { |
coleenp@2497 | 163 | assert(utf8_buffer != NULL, "just checking"); |
coleenp@2497 | 164 | return lookup(utf8_buffer, length, THREAD); |
duke@435 | 165 | } |
coleenp@2497 | 166 | static Symbol* new_symbol(const char* name, TRAPS) { |
coleenp@2497 | 167 | return new_symbol(name, (int)strlen(name), THREAD); |
coleenp@2497 | 168 | } |
coleenp@2497 | 169 | static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) { |
coleenp@2497 | 170 | assert(begin <= end && end <= sym->utf8_length(), "just checking"); |
coleenp@2497 | 171 | return lookup(sym, begin, end, THREAD); |
duke@435 | 172 | } |
duke@435 | 173 | |
duke@435 | 174 | // Symbol lookup |
coleenp@2497 | 175 | static Symbol* lookup(int index, const char* name, int len, TRAPS); |
duke@435 | 176 | |
duke@435 | 177 | // Needed for preloading classes in signatures when compiling. |
duke@435 | 178 | // Returns the symbol is already present in symbol table, otherwise |
duke@435 | 179 | // NULL. NO ALLOCATION IS GUARANTEED! |
coleenp@2497 | 180 | static Symbol* probe(const char* name, int len) { |
jrose@1100 | 181 | unsigned int ignore_hash; |
jrose@1100 | 182 | return lookup_only(name, len, ignore_hash); |
jrose@1100 | 183 | } |
coleenp@2497 | 184 | static Symbol* probe_unicode(const jchar* name, int len) { |
jrose@1100 | 185 | unsigned int ignore_hash; |
jrose@1100 | 186 | return lookup_only_unicode(name, len, ignore_hash); |
jrose@1100 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | // Histogram |
duke@435 | 190 | static void print_histogram() PRODUCT_RETURN; |
coleenp@2497 | 191 | static void print() PRODUCT_RETURN; |
duke@435 | 192 | |
duke@435 | 193 | // Debugging |
duke@435 | 194 | static void verify(); |
duke@435 | 195 | |
duke@435 | 196 | // Sharing |
duke@435 | 197 | static void copy_buckets(char** top, char*end) { |
coleenp@2497 | 198 | the_table()->Hashtable<Symbol*>::copy_buckets(top, end); |
duke@435 | 199 | } |
duke@435 | 200 | static void copy_table(char** top, char*end) { |
coleenp@2497 | 201 | the_table()->Hashtable<Symbol*>::copy_table(top, end); |
duke@435 | 202 | } |
duke@435 | 203 | static void reverse(void* boundary = NULL) { |
coleenp@2497 | 204 | the_table()->Hashtable<Symbol*>::reverse(boundary); |
duke@435 | 205 | } |
duke@435 | 206 | }; |
duke@435 | 207 | |
coleenp@2497 | 208 | class StringTable : public Hashtable<oop> { |
duke@435 | 209 | friend class VMStructs; |
duke@435 | 210 | |
duke@435 | 211 | private: |
duke@435 | 212 | // The string table |
duke@435 | 213 | static StringTable* _the_table; |
duke@435 | 214 | |
duke@435 | 215 | static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS); |
duke@435 | 216 | oop basic_add(int index, Handle string_or_null, jchar* name, int len, |
duke@435 | 217 | unsigned int hashValue, TRAPS); |
duke@435 | 218 | |
duke@435 | 219 | oop lookup(int index, jchar* chars, int length, unsigned int hashValue); |
duke@435 | 220 | |
jcoomes@2660 | 221 | StringTable() : Hashtable<oop>((int)StringTableSize, |
jcoomes@2660 | 222 | sizeof (HashtableEntry<oop>)) {} |
duke@435 | 223 | |
duke@435 | 224 | StringTable(HashtableBucket* t, int number_of_entries) |
jcoomes@2660 | 225 | : Hashtable<oop>((int)StringTableSize, sizeof (HashtableEntry<oop>), t, |
jcoomes@2660 | 226 | number_of_entries) {} |
duke@435 | 227 | |
duke@435 | 228 | public: |
duke@435 | 229 | // The string table |
duke@435 | 230 | static StringTable* the_table() { return _the_table; } |
duke@435 | 231 | |
duke@435 | 232 | static void create_table() { |
duke@435 | 233 | assert(_the_table == NULL, "One string table allowed."); |
duke@435 | 234 | _the_table = new StringTable(); |
duke@435 | 235 | } |
duke@435 | 236 | |
duke@435 | 237 | static void create_table(HashtableBucket* t, int length, |
duke@435 | 238 | int number_of_entries) { |
duke@435 | 239 | assert(_the_table == NULL, "One string table allowed."); |
jcoomes@2660 | 240 | assert((size_t)length == StringTableSize * sizeof(HashtableBucket), |
duke@435 | 241 | "bad shared string size."); |
duke@435 | 242 | _the_table = new StringTable(t, number_of_entries); |
duke@435 | 243 | } |
duke@435 | 244 | |
duke@435 | 245 | // GC support |
duke@435 | 246 | // Delete pointers to otherwise-unreachable objects. |
coleenp@2497 | 247 | static void unlink(BoolObjectClosure* cl); |
duke@435 | 248 | |
duke@435 | 249 | // Invoke "f->do_oop" on the locations of all oops in the table. |
coleenp@2497 | 250 | static void oops_do(OopClosure* f); |
duke@435 | 251 | |
duke@435 | 252 | // Probing |
coleenp@2497 | 253 | static oop lookup(Symbol* symbol); |
duke@435 | 254 | |
duke@435 | 255 | // Interning |
coleenp@2497 | 256 | static oop intern(Symbol* symbol, TRAPS); |
duke@435 | 257 | static oop intern(oop string, TRAPS); |
duke@435 | 258 | static oop intern(const char *utf8_string, TRAPS); |
duke@435 | 259 | |
duke@435 | 260 | // Debugging |
duke@435 | 261 | static void verify(); |
duke@435 | 262 | |
duke@435 | 263 | // Sharing |
duke@435 | 264 | static void copy_buckets(char** top, char*end) { |
coleenp@2497 | 265 | the_table()->Hashtable<oop>::copy_buckets(top, end); |
duke@435 | 266 | } |
duke@435 | 267 | static void copy_table(char** top, char*end) { |
coleenp@2497 | 268 | the_table()->Hashtable<oop>::copy_table(top, end); |
duke@435 | 269 | } |
duke@435 | 270 | static void reverse() { |
coleenp@2497 | 271 | the_table()->Hashtable<oop>::reverse(); |
duke@435 | 272 | } |
duke@435 | 273 | }; |
stefank@2314 | 274 | |
stefank@2314 | 275 | #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP |