jdk.internal.org.objectweb.asm.commons.InstructionAdapter Java Examples

The following examples show how to use jdk.internal.org.objectweb.asm.commons.InstructionAdapter. 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 openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void generateConverterInit(final InstructionAdapter mv, final boolean samOnly) {
    assert !samOnly || !classOverride;
    for(final Map.Entry<Class<?>, String> converterField: converterFields.entrySet()) {
        final Class<?> returnType = converterField.getKey();
        if(!classOverride) {
            mv.visitVarInsn(ALOAD, 0);
        }

        if(samOnly && !samReturnTypes.contains(returnType)) {
            mv.visitInsn(ACONST_NULL);
        } else {
            mv.aconst(Type.getType(converterField.getKey()));
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getObjectConverter", GET_CONVERTER_METHOD_DESCRIPTOR, false);
        }

        if(classOverride) {
            mv.putstatic(generatedClassName, converterField.getValue(), METHOD_HANDLE_TYPE_DESCRIPTOR);
        } else {
            mv.putfield(generatedClassName, converterField.getValue(), METHOD_HANDLE_TYPE_DESCRIPTOR);
        }
    }
}
 
Example #2
Source File: JavaAdapterBytecodeGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        // we should call default method on the immediate "super" type - not on (possibly)
        // the indirectly inherited interface class!
        mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
Example #3
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        // we should call default method on the immediate "super" type - not on (possibly)
        // the indirectly inherited interface class!
        mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
Example #4
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void generateDelegatingConstructor(final Constructor<?> ctor) {
    final Type originalCtorType = Type.getType(ctor);
    final Type[] argTypes = originalCtorType.getArgumentTypes();

    // All constructors must be public, even if in the superclass they were protected.
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC |
            (ctor.isVarArgs() ? ACC_VARARGS : 0), INIT,
            Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));

    mv.visitCode();
    // Invoke super constructor with the same arguments.
    mv.visitVarInsn(ALOAD, 0);
    int offset = 1; // First arg is at position 1, after this.
    for (final Type argType: argTypes) {
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false);

    endInitMethod(mv);
}
 
Example #5
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void generateDelegatingConstructor(final Constructor<?> ctor) {
    final Type originalCtorType = Type.getType(ctor);
    final Type[] argTypes = originalCtorType.getArgumentTypes();

    // All constructors must be public, even if in the superclass they were protected.
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
            Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));

    mv.visitCode();
    // Invoke super constructor with the same arguments.
    mv.visitVarInsn(ALOAD, 0);
    int offset = 1; // First arg is at position 1, after this.
    for (Type argType: argTypes) {
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor());

    endInitMethod(mv);
}
 
Example #6
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        // we should call default method on the immediate "super" type - not on (possibly)
        // the indirectly inherited interface class!
        mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
Example #7
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        mv.invokespecial(Type.getInternalName(owner), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
Example #8
Source File: JavaAdapterBytecodeGenerator.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private void generateDelegatingConstructor(final Constructor<?> ctor) {
    final Type originalCtorType = Type.getType(ctor);
    final Type[] argTypes = originalCtorType.getArgumentTypes();

    // All constructors must be public, even if in the superclass they were protected.
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
            Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));

    mv.visitCode();
    // Invoke super constructor with the same arguments.
    mv.visitVarInsn(ALOAD, 0);
    int offset = 1; // First arg is at position 1, after this.
    for (Type argType: argTypes) {
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor());

    endInitMethod(mv);
}
 
Example #9
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void generateDelegatingConstructor(final Constructor<?> ctor) {
    final Type originalCtorType = Type.getType(ctor);
    final Type[] argTypes = originalCtorType.getArgumentTypes();

    // All constructors must be public, even if in the superclass they were protected.
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
            Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));

    mv.visitCode();
    // Invoke super constructor with the same arguments.
    mv.visitVarInsn(ALOAD, 0);
    int offset = 1; // First arg is at position 1, after this.
    for (Type argType: argTypes) {
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor());

    endInitMethod(mv);
}
 
Example #10
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void generateDelegatingConstructor(final Constructor<?> ctor) {
    final Type originalCtorType = Type.getType(ctor);
    final Type[] argTypes = originalCtorType.getArgumentTypes();

    // All constructors must be public, even if in the superclass they were protected.
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC |
            (ctor.isVarArgs() ? ACC_VARARGS : 0), INIT,
            Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));

    mv.visitCode();
    // Invoke super constructor with the same arguments.
    mv.visitVarInsn(ALOAD, 0);
    int offset = 1; // First arg is at position 1, after this.
    for (final Type argType: argTypes) {
        mv.load(offset, argType);
        offset += argType.getSize();
    }
    mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false);

    endInitMethod(mv);
}
 
Example #11
Source File: JavaAdapterBytecodeGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void boxStackTop(final InstructionAdapter mv, final Type t) {
    switch(t.getSort()) {
    case Type.BOOLEAN:
        invokeValueOf(mv, "Boolean", 'Z');
        break;
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        // bytes and shorts get boxed as integers
        invokeValueOf(mv, "Integer", 'I');
        break;
    case Type.CHAR:
        invokeValueOf(mv, "Character", 'C');
        break;
    case Type.FLOAT:
        // floats get boxed as doubles
        mv.visitInsn(Opcodes.F2D);
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.LONG:
        invokeValueOf(mv, "Long", 'J');
        break;
    case Type.DOUBLE:
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.ARRAY:
    case Type.METHOD:
        // Already boxed
        break;
    case Type.OBJECT:
        if(t.equals(OBJECT_TYPE)) {
            mv.invokestatic(SCRIPTUTILS_TYPE_NAME, "unwrap", UNWRAP_METHOD_DESCRIPTOR, false);
        }
        break;
    default:
        // Not expecting anything else (e.g. VOID)
        assert false;
        break;
    }
}
 
Example #12
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerDelegate(final String finalizerDelegateName) {
    // Generate a delegate that will be invoked from the no-permission trampoline. Note it can be private, as we'll
    // refer to it with a MethodHandle constant pool entry in the overridden finalize() method (see
    // generateFinalizerOverride()).
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PRIVATE | ACC_STATIC,
            finalizerDelegateName, Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE), null, null));

    // Simply invoke super.finalize()
    mv.visitVarInsn(ALOAD, 0);
    mv.checkcast(Type.getType(generatedClassName));
    mv.invokespecial(superClassName, "finalize", Type.getMethodDescriptor(Type.VOID_TYPE), false);

    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example #13
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(final MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);

    endMethod(mv);
}
 
Example #14
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 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 #15
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 #16
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 #17
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(final MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);

    endMethod(mv);
}
 
Example #18
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void emitSuperCall(final InstructionAdapter mv, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }
    mv.invokespecial(superClassName, name, methodDesc);
    mv.areturn(methodType.getReturnType());
}
 
Example #19
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8-source 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 #20
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 #21
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Emits instruction for converting a parameter on the top of the stack to
 * a type that is understood by Nashorn.
 * @param mv the current method visitor
 * @param t the type on the top of the stack
 * @param varArg if the invocation will be variable arity
 */
private static void convertParam(final InstructionAdapter mv, final Type t, final boolean varArg) {
    // We perform conversions of some primitives to accommodate types that
    // Nashorn can handle.
    switch(t.getSort()) {
    case Type.CHAR:
        // Chars are boxed, as we don't know if the JS code wants to treat
        // them as an effective "unsigned short" or as a single-char string.
        CHAR_VALUE_OF.invoke(mv);
        break;
    case Type.FLOAT:
        // Floats are widened to double.
        mv.visitInsn(Opcodes.F2D);
        if (varArg) {
            // We'll be boxing everything anyway for the vararg invocation,
            // so we might as well do it proactively here and thus not cause
            // a widening in the number of slots, as that could even make
            // the array creation invocation go over 255 param slots.
            DOUBLE_VALUE_OF.invoke(mv);
        }
        break;
    case Type.LONG:
        // Longs are boxed as Nashorn can't represent them precisely as a
        // primitive number.
        LONG_VALUE_OF.invoke(mv);
        break;
    case Type.OBJECT:
        if(t.equals(OBJECT_TYPE)) {
            // Object can carry a ScriptObjectMirror and needs to be unwrapped
            // before passing into a Nashorn function.
            UNWRAP.invoke(mv);
        }
        break;
    }
}
 
Example #22
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Emit code to restore the previous Nashorn Context when needed.
 * @param mv the instruction adapter
 * @param currentGlobalVar index of the local variable holding the reference to the current global at method
 * entry.
 * @param globalsDifferVar index of the boolean local variable that is true if the global needs to be restored.
 */
private static void emitFinally(final InstructionAdapter mv, final int currentGlobalVar, final int globalsDifferVar) {
    // Emit code to restore the previous Nashorn global if needed
    mv.visitVarInsn(ILOAD, globalsDifferVar);
    final Label skip = new Label();
    mv.ifeq(skip);
    mv.visitVarInsn(ALOAD, currentGlobalVar);
    invokeSetGlobal(mv);
    mv.visitLabel(skip);
}
 
Example #23
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(final MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);

    endMethod(mv);
}
 
Example #24
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerDelegate(final String finalizerDelegateName) {
    // Generate a delegate that will be invoked from the no-permission trampoline. Note it can be private, as we'll
    // refer to it with a MethodHandle constant pool entry in the overridden finalize() method (see
    // generateFinalizerOverride()).
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PRIVATE | ACC_STATIC,
            finalizerDelegateName, Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE), null, null));

    // Simply invoke super.finalize()
    mv.visitVarInsn(ALOAD, 0);
    mv.checkcast(Type.getType(generatedClassName));
    mv.invokespecial(superClassName, "finalize", Type.getMethodDescriptor(Type.VOID_TYPE), false);

    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example #25
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, name, methodDesc);

    endMethod(mv);
}
 
Example #26
Source File: JavaAdapterBytecodeGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, name, methodDesc);

    endMethod(mv);
}
 
Example #27
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void boxStackTop(final InstructionAdapter mv, final Type t) {
    switch(t.getSort()) {
    case Type.BOOLEAN:
        invokeValueOf(mv, "Boolean", 'Z');
        break;
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        // bytes and shorts get boxed as integers
        invokeValueOf(mv, "Integer", 'I');
        break;
    case Type.CHAR:
        invokeValueOf(mv, "Character", 'C');
        break;
    case Type.FLOAT:
        // floats get boxed as doubles
        mv.visitInsn(Opcodes.F2D);
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.LONG:
        invokeValueOf(mv, "Long", 'J');
        break;
    case Type.DOUBLE:
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.ARRAY:
    case Type.METHOD:
        // Already boxed
        break;
    case Type.OBJECT:
        if(t.equals(OBJECT_TYPE)) {
            mv.invokestatic(SCRIPTUTILS_TYPE_NAME, "unwrap", UNWRAP_METHOD_DESCRIPTOR, false);
        }
        break;
    default:
        // Not expecting anything else (e.g. VOID)
        assert false;
        break;
    }
}
 
Example #28
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerDelegate(final String finalizerDelegateName) {
    // Generate a delegate that will be invoked from the no-permission trampoline. Note it can be private, as we'll
    // refer to it with a MethodHandle constant pool entry in the overridden finalize() method (see
    // generateFinalizerOverride()).
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PRIVATE | ACC_STATIC,
            finalizerDelegateName, Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE), null, null));

    // Simply invoke super.finalize()
    mv.visitVarInsn(ALOAD, 0);
    mv.checkcast(Type.getType(generatedClassName));
    mv.invokespecial(superClassName, "finalize", Type.getMethodDescriptor(Type.VOID_TYPE), false);

    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example #29
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void generateSuperMethod(final MethodInfo mi) {
    final Method method = mi.method;

    final String methodDesc = mi.type.toMethodDescriptorString();
    final String name = mi.getName();

    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(getAccessModifiers(method),
            SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
    mv.visitCode();

    emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);

    endMethod(mv);
}
 
Example #30
Source File: JavaAdapterBytecodeGenerator.java    From openjdk-jdk8u-backup 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);
}