Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Oct 25, 2023
1 parent 8292c8b commit 31eeef5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/hotspot/share/oops/klass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class Klass : public Metadata {
virtual MetaspaceObj::Type type() const { return ClassType; }

inline bool is_loader_alive() const;
inline bool is_loader_alive_safe() const;

void clean_subklass();

Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/oops/klass.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ inline bool Klass::is_loader_alive() const {
return class_loader_data()->is_alive();
}

inline bool Klass::is_loader_alive_safe() const {
ClassLoaderData* cld = class_loader_data();
return os::is_readable_pointer(cld) ? cld->is_alive() : false;
}

inline oop Klass::java_mirror() const {
return _java_mirror.resolve();
}
Expand Down
14 changes: 13 additions & 1 deletion src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Method::Method(ConstMethod* xconst, AccessFlags access_flags, Symbol* name) {
// Release Method*. The nmethod will be gone when we get here because
// we've walked the code cache.
void Method::deallocate_contents(ClassLoaderData* loader_data) {
// jmethodID mid = jmethod_id();
// if (!(mid == nullptr || *((Method**)mid) == nullptr)){
// fprintf(stdout, "!!! jmethodid not cleared out\n");
// }
MetadataFactory::free_metadata(loader_data, constMethod());
set_constMethod(nullptr);
MetadataFactory::free_metadata(loader_data, method_data());
Expand All @@ -137,6 +141,10 @@ void Method::deallocate_contents(ClassLoaderData* loader_data) {

void Method::release_C_heap_structures() {
if (method_data()) {
// jmethodID mid = jmethod_id();
// if (!(mid == nullptr || *((Method**)mid) == nullptr)){
// fprintf(stdout, "!!! jmethodid not cleared out\n");
// }
method_data()->release_C_heap_structures();

// Destroy MethodData embedded lock
Expand Down Expand Up @@ -2231,12 +2239,16 @@ Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
if (o == nullptr || o == JNIMethodBlock::_free_method) {
return nullptr;
}
InstanceKlass* method_holder = o->method_holder_safe();
if (method_holder == nullptr || !os::is_readable_pointer(method_holder)) {
return nullptr;
}
// Method should otherwise be valid. Assert for testing.
assert(is_valid_method(o), "should be valid jmethodid");
// If the method's class holder object is unreferenced, but not yet marked as
// unloaded, we need to return null here too because after a safepoint, its memory
// will be reclaimed.
return o->method_holder()->is_loader_alive() ? o : nullptr;
return method_holder->is_loader_alive_safe() ? o : nullptr;
};

void Method::set_on_stack(const bool value) {
Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/oops/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class Method : public Metadata {

// constant pool for Klass* holding this method
ConstantPool* constants() const { return constMethod()->constants(); }
// constant pool for Klass* holding this method or nullptr if it can't be accessed safely
ConstantPool* constants_safe() const {
ConstMethod* method = constMethod();
return os::is_readable_pointer(method) ? method->constants() : nullptr;
}
void set_constants(ConstantPool* c) { constMethod()->set_constants(c); }

// max stack
Expand Down Expand Up @@ -485,6 +490,11 @@ class Method : public Metadata {

// method holder (the Klass* holding this method)
InstanceKlass* method_holder() const { return constants()->pool_holder(); }
// method holder (the Klass* holding this method) or nullptr if can't be accessed safely
InstanceKlass* method_holder_safe() const {
ConstantPool* cp = constants_safe();
return os::is_readable_pointer(cp) ? cp->pool_holder() : nullptr;
}

Symbol* klass_name() const; // returns the name of the method holder
BasicType result_type() const { return constMethod()->result_type(); }
Expand Down

0 comments on commit 31eeef5

Please sign in to comment.