Path: blob/master/test/hotspot/jtreg/compiler/calls/common/InvokeDynamic.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.calls.common;2425import java.lang.invoke.CallSite;26import java.lang.invoke.ConstantCallSite;27import java.lang.invoke.MethodHandles;28import java.lang.invoke.MethodType;2930/**31* A test class checking InvokeDynamic instruction.32* This is not quite "ready-to-use" class, since javac can't generate indy33* directly(only as part of lambda init) so, this class bytecode should be34* patched with method "caller" which uses indy. Other methods can be written in35* java for easier support and readability.36*/3738public class InvokeDynamic extends CallsBase {39private static final Object LOCK = new Object();4041public static void main(String args[]) {42new InvokeDynamic().runTest(args);43}4445/**46* Caller method to call "callee" method. Must be overwritten with InvokeDynamicPatcher47*/48@Override49public void caller() {50}5152/**53* A bootstrap method for invokedynamic54* @param lookup a lookup object55* @param methodName methodName56* @param type method type57* @return CallSite for method58*/59public static CallSite bootstrapMethod(MethodHandles.Lookup lookup,60String methodName, MethodType type) throws IllegalAccessException,61NoSuchMethodException {62MethodType mtype = MethodType.methodType(boolean.class,63new Class<?>[]{int.class, long.class, float.class,64double.class, String.class});65return new ConstantCallSite(lookup.findVirtual(lookup.lookupClass(),66methodName, mtype));67}6869/**70* A callee method, assumed to be called by "caller"71*/72public boolean callee(int param1, long param2, float param3, double param4,73String param5) {74calleeVisited = true;75CallsBase.checkValues(param1, param2, param3, param4, param5);76return true;77}7879/**80* A native callee method, assumed to be called by "caller"81*/82public native boolean calleeNative(int param1, long param2, float param3,83double param4, String param5);8485/**86* Returns object to lock execution on87* @return lock object88*/89@Override90protected Object getLockObject() {91return LOCK;92}9394@Override95protected void callerNative() {96throw new Error("No native call for invokedynamic");97}98}99100101