Manually merge my AOSP update to the VM tests.
Original change: https://android-review.googlesource.com/32051
Bug: http://code.google.com/p/android/issues/detail?id=21599
Bug: http://code.google.com/p/android/issues/detail?id=21597
Change-Id: I31e440b66b720647afab54ca39fd6eb1bbb0cb60
diff --git a/test/061-out-of-memory/src/Main.java b/test/061-out-of-memory/src/Main.java
index c04d41f..c812c81 100644
--- a/test/061-out-of-memory/src/Main.java
+++ b/test/061-out-of-memory/src/Main.java
@@ -43,18 +43,13 @@
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 64MB max
- */
- final int SIXTY_FOUR_MB = (64 * 1024 * 1024 - 32);
-
Boolean sawEx = false;
- byte a[];
+ byte[] a;
try {
- a = new byte[SIXTY_FOUR_MB];
+ // Just shy of the typical max heap size so that it will actually
+ // try to allocate it instead of short-circuiting.
+ a = new byte[(int) Runtime.getRuntime().maxMemory() - 32];
} catch (OutOfMemoryError oom) {
//Log.i(TAG, "HeapTest/OomeLarge caught " + oom);
sawEx = true;
@@ -71,11 +66,8 @@
/* 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 64MB max
*/
private static boolean testOomeSmallInternal() {
- final int SIXTY_FOUR_MB = (64 * 1024 * 1024);
final int LINK_SIZE = 6 * 4; // estimated size of a LinkedList's node
LinkedList<Object> list = new LinkedList<Object>();
@@ -86,7 +78,7 @@
while (objSize >= LINK_SIZE) {
boolean sawEx = false;
try {
- for (int i = 0; i < SIXTY_FOUR_MB / objSize; i++) {
+ for (int i = 0; i < Runtime.getRuntime().maxMemory() / objSize; i++) {
list.add((Object)new byte[objSize]);
}
} catch (OutOfMemoryError oom) {