15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
27
28 #include "memory/allocation.hpp"
29 #include "memory/memRegion.hpp"
30 #include "memory/metaspace.hpp"
31 #include "memory/metaspaceCounters.hpp"
32 #include "runtime/mutex.hpp"
33 #include "utilities/growableArray.hpp"
34
35 //
36 // A class loader represents a linkset. Conceptually, a linkset identifies
37 // the complete transitive closure of resolved links that a dynamic linker can
38 // produce.
39 //
40 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
41 // used by the dynamic linker to allocate the runtime representation of all
42 // the types it defines.
43 //
44 // ClassLoaderData are stored in the runtime representation of classes and the
45 // system dictionary, are roots of garbage collection, and provides iterators
46 // for root tracing and other GC operations.
47
48 class ClassLoaderData;
49 class JNIMethodBlock;
50 class JNIHandleBlock;
51 class Metadebug;
52 // GC root for walking class loader data created
53
54 class ClassLoaderDataGraph : public AllStatic {
55 friend class ClassLoaderData;
56 friend class ClassLoaderDataGraphMetaspaceIterator;
57 friend class VMStructs;
58 private:
59 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
60 static ClassLoaderData* _head;
61 static ClassLoaderData* _unloading;
62 // CMS support.
63 static ClassLoaderData* _saved_head;
64
65 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
66 public:
67 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
68 static void purge();
69 static void clear_claimed_marks();
70 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
71 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
72 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
73 static void classes_do(KlassClosure* klass_closure);
74 static bool do_unloading(BoolObjectClosure* is_alive);
75
76 // CMS support.
77 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
78 static GrowableArray<ClassLoaderData*>* new_clds();
79
80 static void dump_on(outputStream * const out) PRODUCT_RETURN;
81 static void dump() { dump_on(tty); }
82 static void verify();
83
84 #ifndef PRODUCT
85 // expensive test for pointer in metaspace for debugging
86 static bool contains(address x);
87 static bool contains_loader_data(ClassLoaderData* loader_data);
88 #endif
89 };
90
91 // ClassLoaderData class
92
93 class ClassLoaderData : public CHeapObj<mtClass> {
94 friend class VMStructs;
95 private:
96 class Dependencies VALUE_OBJ_CLASS_SPEC {
97 objArrayOop _list_head;
98 void locked_add(objArrayHandle last,
99 objArrayHandle new_dependency,
100 Thread* THREAD);
101 public:
102 Dependencies() : _list_head(NULL) {}
103 Dependencies(TRAPS) : _list_head(NULL) {
104 init(CHECK);
105 }
106 void add(Handle dependency, TRAPS);
107 void init(TRAPS);
108 void oops_do(OopClosure* f);
154 ClassLoaderData* next() const { return _next; }
155
156 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
157 ~ClassLoaderData();
158
159 void set_metaspace(Metaspace* m) { _metaspace = m; }
160
161 JNIHandleBlock* handles() const;
162 void set_handles(JNIHandleBlock* handles);
163
164 Mutex* metaspace_lock() const { return _metaspace_lock; }
165
166 // GC interface.
167 void clear_claimed() { _claimed = 0; }
168 bool claimed() const { return _claimed == 1; }
169 bool claim();
170
171 void unload();
172 bool keep_alive() const { return _keep_alive; }
173 bool is_alive(BoolObjectClosure* is_alive_closure) const;
174
175 void classes_do(void f(InstanceKlass*));
176
177 // Deallocate free list during class unloading.
178 void free_deallocate_list();
179
180 // Allocate out of this class loader data
181 MetaWord* allocate(size_t size);
182
183 public:
184 // Accessors
185 Metaspace* metaspace_or_null() const { return _metaspace; }
186
187 static ClassLoaderData* the_null_class_loader_data() {
188 return _the_null_class_loader_data;
189 }
190
191 bool is_anonymous() const { return _is_anonymous; }
192
193 static void init_null_class_loader_data() {
194 assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
27
28 #include "memory/allocation.hpp"
29 #include "memory/memRegion.hpp"
30 #include "memory/metaspace.hpp"
31 #include "memory/metaspaceCounters.hpp"
32 #include "runtime/mutex.hpp"
33 #include "utilities/growableArray.hpp"
34
35 #if INCLUDE_TRACE
36 # include "trace/traceTime.hpp"
37 #endif
38
39 //
40 // A class loader represents a linkset. Conceptually, a linkset identifies
41 // the complete transitive closure of resolved links that a dynamic linker can
42 // produce.
43 //
44 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
45 // used by the dynamic linker to allocate the runtime representation of all
46 // the types it defines.
47 //
48 // ClassLoaderData are stored in the runtime representation of classes and the
49 // system dictionary, are roots of garbage collection, and provides iterators
50 // for root tracing and other GC operations.
51
52 class ClassLoaderData;
53 class JNIMethodBlock;
54 class JNIHandleBlock;
55 class Metadebug;
56
57 // GC root for walking class loader data created
58
59 class ClassLoaderDataGraph : public AllStatic {
60 friend class ClassLoaderData;
61 friend class ClassLoaderDataGraphMetaspaceIterator;
62 friend class VMStructs;
63 private:
64 // All CLDs (except the null CLD) can be reached by walking _head->_next->...
65 static ClassLoaderData* _head;
66 static ClassLoaderData* _unloading;
67 // CMS support.
68 static ClassLoaderData* _saved_head;
69
70 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
71 static void post_class_unload_events(void);
72 public:
73 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
74 static void purge();
75 static void clear_claimed_marks();
76 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
77 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
78 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
79 static void classes_do(KlassClosure* klass_closure);
80 static void classes_do(void f(Klass* const));
81 static void classes_unloading_do(void f(Klass* const));
82 static bool do_unloading(BoolObjectClosure* is_alive);
83
84 // CMS support.
85 static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
86 static GrowableArray<ClassLoaderData*>* new_clds();
87
88 static void dump_on(outputStream * const out) PRODUCT_RETURN;
89 static void dump() { dump_on(tty); }
90 static void verify();
91
92 #ifndef PRODUCT
93 // expensive test for pointer in metaspace for debugging
94 static bool contains(address x);
95 static bool contains_loader_data(ClassLoaderData* loader_data);
96 #endif
97
98 #if INCLUDE_TRACE
99 private:
100 static TracingTime _class_unload_time;
101 static void class_unload_event(Klass* const k);
102 #endif
103 };
104
105 // ClassLoaderData class
106
107 class ClassLoaderData : public CHeapObj<mtClass> {
108 friend class VMStructs;
109 private:
110 class Dependencies VALUE_OBJ_CLASS_SPEC {
111 objArrayOop _list_head;
112 void locked_add(objArrayHandle last,
113 objArrayHandle new_dependency,
114 Thread* THREAD);
115 public:
116 Dependencies() : _list_head(NULL) {}
117 Dependencies(TRAPS) : _list_head(NULL) {
118 init(CHECK);
119 }
120 void add(Handle dependency, TRAPS);
121 void init(TRAPS);
122 void oops_do(OopClosure* f);
168 ClassLoaderData* next() const { return _next; }
169
170 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
171 ~ClassLoaderData();
172
173 void set_metaspace(Metaspace* m) { _metaspace = m; }
174
175 JNIHandleBlock* handles() const;
176 void set_handles(JNIHandleBlock* handles);
177
178 Mutex* metaspace_lock() const { return _metaspace_lock; }
179
180 // GC interface.
181 void clear_claimed() { _claimed = 0; }
182 bool claimed() const { return _claimed == 1; }
183 bool claim();
184
185 void unload();
186 bool keep_alive() const { return _keep_alive; }
187 bool is_alive(BoolObjectClosure* is_alive_closure) const;
188 void classes_do(void f(Klass*));
189 void classes_do(void f(InstanceKlass*));
190
191 // Deallocate free list during class unloading.
192 void free_deallocate_list();
193
194 // Allocate out of this class loader data
195 MetaWord* allocate(size_t size);
196
197 public:
198 // Accessors
199 Metaspace* metaspace_or_null() const { return _metaspace; }
200
201 static ClassLoaderData* the_null_class_loader_data() {
202 return _the_null_class_loader_data;
203 }
204
205 bool is_anonymous() const { return _is_anonymous; }
206
207 static void init_null_class_loader_data() {
208 assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
|