Skip to content

Commit

Permalink
Add MemberName finalizer to mark clazz for MemberName list pruning
Browse files Browse the repository at this point in the history
This prevents a memory leak in the maintenance of per-class lists used
to find affected MemberName objects in case of class redefinition.
  • Loading branch information
jdmpapin committed Mar 18, 2024
1 parent c86cd88 commit 1619e47
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/java.base/share/classes/java/lang/invoke/MemberName.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
* ===========================================================================
*/

package java.lang.invoke;

import sun.invoke.util.BytecodeDescriptor;
Expand Down Expand Up @@ -1196,4 +1202,11 @@ private static MemberName[] newMemberBuffer(int length) {
return buf;
}
}

@Override
protected void finalize() {
if (null != clazz) {
MethodHandleNatives.markClassForMemberNamePruning(clazz);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
* ===========================================================================
*/

package java.lang.invoke;

import jdk.internal.access.JavaLangAccess;
Expand Down Expand Up @@ -690,4 +696,9 @@ static Object classData(Class<?> c) {
UNSAFE.ensureClassInitialized(c);
return JLA.classData(c);
}

/**
* Inform the VM that a MemberName belonging to class c has been collected.
*/
static native void markClassForMemberNamePruning(Class<?> c);
}

0 comments on commit 1619e47

Please sign in to comment.