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 #include "utilities/macros.hpp" |
34 #include "utilities/macros.hpp" |
35 #if INCLUDE_TRACE |
35 #if INCLUDE_JFR |
36 #include "utilities/ticks.hpp" |
36 #include "jfr/support/jfrTraceIdExtension.hpp" |
37 #endif |
37 #endif |
38 |
38 |
39 // |
39 // |
40 // A class loader represents a linkset. Conceptually, a linkset identifies |
40 // A class loader represents a linkset. Conceptually, a linkset identifies |
41 // the complete transitive closure of resolved links that a dynamic linker can |
41 // the complete transitive closure of resolved links that a dynamic linker can |
68 static ClassLoaderData* _saved_head; |
68 static ClassLoaderData* _saved_head; |
69 static ClassLoaderData* _saved_unloading; |
69 static ClassLoaderData* _saved_unloading; |
70 static bool _should_purge; |
70 static bool _should_purge; |
71 |
71 |
72 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS); |
72 static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS); |
73 static void post_class_unload_events(void); |
|
74 static void clean_metaspaces(); |
73 static void clean_metaspaces(); |
75 public: |
74 public: |
76 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
75 static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); |
77 static void purge(); |
76 static void purge(); |
78 static void clear_claimed_marks(); |
77 static void clear_claimed_marks(); |
80 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); |
81 static void keep_alive_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 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); |
83 // cld do |
82 // cld do |
84 static void cld_do(CLDClosure* cl); |
83 static void cld_do(CLDClosure* cl); |
|
84 static void cld_unloading_do(CLDClosure* cl); |
85 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak); |
85 static void roots_cld_do(CLDClosure* strong, CLDClosure* weak); |
86 static void keep_alive_cld_do(CLDClosure* cl); |
86 static void keep_alive_cld_do(CLDClosure* cl); |
87 static void always_strong_cld_do(CLDClosure* cl); |
87 static void always_strong_cld_do(CLDClosure* cl); |
88 // klass do |
88 // klass do |
89 static void classes_do(KlassClosure* klass_closure); |
89 static void classes_do(KlassClosure* klass_closure); |
113 static void verify(); |
113 static void verify(); |
114 |
114 |
115 static bool unload_list_contains(const void* x); |
115 static bool unload_list_contains(const void* x); |
116 #ifndef PRODUCT |
116 #ifndef PRODUCT |
117 static bool contains_loader_data(ClassLoaderData* loader_data); |
117 static bool contains_loader_data(ClassLoaderData* loader_data); |
118 #endif |
|
119 |
|
120 #if INCLUDE_TRACE |
|
121 private: |
|
122 static Ticks _class_unload_time; |
|
123 static void class_unload_event(Klass* const k); |
|
124 #endif |
118 #endif |
125 }; |
119 }; |
126 |
120 |
127 // ClassLoaderData class |
121 // ClassLoaderData class |
128 |
122 |
211 // ReadOnly and ReadWrite metaspaces (static because only on the null |
205 // ReadOnly and ReadWrite metaspaces (static because only on the null |
212 // class loader for now). |
206 // class loader for now). |
213 static Metaspace* _ro_metaspace; |
207 static Metaspace* _ro_metaspace; |
214 static Metaspace* _rw_metaspace; |
208 static Metaspace* _rw_metaspace; |
215 |
209 |
|
210 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) |
|
211 |
216 void set_next(ClassLoaderData* next) { _next = next; } |
212 void set_next(ClassLoaderData* next) { _next = next; } |
217 ClassLoaderData* next() const { return _next; } |
213 ClassLoaderData* next() const { return _next; } |
218 |
214 |
219 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies); |
215 ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies); |
220 ~ClassLoaderData(); |
216 ~ClassLoaderData(); |
221 |
217 |
222 void set_metaspace(Metaspace* m) { _metaspace = m; } |
218 void set_metaspace(Metaspace* m) { _metaspace = m; } |
223 |
219 |
224 Mutex* metaspace_lock() const { return _metaspace_lock; } |
220 Mutex* metaspace_lock() const { return _metaspace_lock; } |
225 |
|
226 // GC interface. |
|
227 void clear_claimed() { _claimed = 0; } |
|
228 bool claimed() const { return _claimed == 1; } |
|
229 bool claim(); |
|
230 |
221 |
231 void unload(); |
222 void unload(); |
232 bool keep_alive() const { return _keep_alive; } |
223 bool keep_alive() const { return _keep_alive; } |
233 void classes_do(void f(Klass*)); |
224 void classes_do(void f(Klass*)); |
234 void loaded_classes_do(KlassClosure* klass_closure); |
225 void loaded_classes_do(KlassClosure* klass_closure); |
239 |
230 |
240 // Allocate out of this class loader data |
231 // Allocate out of this class loader data |
241 MetaWord* allocate(size_t size); |
232 MetaWord* allocate(size_t size); |
242 |
233 |
243 public: |
234 public: |
|
235 |
|
236 // GC interface. |
|
237 void clear_claimed() { _claimed = 0; } |
|
238 bool claimed() const { return _claimed == 1; } |
|
239 bool claim(); |
244 |
240 |
245 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
241 bool is_alive(BoolObjectClosure* is_alive_closure) const; |
246 |
242 |
247 // Accessors |
243 // Accessors |
248 Metaspace* metaspace_or_null() const { return _metaspace; } |
244 Metaspace* metaspace_or_null() const { return _metaspace; } |
323 |
319 |
324 // CDS support |
320 // CDS support |
325 Metaspace* ro_metaspace(); |
321 Metaspace* ro_metaspace(); |
326 Metaspace* rw_metaspace(); |
322 Metaspace* rw_metaspace(); |
327 void initialize_shared_metaspaces(); |
323 void initialize_shared_metaspaces(); |
|
324 |
|
325 JFR_ONLY(DEFINE_TRACE_ID_METHODS;) |
328 }; |
326 }; |
329 |
327 |
330 // An iterator that distributes Klasses to parallel worker threads. |
328 // An iterator that distributes Klasses to parallel worker threads. |
331 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |
329 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |
332 Klass* volatile _next_klass; |
330 Klass* volatile _next_klass; |