29 #include "memory/memRegion.hpp" |
29 #include "memory/memRegion.hpp" |
30 #include "memory/metaspace.hpp" |
30 #include "memory/metaspace.hpp" |
31 #include "memory/metaspaceCounters.hpp" |
31 #include "memory/metaspaceCounters.hpp" |
32 #include "runtime/mutex.hpp" |
32 #include "runtime/mutex.hpp" |
33 #include "utilities/growableArray.hpp" |
33 #include "utilities/growableArray.hpp" |
34 |
|
35 #if INCLUDE_TRACE |
34 #if INCLUDE_TRACE |
36 # include "utilities/ticks.hpp" |
35 # include "utilities/ticks.hpp" |
37 #endif |
36 #endif |
38 |
37 |
39 // |
38 // |
57 // GC root for walking class loader data created |
56 // GC root for walking class loader data created |
58 |
57 |
59 class ClassLoaderDataGraph : public AllStatic { |
58 class ClassLoaderDataGraph : public AllStatic { |
60 friend class ClassLoaderData; |
59 friend class ClassLoaderData; |
61 friend class ClassLoaderDataGraphMetaspaceIterator; |
60 friend class ClassLoaderDataGraphMetaspaceIterator; |
|
61 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
62 friend class VMStructs; |
62 friend class VMStructs; |
63 private: |
63 private: |
64 // All CLDs (except the null CLD) can be reached by walking _head->_next->... |
64 // All CLDs (except the null CLD) can be reached by walking _head->_next->... |
65 static ClassLoaderData* _head; |
65 static ClassLoaderData* _head; |
66 static ClassLoaderData* _unloading; |
66 static ClassLoaderData* _unloading; |
72 static void post_class_unload_events(void); |
72 static void post_class_unload_events(void); |
73 public: |
73 public: |
74 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
74 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
75 static void purge(); |
75 static void purge(); |
76 static void clear_claimed_marks(); |
76 static void clear_claimed_marks(); |
|
77 // oops do |
77 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
78 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
|
79 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
78 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
80 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
79 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
81 // cld do |
80 static void cld_do(CLDClosure* cl); |
82 static void cld_do(CLDClosure* cl); |
|
83 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak); |
|
84 static void keep_alive_cld_do(CLDClosure* cl); |
|
85 static void always_strong_cld_do(CLDClosure* cl); |
|
86 // klass do |
81 static void classes_do(KlassClosure* klass_closure); |
87 static void classes_do(KlassClosure* klass_closure); |
82 static void classes_do(void f(Klass* const)); |
88 static void classes_do(void f(Klass* const)); |
83 static void methods_do(void f(Method*)); |
89 static void methods_do(void f(Method*)); |
84 static void loaded_classes_do(KlassClosure* klass_closure); |
90 static void loaded_classes_do(KlassClosure* klass_closure); |
85 static void classes_unloading_do(void f(Klass* const)); |
91 static void classes_unloading_do(void f(Klass* const)); |
101 |
107 |
102 static void dump_on(outputStream * const out) PRODUCT_RETURN; |
108 static void dump_on(outputStream * const out) PRODUCT_RETURN; |
103 static void dump() { dump_on(tty); } |
109 static void dump() { dump_on(tty); } |
104 static void verify(); |
110 static void verify(); |
105 |
111 |
|
112 static bool unload_list_contains(const void* x); |
106 #ifndef PRODUCT |
113 #ifndef PRODUCT |
107 static bool contains_loader_data(ClassLoaderData* loader_data); |
114 static bool contains_loader_data(ClassLoaderData* loader_data); |
108 #endif |
115 #endif |
109 |
116 |
110 #if INCLUDE_TRACE |
117 #if INCLUDE_TRACE |
133 void init(TRAPS); |
140 void init(TRAPS); |
134 void oops_do(OopClosure* f); |
141 void oops_do(OopClosure* f); |
135 }; |
142 }; |
136 |
143 |
137 friend class ClassLoaderDataGraph; |
144 friend class ClassLoaderDataGraph; |
|
145 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
138 friend class ClassLoaderDataGraphMetaspaceIterator; |
146 friend class ClassLoaderDataGraphMetaspaceIterator; |
139 friend class MetaDataFactory; |
147 friend class MetaDataFactory; |
140 friend class Method; |
148 friend class Method; |
141 |
149 |
142 static ClassLoaderData * _the_null_class_loader_data; |
150 static ClassLoaderData * _the_null_class_loader_data; |
192 bool claimed() const { return _claimed == 1; } |
200 bool claimed() const { return _claimed == 1; } |
193 bool claim(); |
201 bool claim(); |
194 |
202 |
195 void unload(); |
203 void unload(); |
196 bool keep_alive() const { return _keep_alive; } |
204 bool keep_alive() const { return _keep_alive; } |
197 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
|
198 void classes_do(void f(Klass*)); |
205 void classes_do(void f(Klass*)); |
199 void loaded_classes_do(KlassClosure* klass_closure); |
206 void loaded_classes_do(KlassClosure* klass_closure); |
200 void classes_do(void f(InstanceKlass*)); |
207 void classes_do(void f(InstanceKlass*)); |
201 void methods_do(void f(Method*)); |
208 void methods_do(void f(Method*)); |
202 |
209 |
205 |
212 |
206 // Allocate out of this class loader data |
213 // Allocate out of this class loader data |
207 MetaWord* allocate(size_t size); |
214 MetaWord* allocate(size_t size); |
208 |
215 |
209 public: |
216 public: |
|
217 |
|
218 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
|
219 |
210 // Accessors |
220 // Accessors |
211 Metaspace* metaspace_or_null() const { return _metaspace; } |
221 Metaspace* metaspace_or_null() const { return _metaspace; } |
212 |
222 |
213 static ClassLoaderData* the_null_class_loader_data() { |
223 static ClassLoaderData* the_null_class_loader_data() { |
214 return _the_null_class_loader_data; |
224 return _the_null_class_loader_data; |
288 |
298 |
289 // CDS support |
299 // CDS support |
290 Metaspace* ro_metaspace(); |
300 Metaspace* ro_metaspace(); |
291 Metaspace* rw_metaspace(); |
301 Metaspace* rw_metaspace(); |
292 void initialize_shared_metaspaces(); |
302 void initialize_shared_metaspaces(); |
|
303 }; |
|
304 |
|
305 // An iterator that distributes Klasses to parallel worker threads. |
|
306 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |
|
307 volatile Klass* _next_klass; |
|
308 public: |
|
309 ClassLoaderDataGraphKlassIteratorAtomic(); |
|
310 Klass* next_klass(); |
|
311 private: |
|
312 static Klass* next_klass_in_cldg(Klass* klass); |
293 }; |
313 }; |
294 |
314 |
295 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { |
315 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { |
296 ClassLoaderData* _data; |
316 ClassLoaderData* _data; |
297 public: |
317 public: |