src/share/vm/classfile/placeholders.cpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

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

mercurial