Java Code Examples for jdk.internal.org.objectweb.asm.commons.InstructionAdapter#invokestatic()

The following examples show how to use jdk.internal.org.objectweb.asm.commons.InstructionAdapter#invokestatic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void generateOverridingConstructorWithObjectParam(final InstructionAdapter mv, final Constructor<?> ctor, final String ctorDescriptor) {
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    final Class<?>[] argTypes = ctor.getParameterTypes();
    int offset = 1; // First arg is at position 1, after this.
    for (int i = 0; i < argTypes.length; ++i) {
        final Type argType = Type.getType(argTypes[i]);
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, ctorDescriptor, false);
    mv.visitVarInsn(ALOAD, offset);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ACONST_NULL);
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_OBJECT_DESCRIPTOR, false);
    endInitMethod(mv);
}
 
Example 2
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void generateOverridingConstructorWithObjectParam(final InstructionAdapter mv, final Constructor<?> ctor, final String ctorDescriptor) {
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    final Class<?>[] argTypes = ctor.getParameterTypes();
    int offset = 1; // First arg is at position 1, after this.
    for (int i = 0; i < argTypes.length; ++i) {
        final Type argType = Type.getType(argTypes[i]);
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, ctorDescriptor, false);
    mv.visitVarInsn(ALOAD, offset);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ACONST_NULL);
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_OBJECT_DESCRIPTOR, false);
    endInitMethod(mv);
}
 
Example 3
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerOverride(final String finalizerDelegateName) {
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
            VOID_NOARG_METHOD_DESCRIPTOR, null, null));
    // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
    mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
            Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
    mv.visitVarInsn(ALOAD, 0);
    // ...and invoke it through JavaAdapterServices.invokeNoPermissions
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
            Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example 4
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void loadMethodTypeAndGetHandle(final InstructionAdapter mv, final MethodInfo mi, final String getHandleDescriptor) {
    // NOTE: we're using generic() here because we'll be linking to the "generic" invoker version of
    // the functions anyway, so we cut down on megamorphism in the invokeExact() calls in adapter
    // bodies. Once we start linking to type-specializing invokers, this should be changed.
    mv.aconst(Type.getMethodType(mi.type.generic().toMethodDescriptorString()));
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false);
}
 
Example 5
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerOverride(final String finalizerDelegateName) {
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
            VOID_NOARG_METHOD_DESCRIPTOR, null, null));
    // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
    mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
            Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
    mv.visitVarInsn(ALOAD, 0);
    // ...and invoke it through JavaAdapterServices.invokeNoPermissions
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
            Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example 6
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerOverride(final String finalizerDelegateName) {
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
            VOID_NOARG_METHOD_DESCRIPTOR, null, null));
    // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
    mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
            Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
    mv.visitVarInsn(ALOAD, 0);
    // ...and invoke it through JavaAdapterServices.invokeNoPermissions
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
            Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example 7
Source File: JavaAdapterBytecodeGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void loadMethodTypeAndGetHandle(final InstructionAdapter mv, final MethodInfo mi, final String getHandleDescriptor) {
    // NOTE: we're using generic() here because we'll be linking to the "generic" invoker version of
    // the functions anyway, so we cut down on megamorphism in the invokeExact() calls in adapter
    // bodies. Once we start linking to type-specializing invokers, this should be changed.
    mv.aconst(Type.getMethodType(mi.type.generic().toMethodDescriptorString()));
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false);
}
 
Example 8
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerOverride(final String finalizerDelegateName) {
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
            VOID_NOARG_METHOD_DESCRIPTOR, null, null));
    // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
    mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
            Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
    mv.visitVarInsn(ALOAD, 0);
    // ...and invoke it through JavaAdapterServices.invokeNoPermissions
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
            Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example 9
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void loadMethodTypeAndGetHandle(final InstructionAdapter mv, final MethodInfo mi, final String getHandleDescriptor) {
    // NOTE: we're using generic() here because we'll be linking to the "generic" invoker version of
    // the functions anyway, so we cut down on megamorphism in the invokeExact() calls in adapter
    // bodies. Once we start linking to type-specializing invokers, this should be changed.
    mv.aconst(Type.getMethodType(mi.type.generic().toMethodDescriptorString()));
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false);
}
 
Example 10
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void loadMethodTypeAndGetHandle(final InstructionAdapter mv, final MethodInfo mi, final String getHandleDescriptor) {
    // NOTE: we're using generic() here because we'll be linking to the "generic" invoker version of
    // the functions anyway, so we cut down on megamorphism in the invokeExact() calls in adapter
    // bodies. Once we start linking to type-specializing invokers, this should be changed.
    mv.aconst(Type.getMethodType(mi.type.generic().toMethodDescriptorString()));
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false);
}
 
Example 11
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeValueOf(final InstructionAdapter mv, final String boxedType, final char unboxedType) {
    mv.invokestatic("java/lang/" + boxedType, "valueOf", "(" + unboxedType + ")Ljava/lang/" + boxedType + ";", false);
}
 
Example 12
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void convertReturnValue(final InstructionAdapter mv, final Class<?> returnType, final Type asmReturnType) {
    switch(asmReturnType.getSort()) {
    case Type.VOID:
        mv.pop();
        break;
    case Type.BOOLEAN:
        JSType.TO_BOOLEAN.invoke(mv);
        break;
    case Type.BYTE:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2B);
        break;
    case Type.SHORT:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2S);
        break;
    case Type.CHAR:
        // JSType doesn't have a TO_CHAR, so we have services supply us one.
        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toCharPrimitive", TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR, false);
        break;
    case Type.INT:
        JSType.TO_INT32.invoke(mv);
        break;
    case Type.LONG:
        JSType.TO_LONG.invoke(mv);
        break;
    case Type.FLOAT:
        JSType.TO_NUMBER.invoke(mv);
        mv.visitInsn(Opcodes.D2F);
        break;
    case Type.DOUBLE:
        JSType.TO_NUMBER.invoke(mv);
        break;
    default:
        if(asmReturnType.equals(OBJECT_TYPE)) {
            // Must hide ConsString (and potentially other internal Nashorn types) from callers
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "exportReturnValue", EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR, false);
        } else if(asmReturnType.equals(STRING_TYPE)){
            // Well-known conversion to String. Not using the JSType one as we want to preserve null as null instead
            // of the string "n,u,l,l".
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toString", TO_STRING_METHOD_DESCRIPTOR, false);
        } else {
            // Invoke converter method handle for everything else. Note that we could have just added an asType or
            // filterReturnValue to the invoked handle instead, but then every instance would have the function
            // method handle wrapped in a separate converter method handle, making handle.invokeExact() megamorphic.
            if(classOverride) {
                mv.getstatic(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            } else {
                mv.visitVarInsn(ALOAD, 0);
                mv.getfield(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            }
            mv.swap();
            emitInvokeExact(mv, MethodType.methodType(returnType, Object.class));
        }
    }
}
 
Example 13
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeSetGlobal(final InstructionAdapter mv) {
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
}
 
Example 14
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeValueOf(final InstructionAdapter mv, final String boxedType, final char unboxedType) {
    mv.invokestatic("java/lang/" + boxedType, "valueOf", "(" + unboxedType + ")Ljava/lang/" + boxedType + ";", false);
}
 
Example 15
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeValueOf(final InstructionAdapter mv, final String boxedType, final char unboxedType) {
    mv.invokestatic("java/lang/" + boxedType, "valueOf", "(" + unboxedType + ")Ljava/lang/" + boxedType + ";", false);
}
 
Example 16
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void convertReturnValue(final InstructionAdapter mv, final Class<?> returnType, final Type asmReturnType) {
    switch(asmReturnType.getSort()) {
    case Type.VOID:
        mv.pop();
        break;
    case Type.BOOLEAN:
        JSType.TO_BOOLEAN.invoke(mv);
        break;
    case Type.BYTE:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2B);
        break;
    case Type.SHORT:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2S);
        break;
    case Type.CHAR:
        // JSType doesn't have a TO_CHAR, so we have services supply us one.
        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toCharPrimitive", TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR, false);
        break;
    case Type.INT:
        JSType.TO_INT32.invoke(mv);
        break;
    case Type.LONG:
        JSType.TO_LONG.invoke(mv);
        break;
    case Type.FLOAT:
        JSType.TO_NUMBER.invoke(mv);
        mv.visitInsn(Opcodes.D2F);
        break;
    case Type.DOUBLE:
        JSType.TO_NUMBER.invoke(mv);
        break;
    default:
        if(asmReturnType.equals(OBJECT_TYPE)) {
            // Must hide ConsString (and potentially other internal Nashorn types) from callers
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "exportReturnValue", EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR, false);
        } else if(asmReturnType.equals(STRING_TYPE)){
            // Well-known conversion to String. Not using the JSType one as we want to preserve null as null instead
            // of the string "n,u,l,l".
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toString", TO_STRING_METHOD_DESCRIPTOR, false);
        } else {
            // Invoke converter method handle for everything else. Note that we could have just added an asType or
            // filterReturnValue to the invoked handle instead, but then every instance would have the function
            // method handle wrapped in a separate converter method handle, making handle.invokeExact() megamorphic.
            if(classOverride) {
                mv.getstatic(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            } else {
                mv.visitVarInsn(ALOAD, 0);
                mv.getfield(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            }
            mv.swap();
            emitInvokeExact(mv, MethodType.methodType(returnType, Object.class));
        }
    }
}
 
Example 17
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeSetGlobal(final InstructionAdapter mv) {
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
}
 
Example 18
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeGetGlobal(final InstructionAdapter mv) {
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false);
}
 
Example 19
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeGetGlobal(final InstructionAdapter mv) {
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false);
}
 
Example 20
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void invokeSetGlobal(final InstructionAdapter mv) {
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
}