src/share/vm/classfile/placeholders.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3900
d2a62e0f25eb
child 4278
070d523b96a7
permissions
-rw-r--r--

6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>

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 #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
zgu@3900 37 class PlaceholderTable : public TwoOopHashtable<Symbol*, mtClass> {
duke@435 38 friend class VMStructs;
duke@435 39
duke@435 40 public:
duke@435 41 PlaceholderTable(int table_size);
duke@435 42
coleenp@4037 43 PlaceholderEntry* new_entry(int hash, Symbol* name, ClassLoaderData* loader_data, bool havesupername, Symbol* supername);
coleenp@2497 44 void free_entry(PlaceholderEntry* entry);
duke@435 45
duke@435 46 PlaceholderEntry* bucket(int i) {
zgu@3900 47 return (PlaceholderEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
duke@435 48 }
duke@435 49
duke@435 50 PlaceholderEntry** bucket_addr(int i) {
zgu@3900 51 return (PlaceholderEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
duke@435 52 }
duke@435 53
duke@435 54 void add_entry(int index, PlaceholderEntry* new_entry) {
zgu@3900 55 Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
duke@435 56 }
duke@435 57
coleenp@2497 58 void add_entry(int index, unsigned int hash, Symbol* name,
coleenp@4037 59 ClassLoaderData* loader_data, 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@4037 63 Symbol* name, ClassLoaderData* loader_data);
duke@435 64
duke@435 65 PlaceholderEntry* get_entry(int index, unsigned int hash,
coleenp@4037 66 Symbol* name, ClassLoaderData* loader_data);
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@4037 88 Symbol* name, ClassLoaderData* loader_data,
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@4037 93 Symbol* name, ClassLoaderData* loader_data);
duke@435 94
duke@435 95 // Remove placeholder information
duke@435 96 void find_and_remove(int index, unsigned int hash,
coleenp@4037 97 Symbol* name, ClassLoaderData* loader_data, Thread* thread);
duke@435 98
duke@435 99 // GC support.
coleenp@4037 100 void classes_do(KlassClosure* f);
duke@435 101
duke@435 102 // JVMTI support
coleenp@4037 103 void entries_do(void f(Symbol*));
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.
zgu@3900 119 class SeenThread: public CHeapObj<mtInternal> {
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
zgu@3900 155 class PlaceholderEntry : public HashtableEntry<Symbol*, mtClass> {
duke@435 156 friend class VMStructs;
duke@435 157
duke@435 158
duke@435 159 private:
coleenp@4037 160 ClassLoaderData* _loader_data; // 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
coleenp@4037 164 Klass* _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
coleenp@4037 179 ClassLoaderData* loader_data() const { return _loader_data; }
coleenp@4037 180 void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
duke@435 181
duke@435 182 bool havesupername() const { return _havesupername; }
duke@435 183 void set_havesupername(bool havesupername) { _havesupername = havesupername; }
duke@435 184
coleenp@2497 185 Symbol* supername() const { return _supername; }
coleenp@2497 186 void set_supername(Symbol* supername) {
coleenp@2497 187 _supername = supername;
coleenp@2497 188 if (_supername != NULL) _supername->increment_refcount();
coleenp@2497 189 }
duke@435 190
duke@435 191 Thread* definer() const {return _definer; }
duke@435 192 void set_definer(Thread* definer) { _definer = definer; }
duke@435 193
coleenp@4037 194 Klass* InstanceKlass() const {return _instanceKlass; }
coleenp@4037 195 void set_instanceKlass(Klass* InstanceKlass) { _instanceKlass = InstanceKlass; }
duke@435 196
duke@435 197 SeenThread* superThreadQ() const { return _superThreadQ; }
duke@435 198 void set_superThreadQ(SeenThread* SeenThread) { _superThreadQ = SeenThread; }
duke@435 199
duke@435 200 SeenThread* loadInstanceThreadQ() const { return _loadInstanceThreadQ; }
duke@435 201 void set_loadInstanceThreadQ(SeenThread* SeenThread) { _loadInstanceThreadQ = SeenThread; }
duke@435 202
duke@435 203 SeenThread* defineThreadQ() const { return _defineThreadQ; }
duke@435 204 void set_defineThreadQ(SeenThread* SeenThread) { _defineThreadQ = SeenThread; }
duke@435 205
duke@435 206 PlaceholderEntry* next() const {
zgu@3900 207 return (PlaceholderEntry*)HashtableEntry<Symbol*, mtClass>::next();
duke@435 208 }
duke@435 209
duke@435 210 PlaceholderEntry** next_addr() {
zgu@3900 211 return (PlaceholderEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
duke@435 212 }
duke@435 213
duke@435 214 // Test for equality
duke@435 215 // Entries are unique for class/classloader name pair
coleenp@4037 216 bool equals(Symbol* class_name, ClassLoaderData* loader) const {
coleenp@4037 217 return (klassname() == class_name && loader_data() == loader);
duke@435 218 }
duke@435 219
duke@435 220 SeenThread* actionToQueue(PlaceholderTable::classloadAction action) {
duke@435 221 SeenThread* queuehead;
duke@435 222 switch (action) {
duke@435 223 case PlaceholderTable::LOAD_INSTANCE:
duke@435 224 queuehead = _loadInstanceThreadQ;
duke@435 225 break;
duke@435 226 case PlaceholderTable::LOAD_SUPER:
duke@435 227 queuehead = _superThreadQ;
duke@435 228 break;
duke@435 229 case PlaceholderTable::DEFINE_CLASS:
duke@435 230 queuehead = _defineThreadQ;
duke@435 231 break;
duke@435 232 default: Unimplemented();
duke@435 233 }
duke@435 234 return queuehead;
duke@435 235 }
duke@435 236
duke@435 237 void set_threadQ(SeenThread* seenthread, PlaceholderTable::classloadAction action) {
duke@435 238 switch (action) {
duke@435 239 case PlaceholderTable::LOAD_INSTANCE:
duke@435 240 _loadInstanceThreadQ = seenthread;
duke@435 241 break;
duke@435 242 case PlaceholderTable::LOAD_SUPER:
duke@435 243 _superThreadQ = seenthread;
duke@435 244 break;
duke@435 245 case PlaceholderTable::DEFINE_CLASS:
duke@435 246 _defineThreadQ = seenthread;
duke@435 247 break;
duke@435 248 default: Unimplemented();
duke@435 249 }
duke@435 250 return;
duke@435 251 }
duke@435 252
duke@435 253 bool super_load_in_progress() {
duke@435 254 return (_superThreadQ != NULL);
duke@435 255 }
duke@435 256
duke@435 257 bool instance_load_in_progress() {
duke@435 258 return (_loadInstanceThreadQ != NULL);
duke@435 259 }
duke@435 260
duke@435 261 bool define_class_in_progress() {
duke@435 262 return (_defineThreadQ != NULL);
duke@435 263 }
duke@435 264
duke@435 265 // Doubly-linked list of Threads per action for class/classloader pair
duke@435 266 // Class circularity support: links in thread before loading superclass
duke@435 267 // bootstrapsearchpath support: links in a thread before load_instance_class
duke@435 268 // definers: use as queue of define requestors, including owner of
duke@435 269 // define token. Appends for debugging of requestor order
duke@435 270 void add_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 271 assert_lock_strong(SystemDictionary_lock);
duke@435 272 SeenThread* threadEntry = new SeenThread(thread);
duke@435 273 SeenThread* seen = actionToQueue(action);
duke@435 274
duke@435 275 if (seen == NULL) {
duke@435 276 set_threadQ(threadEntry, action);
duke@435 277 return;
duke@435 278 }
duke@435 279 SeenThread* next;
duke@435 280 while ((next = seen->next()) != NULL) {
duke@435 281 seen = next;
duke@435 282 }
duke@435 283 seen->set_next(threadEntry);
duke@435 284 threadEntry->set_prev(seen);
duke@435 285 return;
duke@435 286 }
duke@435 287
duke@435 288 bool check_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 289 assert_lock_strong(SystemDictionary_lock);
duke@435 290 SeenThread* threadQ = actionToQueue(action);
duke@435 291 SeenThread* seen = threadQ;
duke@435 292 while (seen) {
duke@435 293 if (thread == seen->thread()) {
duke@435 294 return true;
duke@435 295 }
duke@435 296 seen = seen->next();
duke@435 297 }
duke@435 298 return false;
duke@435 299 }
duke@435 300
duke@435 301 // returns true if seenthreadQ is now empty
duke@435 302 // Note, caller must ensure probe still exists while holding
duke@435 303 // SystemDictionary_lock
duke@435 304 // ignores if cleanup has already been done
duke@435 305 // if found, deletes SeenThread
duke@435 306 bool remove_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
duke@435 307 assert_lock_strong(SystemDictionary_lock);
duke@435 308 SeenThread* threadQ = actionToQueue(action);
duke@435 309 SeenThread* seen = threadQ;
duke@435 310 SeenThread* prev = NULL;
duke@435 311 while (seen) {
duke@435 312 if (thread == seen->thread()) {
duke@435 313 if (prev) {
duke@435 314 prev->set_next(seen->next());
duke@435 315 } else {
duke@435 316 set_threadQ(seen->next(), action);
duke@435 317 }
duke@435 318 if (seen->next()) {
duke@435 319 seen->next()->set_prev(prev);
duke@435 320 }
duke@435 321 delete seen;
duke@435 322 break;
duke@435 323 }
duke@435 324 prev = seen;
duke@435 325 seen = seen->next();
duke@435 326 }
duke@435 327 return (actionToQueue(action) == NULL);
duke@435 328 }
duke@435 329
duke@435 330 // GC support
duke@435 331 // Applies "f->do_oop" to all root oops in the placeholder table.
coleenp@4037 332 void classes_do(KlassClosure* closure);
duke@435 333
duke@435 334 // Print method doesn't append a cr
duke@435 335 void print() const PRODUCT_RETURN;
duke@435 336 void verify() const;
duke@435 337 };
stefank@2314 338
stefank@2314 339 #endif // SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP

mercurial