26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP |
26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP |
27 |
27 |
28 #include "memory/allocation.hpp" |
28 #include "memory/allocation.hpp" |
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" |
|
32 #include "oops/oopHandle.hpp" |
31 #include "oops/oopHandle.hpp" |
33 #include "oops/weakHandle.hpp" |
32 #include "oops/weakHandle.hpp" |
34 #include "runtime/mutex.hpp" |
33 #include "runtime/mutex.hpp" |
35 #include "trace/traceMacros.hpp" |
34 #include "trace/traceMacros.hpp" |
36 #include "utilities/growableArray.hpp" |
35 #include "utilities/growableArray.hpp" |
82 static bool _metaspace_oom; |
81 static bool _metaspace_oom; |
83 |
82 |
84 static volatile size_t _num_instance_classes; |
83 static volatile size_t _num_instance_classes; |
85 static volatile size_t _num_array_classes; |
84 static volatile size_t _num_array_classes; |
86 |
85 |
|
86 static ClassLoaderData* add_to_graph(Handle class_loader, bool anonymous); |
87 static ClassLoaderData* add(Handle class_loader, bool anonymous); |
87 static ClassLoaderData* add(Handle class_loader, bool anonymous); |
88 static void post_class_unload_events(); |
88 static void post_class_unload_events(); |
89 public: |
89 public: |
90 static ClassLoaderData* find_or_create(Handle class_loader); |
90 static ClassLoaderData* find_or_create(Handle class_loader); |
91 static void purge(); |
91 static void purge(); |
218 friend class MetaDataFactory; |
218 friend class MetaDataFactory; |
219 friend class Method; |
219 friend class Method; |
220 |
220 |
221 static ClassLoaderData * _the_null_class_loader_data; |
221 static ClassLoaderData * _the_null_class_loader_data; |
222 |
222 |
223 ClassLoaderWeakHandle _holder; // The oop that determines lifetime of this class loader |
223 WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader |
224 oop _class_loader; // The instance of java/lang/ClassLoader associated with |
224 OopHandle _class_loader; // The instance of java/lang/ClassLoader associated with |
225 // this ClassLoaderData |
225 // this ClassLoaderData |
226 |
226 |
227 ClassLoaderMetaspace * volatile _metaspace; // Meta-space where meta-data defined by the |
227 ClassLoaderMetaspace * volatile _metaspace; // Meta-space where meta-data defined by the |
228 // classes in the class loader are allocated. |
228 // classes in the class loader are allocated. |
229 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup. |
229 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup. |
232 |
232 |
233 // Remembered sets support for the oops in the class loader data. |
233 // Remembered sets support for the oops in the class loader data. |
234 bool _modified_oops; // Card Table Equivalent (YC/CMS support) |
234 bool _modified_oops; // Card Table Equivalent (YC/CMS support) |
235 bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support) |
235 bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support) |
236 |
236 |
237 s2 _keep_alive; // if this CLD is kept alive without a keep_alive_object(). |
237 s2 _keep_alive; // if this CLD is kept alive. |
238 // Used for anonymous classes and the boot class |
238 // Used for anonymous classes and the boot class |
239 // loader. _keep_alive does not need to be volatile or |
239 // loader. _keep_alive does not need to be volatile or |
240 // atomic since there is one unique CLD per anonymous class. |
240 // atomic since there is one unique CLD per anonymous class. |
241 |
241 |
242 volatile int _claimed; // true if claimed, for example during GC traces. |
242 volatile int _claimed; // true if claimed, for example during GC traces. |
263 GrowableArray<Metadata*>* _deallocate_list; |
263 GrowableArray<Metadata*>* _deallocate_list; |
264 |
264 |
265 // Support for walking class loader data objects |
265 // Support for walking class loader data objects |
266 ClassLoaderData* _next; /// Next loader_datas created |
266 ClassLoaderData* _next; /// Next loader_datas created |
267 |
267 |
|
268 // JFR support |
|
269 Klass* _class_loader_klass; |
|
270 Symbol* _class_loader_name; |
268 TRACE_DEFINE_TRACE_ID_FIELD; |
271 TRACE_DEFINE_TRACE_ID_FIELD; |
269 |
272 |
270 void set_next(ClassLoaderData* next) { _next = next; } |
273 void set_next(ClassLoaderData* next) { _next = next; } |
271 ClassLoaderData* next() const { return _next; } |
274 ClassLoaderData* next() const { return _next; } |
272 |
275 |
303 |
306 |
304 // Allocate out of this class loader data |
307 // Allocate out of this class loader data |
305 MetaWord* allocate(size_t size); |
308 MetaWord* allocate(size_t size); |
306 |
309 |
307 Dictionary* create_dictionary(); |
310 Dictionary* create_dictionary(); |
|
311 |
|
312 void initialize_name_and_klass(Handle class_loader); |
308 public: |
313 public: |
309 // GC interface. |
314 // GC interface. |
310 void clear_claimed() { _claimed = 0; } |
315 void clear_claimed() { _claimed = 0; } |
311 bool claimed() const { return _claimed == 1; } |
316 bool claimed() const { return _claimed == 1; } |
312 bool claim(); |
317 bool claim(); |
338 // (Note that the class loader data may be anonymous.) |
343 // (Note that the class loader data may be anonymous.) |
339 bool is_platform_class_loader_data() const; |
344 bool is_platform_class_loader_data() const; |
340 |
345 |
341 // Returns true if this class loader data is for the boot class loader. |
346 // Returns true if this class loader data is for the boot class loader. |
342 // (Note that the class loader data may be anonymous.) |
347 // (Note that the class loader data may be anonymous.) |
343 bool is_boot_class_loader_data() const { |
348 inline bool is_boot_class_loader_data() const; |
344 return class_loader() == NULL; |
|
345 } |
|
346 |
349 |
347 bool is_builtin_class_loader_data() const; |
350 bool is_builtin_class_loader_data() const; |
348 bool is_permanent_class_loader_data() const; |
351 bool is_permanent_class_loader_data() const; |
349 |
352 |
350 // The Metaspace is created lazily so may be NULL. This |
353 // The Metaspace is created lazily so may be NULL. This |
351 // method will allocate a Metaspace if needed. |
354 // method will allocate a Metaspace if needed. |
352 ClassLoaderMetaspace* metaspace_non_null(); |
355 ClassLoaderMetaspace* metaspace_non_null(); |
353 |
356 |
354 oop class_loader() const { return _class_loader; } |
357 inline oop class_loader() const; |
355 |
|
356 // The object the GC is using to keep this ClassLoaderData alive. |
|
357 oop keep_alive_object() const; |
|
358 |
358 |
359 // Returns true if this class loader data is for a loader going away. |
359 // Returns true if this class loader data is for a loader going away. |
360 bool is_unloading() const { |
360 bool is_unloading() const { |
361 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded"); |
361 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded"); |
362 return _unloading; |
362 return _unloading; |
363 } |
363 } |
364 |
364 |
365 // Used to refcount an anonymous class's CLD in order to |
365 // Used to refcount an anonymous class's CLD in order to |
366 // indicate their aliveness without a keep_alive_object(). |
366 // indicate their aliveness. |
367 void inc_keep_alive(); |
367 void inc_keep_alive(); |
368 void dec_keep_alive(); |
368 void dec_keep_alive(); |
369 |
369 |
370 void initialize_holder(Handle holder); |
370 void initialize_holder(Handle holder); |
371 |
371 |
405 |
405 |
406 static ClassLoaderData* class_loader_data(oop loader); |
406 static ClassLoaderData* class_loader_data(oop loader); |
407 static ClassLoaderData* class_loader_data_or_null(oop loader); |
407 static ClassLoaderData* class_loader_data_or_null(oop loader); |
408 static ClassLoaderData* anonymous_class_loader_data(Handle loader); |
408 static ClassLoaderData* anonymous_class_loader_data(Handle loader); |
409 |
409 |
|
410 |
|
411 Klass* class_loader_klass() const { return _class_loader_klass; } |
|
412 Symbol* class_loader_name() const { return _class_loader_name; } |
410 TRACE_DEFINE_TRACE_ID_METHODS; |
413 TRACE_DEFINE_TRACE_ID_METHODS; |
411 }; |
414 }; |
412 |
415 |
413 // An iterator that distributes Klasses to parallel worker threads. |
416 // An iterator that distributes Klasses to parallel worker threads. |
414 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |
417 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { |