src/share/vm/classfile/classLoaderData.hpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6678
7384f6a12fc1
child 6742
e4a6e7f1b90b
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

coleenp@4037 1 /*
coleenp@6316 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
coleenp@4037 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@4037 4 *
coleenp@4037 5 * This code is free software; you can redistribute it and/or modify it
coleenp@4037 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@4037 7 * published by the Free Software Foundation.
coleenp@4037 8 *
coleenp@4037 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@4037 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
katleman@4376 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@4037 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@4037 13 * accompanied this code).
coleenp@4037 14 *
coleenp@4037 15 * You should have received a copy of the GNU General Public License version
coleenp@4037 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@4037 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@4037 18 *
coleenp@4037 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@4037 20 * or visit www.oracle.com if you need additional information or have any
coleenp@4037 21 * questions.
coleenp@4037 22 *
coleenp@4037 23 */
coleenp@4037 24
coleenp@4037 25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
coleenp@4037 26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
coleenp@4037 27
coleenp@4037 28 #include "memory/allocation.hpp"
coleenp@4037 29 #include "memory/memRegion.hpp"
coleenp@4037 30 #include "memory/metaspace.hpp"
coleenp@4037 31 #include "memory/metaspaceCounters.hpp"
coleenp@4037 32 #include "runtime/mutex.hpp"
coleenp@4037 33 #include "utilities/growableArray.hpp"
coleenp@4037 34
sla@5237 35 #if INCLUDE_TRACE
mgronlun@6131 36 # include "utilities/ticks.hpp"
sla@5237 37 #endif
sla@5237 38
coleenp@4037 39 //
coleenp@4037 40 // A class loader represents a linkset. Conceptually, a linkset identifies
coleenp@4037 41 // the complete transitive closure of resolved links that a dynamic linker can
coleenp@4037 42 // produce.
coleenp@4037 43 //
coleenp@4037 44 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
coleenp@4037 45 // used by the dynamic linker to allocate the runtime representation of all
coleenp@4037 46 // the types it defines.
coleenp@4037 47 //
coleenp@4037 48 // ClassLoaderData are stored in the runtime representation of classes and the
coleenp@4037 49 // system dictionary, are roots of garbage collection, and provides iterators
coleenp@4037 50 // for root tracing and other GC operations.
coleenp@4037 51
coleenp@4037 52 class ClassLoaderData;
coleenp@4037 53 class JNIMethodBlock;
coleenp@4037 54 class JNIHandleBlock;
coleenp@4037 55 class Metadebug;
sla@5237 56
coleenp@4037 57 // GC root for walking class loader data created
coleenp@4037 58
coleenp@4037 59 class ClassLoaderDataGraph : public AllStatic {
coleenp@4037 60 friend class ClassLoaderData;
coleenp@4037 61 friend class ClassLoaderDataGraphMetaspaceIterator;
coleenp@4037 62 friend class VMStructs;
coleenp@4037 63 private:
coleenp@4037 64 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
coleenp@4037 65 static ClassLoaderData* _head;
coleenp@4037 66 static ClassLoaderData* _unloading;
coleenp@4037 67 // CMS support.
coleenp@4037 68 static ClassLoaderData* _saved_head;
coleenp@6678 69 static bool _should_purge;
coleenp@4037 70
mgerdin@5013 71 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
sla@5237 72 static void post_class_unload_events(void);
coleenp@4037 73 public:
coleenp@4304 74 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
coleenp@4037 75 static void purge();
coleenp@4037 76 static void clear_claimed_marks();
coleenp@4037 77 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 78 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
coleenp@4304 79 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 80 static void classes_do(KlassClosure* klass_closure);
sla@5237 81 static void classes_do(void f(Klass* const));
farvidsson@6024 82 static void loaded_classes_do(KlassClosure* klass_closure);
sla@5237 83 static void classes_unloading_do(void f(Klass* const));
coleenp@4037 84 static bool do_unloading(BoolObjectClosure* is_alive);
coleenp@4037 85
coleenp@4037 86 // CMS support.
coleenp@4037 87 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
coleenp@4037 88 static GrowableArray<ClassLoaderData*>* new_clds();
coleenp@4037 89
coleenp@6678 90 static void set_should_purge(bool b) { _should_purge = b; }
coleenp@6678 91 static void purge_if_needed() {
coleenp@6678 92 // Only purge the CLDG for CMS if concurrent sweep is complete.
coleenp@6678 93 if (_should_purge) {
coleenp@6678 94 purge();
coleenp@6678 95 // reset for next time.
coleenp@6678 96 set_should_purge(false);
coleenp@6678 97 }
coleenp@6678 98 }
coleenp@6678 99
coleenp@4037 100 static void dump_on(outputStream * const out) PRODUCT_RETURN;
coleenp@4037 101 static void dump() { dump_on(tty); }
coleenp@4037 102 static void verify();
coleenp@4037 103
coleenp@4037 104 #ifndef PRODUCT
coleenp@4037 105 static bool contains_loader_data(ClassLoaderData* loader_data);
coleenp@4037 106 #endif
sla@5237 107
sla@5237 108 #if INCLUDE_TRACE
sla@5237 109 private:
mgronlun@6131 110 static Ticks _class_unload_time;
sla@5237 111 static void class_unload_event(Klass* const k);
sla@5237 112 #endif
coleenp@4037 113 };
coleenp@4037 114
coleenp@4037 115 // ClassLoaderData class
coleenp@4037 116
coleenp@4037 117 class ClassLoaderData : public CHeapObj<mtClass> {
coleenp@4037 118 friend class VMStructs;
coleenp@4037 119 private:
mgerdin@4903 120 class Dependencies VALUE_OBJ_CLASS_SPEC {
mgerdin@4903 121 objArrayOop _list_head;
mgerdin@4903 122 void locked_add(objArrayHandle last,
mgerdin@4903 123 objArrayHandle new_dependency,
mgerdin@4903 124 Thread* THREAD);
mgerdin@4903 125 public:
mgerdin@4903 126 Dependencies() : _list_head(NULL) {}
mgerdin@5016 127 Dependencies(TRAPS) : _list_head(NULL) {
mgerdin@5016 128 init(CHECK);
mgerdin@5016 129 }
mgerdin@4903 130 void add(Handle dependency, TRAPS);
mgerdin@4903 131 void init(TRAPS);
mgerdin@4903 132 void oops_do(OopClosure* f);
mgerdin@4903 133 };
mgerdin@4903 134
coleenp@4037 135 friend class ClassLoaderDataGraph;
coleenp@4037 136 friend class ClassLoaderDataGraphMetaspaceIterator;
coleenp@4037 137 friend class MetaDataFactory;
coleenp@4037 138 friend class Method;
coleenp@4037 139
coleenp@4037 140 static ClassLoaderData * _the_null_class_loader_data;
coleenp@4037 141
mgerdin@4903 142 oop _class_loader; // oop used to uniquely identify a class loader
mgerdin@4903 143 // class loader or a canonical class path
mgerdin@4903 144 Dependencies _dependencies; // holds dependencies from this class loader
mgerdin@4903 145 // data to others.
mgerdin@4903 146
coleenp@4037 147 Metaspace * _metaspace; // Meta-space where meta-data defined by the
coleenp@4037 148 // classes in the class loader are allocated.
coleenp@4037 149 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup.
coleenp@4037 150 bool _unloading; // true if this class loader goes away
coleenp@4304 151 bool _keep_alive; // if this CLD can be unloaded for anonymous loaders
coleenp@4345 152 bool _is_anonymous; // if this CLD is for an anonymous class
coleenp@4037 153 volatile int _claimed; // true if claimed, for example during GC traces.
coleenp@4037 154 // To avoid applying oop closure more than once.
coleenp@4037 155 // Has to be an int because we cas it.
coleenp@4037 156 Klass* _klasses; // The classes defined by the class loader.
coleenp@4037 157
coleenp@4037 158 JNIHandleBlock* _handles; // Handles to constant pool arrays
coleenp@4037 159
coleenp@4037 160 // These method IDs are created for the class loader and set to NULL when the
coleenp@4037 161 // class loader is unloaded. They are rarely freed, only for redefine classes
coleenp@4037 162 // and if they lose a data race in InstanceKlass.
coleenp@4037 163 JNIMethodBlock* _jmethod_ids;
coleenp@4037 164
coleenp@4037 165 // Metadata to be deallocated when it's safe at class unloading, when
coleenp@4037 166 // this class loader isn't unloaded itself.
coleenp@4037 167 GrowableArray<Metadata*>* _deallocate_list;
coleenp@4037 168
coleenp@4037 169 // Support for walking class loader data objects
coleenp@4037 170 ClassLoaderData* _next; /// Next loader_datas created
coleenp@4037 171
coleenp@4037 172 // ReadOnly and ReadWrite metaspaces (static because only on the null
coleenp@4037 173 // class loader for now).
coleenp@4037 174 static Metaspace* _ro_metaspace;
coleenp@4037 175 static Metaspace* _rw_metaspace;
coleenp@4037 176
coleenp@4037 177 void set_next(ClassLoaderData* next) { _next = next; }
coleenp@4037 178 ClassLoaderData* next() const { return _next; }
coleenp@4037 179
mgerdin@5016 180 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
coleenp@4037 181 ~ClassLoaderData();
coleenp@4037 182
coleenp@4037 183 void set_metaspace(Metaspace* m) { _metaspace = m; }
coleenp@4037 184
coleenp@4037 185 JNIHandleBlock* handles() const;
coleenp@4037 186 void set_handles(JNIHandleBlock* handles);
coleenp@4037 187
coleenp@4037 188 Mutex* metaspace_lock() const { return _metaspace_lock; }
coleenp@4037 189
coleenp@4037 190 // GC interface.
coleenp@4037 191 void clear_claimed() { _claimed = 0; }
coleenp@4037 192 bool claimed() const { return _claimed == 1; }
coleenp@4037 193 bool claim();
coleenp@4037 194
coleenp@4304 195 void unload();
coleenp@4304 196 bool keep_alive() const { return _keep_alive; }
coleenp@4304 197 bool is_alive(BoolObjectClosure* is_alive_closure) const;
sla@5237 198 void classes_do(void f(Klass*));
farvidsson@6024 199 void loaded_classes_do(KlassClosure* klass_closure);
coleenp@4037 200 void classes_do(void f(InstanceKlass*));
coleenp@4037 201
coleenp@4037 202 // Deallocate free list during class unloading.
coleenp@4037 203 void free_deallocate_list();
coleenp@4037 204
coleenp@4037 205 // Allocate out of this class loader data
coleenp@4037 206 MetaWord* allocate(size_t size);
coleenp@4037 207
coleenp@4037 208 public:
coleenp@4037 209 // Accessors
coleenp@4037 210 Metaspace* metaspace_or_null() const { return _metaspace; }
coleenp@4037 211
coleenp@4037 212 static ClassLoaderData* the_null_class_loader_data() {
coleenp@4037 213 return _the_null_class_loader_data;
coleenp@4037 214 }
coleenp@4037 215
coleenp@4345 216 bool is_anonymous() const { return _is_anonymous; }
coleenp@4304 217
coleenp@4037 218 static void init_null_class_loader_data() {
coleenp@4037 219 assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
coleenp@4037 220 assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
mgerdin@5016 221
mgerdin@5016 222 // We explicitly initialize the Dependencies object at a later phase in the initialization
mgerdin@5016 223 _the_null_class_loader_data = new ClassLoaderData((oop)NULL, false, Dependencies());
coleenp@4037 224 ClassLoaderDataGraph::_head = _the_null_class_loader_data;
coleenp@4037 225 assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
coleenp@4037 226 if (DumpSharedSpaces) {
coleenp@4037 227 _the_null_class_loader_data->initialize_shared_metaspaces();
coleenp@4037 228 }
coleenp@4037 229 }
coleenp@4037 230
coleenp@4037 231 bool is_the_null_class_loader_data() const {
coleenp@4037 232 return this == _the_null_class_loader_data;
coleenp@4037 233 }
twisti@4866 234 bool is_ext_class_loader_data() const;
coleenp@4037 235
coleenp@4037 236 // The Metaspace is created lazily so may be NULL. This
coleenp@4037 237 // method will allocate a Metaspace if needed.
coleenp@4037 238 Metaspace* metaspace_non_null();
coleenp@4037 239
coleenp@4037 240 oop class_loader() const { return _class_loader; }
coleenp@4037 241
coleenp@4037 242 // Returns true if this class loader data is for a loader going away.
coleenp@4037 243 bool is_unloading() const {
coleenp@4037 244 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
coleenp@4037 245 return _unloading;
coleenp@4037 246 }
coleenp@4304 247 // Anonymous class loader data doesn't have anything to keep them from
coleenp@4304 248 // being unloaded during parsing the anonymous class.
coleenp@4304 249 void set_keep_alive(bool value) { _keep_alive = value; }
coleenp@4037 250
coleenp@4037 251 unsigned int identity_hash() {
coleenp@4037 252 return _class_loader == NULL ? 0 : _class_loader->identity_hash();
coleenp@4037 253 }
coleenp@4037 254
coleenp@4037 255 // Used when tracing from klasses.
coleenp@4037 256 void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 257
coleenp@4037 258 void classes_do(KlassClosure* klass_closure);
coleenp@4037 259
coleenp@4037 260 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; }
coleenp@4037 261 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; }
coleenp@4037 262
coleenp@4037 263 void print_value() { print_value_on(tty); }
acorn@4497 264 void print_value_on(outputStream* out) const;
coleenp@4037 265 void dump(outputStream * const out) PRODUCT_RETURN;
coleenp@4037 266 void verify();
coleenp@4304 267 const char* loader_name();
coleenp@4037 268
coleenp@4037 269 jobject add_handle(Handle h);
coleenp@4037 270 void add_class(Klass* k);
coleenp@4037 271 void remove_class(Klass* k);
coleenp@6316 272 bool contains_klass(Klass* k);
coleenp@4037 273 void record_dependency(Klass* to, TRAPS);
coleenp@4304 274 void init_dependencies(TRAPS);
coleenp@4037 275
coleenp@4037 276 void add_to_deallocate_list(Metadata* m);
coleenp@4037 277
coleenp@4037 278 static ClassLoaderData* class_loader_data(oop loader);
stefank@4667 279 static ClassLoaderData* class_loader_data_or_null(oop loader);
coleenp@4304 280 static ClassLoaderData* anonymous_class_loader_data(oop loader, TRAPS);
coleenp@4037 281 static void print_loader(ClassLoaderData *loader_data, outputStream *out);
coleenp@4037 282
coleenp@4037 283 // CDS support
coleenp@4037 284 Metaspace* ro_metaspace();
coleenp@4037 285 Metaspace* rw_metaspace();
coleenp@4037 286 void initialize_shared_metaspaces();
coleenp@4037 287 };
coleenp@4037 288
coleenp@4037 289 class ClassLoaderDataGraphMetaspaceIterator : public StackObj {
coleenp@4037 290 ClassLoaderData* _data;
coleenp@4037 291 public:
coleenp@4037 292 ClassLoaderDataGraphMetaspaceIterator();
coleenp@4037 293 ~ClassLoaderDataGraphMetaspaceIterator();
coleenp@4037 294 bool repeat() { return _data != NULL; }
coleenp@4037 295 Metaspace* get_next() {
coleenp@4037 296 assert(_data != NULL, "Should not be NULL in call to the iterator");
coleenp@4037 297 Metaspace* result = _data->metaspace_or_null();
coleenp@4037 298 _data = _data->next();
coleenp@4037 299 // This result might be NULL for class loaders without metaspace
coleenp@4037 300 // yet. It would be nice to return only non-null results but
coleenp@4037 301 // there is no guarantee that there will be a non-null result
coleenp@4037 302 // down the list so the caller is going to have to check.
coleenp@4037 303 return result;
coleenp@4037 304 }
coleenp@4037 305 };
coleenp@4037 306 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP

mercurial