David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | import java.lang.reflect.Method; |
| 18 | import java.lang.reflect.InvocationTargetException; |
| 19 | |
| 20 | public 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 Brazdil | 65902e8 | 2016-01-15 09:35:13 +0000 | [diff] [blame] | 60 | |
| 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 Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 66 | |
| 67 | { |
David Brazdil | c047d94 | 2016-01-20 17:00:19 +0000 | [diff] [blame] | 68 | 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 Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 76 | 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 Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 81 | } |
Vladimir Marko | a341f35 | 2016-08-31 12:18:20 +0100 | [diff] [blame] | 82 | |
| 83 | public static boolean doThrow = false; |
| 84 | |
| 85 | public static Object $noinline$HiddenNull() { |
| 86 | if (doThrow) { throw new Error(); } |
| 87 | return null; |
| 88 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 89 | } |