Thu, 01 Sep 2011 01:31:25 -0700
7079673: JSR 292: C1 should inline bytecoded method handle adapters
Reviewed-by: never
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 2003, 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 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/placeholders.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "oops/oop.inline.hpp" |
stefank@2314 | 29 | #include "runtime/fieldType.hpp" |
stefank@2314 | 30 | #include "utilities/hashtable.inline.hpp" |
duke@435 | 31 | |
duke@435 | 32 | // Placeholder methods |
duke@435 | 33 | |
coleenp@2497 | 34 | PlaceholderEntry* PlaceholderTable::new_entry(int hash, Symbol* name, |
duke@435 | 35 | oop loader, bool havesupername, |
coleenp@2497 | 36 | Symbol* supername) { |
coleenp@2497 | 37 | PlaceholderEntry* entry = (PlaceholderEntry*)Hashtable<Symbol*>::new_entry(hash, name); |
coleenp@2497 | 38 | // Hashtable with Symbol* literal must increment and decrement refcount. |
coleenp@2497 | 39 | name->increment_refcount(); |
duke@435 | 40 | entry->set_loader(loader); |
duke@435 | 41 | entry->set_havesupername(havesupername); |
duke@435 | 42 | entry->set_supername(supername); |
duke@435 | 43 | entry->set_superThreadQ(NULL); |
duke@435 | 44 | entry->set_loadInstanceThreadQ(NULL); |
duke@435 | 45 | entry->set_defineThreadQ(NULL); |
duke@435 | 46 | entry->set_definer(NULL); |
duke@435 | 47 | entry->set_instanceKlass(NULL); |
duke@435 | 48 | return entry; |
duke@435 | 49 | } |
duke@435 | 50 | |
coleenp@2497 | 51 | void PlaceholderTable::free_entry(PlaceholderEntry* entry) { |
coleenp@2497 | 52 | // decrement Symbol refcount here because Hashtable doesn't. |
coleenp@2497 | 53 | entry->literal()->decrement_refcount(); |
coleenp@2497 | 54 | if (entry->supername() != NULL) entry->supername()->decrement_refcount(); |
coleenp@2497 | 55 | Hashtable<Symbol*>::free_entry(entry); |
coleenp@2497 | 56 | } |
coleenp@2497 | 57 | |
duke@435 | 58 | |
duke@435 | 59 | // Placeholder objects represent classes currently being loaded. |
duke@435 | 60 | // All threads examining the placeholder table must hold the |
duke@435 | 61 | // SystemDictionary_lock, so we don't need special precautions |
duke@435 | 62 | // on store ordering here. |
duke@435 | 63 | void PlaceholderTable::add_entry(int index, unsigned int hash, |
coleenp@2497 | 64 | Symbol* class_name, Handle class_loader, |
coleenp@2497 | 65 | bool havesupername, Symbol* supername){ |
duke@435 | 66 | assert_locked_or_safepoint(SystemDictionary_lock); |
coleenp@2497 | 67 | assert(class_name != NULL, "adding NULL obj"); |
duke@435 | 68 | |
duke@435 | 69 | // Both readers and writers are locked so it's safe to just |
duke@435 | 70 | // create the placeholder and insert it in the list without a membar. |
coleenp@2497 | 71 | PlaceholderEntry* entry = new_entry(hash, class_name, class_loader(), havesupername, supername); |
duke@435 | 72 | add_entry(index, entry); |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | |
duke@435 | 76 | // Remove a placeholder object. |
duke@435 | 77 | void PlaceholderTable::remove_entry(int index, unsigned int hash, |
coleenp@2497 | 78 | Symbol* class_name, |
duke@435 | 79 | Handle class_loader) { |
duke@435 | 80 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 81 | PlaceholderEntry** p = bucket_addr(index); |
duke@435 | 82 | while (*p) { |
duke@435 | 83 | PlaceholderEntry *probe = *p; |
coleenp@2497 | 84 | if (probe->hash() == hash && probe->equals(class_name, class_loader())) { |
duke@435 | 85 | // Delete entry |
duke@435 | 86 | *p = probe->next(); |
duke@435 | 87 | free_entry(probe); |
duke@435 | 88 | return; |
duke@435 | 89 | } |
duke@435 | 90 | p = probe->next_addr(); |
duke@435 | 91 | } |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash, |
coleenp@2497 | 95 | Symbol* class_name, |
duke@435 | 96 | Handle class_loader) { |
duke@435 | 97 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 98 | |
duke@435 | 99 | oop class_loader_ = class_loader(); |
duke@435 | 100 | |
duke@435 | 101 | for (PlaceholderEntry *place_probe = bucket(index); |
duke@435 | 102 | place_probe != NULL; |
duke@435 | 103 | place_probe = place_probe->next()) { |
duke@435 | 104 | if (place_probe->hash() == hash && |
coleenp@2497 | 105 | place_probe->equals(class_name, class_loader_)) { |
duke@435 | 106 | return place_probe; |
duke@435 | 107 | } |
duke@435 | 108 | } |
duke@435 | 109 | return NULL; |
duke@435 | 110 | } |
duke@435 | 111 | |
coleenp@2497 | 112 | Symbol* PlaceholderTable::find_entry(int index, unsigned int hash, |
coleenp@2497 | 113 | Symbol* class_name, |
duke@435 | 114 | Handle class_loader) { |
duke@435 | 115 | PlaceholderEntry* probe = get_entry(index, hash, class_name, class_loader); |
coleenp@2497 | 116 | return (probe? probe->klassname(): (Symbol*)NULL); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // find_and_add returns probe pointer - old or new |
duke@435 | 120 | // If no entry exists, add a placeholder entry |
duke@435 | 121 | // If entry exists, reuse entry |
duke@435 | 122 | // For both, push SeenThread for classloadAction |
duke@435 | 123 | // if havesupername: this is used for circularity for instanceklass loading |
coleenp@2497 | 124 | PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash, Symbol* name, Handle loader, classloadAction action, Symbol* supername, Thread* thread) { |
duke@435 | 125 | PlaceholderEntry* probe = get_entry(index, hash, name, loader); |
duke@435 | 126 | if (probe == NULL) { |
duke@435 | 127 | // Nothing found, add place holder |
duke@435 | 128 | add_entry(index, hash, name, loader, (action == LOAD_SUPER), supername); |
duke@435 | 129 | probe = get_entry(index, hash, name, loader); |
duke@435 | 130 | } else { |
duke@435 | 131 | if (action == LOAD_SUPER) { |
duke@435 | 132 | probe->set_havesupername(true); |
coleenp@2497 | 133 | probe->set_supername(supername); |
duke@435 | 134 | } |
duke@435 | 135 | } |
duke@435 | 136 | if (probe) probe->add_seen_thread(thread, action); |
duke@435 | 137 | return probe; |
duke@435 | 138 | } |
duke@435 | 139 | |
duke@435 | 140 | |
duke@435 | 141 | // placeholder used to track class loading internal states |
duke@435 | 142 | // placeholder existence now for loading superclass/superinterface |
duke@435 | 143 | // superthreadQ tracks class circularity, while loading superclass/superinterface |
duke@435 | 144 | // loadInstanceThreadQ tracks load_instance_class calls |
duke@435 | 145 | // definer() tracks the single thread that owns define token |
duke@435 | 146 | // defineThreadQ tracks waiters on defining thread's results |
duke@435 | 147 | // 1st claimant creates placeholder |
duke@435 | 148 | // find_and_add adds SeenThread entry for appropriate queue |
duke@435 | 149 | // All claimants remove SeenThread after completing action |
duke@435 | 150 | // On removal: if definer and all queues empty, remove entry |
duke@435 | 151 | // Note: you can be in both placeholders and systemDictionary |
duke@435 | 152 | // see parse_stream for redefine classes |
duke@435 | 153 | // Therefore - must always check SD first |
duke@435 | 154 | // Ignores the case where entry is not found |
duke@435 | 155 | void PlaceholderTable::find_and_remove(int index, unsigned int hash, |
coleenp@2497 | 156 | Symbol* name, Handle loader, Thread* thread) { |
duke@435 | 157 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 158 | PlaceholderEntry *probe = get_entry(index, hash, name, loader); |
duke@435 | 159 | if (probe != NULL) { |
duke@435 | 160 | // No other threads using this entry |
duke@435 | 161 | if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL) |
duke@435 | 162 | && (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) { |
duke@435 | 163 | remove_entry(index, hash, name, loader); |
duke@435 | 164 | } |
duke@435 | 165 | } |
duke@435 | 166 | } |
duke@435 | 167 | |
duke@435 | 168 | PlaceholderTable::PlaceholderTable(int table_size) |
coleenp@2497 | 169 | : TwoOopHashtable<Symbol*>(table_size, sizeof(PlaceholderEntry)) { |
duke@435 | 170 | } |
duke@435 | 171 | |
duke@435 | 172 | |
duke@435 | 173 | void PlaceholderTable::oops_do(OopClosure* f) { |
duke@435 | 174 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 175 | for (PlaceholderEntry* probe = bucket(index); |
duke@435 | 176 | probe != NULL; |
duke@435 | 177 | probe = probe->next()) { |
duke@435 | 178 | probe->oops_do(f); |
duke@435 | 179 | } |
duke@435 | 180 | } |
duke@435 | 181 | } |
duke@435 | 182 | |
duke@435 | 183 | |
duke@435 | 184 | void PlaceholderEntry::oops_do(OopClosure* blk) { |
coleenp@2497 | 185 | assert(klassname() != NULL, "should have a non-null klass"); |
duke@435 | 186 | if (_loader != NULL) { |
duke@435 | 187 | blk->do_oop(loader_addr()); |
duke@435 | 188 | } |
duke@435 | 189 | if (_instanceKlass != NULL) { |
duke@435 | 190 | blk->do_oop((oop*)instanceKlass_addr()); |
duke@435 | 191 | } |
duke@435 | 192 | } |
duke@435 | 193 | |
duke@435 | 194 | // do all entries in the placeholder table |
coleenp@2497 | 195 | void PlaceholderTable::entries_do(void f(Symbol*, oop)) { |
duke@435 | 196 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 197 | for (PlaceholderEntry* probe = bucket(index); |
duke@435 | 198 | probe != NULL; |
duke@435 | 199 | probe = probe->next()) { |
coleenp@2497 | 200 | f(probe->klassname(), probe->loader()); |
duke@435 | 201 | } |
duke@435 | 202 | } |
duke@435 | 203 | } |
duke@435 | 204 | |
duke@435 | 205 | |
duke@435 | 206 | #ifndef PRODUCT |
duke@435 | 207 | // Note, doesn't append a cr |
duke@435 | 208 | void PlaceholderEntry::print() const { |
coleenp@2497 | 209 | klassname()->print_value(); |
duke@435 | 210 | if (loader() != NULL) { |
duke@435 | 211 | tty->print(", loader "); |
duke@435 | 212 | loader()->print_value(); |
duke@435 | 213 | } |
duke@435 | 214 | if (supername() != NULL) { |
duke@435 | 215 | tty->print(", supername "); |
duke@435 | 216 | supername()->print_value(); |
duke@435 | 217 | } |
duke@435 | 218 | if (definer() != NULL) { |
duke@435 | 219 | tty->print(", definer "); |
duke@435 | 220 | definer()->print_value(); |
duke@435 | 221 | } |
duke@435 | 222 | if (instanceKlass() != NULL) { |
duke@435 | 223 | tty->print(", instanceKlass "); |
duke@435 | 224 | instanceKlass()->print_value(); |
duke@435 | 225 | } |
duke@435 | 226 | tty->print("\n"); |
duke@435 | 227 | tty->print("loadInstanceThreadQ threads:"); |
duke@435 | 228 | loadInstanceThreadQ()->printActionQ(); |
duke@435 | 229 | tty->print("\n"); |
duke@435 | 230 | tty->print("superThreadQ threads:"); |
duke@435 | 231 | superThreadQ()->printActionQ(); |
duke@435 | 232 | tty->print("\n"); |
duke@435 | 233 | tty->print("defineThreadQ threads:"); |
duke@435 | 234 | defineThreadQ()->printActionQ(); |
duke@435 | 235 | tty->print("\n"); |
duke@435 | 236 | } |
duke@435 | 237 | #endif |
duke@435 | 238 | |
duke@435 | 239 | void PlaceholderEntry::verify() const { |
duke@435 | 240 | guarantee(loader() == NULL || loader()->is_instance(), |
duke@435 | 241 | "checking type of _loader"); |
duke@435 | 242 | guarantee(instanceKlass() == NULL |
duke@435 | 243 | || Klass::cast(instanceKlass())->oop_is_instance(), |
duke@435 | 244 | "checking type of instanceKlass result"); |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | void PlaceholderTable::verify() { |
duke@435 | 248 | int element_count = 0; |
duke@435 | 249 | for (int pindex = 0; pindex < table_size(); pindex++) { |
duke@435 | 250 | for (PlaceholderEntry* probe = bucket(pindex); |
duke@435 | 251 | probe != NULL; |
duke@435 | 252 | probe = probe->next()) { |
duke@435 | 253 | probe->verify(); |
duke@435 | 254 | element_count++; // both klasses and place holders count |
duke@435 | 255 | } |
duke@435 | 256 | } |
duke@435 | 257 | guarantee(number_of_entries() == element_count, |
duke@435 | 258 | "Verify of system dictionary failed"); |
duke@435 | 259 | } |
duke@435 | 260 | |
duke@435 | 261 | |
duke@435 | 262 | #ifndef PRODUCT |
duke@435 | 263 | void PlaceholderTable::print() { |
duke@435 | 264 | for (int pindex = 0; pindex < table_size(); pindex++) { |
duke@435 | 265 | for (PlaceholderEntry* probe = bucket(pindex); |
duke@435 | 266 | probe != NULL; |
duke@435 | 267 | probe = probe->next()) { |
duke@435 | 268 | if (Verbose) tty->print("%4d: ", pindex); |
duke@435 | 269 | tty->print(" place holder "); |
duke@435 | 270 | |
duke@435 | 271 | probe->print(); |
duke@435 | 272 | tty->cr(); |
duke@435 | 273 | } |
duke@435 | 274 | } |
duke@435 | 275 | } |
duke@435 | 276 | #endif |