OSDN Git Service

Fix test 104 for --relocate --no-patchoat
authorMathieu Chartier <mathieuc@google.com>
Tue, 14 Apr 2015 18:33:53 +0000 (11:33 -0700)
committerMathieu Chartier <mathieuc@google.com>
Tue, 14 Apr 2015 18:41:17 +0000 (11:41 -0700)
Failure caused by keeping an array live in a vreg, this caused
getDeclaredMethod to throw OOME.

Change-Id: Id2aa976af0978cdd7354fb94b3becfcc85e19ca2

test/104-growth-limit/src/Main.java

index 55469db..d666377 100644 (file)
@@ -21,8 +21,14 @@ import java.util.List;
 public class Main {
 
     public static void main(String[] args) throws Exception {
-
         int alloc1 = 1;
+        // Setup reflection stuff before allocating to prevent OOME caused by allocations from
+        // Class.forName or getDeclaredMethod.
+        // Reflective equivalent of: dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
+        final Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
+        final Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
+        final Object runtime = get_runtime.invoke(null);
+        final Method clear_growth_limit = vm_runtime.getDeclaredMethod("clearGrowthLimit");
         try {
             List<byte[]> l = new ArrayList<byte[]>();
             while (true) {
@@ -33,13 +39,7 @@ public class Main {
         } catch (OutOfMemoryError e) {
         }
         // Expand the heap to the maximum size.
-        // Reflective equivalent of: dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
-        Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
-        Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
-        Object runtime = get_runtime.invoke(null);
-        Method clear_growth_limit = vm_runtime.getDeclaredMethod("clearGrowthLimit");
         clear_growth_limit.invoke(runtime);
-
         int alloc2 = 1;
         try {
             List<byte[]> l = new ArrayList<byte[]>();