OSDN Git Service

Don't init class during reflection signature scan.
authorAndy McFadden <fadden@android.com>
Tue, 16 Jun 2009 19:10:04 +0000 (12:10 -0700)
committerAndy McFadden <fadden@android.com>
Tue, 14 Jul 2009 17:47:19 +0000 (10:47 -0700)
Do not merge to master -- this is 57ea16e8 from there.

When processing Class.getDeclaredMethods() we create Method objects.
These have arrays of classes that indicate the method parameter types.
While generating the array we were initializing the classes we found,
which isn't necessary and led to some unpleasantness described in
external bug 3005.

tests/046-reflect/expected.txt
tests/046-reflect/src/Main.java
vm/reflect/Reflect.c

index eefa448..3be8d1c 100644 (file)
@@ -92,3 +92,6 @@ myMethod (I)I
 ReflectTest done!
 checkType invoking null
 checkType got expected exception
+got methods
+NoisyInitUser is initializing
+NoisyInit is initializing
index 1ec63d8..99b1c4e 100644 (file)
@@ -332,11 +332,23 @@ public class Main {
         }
     }
 
+    public static void checkInit() {
+        Class niuClass = NoisyInitUser.class;
+        Method[] methods;
+
+        methods = niuClass.getDeclaredMethods();
+        System.out.println("got methods");
+        /* neither NoisyInit nor NoisyInitUser should be initialized yet */
+        NoisyInitUser niu = new NoisyInitUser();
+        NoisyInit ni = new NoisyInit();
+    }
+
     public static void main(String[] args) {
         Main test = new Main();
         test.run();
 
         checkType();
+        checkInit();
     }
 }
 
@@ -407,3 +419,18 @@ class Target extends SuperTarget {
     public static double staticDouble = 3.3;
 }
 
+class NoisyInit {
+    static {
+        System.out.println("NoisyInit is initializing");
+        //Throwable th = new Throwable();
+        //th.printStackTrace();
+    }
+}
+
+class NoisyInitUser {
+    static {
+        System.out.println("NoisyInitUser is initializing");
+    }
+    public void createNoisyInit(NoisyInit ni) {}
+}
+
index b7de934..2e3c549 100644 (file)
@@ -212,7 +212,7 @@ static ClassObject* convertSignaturePartToClass(char** pSignature,
             ;
         savedChar = *++signature;
         *signature = '\0';
-        clazz = dvmFindClass(*pSignature, defClass->classLoader);
+        clazz = dvmFindClassNoInit(*pSignature, defClass->classLoader);
         *signature = savedChar;
     } else {
         clazz = dvmFindPrimitiveClass(*signature++);