本文整理汇总了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;
}
}
示例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;
}
示例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;
}
示例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\")");
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}