diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index a1c7eae402a4f..b532dff6015ec 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -587,15 +587,20 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { // Also remove mirror from handles loader_data->remove_handle(_java_mirror); - // Need to take this class off the class loader data list. - loader_data->remove_class(this); - // The array_klass for this class is created later, after error handling. // For class redefinition, we keep the original class so this scratch class // doesn't have an array class. Either way, assert that there is nothing // to deallocate. assert(array_klasses() == nullptr, "array classes shouldn't be created for this class yet"); + jmethodID* jmeths = methods_jmethod_ids_acquire(); + if (jmeths != (jmethodID*)nullptr) { + size_t count = (size_t)jmeths[0]; + for (size_t i = 1; i <= count; i++) { + *((Method**)jmeths[i]) = nullptr; + } + } + // Release C heap allocated data that this points to, which includes // reference counting symbol names. // Can't release the constant pool or MethodData C heap data here because the constant diff --git a/src/hotspot/share/oops/method.hpp b/src/hotspot/share/oops/method.hpp index b7beb9b00f0d5..afecc543308f7 100644 --- a/src/hotspot/share/oops/method.hpp +++ b/src/hotspot/share/oops/method.hpp @@ -783,7 +783,9 @@ class Method : public Metadata { // (see AsyncGetCallTrace support for Forte Analyzer) and this // needs to be async-safe. No allocation should be done and // so handles are not used to avoid deadlock. - jmethodID find_jmethod_id_or_null() { return method_holder()->jmethod_id_or_null(this); } + jmethodID find_jmethod_id_or_null() { + return method_holder() != nullptr ? method_holder()->jmethod_id_or_null(this) : nullptr; + } // Support for inlining of intrinsic methods vmIntrinsicID intrinsic_id() const { return (vmIntrinsicID) _intrinsic_id; }