src/share/vm/classfile/placeholders.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP
aoqi@0 26 #define SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/thread.hpp"
aoqi@0 29 #include "utilities/hashtable.hpp"
aoqi@0 30
aoqi@0 31 class PlaceholderEntry;
aoqi@0 32
aoqi@0 33 // Placeholder objects. These represent classes currently
aoqi@0 34 // being loaded, as well as arrays of primitives.
aoqi@0 35 //
aoqi@0 36
aoqi@0 37 class PlaceholderTable : public TwoOopHashtable<Symbol*, mtClass> {
aoqi@0 38 friend class VMStructs;
aoqi@0 39
aoqi@0 40 public:
aoqi@0 41 PlaceholderTable(int table_size);
aoqi@0 42
aoqi@0 43 PlaceholderEntry* new_entry(int hash, Symbol* name, ClassLoaderData* loader_data, bool havesupername, Symbol* supername);
aoqi@0 44 void free_entry(PlaceholderEntry* entry);
aoqi@0 45
aoqi@0 46 PlaceholderEntry* bucket(int i) {
aoqi@0 47 return (PlaceholderEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 PlaceholderEntry** bucket_addr(int i) {
aoqi@0 51 return (PlaceholderEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 void add_entry(int index, PlaceholderEntry* new_entry) {
aoqi@0 55 Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 void add_entry(int index, unsigned int hash, Symbol* name,
aoqi@0 59 ClassLoaderData* loader_data, bool havesupername, Symbol* supername);
aoqi@0 60
aoqi@0 61 // This returns a Symbol* to match type for SystemDictionary
aoqi@0 62 Symbol* find_entry(int index, unsigned int hash,
aoqi@0 63 Symbol* name, ClassLoaderData* loader_data);
aoqi@0 64
aoqi@0 65 PlaceholderEntry* get_entry(int index, unsigned int hash,
aoqi@0 66 Symbol* name, ClassLoaderData* loader_data);
aoqi@0 67
aoqi@0 68 // caller to create a placeholder entry must enumerate an action
aoqi@0 69 // caller claims ownership of that action
aoqi@0 70 // For parallel classloading:
aoqi@0 71 // multiple LOAD_INSTANCE threads can proceed in parallel
aoqi@0 72 // multiple LOAD_SUPER threads can proceed in parallel
aoqi@0 73 // LOAD_SUPER needed to check for class circularity
aoqi@0 74 // DEFINE_CLASS: ultimately define class must be single threaded
aoqi@0 75 // on a class/classloader basis
aoqi@0 76 // so the head of that queue owns the token
aoqi@0 77 // and the rest of the threads return the result the first thread gets
aoqi@0 78 enum classloadAction {
aoqi@0 79 LOAD_INSTANCE = 1, // calling load_instance_class
aoqi@0 80 LOAD_SUPER = 2, // loading superclass for this class
aoqi@0 81 DEFINE_CLASS = 3 // find_or_define class
aoqi@0 82 };
aoqi@0 83
aoqi@0 84 // find_and_add returns probe pointer - old or new
aoqi@0 85 // If no entry exists, add a placeholder entry and push SeenThread for classloadAction
aoqi@0 86 // If entry exists, reuse entry and push SeenThread for classloadAction
aoqi@0 87 PlaceholderEntry* find_and_add(int index, unsigned int hash,
aoqi@0 88 Symbol* name, ClassLoaderData* loader_data,
aoqi@0 89 classloadAction action, Symbol* supername,
aoqi@0 90 Thread* thread);
aoqi@0 91
aoqi@0 92 void remove_entry(int index, unsigned int hash,
aoqi@0 93 Symbol* name, ClassLoaderData* loader_data);
aoqi@0 94
aoqi@0 95 // find_and_remove first removes SeenThread for classloadAction
aoqi@0 96 // If all queues are empty and definer is null, remove the PlacheholderEntry completely
aoqi@0 97 void find_and_remove(int index, unsigned int hash,
aoqi@0 98 Symbol* name, ClassLoaderData* loader_data,
aoqi@0 99 classloadAction action, Thread* thread);
aoqi@0 100
aoqi@0 101 // GC support.
aoqi@0 102 void classes_do(KlassClosure* f);
aoqi@0 103
aoqi@0 104 // JVMTI support
aoqi@0 105 void entries_do(void f(Symbol*));
aoqi@0 106
aoqi@0 107 #ifndef PRODUCT
aoqi@0 108 void print();
aoqi@0 109 #endif
aoqi@0 110 void verify();
aoqi@0 111 };
aoqi@0 112
aoqi@0 113 // SeenThread objects represent list of threads that are
aoqi@0 114 // currently performing a load action on a class.
aoqi@0 115 // For class circularity, set before loading a superclass.
aoqi@0 116 // For bootclasssearchpath, set before calling load_instance_class.
aoqi@0 117 // Defining must be single threaded on a class/classloader basis
aoqi@0 118 // For DEFINE_CLASS, the head of the queue owns the
aoqi@0 119 // define token and the rest of the threads wait to return the
aoqi@0 120 // result the first thread gets.
aoqi@0 121 class SeenThread: public CHeapObj<mtInternal> {
aoqi@0 122 private:
aoqi@0 123 Thread *_thread;
aoqi@0 124 SeenThread* _stnext;
aoqi@0 125 SeenThread* _stprev;
aoqi@0 126 public:
aoqi@0 127 SeenThread(Thread *thread) {
aoqi@0 128 _thread = thread;
aoqi@0 129 _stnext = NULL;
aoqi@0 130 _stprev = NULL;
aoqi@0 131 }
aoqi@0 132 Thread* thread() const { return _thread;}
aoqi@0 133 void set_thread(Thread *thread) { _thread = thread; }
aoqi@0 134
aoqi@0 135 SeenThread* next() const { return _stnext;}
aoqi@0 136 void set_next(SeenThread *seen) { _stnext = seen; }
aoqi@0 137 void set_prev(SeenThread *seen) { _stprev = seen; }
aoqi@0 138
aoqi@0 139 #ifndef PRODUCT
aoqi@0 140 void printActionQ() {
aoqi@0 141 SeenThread* seen = this;
aoqi@0 142 while (seen != NULL) {
aoqi@0 143 seen->thread()->print_value();
aoqi@0 144 tty->print(", ");
aoqi@0 145 seen = seen->next();
aoqi@0 146 }
aoqi@0 147 }
aoqi@0 148 #endif // PRODUCT
aoqi@0 149 };
aoqi@0 150
aoqi@0 151 // Placeholder objects represent classes currently being loaded.
aoqi@0 152 // All threads examining the placeholder table must hold the
aoqi@0 153 // SystemDictionary_lock, so we don't need special precautions
aoqi@0 154 // on store ordering here.
aoqi@0 155 // The system dictionary is the only user of this class.
aoqi@0 156
aoqi@0 157 class PlaceholderEntry : public HashtableEntry<Symbol*, mtClass> {
aoqi@0 158 friend class VMStructs;
aoqi@0 159
aoqi@0 160
aoqi@0 161 private:
aoqi@0 162 ClassLoaderData* _loader_data; // initiating loader
aoqi@0 163 bool _havesupername; // distinguish between null supername, and unknown
aoqi@0 164 Symbol* _supername;
aoqi@0 165 Thread* _definer; // owner of define token
aoqi@0 166 Klass* _instanceKlass; // InstanceKlass from successful define
aoqi@0 167 SeenThread* _superThreadQ; // doubly-linked queue of Threads loading a superclass for this class
aoqi@0 168 SeenThread* _loadInstanceThreadQ; // loadInstance thread
aoqi@0 169 // can be multiple threads if classloader object lock broken by application
aoqi@0 170 // or if classloader supports parallel classloading
aoqi@0 171
aoqi@0 172 SeenThread* _defineThreadQ; // queue of Threads trying to define this class
aoqi@0 173 // including _definer
aoqi@0 174 // _definer owns token
aoqi@0 175 // queue waits for and returns results from _definer
aoqi@0 176
aoqi@0 177 public:
aoqi@0 178 // Simple accessors, used only by SystemDictionary
aoqi@0 179 Symbol* klassname() const { return literal(); }
aoqi@0 180
aoqi@0 181 ClassLoaderData* loader_data() const { return _loader_data; }
aoqi@0 182 void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
aoqi@0 183
aoqi@0 184 bool havesupername() const { return _havesupername; }
aoqi@0 185 void set_havesupername(bool havesupername) { _havesupername = havesupername; }
aoqi@0 186
aoqi@0 187 Symbol* supername() const { return _supername; }
aoqi@0 188 void set_supername(Symbol* supername) {
aoqi@0 189 _supername = supername;
aoqi@0 190 if (_supername != NULL) _supername->increment_refcount();
aoqi@0 191 }
aoqi@0 192
aoqi@0 193 Thread* definer() const {return _definer; }
aoqi@0 194 void set_definer(Thread* definer) { _definer = definer; }
aoqi@0 195
aoqi@0 196 Klass* instance_klass() const {return _instanceKlass; }
aoqi@0 197 void set_instance_klass(Klass* ik) { _instanceKlass = ik; }
aoqi@0 198
aoqi@0 199 SeenThread* superThreadQ() const { return _superThreadQ; }
aoqi@0 200 void set_superThreadQ(SeenThread* SeenThread) { _superThreadQ = SeenThread; }
aoqi@0 201
aoqi@0 202 SeenThread* loadInstanceThreadQ() const { return _loadInstanceThreadQ; }
aoqi@0 203 void set_loadInstanceThreadQ(SeenThread* SeenThread) { _loadInstanceThreadQ = SeenThread; }
aoqi@0 204
aoqi@0 205 SeenThread* defineThreadQ() const { return _defineThreadQ; }
aoqi@0 206 void set_defineThreadQ(SeenThread* SeenThread) { _defineThreadQ = SeenThread; }
aoqi@0 207
aoqi@0 208 PlaceholderEntry* next() const {
aoqi@0 209 return (PlaceholderEntry*)HashtableEntry<Symbol*, mtClass>::next();
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 PlaceholderEntry** next_addr() {
aoqi@0 213 return (PlaceholderEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 // Test for equality
aoqi@0 217 // Entries are unique for class/classloader name pair
aoqi@0 218 bool equals(Symbol* class_name, ClassLoaderData* loader) const {
aoqi@0 219 return (klassname() == class_name && loader_data() == loader);
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 SeenThread* actionToQueue(PlaceholderTable::classloadAction action) {
aoqi@0 223 SeenThread* queuehead;
aoqi@0 224 switch (action) {
aoqi@0 225 case PlaceholderTable::LOAD_INSTANCE:
aoqi@0 226 queuehead = _loadInstanceThreadQ;
aoqi@0 227 break;
aoqi@0 228 case PlaceholderTable::LOAD_SUPER:
aoqi@0 229 queuehead = _superThreadQ;
aoqi@0 230 break;
aoqi@0 231 case PlaceholderTable::DEFINE_CLASS:
aoqi@0 232 queuehead = _defineThreadQ;
aoqi@0 233 break;
aoqi@0 234 default: Unimplemented();
aoqi@0 235 }
aoqi@0 236 return queuehead;
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 void set_threadQ(SeenThread* seenthread, PlaceholderTable::classloadAction action) {
aoqi@0 240 switch (action) {
aoqi@0 241 case PlaceholderTable::LOAD_INSTANCE:
aoqi@0 242 _loadInstanceThreadQ = seenthread;
aoqi@0 243 break;
aoqi@0 244 case PlaceholderTable::LOAD_SUPER:
aoqi@0 245 _superThreadQ = seenthread;
aoqi@0 246 break;
aoqi@0 247 case PlaceholderTable::DEFINE_CLASS:
aoqi@0 248 _defineThreadQ = seenthread;
aoqi@0 249 break;
aoqi@0 250 default: Unimplemented();
aoqi@0 251 }
aoqi@0 252 return;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 bool super_load_in_progress() {
aoqi@0 256 return (_superThreadQ != NULL);
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 bool instance_load_in_progress() {
aoqi@0 260 return (_loadInstanceThreadQ != NULL);
aoqi@0 261 }
aoqi@0 262
aoqi@0 263 bool define_class_in_progress() {
aoqi@0 264 return (_defineThreadQ != NULL);
aoqi@0 265 }
aoqi@0 266
aoqi@0 267 // Doubly-linked list of Threads per action for class/classloader pair
aoqi@0 268 // Class circularity support: links in thread before loading superclass
aoqi@0 269 // bootstrapsearchpath support: links in a thread before load_instance_class
aoqi@0 270 // definers: use as queue of define requestors, including owner of
aoqi@0 271 // define token. Appends for debugging of requestor order
aoqi@0 272 void add_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
aoqi@0 273 assert_lock_strong(SystemDictionary_lock);
aoqi@0 274 SeenThread* threadEntry = new SeenThread(thread);
aoqi@0 275 SeenThread* seen = actionToQueue(action);
aoqi@0 276
aoqi@0 277 if (seen == NULL) {
aoqi@0 278 set_threadQ(threadEntry, action);
aoqi@0 279 return;
aoqi@0 280 }
aoqi@0 281 SeenThread* next;
aoqi@0 282 while ((next = seen->next()) != NULL) {
aoqi@0 283 seen = next;
aoqi@0 284 }
aoqi@0 285 seen->set_next(threadEntry);
aoqi@0 286 threadEntry->set_prev(seen);
aoqi@0 287 return;
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 bool check_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
aoqi@0 291 assert_lock_strong(SystemDictionary_lock);
aoqi@0 292 SeenThread* threadQ = actionToQueue(action);
aoqi@0 293 SeenThread* seen = threadQ;
aoqi@0 294 while (seen) {
aoqi@0 295 if (thread == seen->thread()) {
aoqi@0 296 return true;
aoqi@0 297 }
aoqi@0 298 seen = seen->next();
aoqi@0 299 }
aoqi@0 300 return false;
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 // returns true if seenthreadQ is now empty
aoqi@0 304 // Note, caller must ensure probe still exists while holding
aoqi@0 305 // SystemDictionary_lock
aoqi@0 306 // ignores if cleanup has already been done
aoqi@0 307 // if found, deletes SeenThread
aoqi@0 308 bool remove_seen_thread(Thread* thread, PlaceholderTable::classloadAction action) {
aoqi@0 309 assert_lock_strong(SystemDictionary_lock);
aoqi@0 310 SeenThread* threadQ = actionToQueue(action);
aoqi@0 311 SeenThread* seen = threadQ;
aoqi@0 312 SeenThread* prev = NULL;
aoqi@0 313 while (seen) {
aoqi@0 314 if (thread == seen->thread()) {
aoqi@0 315 if (prev) {
aoqi@0 316 prev->set_next(seen->next());
aoqi@0 317 } else {
aoqi@0 318 set_threadQ(seen->next(), action);
aoqi@0 319 }
aoqi@0 320 if (seen->next()) {
aoqi@0 321 seen->next()->set_prev(prev);
aoqi@0 322 }
aoqi@0 323 delete seen;
aoqi@0 324 break;
aoqi@0 325 }
aoqi@0 326 prev = seen;
aoqi@0 327 seen = seen->next();
aoqi@0 328 }
aoqi@0 329 return (actionToQueue(action) == NULL);
aoqi@0 330 }
aoqi@0 331
aoqi@0 332 // GC support
aoqi@0 333 // Applies "f->do_oop" to all root oops in the placeholder table.
aoqi@0 334 void classes_do(KlassClosure* closure);
aoqi@0 335
aoqi@0 336 // Print method doesn't append a cr
aoqi@0 337 void print() const PRODUCT_RETURN;
aoqi@0 338 void verify() const;
aoqi@0 339 };
aoqi@0 340
aoqi@0 341 #endif // SHARE_VM_CLASSFILE_PLACEHOLDERS_HPP

mercurial