src/share/vm/classfile/classLoaderData.hpp

Tue, 09 Oct 2012 07:41:27 +0200

author
rbackman
date
Tue, 09 Oct 2012 07:41:27 +0200
changeset 4151
6e5a59a8e4a7
parent 4068
e861d44e0c9c
child 4304
90273fc0a981
permissions
-rw-r--r--

Merge

coleenp@4037 1 /*
coleenp@4037 2 * Copyright (c) 2012, 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
coleenp@4037 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
coleenp@4037 35 //
coleenp@4037 36 // A class loader represents a linkset. Conceptually, a linkset identifies
coleenp@4037 37 // the complete transitive closure of resolved links that a dynamic linker can
coleenp@4037 38 // produce.
coleenp@4037 39 //
coleenp@4037 40 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
coleenp@4037 41 // used by the dynamic linker to allocate the runtime representation of all
coleenp@4037 42 // the types it defines.
coleenp@4037 43 //
coleenp@4037 44 // ClassLoaderData are stored in the runtime representation of classes and the
coleenp@4037 45 // system dictionary, are roots of garbage collection, and provides iterators
coleenp@4037 46 // for root tracing and other GC operations.
coleenp@4037 47
coleenp@4037 48 class ClassLoaderData;
coleenp@4037 49 class JNIMethodBlock;
coleenp@4037 50 class JNIHandleBlock;
coleenp@4037 51 class Metadebug;
coleenp@4037 52 // GC root for walking class loader data created
coleenp@4037 53
coleenp@4037 54 class ClassLoaderDataGraph : public AllStatic {
coleenp@4037 55 friend class ClassLoaderData;
coleenp@4037 56 friend class ClassLoaderDataGraphMetaspaceIterator;
coleenp@4037 57 friend class VMStructs;
coleenp@4037 58 private:
coleenp@4037 59 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
coleenp@4037 60 static ClassLoaderData* _head;
coleenp@4037 61 static ClassLoaderData* _unloading;
coleenp@4037 62 // CMS support.
coleenp@4037 63 static ClassLoaderData* _saved_head;
coleenp@4037 64
coleenp@4037 65 static ClassLoaderData* add(ClassLoaderData** loader_data_addr, Handle class_loader);
coleenp@4037 66 public:
coleenp@4037 67 static ClassLoaderData* find_or_create(Handle class_loader);
coleenp@4037 68 static void purge();
coleenp@4037 69 static void clear_claimed_marks();
coleenp@4037 70 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 71 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 72 static void classes_do(KlassClosure* klass_closure);
coleenp@4037 73 static bool do_unloading(BoolObjectClosure* is_alive);
coleenp@4037 74
coleenp@4037 75 // CMS support.
coleenp@4037 76 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
coleenp@4037 77 static GrowableArray<ClassLoaderData*>* new_clds();
coleenp@4037 78
coleenp@4037 79 static void dump_on(outputStream * const out) PRODUCT_RETURN;
coleenp@4037 80 static void dump() { dump_on(tty); }
coleenp@4037 81 static void verify();
coleenp@4037 82
coleenp@4037 83 #ifndef PRODUCT
coleenp@4037 84 // expensive test for pointer in metaspace for debugging
coleenp@4037 85 static bool contains(address x);
coleenp@4037 86 static bool contains_loader_data(ClassLoaderData* loader_data);
coleenp@4037 87 #endif
coleenp@4037 88 };
coleenp@4037 89
coleenp@4037 90 // ClassLoaderData class
coleenp@4037 91
coleenp@4037 92 class ClassLoaderData : public CHeapObj<mtClass> {
coleenp@4037 93 friend class VMStructs;
coleenp@4037 94 private:
coleenp@4037 95 friend class ClassLoaderDataGraph;
coleenp@4037 96 friend class ClassLoaderDataGraphMetaspaceIterator;
coleenp@4037 97 friend class MetaDataFactory;
coleenp@4037 98 friend class Method;
coleenp@4037 99
coleenp@4037 100 static ClassLoaderData * _the_null_class_loader_data;
coleenp@4037 101
coleenp@4037 102 oop _class_loader; // oop used to uniquely identify a class loader
coleenp@4037 103 // class loader or a canonical class path
coleenp@4037 104 Metaspace * _metaspace; // Meta-space where meta-data defined by the
coleenp@4037 105 // classes in the class loader are allocated.
coleenp@4037 106 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup.
coleenp@4037 107 bool _unloading; // true if this class loader goes away
coleenp@4037 108 volatile int _claimed; // true if claimed, for example during GC traces.
coleenp@4037 109 // To avoid applying oop closure more than once.
coleenp@4037 110 // Has to be an int because we cas it.
coleenp@4037 111 Klass* _klasses; // The classes defined by the class loader.
coleenp@4037 112
coleenp@4037 113 JNIHandleBlock* _handles; // Handles to constant pool arrays
coleenp@4037 114
coleenp@4037 115 // These method IDs are created for the class loader and set to NULL when the
coleenp@4037 116 // class loader is unloaded. They are rarely freed, only for redefine classes
coleenp@4037 117 // and if they lose a data race in InstanceKlass.
coleenp@4037 118 JNIMethodBlock* _jmethod_ids;
coleenp@4037 119
coleenp@4037 120 // Metadata to be deallocated when it's safe at class unloading, when
coleenp@4037 121 // this class loader isn't unloaded itself.
coleenp@4037 122 GrowableArray<Metadata*>* _deallocate_list;
coleenp@4037 123
coleenp@4037 124 // Support for walking class loader data objects
coleenp@4037 125 ClassLoaderData* _next; /// Next loader_datas created
coleenp@4037 126
coleenp@4037 127 // ReadOnly and ReadWrite metaspaces (static because only on the null
coleenp@4037 128 // class loader for now).
coleenp@4037 129 static Metaspace* _ro_metaspace;
coleenp@4037 130 static Metaspace* _rw_metaspace;
coleenp@4037 131
coleenp@4037 132 bool has_dependency(ClassLoaderData* cld);
coleenp@4037 133 void add_dependency(ClassLoaderData* to_loader_data, TRAPS);
coleenp@4037 134
coleenp@4037 135 void set_next(ClassLoaderData* next) { _next = next; }
coleenp@4037 136 ClassLoaderData* next() const { return _next; }
coleenp@4037 137
coleenp@4037 138 ClassLoaderData(Handle h_class_loader);
coleenp@4037 139 ~ClassLoaderData();
coleenp@4037 140
coleenp@4037 141 void set_metaspace(Metaspace* m) { _metaspace = m; }
coleenp@4037 142
coleenp@4037 143 JNIHandleBlock* handles() const;
coleenp@4037 144 void set_handles(JNIHandleBlock* handles);
coleenp@4037 145
coleenp@4037 146 Mutex* metaspace_lock() const { return _metaspace_lock; }
coleenp@4037 147
coleenp@4037 148 // GC interface.
coleenp@4037 149 void clear_claimed() { _claimed = 0; }
coleenp@4037 150 bool claimed() const { return _claimed == 1; }
coleenp@4037 151 bool claim();
coleenp@4037 152
coleenp@4037 153 void mark_for_unload() { _unloading = true; }
coleenp@4037 154
coleenp@4037 155 void classes_do(void f(InstanceKlass*));
coleenp@4037 156
coleenp@4037 157 // Deallocate free list during class unloading.
coleenp@4037 158 void free_deallocate_list();
coleenp@4037 159
coleenp@4037 160 // Allocate out of this class loader data
coleenp@4037 161 MetaWord* allocate(size_t size);
coleenp@4037 162
coleenp@4037 163 public:
coleenp@4037 164 // Accessors
coleenp@4037 165 Metaspace* metaspace_or_null() const { return _metaspace; }
coleenp@4037 166
coleenp@4037 167 static ClassLoaderData* the_null_class_loader_data() {
coleenp@4037 168 return _the_null_class_loader_data;
coleenp@4037 169 }
coleenp@4037 170
coleenp@4037 171 static void init_null_class_loader_data() {
coleenp@4037 172 assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
coleenp@4037 173 assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
coleenp@4037 174 _the_null_class_loader_data = new ClassLoaderData((oop)NULL);
coleenp@4037 175 ClassLoaderDataGraph::_head = _the_null_class_loader_data;
coleenp@4037 176 assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
coleenp@4037 177 if (DumpSharedSpaces) {
coleenp@4037 178 _the_null_class_loader_data->initialize_shared_metaspaces();
coleenp@4037 179 }
coleenp@4037 180 }
coleenp@4037 181
coleenp@4037 182 bool is_the_null_class_loader_data() const {
coleenp@4037 183 return this == _the_null_class_loader_data;
coleenp@4037 184 }
coleenp@4037 185
coleenp@4037 186 // The Metaspace is created lazily so may be NULL. This
coleenp@4037 187 // method will allocate a Metaspace if needed.
coleenp@4037 188 Metaspace* metaspace_non_null();
coleenp@4037 189
coleenp@4037 190 oop class_loader() const { return _class_loader; }
coleenp@4037 191
coleenp@4037 192 // Returns true if this class loader data is for a loader going away.
coleenp@4037 193 bool is_unloading() const {
coleenp@4037 194 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
coleenp@4037 195 return _unloading;
coleenp@4037 196 }
coleenp@4037 197
coleenp@4037 198 unsigned int identity_hash() {
coleenp@4037 199 return _class_loader == NULL ? 0 : _class_loader->identity_hash();
coleenp@4037 200 }
coleenp@4037 201
coleenp@4037 202 // Used when tracing from klasses.
coleenp@4037 203 void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
coleenp@4037 204
coleenp@4037 205 void classes_do(KlassClosure* klass_closure);
coleenp@4037 206
coleenp@4037 207 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; }
coleenp@4037 208 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; }
coleenp@4037 209
coleenp@4037 210 void print_value() { print_value_on(tty); }
coleenp@4037 211 void print_value_on(outputStream* out) const PRODUCT_RETURN;
coleenp@4037 212 void dump(outputStream * const out) PRODUCT_RETURN;
coleenp@4037 213 void verify();
coleenp@4037 214
coleenp@4037 215 jobject add_handle(Handle h);
coleenp@4037 216 void add_class(Klass* k);
coleenp@4037 217 void remove_class(Klass* k);
coleenp@4037 218 void record_dependency(Klass* to, TRAPS);
coleenp@4037 219
coleenp@4037 220 void add_to_deallocate_list(Metadata* m);
coleenp@4037 221
coleenp@4037 222 static ClassLoaderData* class_loader_data(oop loader);
coleenp@4037 223 static void print_loader(ClassLoaderData *loader_data, outputStream *out);
coleenp@4037 224
coleenp@4037 225 // CDS support
coleenp@4037 226 Metaspace* ro_metaspace();
coleenp@4037 227 Metaspace* rw_metaspace();
coleenp@4037 228 void initialize_shared_metaspaces();
coleenp@4037 229 };
coleenp@4037 230
coleenp@4037 231 class ClassLoaderDataGraphMetaspaceIterator : public StackObj {
coleenp@4037 232 ClassLoaderData* _data;
coleenp@4037 233 public:
coleenp@4037 234 ClassLoaderDataGraphMetaspaceIterator();
coleenp@4037 235 ~ClassLoaderDataGraphMetaspaceIterator();
coleenp@4037 236 bool repeat() { return _data != NULL; }
coleenp@4037 237 Metaspace* get_next() {
coleenp@4037 238 assert(_data != NULL, "Should not be NULL in call to the iterator");
coleenp@4037 239 Metaspace* result = _data->metaspace_or_null();
coleenp@4037 240 _data = _data->next();
coleenp@4037 241 // This result might be NULL for class loaders without metaspace
coleenp@4037 242 // yet. It would be nice to return only non-null results but
coleenp@4037 243 // there is no guarantee that there will be a non-null result
coleenp@4037 244 // down the list so the caller is going to have to check.
coleenp@4037 245 return result;
coleenp@4037 246 }
coleenp@4037 247 };
coleenp@4037 248 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP

mercurial