annotate src/hotspot/share/classfile/classLoaderData.hpp @ 54526:ee29b516a36a

revert changes
author jlaskey
date Wed, 23 Jan 2019 16:09:20 -0400
parents 7cc17c043ce0
children 33fe50b6d707
rev   line source
coleenp@13728 1 /*
coleenp@54304 2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
coleenp@13728 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@13728 4 *
coleenp@13728 5 * This code is free software; you can redistribute it and/or modify it
coleenp@13728 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@13728 7 * published by the Free Software Foundation.
coleenp@13728 8 *
coleenp@13728 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@13728 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
katleman@14847 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@13728 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@13728 13 * accompanied this code).
coleenp@13728 14 *
coleenp@13728 15 * You should have received a copy of the GNU General Public License version
coleenp@13728 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@13728 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@13728 18 *
coleenp@13728 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@13728 20 * or visit www.oracle.com if you need additional information or have any
coleenp@13728 21 * questions.
coleenp@13728 22 *
coleenp@13728 23 */
coleenp@13728 24
coleenp@54304 25 #ifndef SHARE_CLASSFILE_CLASSLOADERDATA_HPP
coleenp@54304 26 #define SHARE_CLASSFILE_CLASSLOADERDATA_HPP
coleenp@13728 27
coleenp@13728 28 #include "memory/allocation.hpp"
coleenp@13728 29 #include "memory/memRegion.hpp"
coleenp@13728 30 #include "memory/metaspace.hpp"
coleenp@46961 31 #include "oops/oopHandle.hpp"
coleenp@50233 32 #include "oops/weakHandle.hpp"
coleenp@13728 33 #include "runtime/mutex.hpp"
coleenp@13728 34 #include "utilities/growableArray.hpp"
mgronlun@27673 35 #include "utilities/macros.hpp"
egahlin@50662 36 #if INCLUDE_JFR
egahlin@50662 37 #include "jfr/support/jfrTraceIdExtension.hpp"
sla@18025 38 #endif
sla@18025 39
lfoltan@51268 40 // external name (synthetic) for the primordial "bootstrap" class loader instance
lfoltan@51268 41 #define BOOTSTRAP_LOADER_NAME "bootstrap"
lfoltan@51268 42 #define BOOTSTRAP_LOADER_NAME_LEN 9
egahlin@50662 43
coleenp@13728 44 //
coleenp@13728 45 // A class loader represents a linkset. Conceptually, a linkset identifies
coleenp@13728 46 // the complete transitive closure of resolved links that a dynamic linker can
coleenp@13728 47 // produce.
coleenp@13728 48 //
coleenp@13728 49 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
coleenp@13728 50 // used by the dynamic linker to allocate the runtime representation of all
coleenp@13728 51 // the types it defines.
coleenp@13728 52 //
coleenp@46729 53 // ClassLoaderData are stored in the runtime representation of classes,
coleenp@46729 54 // and provides iterators for root tracing and other GC operations.
coleenp@13728 55
coleenp@52788 56 class ClassLoaderDataGraph;
coleenp@13728 57 class JNIMethodBlock;
alanb@36508 58 class ModuleEntry;
alanb@36508 59 class PackageEntry;
alanb@36508 60 class ModuleEntryTable;
alanb@36508 61 class PackageEntryTable;
coleenp@46729 62 class DictionaryEntry;
coleenp@46729 63 class Dictionary;
sla@18025 64
coleenp@13728 65 // ClassLoaderData class
coleenp@13728 66
coleenp@13728 67 class ClassLoaderData : public CHeapObj<mtClass> {
coleenp@13728 68 friend class VMStructs;
coleenp@49813 69
coleenp@13728 70 private:
coleenp@49829 71 class ChunkedHandleList {
ehelin@44084 72 struct Chunk : public CHeapObj<mtClass> {
ehelin@44084 73 static const size_t CAPACITY = 32;
ehelin@44084 74
ehelin@44084 75 oop _data[CAPACITY];
ehelin@44084 76 volatile juint _size;
ehelin@44084 77 Chunk* _next;
ehelin@44084 78
tschatzl@52035 79 Chunk(Chunk* c) : _size(0), _next(c) { }
ehelin@44084 80 };
ehelin@44084 81
coleenp@47789 82 Chunk* volatile _head;
ehelin@44084 83
ehelin@44084 84 void oops_do_chunk(OopClosure* f, Chunk* c, const juint size);
ehelin@44084 85
ehelin@44084 86 public:
ehelin@44084 87 ChunkedHandleList() : _head(NULL) {}
ehelin@44084 88 ~ChunkedHandleList();
ehelin@44084 89
ehelin@44084 90 // Only one thread at a time can add, guarded by ClassLoaderData::metaspace_lock().
ehelin@44084 91 // However, multiple threads can execute oops_do concurrently with add.
ehelin@44084 92 oop* add(oop o);
coleenp@49813 93 bool contains(oop p);
coleenp@49868 94 NOT_PRODUCT(bool owner_of(oop* p);)
ehelin@44084 95 void oops_do(OopClosure* f);
coleenp@49813 96
coleenp@49813 97 int count() const;
ehelin@44084 98 };
ehelin@44084 99
coleenp@13728 100 friend class ClassLoaderDataGraph;
coleenp@52376 101 friend class ClassLoaderDataGraphIterator;
stefank@25492 102 friend class ClassLoaderDataGraphKlassIteratorAtomic;
coleenp@46729 103 friend class ClassLoaderDataGraphKlassIteratorStatic;
coleenp@13728 104 friend class ClassLoaderDataGraphMetaspaceIterator;
never@51380 105 friend class Klass;
coleenp@13728 106 friend class MetaDataFactory;
coleenp@13728 107 friend class Method;
coleenp@13728 108
coleenp@13728 109 static ClassLoaderData * _the_null_class_loader_data;
coleenp@13728 110
coleenp@50319 111 WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
coleenp@50319 112 OopHandle _class_loader; // The instance of java/lang/ClassLoader associated with
coleenp@50233 113 // this ClassLoaderData
mgerdin@16684 114
stuefe@49866 115 ClassLoaderMetaspace * volatile _metaspace; // Meta-space where meta-data defined by the
dholmes@38937 116 // classes in the class loader are allocated.
coleenp@13728 117 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup.
coleenp@13728 118 bool _unloading; // true if this class loader goes away
lfoltan@52170 119 bool _is_unsafe_anonymous; // CLD is dedicated to one class and that class determines the CLDs lifecycle.
lfoltan@52170 120 // For example, an unsafe anonymous class.
coleenp@47735 121
coleenp@47735 122 // Remembered sets support for the oops in the class loader data.
coleenp@47735 123 bool _modified_oops; // Card Table Equivalent (YC/CMS support)
coleenp@47735 124 bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
coleenp@47735 125
coleenp@50319 126 s2 _keep_alive; // if this CLD is kept alive.
lfoltan@52170 127 // Used for unsafe anonymous classes and the boot class
lfoltan@40358 128 // loader. _keep_alive does not need to be volatile or
lfoltan@52170 129 // atomic since there is one unique CLD per unsafe anonymous class.
coleenp@47735 130
eosterlund@53070 131 volatile int _claim; // non-zero if claimed, for example during GC traces.
eosterlund@53070 132 // To avoid applying oop closure more than once.
ehelin@44084 133 ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
ehelin@44084 134 // have the same life cycle of the corresponding ClassLoader.
alanb@36508 135
coleenp@49813 136 NOT_PRODUCT(volatile int _dependency_count;) // number of class loader dependencies
coleenp@49813 137
dholmes@38937 138 Klass* volatile _klasses; // The classes defined by the class loader.
dholmes@38937 139 PackageEntryTable* volatile _packages; // The packages defined by the class loader.
coleenp@46729 140 ModuleEntryTable* volatile _modules; // The modules defined by the class loader.
rprotacio@46387 141 ModuleEntry* _unnamed_module; // This class loader's unnamed module.
coleenp@46729 142 Dictionary* _dictionary; // The loaded InstanceKlasses, including initiated by this class loader
vlivanov@31046 143
coleenp@13728 144 // These method IDs are created for the class loader and set to NULL when the
coleenp@13728 145 // class loader is unloaded. They are rarely freed, only for redefine classes
coleenp@13728 146 // and if they lose a data race in InstanceKlass.
coleenp@13728 147 JNIMethodBlock* _jmethod_ids;
coleenp@13728 148
coleenp@13728 149 // Metadata to be deallocated when it's safe at class unloading, when
coleenp@13728 150 // this class loader isn't unloaded itself.
coleenp@13728 151 GrowableArray<Metadata*>* _deallocate_list;
coleenp@13728 152
coleenp@13728 153 // Support for walking class loader data objects
coleenp@13728 154 ClassLoaderData* _next; /// Next loader_datas created
coleenp@13728 155
coleenp@50319 156 Klass* _class_loader_klass;
lfoltan@51268 157 Symbol* _name;
lfoltan@51268 158 Symbol* _name_and_id;
egahlin@50662 159 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
mgronlun@42639 160
coleenp@13728 161 void set_next(ClassLoaderData* next) { _next = next; }
coleenp@13728 162 ClassLoaderData* next() const { return _next; }
coleenp@13728 163
lfoltan@52170 164 ClassLoaderData(Handle h_class_loader, bool is_unsafe_anonymous);
coleenp@13728 165 ~ClassLoaderData();
coleenp@13728 166
coleenp@47735 167 // The CLD are not placed in the Heap, so the Card Table or
coleenp@47735 168 // the Mod Union Table can't be used to mark when CLD have modified oops.
coleenp@47735 169 // The CT and MUT bits saves this information for the whole class loader data.
coleenp@47735 170 void clear_modified_oops() { _modified_oops = false; }
coleenp@47735 171 public:
coleenp@47735 172 void record_modified_oops() { _modified_oops = true; }
coleenp@47735 173 bool has_modified_oops() { return _modified_oops; }
coleenp@47735 174
coleenp@47735 175 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = true; }
coleenp@47735 176 void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; }
coleenp@47735 177 bool has_accumulated_modified_oops() { return _accumulated_modified_oops; }
eosterlund@52450 178 oop holder_no_keepalive() const;
coleenp@53944 179 oop holder_phantom() const;
eosterlund@52450 180
coleenp@47735 181 private:
coleenp@14588 182 void unload();
lfoltan@38014 183 bool keep_alive() const { return _keep_alive > 0; }
coleenp@50233 184
simonis@52802 185 void classes_do(void f(Klass* const));
farvidsson@21183 186 void loaded_classes_do(KlassClosure* klass_closure);
coleenp@13728 187 void classes_do(void f(InstanceKlass*));
roland@23526 188 void methods_do(void f(Method*));
alanb@36508 189 void modules_do(void f(ModuleEntry*));
alanb@36508 190 void packages_do(void f(PackageEntry*));
coleenp@13728 191
coleenp@13728 192 // Deallocate free list during class unloading.
coleenp@52039 193 void free_deallocate_list(); // for the classes that are not unloaded
coleenp@52039 194 void free_deallocate_list_C_heap_structures(); // for the classes that are unloaded
coleenp@13728 195
coleenp@13728 196 // Allocate out of this class loader data
coleenp@13728 197 MetaWord* allocate(size_t size);
coleenp@13728 198
coleenp@46729 199 Dictionary* create_dictionary();
coleenp@50319 200
lfoltan@51393 201 void initialize_name(Handle class_loader);
eosterlund@53070 202
coleenp@13728 203 public:
mgronlun@48832 204 // GC interface.
eosterlund@53070 205
eosterlund@53070 206 // The "claim" is typically used to check if oops_do needs to be applied on
eosterlund@53070 207 // the CLD or not. Most GCs only perform strong marking during the marking phase.
eosterlund@53070 208 enum {
eosterlund@53070 209 _claim_none = 0,
eosterlund@53070 210 _claim_finalizable = 2,
eosterlund@53070 211 _claim_strong = 3
eosterlund@53070 212 };
eosterlund@53070 213 void clear_claim() { _claim = 0; }
eosterlund@53070 214 bool claimed() const { return _claim != 0; }
eosterlund@53070 215 bool try_claim(int claim);
eosterlund@53070 216 int get_claim() const { return _claim; }
eosterlund@53070 217 void set_claim(int claim) { _claim = claim; }
stefank@25492 218
eosterlund@52449 219 // Computes if the CLD is alive or not. This is safe to call in concurrent
eosterlund@52449 220 // contexts.
coleenp@50233 221 bool is_alive() const;
stefank@25492 222
coleenp@13728 223 // Accessors
stuefe@49866 224 ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
coleenp@13728 225
coleenp@13728 226 static ClassLoaderData* the_null_class_loader_data() {
coleenp@13728 227 return _the_null_class_loader_data;
coleenp@13728 228 }
coleenp@13728 229
coleenp@25325 230 Mutex* metaspace_lock() const { return _metaspace_lock; }
coleenp@25325 231
lfoltan@52170 232 bool is_unsafe_anonymous() const { return _is_unsafe_anonymous; }
coleenp@14588 233
coleenp@49813 234 static void init_null_class_loader_data();
coleenp@13728 235
coleenp@13728 236 bool is_the_null_class_loader_data() const {
coleenp@13728 237 return this == _the_null_class_loader_data;
coleenp@13728 238 }
iklam@49817 239
iklam@49817 240 // Returns true if this class loader data is for the system class loader.
lfoltan@52170 241 // (Note that the class loader data may be unsafe anonymous.)
lfoltan@39616 242 bool is_system_class_loader_data() const;
iklam@49817 243
iklam@49817 244 // Returns true if this class loader data is for the platform class loader.
lfoltan@52170 245 // (Note that the class loader data may be unsafe anonymous.)
alanb@36508 246 bool is_platform_class_loader_data() const;
hseigel@49255 247
hseigel@49255 248 // Returns true if this class loader data is for the boot class loader.
lfoltan@52170 249 // (Note that the class loader data may be unsafe anonymous.)
coleenp@50319 250 inline bool is_boot_class_loader_data() const;
hseigel@49255 251
lfoltan@39616 252 bool is_builtin_class_loader_data() const;
hseigel@49244 253 bool is_permanent_class_loader_data() const;
coleenp@13728 254
coleenp@13728 255 // The Metaspace is created lazily so may be NULL. This
coleenp@13728 256 // method will allocate a Metaspace if needed.
stuefe@49866 257 ClassLoaderMetaspace* metaspace_non_null();
coleenp@13728 258
coleenp@50319 259 inline oop class_loader() const;
stefank@22900 260
coleenp@13728 261 // Returns true if this class loader data is for a loader going away.
eosterlund@52449 262 // Note that this is only safe after the GC has computed if the CLD is
eosterlund@52449 263 // unloading or not. In concurrent contexts where there are no such
eosterlund@52449 264 // guarantees, is_alive() should be used instead.
coleenp@13728 265 bool is_unloading() const {
coleenp@13728 266 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
coleenp@13728 267 return _unloading;
coleenp@13728 268 }
stefank@22900 269
lfoltan@52170 270 // Used to refcount an unsafe anonymous class's CLD in order to
coleenp@50319 271 // indicate their aliveness.
lfoltan@38014 272 void inc_keep_alive();
lfoltan@38014 273 void dec_keep_alive();
coleenp@13728 274
coleenp@50233 275 void initialize_holder(Handle holder);
coleenp@50233 276
eosterlund@53070 277 void oops_do(OopClosure* f, int claim_value, bool clear_modified_oops = false);
coleenp@13728 278
coleenp@13728 279 void classes_do(KlassClosure* klass_closure);
coleenp@46729 280 Klass* klasses() { return _klasses; }
coleenp@13728 281
coleenp@13728 282 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; }
coleenp@13728 283 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; }
coleenp@13728 284
coleenp@46729 285 void print() { print_on(tty); }
coleenp@49813 286 void print_on(outputStream* out) const PRODUCT_RETURN;
coleenp@46729 287 void print_value() { print_value_on(tty); }
acorn@15437 288 void print_value_on(outputStream* out) const;
coleenp@13728 289 void verify();
coleenp@13728 290
coleenp@46961 291 OopHandle add_handle(Handle h);
coleenp@47095 292 void remove_handle(OopHandle h);
coleenp@46961 293 void init_handle_locked(OopHandle& pd, Handle h); // used for concurrent access to ModuleEntry::_pd field
mgronlun@34666 294 void add_class(Klass* k, bool publicize = true);
coleenp@13728 295 void remove_class(Klass* k);
coleenp@22794 296 bool contains_klass(Klass* k);
coleenp@49813 297 void record_dependency(const Klass* to);
hseigel@46420 298 PackageEntryTable* packages() { return _packages; }
rprotacio@46387 299 ModuleEntry* unnamed_module() { return _unnamed_module; }
alanb@36508 300 ModuleEntryTable* modules();
alanb@36508 301 bool modules_defined() { return (_modules != NULL); }
coleenp@13728 302
coleenp@46729 303 // Loaded class dictionary
coleenp@46729 304 Dictionary* dictionary() const { return _dictionary; }
coleenp@46729 305
coleenp@13728 306 void add_to_deallocate_list(Metadata* m);
coleenp@13728 307
coleenp@13728 308 static ClassLoaderData* class_loader_data(oop loader);
stefank@15847 309 static ClassLoaderData* class_loader_data_or_null(oop loader);
lfoltan@52170 310 static ClassLoaderData* unsafe_anonymous_class_loader_data(Handle loader);
coleenp@13728 311
lfoltan@51268 312 // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
stuefe@50886 313 // Also works if unloading.
stuefe@50886 314 Klass* class_loader_klass() const { return _class_loader_klass; }
coleenp@50319 315
lfoltan@51268 316 // Returns the class loader's explict name as specified during
lfoltan@51268 317 // construction or the class loader's qualified class name.
lfoltan@51268 318 // Works during unloading.
lfoltan@51268 319 const char* loader_name() const;
lfoltan@51268 320 // Returns the explicitly specified class loader name or NULL.
lfoltan@51268 321 Symbol* name() const { return _name; }
lfoltan@51268 322
lfoltan@51268 323 // Obtain the class loader's _name_and_id, works during unloading.
lfoltan@51268 324 const char* loader_name_and_id() const;
lfoltan@51268 325 Symbol* name_and_id() const { return _name_and_id; }
stuefe@50886 326
egahlin@50662 327 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
coleenp@13728 328 };
coleenp@13728 329
coleenp@54304 330 #endif // SHARE_CLASSFILE_CLASSLOADERDATA_HPP