Example usage for org.objectweb.asm.commons InstructionAdapter invokevirtual

List of usage examples for org.objectweb.asm.commons InstructionAdapter invokevirtual

Introduction

In this page you can find the example usage for org.objectweb.asm.commons InstructionAdapter invokevirtual.

Prototype

public void invokevirtual(final String owner, final String name, final String descriptor,
        final boolean isInterface) 

Source Link

Document

Generates the instruction to call the given virtual method.

Usage

From source file:com.gargoylesoftware.js.nashorn.internal.runtime.linker.JavaAdapterBytecodeGenerator.java

License:Open Source License

private static void invokeGetGlobalWithNullCheck(final InstructionAdapter mv) {
    invokeGetGlobal(mv);//  w w w. j  a  v  a 2  s. c o  m
    mv.dup();
    mv.invokevirtual(OBJECT_TYPE_NAME, "getClass", GET_CLASS_METHOD_DESCRIPTOR, false); // check against null Context
    mv.pop();
}

From source file:com.gargoylesoftware.js.nashorn.internal.runtime.linker.JavaAdapterBytecodeGenerator.java

License:Open Source License

private static void emitInvokeExact(final InstructionAdapter mv, final MethodType type) {
    mv.invokevirtual(METHOD_HANDLE_TYPE.getInternalName(), "invokeExact", type.toMethodDescriptorString(),
            false);/*from ww w. j ava  2  s . c  om*/
}

From source file:com.gargoylesoftware.js.nashorn.internal.runtime.linker.JavaAdapterServices.java

License:Open Source License

private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();/*ww  w  . jav  a  2s  .c  o m*/
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact",
            Type.getMethodDescriptor(Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if (name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[]) null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch (final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}