1 /* 2 * Copyright (C) 2017 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.invoke.CallSite; 18 import java.lang.invoke.MethodType; 19 import java.lang.invoke.MutableCallSite; 20 21 public class Main extends TestBase { 22 TestUninitializedCallSite()23 private static void TestUninitializedCallSite() throws Throwable { 24 CallSite callSite = new MutableCallSite(MethodType.methodType(int.class)); 25 try { 26 callSite.getTarget().invoke(); 27 fail(); 28 } catch (IllegalStateException e) { 29 System.out.println("Caught exception from uninitialized call site"); 30 } 31 32 callSite = new MutableCallSite(MethodType.methodType(String.class, int.class, char.class)); 33 try { 34 callSite.getTarget().invoke(1535, 'd'); 35 fail(); 36 } catch (IllegalStateException e) { 37 System.out.println("Caught exception from uninitialized call site"); 38 } 39 } 40 TestLinkerMethodMultipleArgumentTypes()41 private static void TestLinkerMethodMultipleArgumentTypes() throws Throwable { 42 TestLinkerMethodMultipleArgumentTypes.test(33, 67); 43 TestLinkerMethodMultipleArgumentTypes.test(-10000, 1000); 44 TestLinkerMethodMultipleArgumentTypes.test(-1000, 10000); 45 } 46 TestLinkerMethodMinimalArguments()47 private static void TestLinkerMethodMinimalArguments() throws Throwable { 48 try { 49 TestLinkerMethodMinimalArguments.test( 50 TestLinkerMethodMinimalArguments.FAILURE_TYPE_LINKER_METHOD_RETURNS_NULL, 51 10, 52 10); 53 assertNotReached(); 54 } catch (BootstrapMethodError e) { 55 assertEquals(e.getCause().getClass(), ClassCastException.class); 56 } 57 58 try { 59 TestLinkerMethodMinimalArguments.test( 60 TestLinkerMethodMinimalArguments.FAILURE_TYPE_LINKER_METHOD_THROWS, 10, 11); 61 assertNotReached(); 62 } catch (BootstrapMethodError e) { 63 assertEquals(e.getCause().getClass(), InstantiationException.class); 64 } 65 66 try { 67 TestLinkerMethodMinimalArguments.test( 68 TestLinkerMethodMinimalArguments.FAILURE_TYPE_TARGET_METHOD_THROWS, 10, 12); 69 assertNotReached(); 70 } catch (ArithmeticException e) { 71 } 72 73 TestLinkerMethodMinimalArguments.test( 74 TestLinkerMethodMinimalArguments.FAILURE_TYPE_NONE, 10, 13); 75 } 76 TestInvokeCustomWithConcurrentThreads()77 private static void TestInvokeCustomWithConcurrentThreads() throws Throwable { 78 // This is a concurrency test that attempts to run invoke-custom on the same 79 // call site. 80 TestInvokeCustomWithConcurrentThreads.test(); 81 } 82 main(String[] args)83 public static void main(String[] args) throws Throwable { 84 TestUninitializedCallSite(); 85 TestLinkerMethodMinimalArguments(); 86 TestLinkerMethodMultipleArgumentTypes(); 87 TestLinkerUnrelatedBSM.test(); 88 TestInvokeCustomWithConcurrentThreads(); 89 TestInvocationKinds.test(); 90 } 91 } 92