diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-09-04 14:15:35 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-09-04 15:18:34 -0700 |
commit | 3a5fa5ed91bf76c32913fe8149a83ba4205aa0bf (patch) | |
tree | d8aa45bf317cb8b818717d5193928580f79fb1e6 /test | |
parent | 552da6697f77b1d94a69b0ba54509a25a0de3ae7 (diff) | |
download | art-3a5fa5ed91bf76c32913fe8149a83ba4205aa0bf.zip art-3a5fa5ed91bf76c32913fe8149a83ba4205aa0bf.tar.gz art-3a5fa5ed91bf76c32913fe8149a83ba4205aa0bf.tar.bz2 |
Add test case for runFinalization.
There was a bug causing runFinalization to return before recently
freed objects were finalized. This is a regression test for this bug.
Bug: 17381967
Change-Id: Ide6e2037685324423e83965fae3935f3e7f0aba6
Diffstat (limited to 'test')
-rw-r--r-- | test/036-finalizer/expected.txt | 1 | ||||
-rw-r--r-- | test/036-finalizer/src/Main.java | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/test/036-finalizer/expected.txt b/test/036-finalizer/expected.txt index a2a74fc..36fa5f8 100644 --- a/test/036-finalizer/expected.txt +++ b/test/036-finalizer/expected.txt @@ -11,3 +11,4 @@ gc + finalize sleep reborn: [FinalizerTest message=nothing, finalized=false] wimp: null +Finalized 1024 / 1024 diff --git a/test/036-finalizer/src/Main.java b/test/036-finalizer/src/Main.java index 328425f..390472d 100644 --- a/test/036-finalizer/src/Main.java +++ b/test/036-finalizer/src/Main.java @@ -120,6 +120,39 @@ public class Main { System.out.println("reborn: " + FinalizerTest.mReborn); System.out.println("wimp: " + wimpString(wimp)); + // Test runFinalization with multiple objects. + runFinalizationTest(); + } + + static class FinalizeCounter { + private static Object finalizeLock = new Object(); + private static volatile int finalizeCount = 0; + private int index; + static int getCount() { + return finalizeCount; + } + FinalizeCounter(int index) { + this.index = index; + } + protected void finalize() { + synchronized(finalizeLock) { + ++finalizeCount; + } + } + } + + private static void runFinalizationTest() { + int count = 1024; + Object[] objs = new Object[count]; + for (int i = 0; i < count; ++i) { + objs[i] = new FinalizeCounter(i); + } + for (int i = 0; i < count; ++i) { + objs[i] = null; + } + System.gc(); + System.runFinalization(); + System.out.println("Finalized " + FinalizeCounter.getCount() + " / " + count); } public static class FinalizerTest { |