diff options
author | Andy McFadden <fadden@android.com> | 2011-02-09 13:12:36 -0800 |
---|---|---|
committer | Andy McFadden <fadden@android.com> | 2011-02-09 13:12:36 -0800 |
commit | f6b6389dc3096c361d86e664b5db7292acb113b0 (patch) | |
tree | 01be69ee3a16e330a065150ae3bda58c05d4a2bd /tests | |
parent | 8dcf274871fbce24f2891ddb05bdd8e5af2a53cd (diff) | |
download | android_dalvik-f6b6389dc3096c361d86e664b5db7292acb113b0.tar.gz android_dalvik-f6b6389dc3096c361d86e664b5db7292acb113b0.tar.bz2 android_dalvik-f6b6389dc3096c361d86e664b5db7292acb113b0.zip |
Add huge-array OOM test
Added a regression test for allocation of 4GB+ arrays.
Change-Id: Ibac82bbba9ef25b0850386a35e0f5b8554abbaa3
Diffstat (limited to 'tests')
-rw-r--r-- | tests/061-out-of-memory/expected.txt | 1 | ||||
-rw-r--r-- | tests/061-out-of-memory/src/Main.java | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/061-out-of-memory/expected.txt b/tests/061-out-of-memory/expected.txt index e1ed5da64..ca876299f 100644 --- a/tests/061-out-of-memory/expected.txt +++ b/tests/061-out-of-memory/expected.txt @@ -1,4 +1,5 @@ tests beginning +Got expected huge-array OOM testOomeLarge beginning testOomeLarge succeeded testOomeSmall beginning diff --git a/tests/061-out-of-memory/src/Main.java b/tests/061-out-of-memory/src/Main.java index fcf71362d..b5999b34b 100644 --- a/tests/061-out-of-memory/src/Main.java +++ b/tests/061-out-of-memory/src/Main.java @@ -14,6 +14,7 @@ * limitations under the License. */ +import java.util.Arrays; import java.util.LinkedList; /** @@ -22,16 +23,30 @@ import java.util.LinkedList; public class Main { public static void main(String args[]) { System.out.println("tests beginning"); + testHugeArray(); testOomeLarge(); testOomeSmall(); System.out.println("tests succeeded"); } + private static void testHugeArray() { + try { + final int COUNT = 32768*32768 + 4; + int[] tooBig = new int[COUNT]; + + Arrays.fill(tooBig, 0xdd); + } catch (OutOfMemoryError oom) { + System.out.println("Got expected huge-array OOM"); + } + } + private static void testOomeLarge() { System.out.println("testOomeLarge beginning"); /* Just shy of the typical max heap size so that it will actually * try to allocate it instead of short-circuiting. + * + * TODO: stop assuming the VM defaults to 16MB max */ final int SIXTEEN_MB = (16 * 1024 * 1024 - 32); @@ -56,6 +71,8 @@ public class Main { /* Do this in another method so that the GC has a chance of freeing the * list afterwards. Even if we null out list when we're done, the conservative * GC may see a stale pointer to it in a register. + * + * TODO: stop assuming the VM defaults to 16MB max */ private static boolean testOomeSmallInternal() { final int SIXTEEN_MB = (16 * 1024 * 1024); |