当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor类代码示例

本文整理汇总了Java中jdk.internal.org.objectweb.asm.MethodVisitor的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor类的具体用法?Java MethodVisitor怎么用?Java MethodVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodVisitor类属于jdk.internal.org.objectweb.asm包,在下文中一共展示了MethodVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: accept

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:FrameNode.java

示例2: dup

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:Type.java

示例3: ldc

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public Type ldc(final MethodVisitor method, final Object c) {
    assert c instanceof Long;

    final long value = (Long) c;

    if (value == 0L) {
        method.visitInsn(LCONST_0);
    } else if (value == 1L) {
        method.visitInsn(LCONST_1);
    } else {
        method.visitLdcInsn(c);
    }

    return Type.LONG;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:LongType.java

示例4: createMethodBody

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
private static void createMethodBody(MethodVisitor mv) {
    Label classExists = new Label();

    // Cache resolution errors
    createLoadNonExistentClassCode(mv, classExists);

    // Redefine our own class and method
    mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V");

    // Provoke the same error again to make sure the resolution error cache works
    createLoadNonExistentClassCode(mv, classExists);

    // Test passed
    mv.visitInsn(RETURN);

    mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]);
    mv.visitLabel(classExists);

    createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RedefineRunningMethodsWithResolutionErrors.java

示例5: convert

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public Type convert(final MethodVisitor method, final Type to) {
    if (isEquivalentTo(to)) {
        return null;
    }

    if (to.isInteger()) {
        invokestatic(method, JSType.TO_INT32_D);
    } else if (to.isLong()) {
        invokestatic(method, JSType.TO_LONG_D);
    } else if (to.isBoolean()) {
        invokestatic(method, JSType.TO_BOOLEAN_D);
    } else if (to.isString()) {
        invokestatic(method, JSType.TO_STRING_D);
    } else if (to.isObject()) {
        invokestatic(method, VALUE_OF);
    } else {
        throw new UnsupportedOperationException("Illegal conversion " + this + " -> " + to);
    }

    return to;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:NumberType.java

示例6: createLoadNonExistentClassCode

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
    Label tryLoadBegin = new Label();
    Label tryLoadEnd = new Label();
    Label catchLoadBlock = new Label();
    mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");

    // Try to load a class that does not exist to provoke resolution errors
    mv.visitLabel(tryLoadBegin);
    mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
    mv.visitLabel(tryLoadEnd);

    // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
    mv.visitJumpInsn(GOTO, classExists);

    mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
    mv.visitLabel(catchLoadBlock);

    // Ignore the expected NoClassDefFoundError
    mv.visitInsn(POP);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RedefineRunningMethodsWithResolutionErrors.java

示例7: visitMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public final MethodVisitor visitMethod(int access, String name,
                                       String desc, String signature,
                                       String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (targetDesc.equals(desc) && targetName.equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, mv) {
            @Override
            public void visitLineNumber(int i, Label label) {
                super.visitLineNumber(i, label);
                lineNumbers.put(label, i);
            }
        };
    }
    return  mv;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CTVMUtilities.java

示例8: emitStaticInitializer

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
private void emitStaticInitializer() {
    final String className = scriptClassInfo.getJavaName();
    if (! staticInitFound) {
        // no user written <clinit> and so create one
        final MethodVisitor mv = ClassGenerator.makeStaticInitializer(this);
        mv.visitCode();
        mv.visitInsn(RETURN);
        mv.visitMaxs(Short.MAX_VALUE, 0);
        mv.visitEnd();
    }
    // Now generate $clinit$
    final MethodGenerator mi = ClassGenerator.makeStaticInitializer(this, $CLINIT$);
    ClassGenerator.emitStaticInitPrefix(mi, className, memberCount);
    if (memberCount > 0) {
        for (final MemberInfo memInfo : scriptClassInfo.getMembers()) {
            if (memInfo.isInstanceProperty() || memInfo.isInstanceFunction()) {
                ClassGenerator.linkerAddGetterSetter(mi, className, memInfo);
            } else if (memInfo.isInstanceGetter()) {
                final MemberInfo setter = scriptClassInfo.findSetter(memInfo);
                ClassGenerator.linkerAddGetterSetter(mi, className, memInfo, setter);
            }
        }
    }
    ClassGenerator.emitStaticInitSuffix(mi, className);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ScriptClassInstrumentor.java

示例9: verifyASM

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
static void verifyASM() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_8, ACC_PUBLIC, "X", null, "java/lang/Object", null);
    MethodVisitor mv = cw.visitMethod(ACC_STATIC, "foo",
            "()V", null, null);
    mv.visitMaxs(2, 1);
    mv.visitMethodInsn(INVOKESTATIC,
            "java/util/function/Function.class",
            "identity", "()Ljava/util/function/Function;", true);
    mv.visitInsn(RETURN);
    cw.visitEnd();
    byte[] carray = cw.toByteArray();
    // for debugging
    // write((new File("X.class")).toPath(), carray, CREATE, TRUNCATE_EXISTING);

    // verify using javap/classfile reader
    ClassFile cf = ClassFile.read(new ByteArrayInputStream(carray));
    int mcount = checkMethod(cf, "foo");
    if (mcount < 1) {
        throw new RuntimeException("unexpected method count, expected 1" +
                "but got " + mcount);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LambdaAsm.java

示例10: ldc

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public Type ldc(final MethodVisitor method, final Object c) {
    assert c instanceof Double;

    final double value = (Double) c;

    if (Double.doubleToLongBits(value) == 0L) { // guard against -0.0
        method.visitInsn(DCONST_0);
    } else if (value == 1.0) {
        method.visitInsn(DCONST_1);
    } else {
        method.visitLdcInsn(value);
    }

    return NUMBER;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:NumberType.java

示例11: visitMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
        String signature, String[] exceptions) {
    String newDesc = remapper.mapMethodDesc(desc);
    MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName(
            className, name, desc), newDesc, remapper.mapSignature(
            signature, false),
            exceptions == null ? null : remapper.mapTypes(exceptions));
    return mv == null ? null : createMethodRemapper(mv);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ClassRemapper.java

示例12: defineIndyBootstrapMethodClass

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
void defineIndyBootstrapMethodClass(ClassWriter cw) {
    cw.visit(52, ACC_SUPER | ACC_PUBLIC,
             BOOTSTRAP_METHOD_CLASS_NAME, null, "java/lang/Object", null);
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC,
                                      BOOTSTRAP_METHOD_NAME, BOOTSTRAP_METHOD_DESC, null, null);
    mv.visitCode();
    defineIndyBootstrapMethodBody(mv);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:BootstrapMethodErrorTest.java

示例13: div

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:IntType.java

示例14: visitMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE
            + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC
            + Opcodes.ACC_FINAL + Opcodes.ACC_SYNCHRONIZED
            + Opcodes.ACC_BRIDGE + Opcodes.ACC_VARARGS + Opcodes.ACC_NATIVE
            + Opcodes.ACC_ABSTRACT + Opcodes.ACC_STRICT
            + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    if (!"<init>".equals(name) && !"<clinit>".equals(name)) {
        CheckMethodAdapter.checkMethodIdentifier(version, name,
                "method name");
    }
    CheckMethodAdapter.checkMethodDesc(desc);
    if (signature != null) {
        checkMethodSignature(signature);
    }
    if (exceptions != null) {
        for (int i = 0; i < exceptions.length; ++i) {
            CheckMethodAdapter.checkInternalName(exceptions[i],
                    "exception name at index " + i);
        }
    }
    CheckMethodAdapter cma;
    if (checkDataFlow) {
        cma = new CheckMethodAdapter(access, name, desc, super.visitMethod(
                access, name, desc, signature, exceptions), labels);
    } else {
        cma = new CheckMethodAdapter(super.visitMethod(access, name, desc,
                signature, exceptions), labels);
    }
    cma.version = version;
    return cma;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:CheckClassAdapter.java

示例15: defineIndyBootstrapMethodBody

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入依赖的package包/类
@Override
void defineIndyBootstrapMethodBody(MethodVisitor mv) {
    // Invoke the method BootstrapMethodErrorTest.getCallSite to obtain
    // a CallSite instance whose target is different from that of
    // the indy call site
    mv.visitMethodInsn(INVOKESTATIC, "BootstrapMethodErrorTest",
                       "getCallSite", "()Ljava/lang/invoke/CallSite;", false);
    mv.visitInsn(ARETURN);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:BootstrapMethodErrorTest.java


注:本文中的jdk.internal.org.objectweb.asm.MethodVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。