blob: e0bfa7d5b14a5df94d15a5f430f9f8f49e03b0df [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 }
60
61 {
62 c.getMethod("catchNewInstance").invoke(null, (Object[]) null);
63 }
64 }
65}