diff options
author | Elliott Hughes <enh@google.com> | 2013-04-11 18:13:31 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-04-11 18:13:31 -0700 |
commit | ff9af2220a9d0ef8e7c7f34448c6cfae144e7509 (patch) | |
tree | fbdaab19dd0aa5f0cadd85ce716f16d143fd3582 /test/080-oom-throw | |
parent | c1fcdf1ec5a8c5ffaf9e857ea81ac7358d1df7f5 (diff) | |
download | art-ff9af2220a9d0ef8e7c7f34448c6cfae144e7509.zip art-ff9af2220a9d0ef8e7c7f34448c6cfae144e7509.tar.gz art-ff9af2220a9d0ef8e7c7f34448c6cfae144e7509.tar.bz2 |
Port AOSP dalvik change 9e11a836e0927e6ea9246b56d99e0482920b81c6 to art.
The flakiness had already been worked around in art, but not backported.
The new dalvik fix is cleaner anyway.
Bug: https://code.google.com/p/android/issues/detail?id=54114
Change-Id: If21e493f3614a14fc5e645bf7055515b963832bb
Diffstat (limited to 'test/080-oom-throw')
-rw-r--r-- | test/080-oom-throw/expected.txt | 4 | ||||
-rw-r--r-- | test/080-oom-throw/src/Main.java | 65 |
2 files changed, 31 insertions, 38 deletions
diff --git a/test/080-oom-throw/expected.txt b/test/080-oom-throw/expected.txt index 811f68c..73cc0d8 100644 --- a/test/080-oom-throw/expected.txt +++ b/test/080-oom-throw/expected.txt @@ -1,2 +1,2 @@ -Array allocation failed -Instance allocation failed +NEW_ARRAY correctly threw OOME +NEW_INSTANCE correctly threw OOME diff --git a/test/080-oom-throw/src/Main.java b/test/080-oom-throw/src/Main.java index 052feb6..3ffe2f3 100644 --- a/test/080-oom-throw/src/Main.java +++ b/test/080-oom-throw/src/Main.java @@ -16,68 +16,61 @@ public class Main { static class ArrayMemEater { - static int blowup(char[][] holder, int size) { - int i = 0; + static boolean sawOome; + + static void blowup(char[][] holder) { try { - for ( ; i < size; i++) - holder[i] = new char[128]; + for (int i = 0; i < holder.length; ++i) { + holder[i] = new char[128 * 1024]; + } } catch (OutOfMemoryError oome) { - return i; + ArrayMemEater.sawOome = true; } - - return size; - } - - static void confuseCompilerOptimization(char[][] holder) { } } static class InstanceMemEater { + static boolean sawOome; + InstanceMemEater next; - double d1, d2, d3, d4, d5, d6, d7, d8; + double d1, d2, d3, d4, d5, d6, d7, d8; // Bloat this object so we fill the heap faster. - static InstanceMemEater blowup() { - InstanceMemEater memEater; + static InstanceMemEater allocate() { try { - memEater = new InstanceMemEater(); + return new InstanceMemEater(); } catch (OutOfMemoryError e) { - memEater = null; + InstanceMemEater.sawOome = true; + return null; } - return memEater; } - static void confuseCompilerOptimization(InstanceMemEater memEater) { + static void confuseCompilerOptimization(InstanceMemEater instance) { } } - static void triggerArrayOOM() { - int size = 1 * 1024 * 1024; - char[][] holder = new char[size][]; - - int count = ArrayMemEater.blowup(holder, size); - ArrayMemEater.confuseCompilerOptimization(holder); - // Ensure there is some reclaimable memory for println. - holder = null; - if (count < size) { - System.out.println("Array allocation failed"); - } + static boolean triggerArrayOOM() { + ArrayMemEater.blowup(new char[1 * 1024 * 1024][]); + return ArrayMemEater.sawOome; } - static void triggerInstanceOOM() { - InstanceMemEater memEater = InstanceMemEater.blowup(); + static boolean triggerInstanceOOM() { + InstanceMemEater memEater = InstanceMemEater.allocate(); InstanceMemEater lastMemEater = memEater; do { - lastMemEater.next = InstanceMemEater.blowup(); + lastMemEater.next = InstanceMemEater.allocate(); lastMemEater = lastMemEater.next; } while (lastMemEater != null); memEater.confuseCompilerOptimization(memEater); - // Ensure there is some reclaimable memory for println. - memEater = null; - System.out.println("Instance allocation failed"); + return InstanceMemEater.sawOome; } public static void main(String[] args) { - triggerArrayOOM(); - triggerInstanceOOM(); + if (triggerArrayOOM()) { + System.out.println("NEW_ARRAY correctly threw OOME"); + } + + if (triggerInstanceOOM()) { + System.out.println("NEW_INSTANCE correctly threw OOME"); + } } } |