blob: 78cb37ae09cc84410bc46ad2498459ae2dccdedd [file] [log] [blame]
David Brazdil6de19382016-01-08 17:37:10 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.lang.reflect.Method;
18import java.lang.reflect.InvocationTargetException;
19
20public class Main {
21 // Workaround for b/18051191.
22 class Inner {}
23
24 public static native void assertIsInterpreted();
25
26 private static void assertEqual(String expected, String actual) {
27 if (!expected.equals(actual)) {
28 throw new Error("Assertion failed: " + expected + " != " + actual);
29 }
30 }
31
32 public static void main(String[] args) throws Throwable {
33 System.loadLibrary(args[0]);
34 Class<?> c = Class.forName("TestCase");
35 String testString = "Hello world";
36 byte[] testData = testString.getBytes("UTF8");
37
38 {
39 Method m = c.getMethod("vregAliasing", byte[].class);
40 String result = (String) m.invoke(null, new Object[] { testData });
41 assertEqual(testString, result);
42 }
43
44 {
45 c.getMethod("compareNewInstance").invoke(null, (Object[]) null);
46 }
47
48 {
49 Method m = c.getMethod("deoptimizeNewInstance", int[].class, byte[].class);
50 try {
51 m.invoke(null, new Object[] { new int[] { 1, 2, 3 }, testData });
52 } catch (InvocationTargetException ex) {
53 if (ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
54 // Expected.
55 } else {
56 throw ex.getCause();
57 }
58 }
59 }
David Brazdil65902e82016-01-15 09:35:13 +000060
61 {
62 Method m = c.getMethod("removeNewInstance", byte[].class);
63 String result = (String) m.invoke(null, new Object[] { testData });
64 assertEqual(testString, result);
65 }
David Brazdilbc9ab162016-01-20 14:50:19 +000066
67 {
David Brazdilc047d942016-01-20 17:00:19 +000068 Method m = c.getMethod("thisNotNewInstance1", byte[].class, boolean.class);
69 String result = (String) m.invoke(null, new Object[] { testData, true });
70 assertEqual(testString, result);
71 result = (String) m.invoke(null, new Object[] { testData, false });
72 assertEqual(testString, result);
73 }
74 {
75 Method m = c.getMethod("thisNotNewInstance2", byte[].class, boolean.class);
David Brazdilbc9ab162016-01-20 14:50:19 +000076 String result = (String) m.invoke(null, new Object[] { testData, true });
77 assertEqual(testString, result);
78 result = (String) m.invoke(null, new Object[] { testData, false });
79 assertEqual(testString, result);
80 }
David Brazdil6de19382016-01-08 17:37:10 +000081 }
Vladimir Markoa341f352016-08-31 12:18:20 +010082
83 public static boolean doThrow = false;
84
85 public static Object $noinline$HiddenNull() {
86 if (doThrow) { throw new Error(); }
87 return null;
88 }
David Brazdil6de19382016-01-08 17:37:10 +000089}