jdk.internal.org.objectweb.asm.MethodVisitor Java Examples

The following examples show how to use jdk.internal.org.objectweb.asm.MethodVisitor. 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: Type.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static Type dup(final MethodVisitor method, final Type type, final int depth) {
    final boolean       cat2 = type.isCategory2();

    switch (depth) {
    case 0:
        method.visitInsn(cat2 ? DUP2 : DUP);
        break;
    case 1:
        method.visitInsn(cat2 ? DUP2_X1 : DUP_X1);
        break;
    case 2:
        method.visitInsn(cat2 ? DUP2_X2 : DUP_X2);
        break;
    default:
        return null; //invalid depth
    }

    return type;
}
 
Example #2
Source File: NullVisitor.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final String[] exceptions) {
    return new MethodVisitor(Opcodes.ASM4) {
        @Override
        public AnnotationVisitor visitAnnotationDefault() {
            return new NullAnnotationVisitor();
        }

        @Override
        public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
            return new NullAnnotationVisitor();
        }
    };
}
 
Example #3
Source File: FrameNode.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Makes the given visitor visit this stack map frame.
 *
 * @param mv
 *            a method visitor.
 */
@Override
public void accept(final MethodVisitor mv) {
    switch (type) {
    case Opcodes.F_NEW:
    case Opcodes.F_FULL:
        mv.visitFrame(type, local.size(), asArray(local), stack.size(),
                asArray(stack));
        break;
    case Opcodes.F_APPEND:
        mv.visitFrame(type, local.size(), asArray(local), 0, null);
        break;
    case Opcodes.F_CHOP:
        mv.visitFrame(type, local.size(), null, 0, null);
        break;
    case Opcodes.F_SAME:
        mv.visitFrame(type, 0, null, 0, null);
        break;
    case Opcodes.F_SAME1:
        mv.visitFrame(type, 0, null, 1, asArray(stack));
        break;
    }
}
 
Example #4
Source File: TestConcreteClassWithAbstractMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] dumpT2() {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T2", null, "p1/T1", null);
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "p1/T1", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "m", "()I", null, null);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();
}
 
Example #5
Source File: LookupSwitchInsnNode.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
    acceptAnnotations(mv);
}
 
Example #6
Source File: AddressVarHandleGenerator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void addCarrierAccessor(BinderClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(ACC_FINAL, "carrier", "()Ljava/lang/Class;", null, null);
    mv.visitCode();
    mv.visitLdcInsn(cw.makeConstantPoolPatch(carrier));
    mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Class.class));
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example #7
Source File: BooleanType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type add(final MethodVisitor method, final int programPoint) {
    // Adding booleans in JavaScript is perfectly valid, they add as if false=0 and true=1
    if(programPoint == INVALID_PROGRAM_POINT) {
        method.visitInsn(IADD);
    } else {
        method.visitInvokeDynamicInsn("iadd", "(II)I", MATHBOOTSTRAP, programPoint);
    }
    return INT;
}
 
Example #8
Source File: BoundMethodHandle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void emitPushFields(String types, String className, MethodVisitor mv) {
    for (int i = 0; i < types.length(); ++i) {
        char tc = types.charAt(i);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
    }
}
 
Example #9
Source File: BoundMethodHandle.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void emitPushFields(String types, String className, MethodVisitor mv) {
    for (int i = 0; i < types.length(); ++i) {
        char tc = types.charAt(i);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
    }
}
 
Example #10
Source File: InsnList.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes the given visitor visit all of the instructions in this list.
 *
 * @param mv
 *            the method visitor that must visit the instructions.
 */
public void accept(final MethodVisitor mv) {
    AbstractInsnNode insn = first;
    while (insn != null) {
        insn.accept(mv);
        insn = insn.next;
    }
}
 
Example #11
Source File: LocalVariablesSorter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new {@link LocalVariablesSorter}.
 *
 * @param api the ASM API version implemented by this visitor. Must be one
 *        of {@link Opcodes#ASM4}.
 * @param access access flags of the adapted method.
 * @param desc the method's descriptor (see {@link Type Type}).
 * @param mv the method visitor to which this adapter delegates calls.
 */
protected LocalVariablesSorter(
    final int api,
    final int access,
    final String desc,
    final MethodVisitor mv)
{
    super(api, mv);
    Type[] args = Type.getArgumentTypes(desc);
    nextLocal = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0;
    for (int i = 0; i < args.length; i++) {
        nextLocal += args[i].getSize();
    }
    firstLocal = nextLocal;
}
 
Example #12
Source File: TestPrivateInterfaceMethodReflect.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private byte[] loadClassData(String name) throws Exception {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;
    switch (name) {
        case INTERFACE_NAME:
            cw.visit(V1_8, ACC_ABSTRACT | ACC_INTERFACE | ACC_PUBLIC, INTERFACE_NAME, null, "java/lang/Object", null);
            {
                mv = cw.visitMethod(ACC_PRIVATE, "privInstance", "()I", null, null);
                mv.visitCode();
                mv.visitLdcInsn(EXPECTED);
                mv.visitInsn(IRETURN);
                mv.visitMaxs(1, 1);
                mv.visitEnd();
            }
            break;
        case CLASS_NAME:
            cw.visit(52, ACC_SUPER | ACC_PUBLIC, CLASS_NAME, null, "java/lang/Object", new String[]{INTERFACE_NAME});
            {
                mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
                mv.visitCode();
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
                mv.visitInsn(RETURN);
                mv.visitMaxs(1, 1);
                mv.visitEnd();
            }
            break;
        default:
            break;
    }
    cw.visitEnd();

    return cw.toByteArray();
}
 
Example #13
Source File: ClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example #14
Source File: IntType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type div(final MethodVisitor method, final int programPoint) {
    if (programPoint == INVALID_PROGRAM_POINT) {
        JSType.DIV_ZERO.invoke(method);
    } else {
        method.visitInvokeDynamicInsn("idiv", "(II)I", MATHBOOTSTRAP, programPoint);
    }
    return INT;
}
 
Example #15
Source File: ClassEmitter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a new method to the class, representing a rest-of version of the
 * function node.
 *
 * @param functionNode the function node to generate a method for
 *
 * @return method emitter to use for weaving this method
 */
MethodEmitter restOfMethod(final FunctionNode functionNode) {
    methodCount++;
    methodNames.add(functionNode.getName());
    final MethodVisitor mv = cw.visitMethod(
        ACC_PUBLIC | ACC_STATIC,
        functionNode.getName(),
        Type.getMethodDescriptor(functionNode.getReturnType().getTypeClass(), RewriteException.class),
        null,
        null);

    return new MethodEmitter(this, mv, functionNode);
}
 
Example #16
Source File: IntType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type add(final MethodVisitor method, final int programPoint) {
    if(programPoint == INVALID_PROGRAM_POINT) {
        method.visitInsn(IADD);
    } else {
        method.visitInvokeDynamicInsn("iadd", "(II)I", MATHBOOTSTRAP, programPoint);
    }
    return INT;
}
 
Example #17
Source File: InsnList.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
  * Makes the given visitor visit all the instructions in this list.
  *
  * @param methodVisitor the method visitor that must visit the instructions.
  */
public void accept(final MethodVisitor methodVisitor) {
    AbstractInsnNode currentInsn = firstInsn;
    while (currentInsn != null) {
        currentInsn.accept(methodVisitor);
        currentInsn = currentInsn.nextInsn;
    }
}
 
Example #18
Source File: LongType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type add(final MethodVisitor method, final int programPoint) {
    if(programPoint == INVALID_PROGRAM_POINT) {
        method.visitInsn(LADD);
    } else {
        method.visitInvokeDynamicInsn("ladd", "(JJ)J", MATHBOOTSTRAP, programPoint);
    }
    return LONG;
}
 
Example #19
Source File: RedefineRunningMethodsWithResolutionErrors.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] loadC(boolean redefine) {
    ClassWriter cw = new ClassWriter(0);

    cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null);
    {
        MethodVisitor mv;

        mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "m", "()V", null, null);
        mv.visitCode();

        // First time we run we will:
        // 1) Cache resolution errors
        // 2) Redefine the class / method
        // 3) Try to read the resolution errors that were cached
        //
        // The redefined method will never run, throw error to be sure
        if (redefine) {
            createThrowRuntimeExceptionCode(mv, "The redefined method was called");
        } else {
            createMethodBody(mv);
        }
        mv.visitMaxs(3, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
 
Example #20
Source File: LookupSwitchInsnNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
    acceptAnnotations(mv);
}
 
Example #21
Source File: ClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example #22
Source File: MultiANewArrayInsnNode.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitMultiANewArrayInsn(desc, dims);
    acceptAnnotations(mv);
}
 
Example #23
Source File: Type.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type convert(final MethodVisitor method, final Type to) {
    throw new UnsupportedOperationException("convert => " + to);
}
 
Example #24
Source File: RemappingClassAdapter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected MethodVisitor createRemappingMethodAdapter(int access,
        String newDesc, MethodVisitor mv) {
    return new RemappingMethodAdapter(access, newDesc, mv, remapper);
}
 
Example #25
Source File: Type.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type load(final MethodVisitor method, final int slot) {
    throw new UnsupportedOperationException("load " + slot);
}
 
Example #26
Source File: ArrayType.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type load(final MethodVisitor method, final int slot) {
    assert slot != -1;
    method.visitVarInsn(ALOAD, slot);
    return this;
}
 
Example #27
Source File: IntType.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void _return(final MethodVisitor method) {
    method.visitInsn(IRETURN);
}
 
Example #28
Source File: LongType.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void store(final MethodVisitor method, final int slot) {
    assert slot != -1;
    method.visitVarInsn(LSTORE, slot);
}
 
Example #29
Source File: VarInsnNode.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitVarInsn(opcode, var);
    acceptAnnotations(mv);
}
 
Example #30
Source File: Type.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void store(final MethodVisitor method, final int slot) {
    throw new UnsupportedOperationException("store " + slot);
}