src/share/vm/classfile/placeholders.hpp

Tue, 22 Mar 2011 13:36:33 -0700

author
jcoomes
date
Tue, 22 Mar 2011 13:36:33 -0700
changeset 2661
b099aaf51bf8
parent 2497
3582bf76420e
child 2708
1d1603768966
permissions
-rw-r--r--

6962931: move interned strings out of the perm gen
Reviewed-by: never, coleenp, ysr, jwilhelm

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, 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_PLACEHOLDERS_HPP
stefank@2314 26 #define SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP
stefank@2314 27
stefank@2325 28 #include "runtime/thread.hpp"
stefank@2314 29 #include "utilities/hashtable.hpp"
stefank@2314 30
duke@435 31 class PlaceholderEntry;
duke@435 32
duke@435 33 // Placeholder objects. These represent classes currently
duke@435 34 // being loaded, as well as arrays of primitives.
duke@435 35 //
duke@435 36
coleenp@2497 37 class PlaceholderTable : public TwoOopHashtable<Symbol*> {
duke@435 38 friend class VMStructs;
duke@435 39
duke@435 40 public:
duke@435 41 PlaceholderTable(int table_size);
duke@435 42
coleenp@2497 43 PlaceholderEntry* new_entry(int hash, Symbol* name, oop loader, bool havesupername, Symbol* supername);
coleenp@2497 44 void free_entry(PlaceholderEntry* entry);
duke@435 45
duke@435 46 PlaceholderEntry* bucket(int i) {
coleenp@2497 47 return (PlaceholderEntry*)Hashtable<Symbol*>::bucket(i);
duke@435 48 }
duke@435 49
duke@435 50 PlaceholderEntry** bucket_addr(int i) {
coleenp@2497 51 return (PlaceholderEntry**)Hashtable<Symbol*>::bucket_addr(i);
duke@435 52 }
duke@435 53
duke@435 54 void add_entry(int index, PlaceholderEntry* new_entry) {
coleenp@2497 55 Hashtable<Symbol*>::add_entry(index, (HashtableEntry<Symbol*>*)new_entry);
duke@435 56 }
duke@435 57
coleenp@2497 58 void add_entry(int index, unsigned int hash, Symbol* name,
coleenp@2497 59 Handle loader, bool havesupername, Symbol* supername);
duke@435 60
coleenp@2497 61 // This returns a Symbol* to match type for SystemDictionary
coleenp@2497 62 Symbol* find_entry(int index, unsigned int hash,
coleenp@2497 63 Symbol* name, Handle loader);
duke@435 64
duke@435 65 PlaceholderEntry* get_entry(int index, unsigned int hash,
coleenp@2497 66 Symbol* name, Handle loader);
duke@435 67
duke@435 68 // caller to create a placeholder entry must enumerate an action
duke@435 69 // caller claims ownership of that action
duke@435 70 // For parallel classloading:
duke@435 71 // multiple LOAD_INSTANCE threads can proceed in parallel
duke@435 72 // multiple LOAD_SUPER threads can proceed in parallel
duke@435 73 // LOAD_SUPER needed to check for class circularity
duke@435 74 // DEFINE_CLASS: ultimately define class must be single threaded
duke@435 75 // on a class/classloader basis
duke@435 76 // so the head of that queue owns the token
duke@435 77 // and the rest of the threads return the result the first thread gets
duke@435 78 enum classloadAction {
duke@435 79 LOAD_INSTANCE = 1, // calling load_instance_class
duke@435 80 LOAD_SUPER = 2, // loading superclass for this class
duke@435 81 DEFINE_CLASS = 3 // find_or_define class
duke@435 82 };
duke@435 83
duke@435 84 // find_and_add returns probe pointer - old or new
duke@435 85 // If no entry exists, add a placeholder entry and push SeenThread
duke@435 86 // If entry exists, reuse entry and push SeenThread for classloadAction
duke@435 87 PlaceholderEntry* find_and_add(int index, unsigned int hash,
coleenp@2497 88 Symbol* name, Handle loader,
coleenp@2497 89 classloadAction action, Symbol* supername,
duke@435 90 Thread* thread);
duke@435 91
duke@435 92 void remove_entry(int index, unsigned int hash,
coleenp@2497 93 Symbol* name, Handle loader);
duke@435 94
duke@435 95 // Remove placeholder information
duke@435 96 void find_and_remove(int index, unsigned int hash,
coleenp@2497 97 Symbol* name, Handle loader, Thread* thread);
duke@435 98
duke@435 99 // GC support.
duke@435 100 void oops_do(OopClosure* f);
duke@435 101
duke@435 102 // JVMTI support
coleenp@2497 103 void entries_do(void f(Symbol*, oop));
duke@435 104
duke@435 105 #ifndef PRODUCT
duke@435 106 void print();
duke@435 107 #endif
duke@435 108 void verify();
duke@435 109 };
duke@435 110
duke@435 111 // SeenThread objects represent list of threads that are
duke@435 112 // currently performing a load action on a class.
duke@435 113 // For class circularity, set before loading a superclass.
duke@435 114 // For bootclasssearchpath, set before calling load_instance_class.
duke@435 115 // Defining must be single threaded on a class/classloader basis
duke@435 116 // For DEFINE_CLASS, the head of the queue owns the
duke@435 117 // define token and the rest of the threads wait to return the
duke@435 118 // result the first thread gets.
duke@435 119 class SeenThread: public CHeapObj {
duke@435 120 private:
duke@435 121 Thread *_thread;
duke@435 122 SeenThread* _stnext;
duke@435 123 SeenThread* _stprev;
duke@435 124 public:
duke@435 125 SeenThread(Thread *thread) {
duke@435 126 _thread = thread;
duke@435 127 _stnext = NULL;
duke@435 128 _stprev = NULL;
duke@435 129 }
duke@435 130 Thread* thread() const { return _thread;}
duke@435 131 void set_thread(Thread *thread) { _thread = thread; }
duke@435 132
duke@435 133 SeenThread* next() const { return _stnext;}
duke@435 134 void set_next(SeenThread *seen) { _stnext = seen; }
duke@435 135 void set_prev(SeenThread *seen) { _stprev = seen; }
duke@435 136
duke@435 137 #ifndef PRODUCT
duke@435 138 void printActionQ() {
duke@435 139 SeenThread* seen = this;
duke@435 140 while (seen != NULL) {
duke@435 141 seen->thread()->print_value();
duke@435 142 tty->print(", ");
duke@435 143 seen = seen->next();
duke@435 144 }
duke@435 145 }
duke@435 146 #endif // PRODUCT
duke@435 147 };
duke@435 148
duke@435 149 // Placeholder objects represent classes currently being loaded.
duke@435 150 // All threads examining the placeholder table must hold the
duke@435 151 // SystemDictionary_lock, so we don't need special precautions
duke@435 152 // on store ordering here.
duke@435 153 // The system dictionary is the only user of this class.
duke@435 154
coleenp@2497 155 class PlaceholderEntry : public HashtableEntry<Symbol*> {
duke@435 156 friend class VMStructs;
duke@435 157
duke@435 158
duke@435 159 private:
duke@435 160 oop _loader; // initiating loader
duke@435 161 bool _havesupername; // distinguish between null supername, and unknown
coleenp@2497 162 Symbol* _supername;
duke@435 163 Thread* _definer; // owner of define token
duke@435 164 klassOop _instanceKlass; // instanceKlass from successful define
duke@435 165 SeenThread* _superThreadQ; // doubly-linked queue of Threads loading a superclass for this class
duke@435 166 SeenThread* _loadInstanceThreadQ; // loadInstance thread
duke@435 167 // can be multiple threads if classloader object lock broken by application
duke@435 168 // or if classloader supports parallel classloading
duke@435 169
duke@435 170 SeenThread* _defineThreadQ; // queue of Threads trying to define this class
duke@435 171 // including _definer
duke@435 172 // _definer owns token
duke@435 173 // queue waits for and returns results from _definer
duke@435 174
duke@435 175 public:
duke@435 176 // Simple accessors, used only by SystemDictionary
coleenp@2497 177 Symbol* klassname() const { return literal(); }
duke@435 178
duke@435 179 oop loader() const { return _loader; }
duke@435 180 void set_loader(oop loader) { _loader = loader; }
duke@435 181 oop* loader_addr() { return &_loader; }
duke@435 182
duke@435 183 bool havesupername() const { return _havesupername; }
duke@435 184 void set_havesupername(bool havesupername) { _havesupername = havesupername; }
duke@435 185
coleenp@2497 186 Symbol* supername() const { return _supername; }
coleenp@2497 187 void set_supername(Symbol* supername) {
coleenp@2497 188 _supername = supername;
coleenp@2497 189 if (_supername != NULL) _supername->increment_refcount();
coleenp@2497 190 }
duke@435 191
duke@435 192 Thread* definer() const {return _definer; }
duke@435 193 void set_definer(Thread* definer) { _definer = definer; }
duke@435 194
duke@435 195 klassOop instanceKlass() const {return _instanceKlass; }
duke@435 196 void set_instanceKlass(klassOop instanceKlass) { _instanceKlass = instanceKlass; }
duke@435 197 klassOop* instanceKlass_addr() { return &_instanceKlass; }
duke@435 198
duke@435 199 SeenThread* superThreadQ() const { return _superThreadQ; }
duke@435 200 void set_superThreadQ(SeenThread* SeenThread) { _superThreadQ = SeenThread; }
duke@435 201
duke@435 202 SeenThread* loadInstanceThreadQ() const { return _loadInstanceThreadQ; }
duke@435 203 void set_loadInstanceThreadQ(SeenThread* SeenThread) { _loadInstanceThreadQ = SeenThread; }
duke@435 204
duke@435 205 SeenThread* defineThreadQ() const { return _defineThreadQ; }
duke@435 206 void set_defineThreadQ(SeenThread* SeenThread) { _defineThreadQ = SeenThread; }
duke@435 207
duke@435 208 PlaceholderEntry* next() const {
coleenp@2497 209 return (PlaceholderEntry*)HashtableEntry<Symbol*>::next();
duke@435 210 }
duke@435 211
duke@435 212 PlaceholderEntry** next_addr() {
coleenp@2497 213 return (PlaceholderEntry**)HashtableEntry<Symbol*>::next_addr();
duke@435 214 }
duke@435 215
duke@435 216 // Test for equality
duke@435 217 // Entries are unique for class/classloader name pair
coleenp@2497 218 bool equals(Symbol* class_name, oop class_loader) const {
coleenp@2497 219 return (klassname() == class_name && loader() == class_loader);
duke@435 220 }
duke@435 221
duke@435 222 SeenThread* actionToQueue(PlaceholderTable::classloadAction action) {
duke@435 223 SeenThread* queuehead;
duke@435 224 switch (action) {
duke@435 225 case PlaceholderTable::LOAD_INSTANCE:
duke@435 226 queuehead = _loadInstanceThreadQ;
duke@435 227 break;
duke@435 228 case PlaceholderTable::LOAD_SUPER:
duke@435 229 queuehead = _superThreadQ;
duke@435 230 break;
duke@435 231 case PlaceholderTable::DEFINE_CLASS:
duke@435 232 queuehead = _defineThreadQ;
duke@435 233 break;
duke@435 234 default: Unimplemented();
duke@435 235 }
duke@435 236 return queuehead;
duke@435 237 }
duke@435 238
duke@435 239 void set_threadQ(SeenThread* seenthread, PlaceholderTable::classloadAction action) {
duke@435 240 switch (action) {
duke@435 241 case PlaceholderTable::LOAD_INSTANCE:
duke@435 242 _loadInstanceThreadQ = seenthread;
duke@435 243 break;
duke@435 244 case PlaceholderTable::LOAD_SUPER:
duke@435 245 _superThreadQ = seenthread;
duke@435 246 break;
duke@435 247 case PlaceholderTable::DEFINE_CLASS:
duke@435 248 _defineThreadQ = seenthread;
duke@435 249 break;
duke@435 250 default: Unimplemented();
duke@435 251 }
duke@435 252 return;
duke@435 253 }
duke@435 254
duke@435 255 bool super_load_in_progress() {
duke@435 256 return (_superThreadQ != NULL);
duke@435 257 }
duke@435 258
duke@435 259 bool instance_load_in_progress() {
duke@435 260 return (_loadInstanceThreadQ != NULL);
duke@435 261 }
duke@435 262
duke@435 263 bool define_class_in_progress() {
duke@435 264 return (_defineThreadQ != NULL);
duke@435 265 }
duke@435 266
duke@435 267 // Doubly-linked list of Threads per action for class/classloader pair
duke@435 268 // Class circularity support: links in thread before loading superclass
duke@435 269 // bootstrapsearchpath support: links in a thread before load_instance_class
duke@435 270 // definers: use as queue of define requestors, including owner of
duke@435 271 // define token. Appends for debugging of requestor order
duke@435 272 void add_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 273 assert_lock_strong(SystemDictionary_lock);
duke@435 274 SeenThread* threadEntry = new SeenThread(thread);
duke@435 275 SeenThread* seen = actionToQueue(action);
duke@435 276
duke@435 277 if (seen == NULL) {
duke@435 278 set_threadQ(threadEntry, action);
duke@435 279 return;
duke@435 280 }
duke@435 281 SeenThread* next;
duke@435 282 while ((next = seen->next()) != NULL) {
duke@435 283 seen = next;
duke@435 284 }
duke@435 285 seen->set_next(threadEntry);
duke@435 286 threadEntry->set_prev(seen);
duke@435 287 return;
duke@435 288 }
duke@435 289
duke@435 290 bool check_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 291 assert_lock_strong(SystemDictionary_lock);
duke@435 292 SeenThread* threadQ = actionToQueue(action);
duke@435 293 SeenThread* seen = threadQ;
duke@435 294 while (seen) {
duke@435 295 if (thread == seen->thread()) {
duke@435 296 return true;
duke@435 297 }
duke@435 298 seen = seen->next();
duke@435 299 }
duke@435 300 return false;
duke@435 301 }
duke@435 302
duke@435 303 // returns true if seenthreadQ is now empty
duke@435 304 // Note, caller must ensure probe still exists while holding
duke@435 305 // SystemDictionary_lock
duke@435 306 // ignores if cleanup has already been done
duke@435 307 // if found, deletes SeenThread
duke@435 308 bool remove_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 309 assert_lock_strong(SystemDictionary_lock);
duke@435 310 SeenThread* threadQ = actionToQueue(action);
duke@435 311 SeenThread* seen = threadQ;
duke@435 312 SeenThread* prev = NULL;
duke@435 313 while (seen) {
duke@435 314 if (thread == seen->thread()) {
duke@435 315 if (prev) {
duke@435 316 prev->set_next(seen->next());
duke@435 317 } else {
duke@435 318 set_threadQ(seen->next(), action);
duke@435 319 }
duke@435 320 if (seen->next()) {
duke@435 321 seen->next()->set_prev(prev);
duke@435 322 }
duke@435 323 delete seen;
duke@435 324 break;
duke@435 325 }
duke@435 326 prev = seen;
duke@435 327 seen = seen->next();
duke@435 328 }
duke@435 329 return (actionToQueue(action) == NULL);
duke@435 330 }
duke@435 331
duke@435 332 // GC support
duke@435 333 // Applies "f->do_oop" to all root oops in the placeholder table.
duke@435 334 void oops_do(OopClosure* blk);
duke@435 335
duke@435 336 // Print method doesn't append a cr
duke@435 337 void print() const PRODUCT_RETURN;
duke@435 338 void verify() const;
duke@435 339 };
stefank@2314 340
stefank@2314 341 #endif // SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP

mercurial