summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/036-finalizer/src/Main.java14
1 files changed, 8 insertions, 6 deletions
diff --git a/test/036-finalizer/src/Main.java b/test/036-finalizer/src/Main.java
index ff6186b240..51d4a81150 100644
--- a/test/036-finalizer/src/Main.java
+++ b/test/036-finalizer/src/Main.java
@@ -70,15 +70,17 @@ public class Main {
return s[0];
}
- private static void printWeakReference(WeakReference<FinalizerTest> wimp) {
+ public static void main(String[] args) {
+ WeakReference<FinalizerTest> wimp = makeRef();
// Reference ft so we are sure the WeakReference cannot be cleared.
+ // Note: This is very fragile. It was previously in a helper function but that
+ // doesn't work for JIT-on-first-use with --gcstress where the object would be
+ // collected when JIT internally allocates an array. Also adding a scope around
+ // the keepLive lifetime somehow keeps a non-null `keepLive` around and makes
+ // the test fail (even when keeping the `null` assignment). b/76454261
FinalizerTest keepLive = wimp.get();
System.out.println("wimp: " + wimpString(wimp));
- }
-
- public static void main(String[] args) {
- WeakReference<FinalizerTest> wimp = makeRef();
- printWeakReference(wimp);
+ keepLive = null; // Clear the reference.
/* this will try to collect and finalize ft */
System.out.println("gc");