summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tobias Thierer <tobiast@google.com> 2017-12-11 22:29:17 +0000
committer Tobias Thierer <tobiast@google.com> 2017-12-15 18:52:15 +0000
commitbb68b222ac429c419b3b591e239fc43c9c3f5b83 (patch)
tree0b64302318d1baa09df5ab4f2012e1d8044c5aa8
parentd1c3915293412da3ae4898b446d3cdffa3d07058 (diff)
Tweak art tests to decouple better from toolchain version.
This CL changes some nested classes to be prebuilt rather than compiled each time the test is run so they don't depend on javac behavior, which changed between OpenJDK 8 and OpenJDK 9. This way, the tests pass when run on either OpenJDK 8 or 9. The class files were generated using OpenJDK 8 javac and converted to jasmin (.j) using ClassFileAnalyzer 0.7.0 [1] and Jasper 1.00 [2], respectively; license headers and comments were added to the generated .j files. [1] http://classfileanalyzer.javaseiten.de/ [2] http://www.angelfire.com/tx4/cus/jasper/ 031-class-attributes: Unlike OpenJDK 8 javac, OpenJDK 9 javac does not consider an anonymous class declared inside a static method to be static. This affects ClassAttr$1.j, which is now prebuilt. 085-old-style-inner-class: Main$1 and Main$2 relied on compilation with javac -source 1.4 -target 1.4, which OpenJDK 9 javac doesn't support. They are now prebuilt. The two classes are identical in all relevant aspects; a future CL could simplify the test by dropping one of them. Bug: 69449021 Test: The two tests touched by this CL pass in: EXPERIMENTAL_USE_OPENJDK9=1.8 \ art/test/testrunner/run_build_test_target.py -j40 art-interpreter Change-Id: I72ba88eb6325a641876b7143008dfb209a16047e
-rw-r--r--test/031-class-attributes/jasmin/ClassAttrs$1.j49
-rw-r--r--test/031-class-attributes/src/ClassAttrs.java11
-rw-r--r--test/085-old-style-inner-class/build33
-rw-r--r--test/085-old-style-inner-class/jasmin/Main$1.j39
-rw-r--r--test/085-old-style-inner-class/jasmin/Main$2.j39
-rw-r--r--test/085-old-style-inner-class/src/Main.java10
6 files changed, 142 insertions, 39 deletions
diff --git a/test/031-class-attributes/jasmin/ClassAttrs$1.j b/test/031-class-attributes/jasmin/ClassAttrs$1.j
new file mode 100644
index 0000000000..ea767efdba
--- /dev/null
+++ b/test/031-class-attributes/jasmin/ClassAttrs$1.j
@@ -0,0 +1,49 @@
+; Copyright (C) 2017 The Android Open Source Project
+;
+; Licensed under the Apache License, Version 2.0 (the "License");
+; you may not use this file except in compliance with the License.
+; You may obtain a copy of the License at
+;
+; http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+
+; (new OtherClass() { int i = 5; }).getClass()
+
+; ClassAttrs$1.j
+
+; Generated by ClassFileAnalyzer (Can)
+; Analyzer and Disassembler for Java class files
+; (Jasmin syntax 2, http://jasmin.sourceforge.net)
+;
+; ClassFileAnalyzer, version 0.7.0
+
+.bytecode 52.0
+.source ClassAttrs.java
+.class final ClassAttrs$1
+.super OtherClass
+.enclosing method ClassAttrs/main()V
+; OpenJDK javac versions <= 8 consider anonymous classes declared side
+; static methods to be static (as is this one), whereas OpenJDK 9 javac
+; does not. See http://b/62290080
+.inner class static inner ClassAttrs$1 ; <anonymous> <not a member>
+
+.field i I
+
+.method <init>()V
+ .limit stack 2
+ .limit locals 1
+ .line 112
+ 0: aload_0
+ 1: invokespecial OtherClass/<init>()V
+ 4: aload_0
+ 5: iconst_5
+ 6: putfield ClassAttrs$1/i I
+ 9: return
+.end method
+
+
diff --git a/test/031-class-attributes/src/ClassAttrs.java b/test/031-class-attributes/src/ClassAttrs.java
index 8489a2c222..f55a34c5f2 100644
--- a/test/031-class-attributes/src/ClassAttrs.java
+++ b/test/031-class-attributes/src/ClassAttrs.java
@@ -107,9 +107,14 @@ public class ClassAttrs {
inner.showMe();
ClassAttrs attrs = new ClassAttrs();
-
- /* anonymous, not local, not member */
- printClassAttrs((new OtherClass() { int i = 5; }).getClass());
+ try {
+ /* anonymous, not local, not member */
+ printClassAttrs(Class.forName("ClassAttrs$1")); // ClassAttrs$1.j
+ } catch (ClassNotFoundException e) {
+ System.out.println("FAILED: " + e);
+ e.printStackTrace(System.out);
+ throw new AssertionError(e);
+ }
/* member, not anonymous, not local */
printClassAttrs(MemberClass.class);
diff --git a/test/085-old-style-inner-class/build b/test/085-old-style-inner-class/build
deleted file mode 100644
index 21dc66269d..0000000000
--- a/test/085-old-style-inner-class/build
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Stop if something fails.
-set -e
-
-# We compile for a 1.4 target to suppress the use of EnclosingMethod
-# attributes.
-mkdir classes
-${JAVAC} -source 1.4 -target 1.4 -d classes `find src -name '*.java'`
-
-if [ ${USE_JACK} = "true" ]; then
- jar cf classes.jill.jar -C classes .
- ${JACK} --import classes.jill.jar --output-dex .
-else
- # Suppress stderr to keep the inner class warnings out of the expected output.
- ${DX} --debug --dex --dump-to=classes.lst --output=classes.dex --dump-width=1000 classes 2>/dev/null
-fi
-
-zip $TEST_NAME.jar classes.dex
diff --git a/test/085-old-style-inner-class/jasmin/Main$1.j b/test/085-old-style-inner-class/jasmin/Main$1.j
new file mode 100644
index 0000000000..fde1ddea53
--- /dev/null
+++ b/test/085-old-style-inner-class/jasmin/Main$1.j
@@ -0,0 +1,39 @@
+; Copyright (C) 2017 The Android Open Source Project
+;
+; Licensed under the Apache License, Version 2.0 (the "License");
+; you may not use this file except in compliance with the License.
+; You may obtain a copy of the License at
+;
+; http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+
+.source Main.java
+.class final Main$1
+.super java/lang/Object
+.implements java/lang/Runnable
+
+; new Runnable() {
+; public void run() { }
+; };
+
+.method <init>()V
+ .limit stack 1
+ .limit locals 1
+ .line 23
+ aload_0
+ invokespecial java/lang/Object/<init>()V
+ return
+.end method
+
+.method public run()V
+ .limit stack 0
+ .limit locals 1
+ .line 24
+ return
+.end method
+
diff --git a/test/085-old-style-inner-class/jasmin/Main$2.j b/test/085-old-style-inner-class/jasmin/Main$2.j
new file mode 100644
index 0000000000..dedbe8682e
--- /dev/null
+++ b/test/085-old-style-inner-class/jasmin/Main$2.j
@@ -0,0 +1,39 @@
+; Copyright (C) 2017 The Android Open Source Project
+;
+; Licensed under the Apache License, Version 2.0 (the "License");
+; you may not use this file except in compliance with the License.
+; You may obtain a copy of the License at
+;
+; http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+
+.source Main.java
+.class final Main$2
+.super java/lang/Object
+.implements java/lang/Runnable
+
+; new Runnable() {
+; public void run() { }
+; };
+
+.method <init>()V
+ .limit stack 1
+ .limit locals 1
+ .line 28
+ aload_0
+ invokespecial java/lang/Object/<init>()V
+ return
+.end method
+
+.method public run()V
+ .limit stack 0
+ .limit locals 1
+ .line 29
+ return
+.end method
+
diff --git a/test/085-old-style-inner-class/src/Main.java b/test/085-old-style-inner-class/src/Main.java
index c9a5b72dbd..831364cae1 100644
--- a/test/085-old-style-inner-class/src/Main.java
+++ b/test/085-old-style-inner-class/src/Main.java
@@ -20,15 +20,19 @@ import java.lang.reflect.Method;
* Test reflection on old-style inner classes.
*/
public class Main {
+ /*
+ // Main$1.j
private static Runnable theRunnable = new Runnable() {
public void run() { }
};
+ // Main$1.2
private static Runnable create() {
return new Runnable() {
public void run() { }
};
}
+ */
private static String nameOf(Class clazz) {
return (clazz == null) ? "(null)" : clazz.getName();
@@ -48,8 +52,8 @@ public class Main {
nameOf(clazz.getEnclosingMethod()));
}
- public static void main(String args[]) {
- infoFor(theRunnable.getClass());
- infoFor(create().getClass());
+ public static void main(String args[]) throws ClassNotFoundException {
+ infoFor(Class.forName("Main$1"));
+ infoFor(Class.forName("Main$2"));
}
}