src/share/vm/classfile/placeholders.cpp

Mon, 20 Jan 2014 11:47:07 +0100

author
tschatzl
date
Mon, 20 Jan 2014 11:47:07 +0100
changeset 6229
5a32d2a3cc1e
parent 4425
aefb345d3f5e
child 6876
710a3c8b516e
permissions
-rw-r--r--

8027476: Improve performance of Stringtable unlink
8027455: Improve symbol table scan times during gc pauses
Summary: Parallelize string table and symbol table scan during remark and full GC. Some additional statistics output if the experimental flag G1TraceStringSymbolTableScrubbing is set.
Reviewed-by: mgerdin, coleenp, brutisso

duke@435 1 /*
acorn@4425 2 * Copyright (c) 2003, 2013, 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
acorn@4425 145 // placeholder is 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 // Therefore - must always check SD first
duke@435 157 // Ignores the case where entry is not found
duke@435 158 void PlaceholderTable::find_and_remove(int index, unsigned int hash,
acorn@4425 159 Symbol* name, ClassLoaderData* loader_data,
acorn@4425 160 classloadAction action,
acorn@4425 161 Thread* thread) {
duke@435 162 assert_locked_or_safepoint(SystemDictionary_lock);
coleenp@4037 163 PlaceholderEntry *probe = get_entry(index, hash, name, loader_data);
duke@435 164 if (probe != NULL) {
acorn@4425 165 probe->remove_seen_thread(thread, action);
acorn@4425 166 // If no other threads using this entry, and this thread is not using this entry for other states
duke@435 167 if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL)
duke@435 168 && (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) {
coleenp@4037 169 remove_entry(index, hash, name, loader_data);
duke@435 170 }
duke@435 171 }
duke@435 172 }
duke@435 173
duke@435 174 PlaceholderTable::PlaceholderTable(int table_size)
zgu@3900 175 : TwoOopHashtable<Symbol*, mtClass>(table_size, sizeof(PlaceholderEntry)) {
duke@435 176 }
duke@435 177
duke@435 178
coleenp@4037 179 void PlaceholderTable::classes_do(KlassClosure* f) {
duke@435 180 for (int index = 0; index < table_size(); index++) {
duke@435 181 for (PlaceholderEntry* probe = bucket(index);
duke@435 182 probe != NULL;
duke@435 183 probe = probe->next()) {
coleenp@4037 184 probe->classes_do(f);
duke@435 185 }
duke@435 186 }
duke@435 187 }
duke@435 188
duke@435 189
coleenp@4037 190 void PlaceholderEntry::classes_do(KlassClosure* closure) {
coleenp@2497 191 assert(klassname() != NULL, "should have a non-null klass");
duke@435 192 if (_instanceKlass != NULL) {
hseigel@4278 193 closure->do_klass(instance_klass());
duke@435 194 }
duke@435 195 }
duke@435 196
duke@435 197 // do all entries in the placeholder table
coleenp@4037 198 void PlaceholderTable::entries_do(void f(Symbol*)) {
duke@435 199 for (int index = 0; index < table_size(); index++) {
duke@435 200 for (PlaceholderEntry* probe = bucket(index);
duke@435 201 probe != NULL;
duke@435 202 probe = probe->next()) {
coleenp@4037 203 f(probe->klassname());
duke@435 204 }
duke@435 205 }
duke@435 206 }
duke@435 207
duke@435 208
duke@435 209 #ifndef PRODUCT
duke@435 210 // Note, doesn't append a cr
duke@435 211 void PlaceholderEntry::print() const {
coleenp@2497 212 klassname()->print_value();
coleenp@4037 213 if (loader_data() != NULL) {
duke@435 214 tty->print(", loader ");
coleenp@4037 215 loader_data()->print_value();
duke@435 216 }
duke@435 217 if (supername() != NULL) {
duke@435 218 tty->print(", supername ");
duke@435 219 supername()->print_value();
duke@435 220 }
duke@435 221 if (definer() != NULL) {
duke@435 222 tty->print(", definer ");
duke@435 223 definer()->print_value();
duke@435 224 }
hseigel@4278 225 if (instance_klass() != NULL) {
coleenp@4037 226 tty->print(", InstanceKlass ");
hseigel@4278 227 instance_klass()->print_value();
duke@435 228 }
duke@435 229 tty->print("\n");
duke@435 230 tty->print("loadInstanceThreadQ threads:");
duke@435 231 loadInstanceThreadQ()->printActionQ();
duke@435 232 tty->print("\n");
duke@435 233 tty->print("superThreadQ threads:");
duke@435 234 superThreadQ()->printActionQ();
duke@435 235 tty->print("\n");
duke@435 236 tty->print("defineThreadQ threads:");
duke@435 237 defineThreadQ()->printActionQ();
duke@435 238 tty->print("\n");
duke@435 239 }
duke@435 240 #endif
duke@435 241
duke@435 242 void PlaceholderEntry::verify() const {
coleenp@4037 243 guarantee(loader_data() != NULL, "Must have been setup.");
coleenp@4037 244 guarantee(loader_data()->class_loader() == NULL || loader_data()->class_loader()->is_instance(),
duke@435 245 "checking type of _loader");
hseigel@4278 246 guarantee(instance_klass() == NULL
hseigel@4278 247 || instance_klass()->oop_is_instance(),
hseigel@4278 248 "checking type of instance_klass result");
duke@435 249 }
duke@435 250
duke@435 251 void PlaceholderTable::verify() {
duke@435 252 int element_count = 0;
duke@435 253 for (int pindex = 0; pindex < table_size(); pindex++) {
duke@435 254 for (PlaceholderEntry* probe = bucket(pindex);
duke@435 255 probe != NULL;
duke@435 256 probe = probe->next()) {
duke@435 257 probe->verify();
duke@435 258 element_count++; // both klasses and place holders count
duke@435 259 }
duke@435 260 }
duke@435 261 guarantee(number_of_entries() == element_count,
duke@435 262 "Verify of system dictionary failed");
duke@435 263 }
duke@435 264
duke@435 265
duke@435 266 #ifndef PRODUCT
duke@435 267 void PlaceholderTable::print() {
duke@435 268 for (int pindex = 0; pindex < table_size(); pindex++) {
duke@435 269 for (PlaceholderEntry* probe = bucket(pindex);
duke@435 270 probe != NULL;
duke@435 271 probe = probe->next()) {
duke@435 272 if (Verbose) tty->print("%4d: ", pindex);
duke@435 273 tty->print(" place holder ");
duke@435 274
duke@435 275 probe->print();
duke@435 276 tty->cr();
duke@435 277 }
duke@435 278 }
duke@435 279 }
duke@435 280 #endif

mercurial