本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitVarInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitVarInsn方法的具体用法?Java MethodVisitor.visitVarInsn怎么用?Java MethodVisitor.visitVarInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitVarInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectRender
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void createObjectRender(ClassWriter cw, String className, String classDesc, Type data) {
Label start = new Label();
Label end = new Label();
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "render",
Type.getMethodDescriptor(BytecodeGenerator.STRING, BytecodeGenerator.OBJECT), null, null);
mv.visitCode();
mv.visitLabel(start);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, data.getInternalName());
mv.visitMethodInsn(INVOKEVIRTUAL, className, "render", Type.getMethodDescriptor(BytecodeGenerator.STRING, data), false);
mv.visitInsn(ARETURN);
mv.visitLabel(end);
mv.visitLocalVariable("this", classDesc, null, start, end, 0);
//mv.visitLocalVariable("obj", data.getDescriptor(), null, start, end, 1);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
示例2: addSetProperty
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void addSetProperty() {
MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "setProperty", RETURN_VOID_FROM_STRING_OBJECT, null, null);
methodVisitor.visitCode();
// this.getMetaClass()
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "getMetaClass", RETURN_META_CLASS, false);
// setProperty(this, name, value)
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, META_CLASS_TYPE.getInternalName(), "setProperty", RETURN_VOID_FROM_OBJECT_STRING_OBJECT, true);
methodVisitor.visitInsn(Opcodes.RETURN);
methodVisitor.visitMaxs(4, 3);
methodVisitor.visitEnd();
}
示例3: generateDefaultTraceAfter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateDefaultTraceAfter(InterceptedCall call, MethodVisitor mv, int mcvar, Type retType, MethodInfo minfo) {
if (retType.getSort() == Type.VOID) {
// Do nothing
} else if (retType.getSort() == Type.ARRAY || retType.getSort() == Type.OBJECT) {
mv.visitVarInsn(ALOAD, mcvar);
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValue", "(Ljava/lang/Object;" + MethodCall_Desc + ")Ljava/lang/Object;", false);
if (!"java/lang/Object".equals(retType.getInternalName()))
mv.visitTypeInsn(CHECKCAST, retType.getInternalName());
} else {
mv.visitVarInsn(ALOAD, mcvar);
String returnNativeType = minfo.returnNativeType;
if ("GLenum".equals(returnNativeType) || "GLboolean".equals(returnNativeType)) {
loadGLenumReturn(call.glName, "glEnumReturn", mv);
} else if ("GLFWwindow *".equals(returnNativeType)) {
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValueGlfwWindow", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
} else if ("GLFWmonitor *".equals(returnNativeType)) {
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValueGlfwMonitor", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
} else {
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValue", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
}
}
mv.visitVarInsn(ALOAD, mcvar);
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "methodCall", "(Lorg/lwjglx/debug/MethodCall;)V", false);
}
示例4: createBooleanObj
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createBooleanObj(MethodVisitor mv, int argsPostion) {
mv.visitTypeInsn(Opcodes.NEW, "java/lang/Byte");
mv.visitInsn(Opcodes.DUP);
mv.visitVarInsn(Opcodes.ILOAD, argsPostion);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Byte", "<init>", "(B)V");
mv.visitInsn(Opcodes.AASTORE);
}
示例5: generateParametersGetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateParametersGetter(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "parameters", "()Ljava/util/List;", "()Ljava/util/List<Ljava/lang/reflect/Parameter;>;", null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例6: createConstructor
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void createConstructor(ClassWriter cw, String classDesc) {
Label start = new Label();
Label end = new Label();
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitLabel(start);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, BytecodeGenerator.OBJECT.getInternalName(), "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitLabel(end);
mv.visitLocalVariable("this", classDesc, null, start, end, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例7: createIntegerObj
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createIntegerObj(MethodVisitor mv, int argsPostion) {
mv.visitTypeInsn(Opcodes.NEW, "java/lang/Integer");
mv.visitInsn(Opcodes.DUP);
mv.visitVarInsn(Opcodes.ILOAD, argsPostion);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Integer", "<init>", "(I)V");
mv.visitInsn(Opcodes.AASTORE);
}
示例8: apply
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void apply(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "updateToDB", "(Lcom/lhh/lkdb/ILKDBModel;Ljava/lang/Object;)Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
示例9: loadArguments
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void loadArguments(MethodVisitor mv, Type[] paramTypes) {
int var = 0;
for (int i = 0; i < paramTypes.length; i++) {
Type paramType = paramTypes[i];
mv.visitVarInsn(paramType.getOpcode(ILOAD), var);
var += paramType.getSize();
}
}
示例10: accept
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
mv.visitVarInsn(opcode, var);
acceptAnnotations(mv);
}
示例11: buildClosureClass
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void buildClosureClass(TContext closure_ctx) throws CompileException {
Debug.assertion(closure_ctx instanceof TContextClosure, "closure_ctx should be closure ctx");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
((TContextClosure) closure_ctx).setClassWriter(cw);
cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, closure_ctx.getName(), null, "java/lang/Object", null);
// default constructor
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
LOG.info("ALOAD 0 for this");
LOG.info("INVOKESPECIAL java/lang/Object");
mv.visitVarInsn(Opcodes.ALOAD, 0); // this
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
if (Debug.enable_compile_debug_print) {
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn(closure_ctx.getName() + " was instantiated");
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
}
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
// end default constructor
TContext parent_ctx = (TContext) closure_ctx.getOwnerType();
Debug.assertion(parent_ctx != null, "parent_ctx should be valid");
// add closure class member field
Container var_cont = null;
AbsType var_type = null;
LinkedList<Container> var_list = closure_ctx.get_childvar_list();
int var_size = var_list.size();
Container closure_member_var = null;
for (int i = 0; i < var_size; i++) {
closure_member_var = var_list.get(i);
var_cont = closure_member_var.getClosureOrgFuncvarContainer();
Debug.assertion(var_cont != null, "var_cont should be valid");
// Debug.assertion(var_cont.isForm(Container.FORM_FUNSTACK_VAR), "var_cont
// should be stack variable");
Debug.assertion(var_cont.isTypeInitialized(), "var_cont type should be initialized");
if (var_cont.isForm(Container.FORM_FUNSTACK_VAR)) {
// only assigned stack variable will be copied
if (var_cont.isAssigned()) {
LOG.debug(" (" + var_cont.getContextVarIdx() + ") " + var_cont);
var_type = var_cont.getType();
cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
}
} else if (var_cont.isForm(Container.FORM_OBJMEMBER_VAR)) {
LOG.debug(" (" + var_cont.getContextVarIdx() + ") " + var_cont);
var_type = var_cont.getType();
cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
} else {
throw new CompileException("Invalid var_cont form(" + var_cont + ")");
}
}
}
示例12: makeClazz
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static byte[] makeClazz() {
// Code generated the class below using asm.
String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/');
final ClassWriter w = new ClassWriter(0);
w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC,
"t/TestJSR", null, "java/lang/Object",
new String[]{"java/lang/Runnable"});
MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[]{});
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(10, 10);
mv.visitEnd();
mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null);
mv.visitCode();
mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
Label l1 = new Label();
mv.visitJumpInsn(Opcodes.JSR, l1);
mv.visitInsn(Opcodes.RETURN);
mv.visitLabel(l1);
mv.visitVarInsn(Opcodes.ASTORE, 1);
Label lElse = new Label();
Label lEnd = new Label();
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false);
mv.visitInsn(Opcodes.POP2);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
mv.visitInsn(Opcodes.DUP);
mv.visitJumpInsn(Opcodes.IFNULL, lElse);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false);
mv.visitJumpInsn(Opcodes.GOTO, lEnd);
mv.visitLabel(lElse);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false);
mv.visitLabel(lEnd);
mv.visitVarInsn(Opcodes.RET, 1);
mv.visitMaxs(10, 10);
mv.visitEnd();
return w.toByteArray();
}
示例13: putMethodArgumentOnStack
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void putMethodArgumentOnStack(MethodVisitor methodVisitor, Type type, int index) {
methodVisitor.visitVarInsn(type.getOpcode(ILOAD), index);
}
示例14: putThisOnStack
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
protected void putThisOnStack(MethodVisitor methodVisitor) {
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
}
示例15: insertGetObject
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static private void insertGetObject(ClassWriter cw, String classNameInternal, ArrayList<Field> fields) {
int maxStack = 6;
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(Ljava/lang/Object;I)Ljava/lang/Object;", null, null);
mv.visitCode();
mv.visitVarInsn(ILOAD, 2);
if (!fields.isEmpty()) {
maxStack--;
Label[] labels = new Label[fields.size()];
for (int i = 0, n = labels.length; i < n; i++)
labels[i] = new Label();
Label defaultLabel = new Label();
mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);
for (int i = 0, n = labels.length; i < n; i++) {
Field field = fields.get(i);
mv.visitLabel(labels[i]);
mv.visitFrame(F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, classNameInternal);
mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), Type.getDescriptor(field.getType()));
Type fieldType = Type.getType(field.getType());
switch (fieldType.getSort()) {
case Type.BOOLEAN:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
break;
case Type.BYTE:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
break;
case Type.CHAR:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
break;
case Type.SHORT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
break;
case Type.INT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
break;
case Type.FLOAT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
break;
case Type.LONG:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
break;
case Type.DOUBLE:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
break;
}
mv.visitInsn(ARETURN);
}
mv.visitLabel(defaultLabel);
mv.visitFrame(F_SAME, 0, null, 0, null);
}
insertThrowExceptionForFieldNotFound(mv);
mv.visitMaxs(maxStack, 3);
mv.visitEnd();
}