From: Mathieu Chartier Date: Sat, 27 Jun 2015 22:42:27 +0000 (-0700) Subject: ART: Fix test 036-finalizer X-Git-Tag: android-x86-7.1-r1~889^2~853^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ef9849e4adc5e9d9068caf7bb4dc834bb33c976a;p=android-x86%2Fart.git 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 e3cf4eedb..8c7c27d79 100644 --- a/test/036-finalizer/src/Main.java +++ b/test/036-finalizer/src/Main.java @@ -34,31 +34,10 @@ public class Main { } public static WeakReference makeRef() { - /* - * Make ft in another thread, so there is no danger of - * a conservative reference leaking onto the main thread's - * stack. - */ - - final List> wimp = - new ArrayList>(); - Thread t = new Thread() { - public void run() { - FinalizerTest ft = new FinalizerTest("wahoo"); - wimp.add(new WeakReference(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 ref = new WeakReference(ft); + ft = null; + return ref; } public static String wimpString(final WeakReference wimp) { @@ -91,10 +70,12 @@ public class Main { public static void main(String[] args) { WeakReference 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();