summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-03-23 11:44:07 -0700
committerElliott Hughes <enh@google.com>2012-03-23 14:42:39 -0700
commit923e8b8e936ead33408e111682aa9372e3a7ed43 (patch)
tree189443deaaff7a72dcd602db59ef597273cabd9b /test
parent634eb2eb14f87753519d0ef2c5f256e55888f378 (diff)
downloadart-923e8b8e936ead33408e111682aa9372e3a7ed43.zip
art-923e8b8e936ead33408e111682aa9372e3a7ed43.tar.gz
art-923e8b8e936ead33408e111682aa9372e3a7ed43.tar.bz2
Expand test 046 and move reflective class initialization later.
We have no reason to do this later; we're just being conservative. We might want to revisit this in a future release so you only pay once, when you cache your Field or Method instance. Change-Id: Ib18fa75c0648561d3c5e1554cb3955ed57ab9314
Diffstat (limited to 'test')
-rw-r--r--test/046-reflect/expected.txt18
-rw-r--r--test/046-reflect/src/Main.java99
2 files changed, 87 insertions, 30 deletions
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt
index 82fe87c..8de373c 100644
--- a/test/046-reflect/expected.txt
+++ b/test/046-reflect/expected.txt
@@ -94,11 +94,21 @@ ReflectTest done!
public method
checkType invoking null
checkType got expected exception
-calling const-class NoisyInitUser.class
-called const-class NoisyInitUser.class
+calling const-class FieldNoisyInitUser.class
+called const-class FieldNoisyInitUser.class
+got fields
+got field
+FieldNoisyInitUser is initializing
+read field value
+FieldNoisyInit is initializing
+
+calling const-class MethodNoisyInitUser.class
+called const-class MethodNoisyInitUser.class
got methods
-NoisyInitUser is initializing
-NoisyInit is initializing
+got method
+MethodNoisyInitUser is initializing
+invoked method
+MethodNoisyInit is initializing
generic field: java.util.List<java.lang.String>
generic method fancyMethod params='[1] java.util.ArrayList<java.lang.String>' ret='java.util.Map<java.lang.Integer, java.lang.String>'
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index 104ead3..cf0a7e6 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -402,19 +402,48 @@ public class Main {
}
}
- public static void checkInit() {
- System.out.println("calling const-class NoisyInitUser.class");
- Class niuClass = NoisyInitUser.class;
- System.out.println("called const-class 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();
-
- System.out.println("");
+ public static void checkClinitForFields() throws Exception {
+ // Loading a class constant shouldn't run <clinit>.
+ System.out.println("calling const-class FieldNoisyInitUser.class");
+ Class niuClass = FieldNoisyInitUser.class;
+ System.out.println("called const-class FieldNoisyInitUser.class");
+
+ // Getting the declared fields doesn't run <clinit>.
+ Field[] fields = niuClass.getDeclaredFields();
+ System.out.println("got fields");
+
+ Field field = niuClass.getField("staticField");
+ System.out.println("got field");
+ field.get(null);
+ System.out.println("read field value");
+
+ // FieldNoisyInitUser should now be initialized, but FieldNoisyInit shouldn't be initialized yet.
+ FieldNoisyInitUser niu = new FieldNoisyInitUser();
+ FieldNoisyInit ni = new FieldNoisyInit();
+
+ System.out.println("");
+ }
+
+ public static void checkClinitForMethods() throws Exception {
+ // Loading a class constant shouldn't run <clinit>.
+ System.out.println("calling const-class MethodNoisyInitUser.class");
+ Class niuClass = MethodNoisyInitUser.class;
+ System.out.println("called const-class MethodNoisyInitUser.class");
+
+ // Getting the declared methods doesn't run <clinit>.
+ Method[] methods = niuClass.getDeclaredMethods();
+ System.out.println("got methods");
+
+ Method method = niuClass.getMethod("staticMethod", (Class[]) null);
+ System.out.println("got method");
+ method.invoke(null);
+ System.out.println("invoked method");
+
+ // MethodNoisyInitUser should now be initialized, but MethodNoisyInit shouldn't be initialized yet.
+ MethodNoisyInitUser niu = new MethodNoisyInitUser();
+ MethodNoisyInit ni = new MethodNoisyInit();
+
+ System.out.println("");
}
@@ -479,13 +508,14 @@ public class Main {
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
Main test = new Main();
test.run();
checkAccess();
checkType();
- checkInit();
+ checkClinitForFields();
+ checkClinitForMethods();
checkGeneric();
}
}
@@ -557,17 +587,34 @@ 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 FieldNoisyInit {
+ static {
+ System.out.println("FieldNoisyInit is initializing");
+ //Throwable th = new Throwable();
+ //th.printStackTrace();
+ }
}
-class NoisyInitUser {
- static {
- System.out.println("NoisyInitUser is initializing");
- }
- public void createNoisyInit(NoisyInit ni) {}
+class FieldNoisyInitUser {
+ static {
+ System.out.println("FieldNoisyInitUser is initializing");
+ }
+ public static int staticField;
+ public static FieldNoisyInit noisy;
+}
+
+class MethodNoisyInit {
+ static {
+ System.out.println("MethodNoisyInit is initializing");
+ //Throwable th = new Throwable();
+ //th.printStackTrace();
+ }
+}
+
+class MethodNoisyInitUser {
+ static {
+ System.out.println("MethodNoisyInitUser is initializing");
+ }
+ public static void staticMethod() {}
+ public void createMethodNoisyInit(MethodNoisyInit ni) {}
}