/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @summary smoke test for invokedynamic instructions
* @build indify.Indify
* @compile InvokeDynamicPrintArgs.java
* indify.Indify
* --verify-specifier-count=3
* --expand-properties --classpath ${test.classes}
* --java test.java.lang.invoke.InvokeDynamicPrintArgs --check-output
* indify.Indify
* --expand-properties --classpath ${test.classes}
* --java test.java.lang.invoke.InvokeDynamicPrintArgs --security-manager
*/
public class InvokeDynamicPrintArgs {
// Hence, BSM specifier count should be 3. See "--verify-specifier-count=3" above.
closeBuf();
}
// check some constant references:
try {
// if SM is installed, must throw before this point
} catch (SecurityException ex) {
// if SM is installed, must throw to this point
}
}
}
private static void setSM() {
// Test for severe security manager interactions (7050328).
class SM extends SecurityManager {
}
if (clazz == InvokeDynamicPrintArgs.class)
}
// allow these others:
}
}
}
private static void openBuf() {
buf = new ByteArrayOutputStream();
}
private static void closeBuf() {
}
}
"Printing some argument lists, starting with a empty one:",
"[test.java.lang.invoke.InvokeDynamicPrintArgs, nothing, ()void][]",
"[test.java.lang.invoke.InvokeDynamicPrintArgs, bar, (String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar arg, 1]",
"[test.java.lang.invoke.InvokeDynamicPrintArgs, bar2, (String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar2 arg, 222]",
"[test.java.lang.invoke.InvokeDynamicPrintArgs, baz, (String,int,double)void, 1234.5][baz arg, 2, 3.14]",
"[test.java.lang.invoke.InvokeDynamicPrintArgs, foo, (String)void][foo arg]",
"Done printing argument lists."
};
private static boolean doPrint = true;
}
}
private static CallSite bsm(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
// ignore caller and name, but match the type:
return new ConstantCallSite(MH_printArgs().bindTo(bsmInfo).asCollector(Object[].class, type.parameterCount()).asType(type));
}
}
}
}
/* Example of a constant call site with user-data.
* In this case, the user data is exactly the BSM data.
* Note that a CCS with user data must use the "hooked" constructor
* to bind the CCS itself into the resulting target.
* A normal constructor would not allow a circular relation
* between the CCS and its target.
*/
PrintingCallSite(Lookup caller, String name, MethodType type, Object... staticArgs) throws Throwable {
super(type, MH_createTarget());
this.staticArgs = staticArgs;
}
try {
} catch (ReflectiveOperationException ex) {
throw new RuntimeException(ex);
}
}
return null;
}
return lookup().findVirtual(lookup().lookupClass(), "createTarget", methodType(MethodHandle.class));
}
}
private static CallSite bsm2(Lookup caller, String name, MethodType type, Object... arg) throws Throwable {
// ignore caller and name, but match the type:
}
}
}
"nothing", methodType(void.class)
)).dynamicInvoker();
}
)).dynamicInvoker();
}
)).dynamicInvoker();
}
)).dynamicInvoker();
}
, 1234.5
)).dynamicInvoker();
}
private static void shouldNotCallThis() {
// if this gets called, the transformation has not taken place
throw new AssertionError("this code should be statically transformed away by Indify");
}
}