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; |
73 static void post_class_unload_events(void); |
73 static void post_class_unload_events(void); |
74 public: |
74 public: |
75 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
75 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
76 static void purge(); |
76 static void purge(); |
77 static void clear_claimed_marks(); |
77 static void clear_claimed_marks(); |
|
78 // oops do |
78 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
79 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); |
|
80 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
79 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
81 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
80 static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); |
82 // cld do |
|
83 static void cld_do(CLDClosure* cl); |
|
84 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak); |
|
85 static void keep_alive_cld_do(CLDClosure* cl); |
|
86 static void always_strong_cld_do(CLDClosure* cl); |
|
87 // klass do |
81 static void classes_do(KlassClosure* klass_closure); |
88 static void classes_do(KlassClosure* klass_closure); |
82 static void classes_do(void f(Klass* const)); |
89 static void classes_do(void f(Klass* const)); |
83 static void loaded_classes_do(KlassClosure* klass_closure); |
90 static void loaded_classes_do(KlassClosure* klass_closure); |
84 static void classes_unloading_do(void f(Klass* const)); |
91 static void classes_unloading_do(void f(Klass* const)); |
85 static bool do_unloading(BoolObjectClosure* is_alive); |
92 static bool do_unloading(BoolObjectClosure* is_alive); |
100 |
107 |
101 static void dump_on(outputStream * const out) PRODUCT_RETURN; |
108 static void dump_on(outputStream * const out) PRODUCT_RETURN; |
102 static void dump() { dump_on(tty); } |
109 static void dump() { dump_on(tty); } |
103 static void verify(); |
110 static void verify(); |
104 |
111 |
|
112 static bool unload_list_contains(const void* x); |
105 #ifndef PRODUCT |
113 #ifndef PRODUCT |
106 static bool contains_loader_data(ClassLoaderData* loader_data); |
114 static bool contains_loader_data(ClassLoaderData* loader_data); |
107 #endif |
115 #endif |
108 |
116 |
109 #if INCLUDE_TRACE |
117 #if INCLUDE_TRACE |
132 void init(TRAPS); |
140 void init(TRAPS); |
133 void oops_do(OopClosure* f); |
141 void oops_do(OopClosure* f); |
134 }; |
142 }; |
135 |
143 |
136 friend class ClassLoaderDataGraph; |
144 friend class ClassLoaderDataGraph; |
|
145 friend class ClassLoaderDataGraphKlassIteratorAtomic; |
137 friend class ClassLoaderDataGraphMetaspaceIterator; |
146 friend class ClassLoaderDataGraphMetaspaceIterator; |
138 friend class MetaDataFactory; |
147 friend class MetaDataFactory; |
139 friend class Method; |
148 friend class Method; |
140 |
149 |
141 static ClassLoaderData * _the_null_class_loader_data; |
150 static ClassLoaderData * _the_null_class_loader_data; |
193 bool claimed() const { return _claimed == 1; } |
202 bool claimed() const { return _claimed == 1; } |
194 bool claim(); |
203 bool claim(); |
195 |
204 |
196 void unload(); |
205 void unload(); |
197 bool keep_alive() const { return _keep_alive; } |
206 bool keep_alive() const { return _keep_alive; } |
198 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
|
199 void classes_do(void f(Klass*)); |
207 void classes_do(void f(Klass*)); |
200 void loaded_classes_do(KlassClosure* klass_closure); |
208 void loaded_classes_do(KlassClosure* klass_closure); |
201 void classes_do(void f(InstanceKlass*)); |
209 void classes_do(void f(InstanceKlass*)); |
202 |
210 |
203 // Deallocate free list during class unloading. |
211 // Deallocate free list during class unloading. |
205 |
213 |
206 // Allocate out of this class loader data |
214 // Allocate out of this class loader data |
207 MetaWord* allocate(size_t size); |
215 MetaWord* allocate(size_t size); |
208 |
216 |
209 public: |
217 public: |
|
218 |
|
219 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
|
220 |
210 // Accessors |
221 // Accessors |
211 Metaspace* metaspace_or_null() const { return _metaspace; } |
222 Metaspace* metaspace_or_null() const { return _metaspace; } |
212 |
223 |
213 static ClassLoaderData* the_null_class_loader_data() { |
224 static ClassLoaderData* the_null_class_loader_data() { |
214 return _the_null_class_loader_data; |
225 return _the_null_class_loader_data; |
286 |
297 |
287 // CDS support |
298 // CDS support |
288 Metaspace* ro_metaspace(); |
299 Metaspace* ro_metaspace(); |
289 Metaspace* rw_metaspace(); |
300 Metaspace* rw_metaspace(); |
290 void initialize_shared_metaspaces(); |
301 void initialize_shared_metaspaces(); |
|
302 }; |
|
303 |
|
304 // An iterator that distributes Klasses to parallel worker threads. |
|
305 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |
|
306 volatile Klass* _next_klass; |
|
307 public: |
|
308 ClassLoaderDataGraphKlassIteratorAtomic(); |
|
309 Klass* next_klass(); |
|
310 private: |
|
311 static Klass* next_klass_in_cldg(Klass* klass); |
291 }; |
312 }; |
292 |
313 |
293 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { |
314 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { |
294 ClassLoaderData* _data; |
315 ClassLoaderData* _data; |
295 public: |
316 public: |