Skip to content

Commit

Permalink
8313816: Accessing jmethodID might lead to spurious crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Aug 7, 2023
1 parent 90d795a commit 01274a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::destroy_jmethod_id(class_loader_data(), jmeths[i]);
}
}

// 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
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/oops/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 01274a2

Please sign in to comment.