summaryrefslogtreecommitdiffstats
path: root/test/425-invoke-super/src
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-11-11 14:40:10 +0000
committerNicolas Geoffray <ngeoffray@google.com>2014-11-12 09:33:10 +0000
commit0d8db99ac5d838f81e0d3be83a5b00d5475edf86 (patch)
treede1bb824aaf8cb2320ded80394dd65a44355fa52 /test/425-invoke-super/src
parent36750ca45fcbe4706d3a3419cf7f988a129a876c (diff)
downloadart-0d8db99ac5d838f81e0d3be83a5b00d5475edf86.zip
art-0d8db99ac5d838f81e0d3be83a5b00d5475edf86.tar.gz
art-0d8db99ac5d838f81e0d3be83a5b00d5475edf86.tar.bz2
Implement invokesuper in optimizing.
- Ensure dex2oat is in PIC mode, as this will drive the decisions made in the compiler driver, and optimizing only suppots PIC anyway. - Since invokesuper is sharpened into invoke-direct, also support sharpening of invokeinterface and invokevirtual. Change-Id: I0a1bd79a13dc1c9e67e3cb11d38f0cd4459968ae
Diffstat (limited to 'test/425-invoke-super/src')
-rw-r--r--test/425-invoke-super/src/Main.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/425-invoke-super/src/Main.java b/test/425-invoke-super/src/Main.java
new file mode 100644
index 0000000..1fb62d0
--- /dev/null
+++ b/test/425-invoke-super/src/Main.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+import java.lang.reflect.Method;
+
+public class Main {
+ static class A {
+ public int foo() { return 1; }
+ }
+
+ static class B extends A {
+ public int $opt$bar() { return super.foo(); }
+ }
+
+ static class C extends B {
+ public int foo() { return 42; }
+ }
+
+ static class D extends C {
+ }
+
+ static void assertEquals(int expected, int value) {
+ if (expected != value) {
+ throw new Error("Expected " + expected + ", got " + value);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ assertEquals(1, new B().$opt$bar());
+ assertEquals(1, new C().$opt$bar());
+ assertEquals(1, new D().$opt$bar());
+
+ Class<?> c = Class.forName("InvokeSuper");
+ Method m = c.getMethod("run");
+ assertEquals(42, ((Integer)m.invoke(c.newInstance(), new Object[0])).intValue());
+
+ c = Class.forName("SubClass");
+ assertEquals(42, ((Integer)m.invoke(c.newInstance(), new Object[0])).intValue());
+ }
+}