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