-
Enhancement
-
Resolution: Fixed
-
P4
-
repo-leyden
When WeakReference object are stored inside the AOT cache, they do not work properly. For example, the following test shows that a WeakReference still holds onto the referent even if the referent is no longer reachable:
[1] Apply this patch onto the https://github.com/openjdk/leyden/tree/premain branch (I tested on top of 7b72b048474091f123c055bd5b8d7fd7c00d19d4)
https://github.com/iklam/jdk/commit/ead3f5adc1eb81b8bbbf9a585aefe77804eb43fb
[2] Run the following program to trigger the calls to AOTHolder.test1(), etc
======================
import java.lang.invoke.MethodType;
public class MyTest {
public static void main(String... av) {
MethodType t1 = MethodType.methodType(Object.class, Test1.class);
MethodType t2 = MethodType.methodType(Object.class, Test2.class);
MethodType t3 = MethodType.methodType(Object.class, Test3.class);
}
}
class Test1 {}
class Test2 {}
class Test3 {}
======================
$ rm -rf tmpclasses
$ mkdir tmpclasses
$ javac -d tmpclasses MyTest.java
$ jar cvf MyTest.jar -C tmpclasses .
$ java -cp MyTest.jar MyTest.java
ref = non-null
ref = null
ref = null
(Note: with the regular "java" program, -XX:+AOTClassLinking is not enabled, so AOTHolder.ref is NOT stored in the AOT cache)
As expected, AOTHolder.ref releases the referent during the call to AOTHolder.test2()
======================
However, the referent is NOT released if AOTHolder.ref is stored into the AOT cache:
$ java -cp MyTest.jar -XX:AOTMode=record -XX:AOTConfiguration=mt.aotconfig MyTest
ref = non-null
ref = null
ref = null
$ java -cp MyTest.jar -XX:AOTMode=create -XX:AOTCache=mt.aot -XX:+AOTClassLinking
[....]
$ java -cp MyTest.jar -XX:AOTMode=on -XX:AOTCache=mt.aot MyTest
ref = non-null
ref = non-null <----- Huh???
ref = non-null
[1] Apply this patch onto the https://github.com/openjdk/leyden/tree/premain branch (I tested on top of 7b72b048474091f123c055bd5b8d7fd7c00d19d4)
https://github.com/iklam/jdk/commit/ead3f5adc1eb81b8bbbf9a585aefe77804eb43fb
[2] Run the following program to trigger the calls to AOTHolder.test1(), etc
======================
import java.lang.invoke.MethodType;
public class MyTest {
public static void main(String... av) {
MethodType t1 = MethodType.methodType(Object.class, Test1.class);
MethodType t2 = MethodType.methodType(Object.class, Test2.class);
MethodType t3 = MethodType.methodType(Object.class, Test3.class);
}
}
class Test1 {}
class Test2 {}
class Test3 {}
======================
$ rm -rf tmpclasses
$ mkdir tmpclasses
$ javac -d tmpclasses MyTest.java
$ jar cvf MyTest.jar -C tmpclasses .
$ java -cp MyTest.jar MyTest.java
ref = non-null
ref = null
ref = null
(Note: with the regular "java" program, -XX:+AOTClassLinking is not enabled, so AOTHolder.ref is NOT stored in the AOT cache)
As expected, AOTHolder.ref releases the referent during the call to AOTHolder.test2()
======================
However, the referent is NOT released if AOTHolder.ref is stored into the AOT cache:
$ java -cp MyTest.jar -XX:AOTMode=record -XX:AOTConfiguration=mt.aotconfig MyTest
ref = non-null
ref = null
ref = null
$ java -cp MyTest.jar -XX:AOTMode=create -XX:AOTCache=mt.aot -XX:+AOTClassLinking
[....]
$ java -cp MyTest.jar -XX:AOTMode=on -XX:AOTCache=mt.aot MyTest
ref = non-null
ref = non-null <----- Huh???
ref = non-null
- relates to
-
JDK-8351004 [leyden] Add test cases for cached Reference objects
-
- Open
-
-
JDK-8351005 [leyden] Revert back to SoftReference for Class::reflectionData
-
- Open
-