ART: Fix test 036-finalizer
Need to fix bug in test 036 where some allocation sites could cause
GC to run which caused the test to fail due to a weak reference
getting cleared. This change is required for the new GCSTRESS mode.
Bug: 22014525
Change-Id: I8099d2f03bc2f14f4ca6d49133f0d17d8aa49a7b
diff --git a/test/036-finalizer/src/Main.java b/test/036-finalizer/src/Main.java
index e3cf4ee..8c7c27d 100644
--- a/test/036-finalizer/src/Main.java
+++ b/test/036-finalizer/src/Main.java
@@ -34,31 +34,10 @@
}
public static WeakReference<FinalizerTest> makeRef() {
- /*
- * Make ft in another thread, so there is no danger of
- * a conservative reference leaking onto the main thread's
- * stack.
- */
-
- final List<WeakReference<FinalizerTest>> wimp =
- new ArrayList<WeakReference<FinalizerTest>>();
- Thread t = new Thread() {
- public void run() {
- FinalizerTest ft = new FinalizerTest("wahoo");
- wimp.add(new WeakReference<FinalizerTest>(ft));
- ft = null;
- }
- };
-
- t.start();
-
- try {
- t.join();
- } catch (InterruptedException ie) {
- throw new RuntimeException(ie);
- }
-
- return wimp.get(0);
+ FinalizerTest ft = new FinalizerTest("wahoo");
+ WeakReference<FinalizerTest> ref = new WeakReference<FinalizerTest>(ft);
+ ft = null;
+ return ref;
}
public static String wimpString(final WeakReference<FinalizerTest> wimp) {
@@ -91,10 +70,12 @@
public static void main(String[] args) {
WeakReference<FinalizerTest> wimp = makeRef();
+ FinalizerTest keepLive = wimp.get();
System.out.println("wimp: " + wimpString(wimp));
/* this will try to collect and finalize ft */
+ keepLive = null;
System.out.println("gc");
Runtime.getRuntime().gc();