Wed, 24 Apr 2013 16:19:35 -0400
8011803: release_C_heap_structures is never called for anonymous classes.
Summary: Call this function from the ClassLoaderData destructor instead of the system dictionary walk.
Reviewed-by: stefank, mgerdin
1.1 --- a/src/share/vm/classfile/classLoaderData.cpp Wed Apr 24 09:00:04 2013 -0400 1.2 +++ b/src/share/vm/classfile/classLoaderData.cpp Wed Apr 24 16:19:35 2013 -0400 1.3 @@ -277,6 +277,9 @@ 1.4 void ClassLoaderData::unload() { 1.5 _unloading = true; 1.6 1.7 + // Tell serviceability tools these classes are unloading 1.8 + classes_do(InstanceKlass::notify_unload_class); 1.9 + 1.10 if (TraceClassLoaderData) { 1.11 ResourceMark rm; 1.12 tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, this); 1.13 @@ -300,6 +303,9 @@ 1.14 1.15 1.16 ClassLoaderData::~ClassLoaderData() { 1.17 + // Release C heap structures for all the classes. 1.18 + classes_do(InstanceKlass::release_C_heap_structures); 1.19 + 1.20 Metaspace *m = _metaspace; 1.21 if (m != NULL) { 1.22 _metaspace = NULL;
2.1 --- a/src/share/vm/classfile/dictionary.cpp Wed Apr 24 09:00:04 2013 -0400 2.2 +++ b/src/share/vm/classfile/dictionary.cpp Wed Apr 24 16:19:35 2013 -0400 2.3 @@ -27,7 +27,6 @@ 2.4 #include "classfile/systemDictionary.hpp" 2.5 #include "oops/oop.inline.hpp" 2.6 #include "prims/jvmtiRedefineClassesTrace.hpp" 2.7 -#include "services/classLoadingService.hpp" 2.8 #include "utilities/hashtable.inline.hpp" 2.9 2.10 2.11 @@ -156,19 +155,7 @@ 2.12 if (k_def_class_loader_data == loader_data) { 2.13 // This is the defining entry, so the referred class is about 2.14 // to be unloaded. 2.15 - // Notify the debugger and clean up the class. 2.16 class_was_unloaded = true; 2.17 - // notify the debugger 2.18 - if (JvmtiExport::should_post_class_unload()) { 2.19 - JvmtiExport::post_class_unload(ik); 2.20 - } 2.21 - 2.22 - // notify ClassLoadingService of class unload 2.23 - ClassLoadingService::notify_class_unloaded(ik); 2.24 - 2.25 - // Clean up C heap 2.26 - ik->release_C_heap_structures(); 2.27 - ik->constants()->release_C_heap_structures(); 2.28 } 2.29 // Also remove this system dictionary entry. 2.30 purge_entry = true;
3.1 --- a/src/share/vm/oops/instanceKlass.cpp Wed Apr 24 09:00:04 2013 -0400 3.2 +++ b/src/share/vm/oops/instanceKlass.cpp Wed Apr 24 16:19:35 2013 -0400 3.3 @@ -54,6 +54,7 @@ 3.4 #include "runtime/javaCalls.hpp" 3.5 #include "runtime/mutexLocker.hpp" 3.6 #include "runtime/thread.inline.hpp" 3.7 +#include "services/classLoadingService.hpp" 3.8 #include "services/threadService.hpp" 3.9 #include "utilities/dtrace.hpp" 3.10 #include "utilities/macros.hpp" 3.11 @@ -2312,7 +2313,29 @@ 3.12 m->clear_all_breakpoints(); 3.13 } 3.14 3.15 + 3.16 +void InstanceKlass::notify_unload_class(InstanceKlass* ik) { 3.17 + // notify the debugger 3.18 + if (JvmtiExport::should_post_class_unload()) { 3.19 + JvmtiExport::post_class_unload(ik); 3.20 + } 3.21 + 3.22 + // notify ClassLoadingService of class unload 3.23 + ClassLoadingService::notify_class_unloaded(ik); 3.24 +} 3.25 + 3.26 +void InstanceKlass::release_C_heap_structures(InstanceKlass* ik) { 3.27 + // Clean up C heap 3.28 + ik->release_C_heap_structures(); 3.29 + ik->constants()->release_C_heap_structures(); 3.30 +} 3.31 + 3.32 void InstanceKlass::release_C_heap_structures() { 3.33 + 3.34 + // Can't release the constant pool here because the constant pool can be 3.35 + // deallocated separately from the InstanceKlass for default methods and 3.36 + // redefine classes. 3.37 + 3.38 // Deallocate oop map cache 3.39 if (_oop_map_cache != NULL) { 3.40 delete _oop_map_cache;
4.1 --- a/src/share/vm/oops/instanceKlass.hpp Wed Apr 24 09:00:04 2013 -0400 4.2 +++ b/src/share/vm/oops/instanceKlass.hpp Wed Apr 24 16:19:35 2013 -0400 4.3 @@ -236,7 +236,7 @@ 4.4 _misc_rewritten = 1 << 0, // methods rewritten. 4.5 _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops 4.6 _misc_should_verify_class = 1 << 2, // allow caching of preverification 4.7 - _misc_is_anonymous = 1 << 3, // has embedded _inner_classes field 4.8 + _misc_is_anonymous = 1 << 3, // has embedded _host_klass field 4.9 _misc_is_contended = 1 << 4, // marked with contended annotation 4.10 _misc_has_default_methods = 1 << 5 // class/superclass/implemented interfaces has default methods 4.11 }; 4.12 @@ -934,7 +934,9 @@ 4.13 // referenced by handles. 4.14 bool on_stack() const { return _constants->on_stack(); } 4.15 4.16 - void release_C_heap_structures(); 4.17 + // callbacks for actions during class unloading 4.18 + static void notify_unload_class(InstanceKlass* ik); 4.19 + static void release_C_heap_structures(InstanceKlass* ik); 4.20 4.21 // Parallel Scavenge and Parallel Old 4.22 PARALLEL_GC_DECLS 4.23 @@ -1022,6 +1024,8 @@ 4.24 // Returns the array class with this class as element type 4.25 Klass* array_klass_impl(bool or_null, TRAPS); 4.26 4.27 + // Free CHeap allocated fields. 4.28 + void release_C_heap_structures(); 4.29 public: 4.30 // CDS support - remove and restore oops from metadata. Oops are not shared. 4.31 virtual void remove_unshareable_info();