本文整理汇总了Java中org.objectweb.asm.commons.GeneratorAdapter.visitVarInsn方法的典型用法代码示例。如果您正苦于以下问题:Java GeneratorAdapter.visitVarInsn方法的具体用法?Java GeneratorAdapter.visitVarInsn怎么用?Java GeneratorAdapter.visitVarInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.commons.GeneratorAdapter
的用法示例。
在下文中一共展示了GeneratorAdapter.visitVarInsn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadVariableArray
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
/**
* Given an array on the stack, it loads it with the values of the given variables stating at
* offset.
*/
static void loadVariableArray(
GeneratorAdapter mv,
List<LocalVariable> variables, int offset) {
// we need to maintain the stack index when loading parameters from, as for long and double
// values, it uses 2 stack elements, all others use only 1 stack element.
for (int i = offset; i < variables.size(); i++) {
LocalVariable variable = variables.get(i);
// duplicate the array of objects reference, it will be used to store the value in.
mv.dup();
// index in the array of objects to store the boxed parameter.
mv.push(i);
// Pushes the appropriate local variable on the stack
mv.visitVarInsn(variable.type.getOpcode(Opcodes.ILOAD), variable.var);
// potentially box up intrinsic types.
mv.box(variable.type);
// store it in the array
mv.arrayStore(Type.getType(Object.class));
}
}
示例2: prepareMethodParameters
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
private static void prepareMethodParameters(GeneratorAdapter mv, String className, List<Type> args, Type returnType, boolean isStatic, int methodId) {
//第一个参数:new Object[]{...};,如果方法没有参数直接传入new Object[0]
if (args.size() == 0) {
mv.visitInsn(Opcodes.ICONST_0);
mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
} else {
createObjectArray(mv, args, isStatic);
}
//第二个参数:this,如果方法是static的话就直接传入null
if (isStatic) {
mv.visitInsn(Opcodes.ACONST_NULL);
} else {
mv.visitVarInsn(Opcodes.ALOAD, 0);
}
//第三个参数:changeQuickRedirect
mv.visitFieldInsn(Opcodes.GETSTATIC,
className,
REDIRECTFIELD_NAME,
REDIRECTCLASSNAME);
//第四个参数:false,标志是否为static
mv.visitInsn(isStatic ? Opcodes.ICONST_1 : Opcodes.ICONST_0);
//第五个参数:
mv.push(methodId);
//第六个参数:参数class数组
createClassArray(mv, args);
//第七个参数:返回值类型class
createReturnClass(mv, returnType);
}
示例3: emitUnboxedLocal
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
private void emitUnboxedLocal(GeneratorAdapter gen, LocalBinding lb){
int argoff = canBeDirect ?0:1;
Class primc = lb.getPrimitiveType();
if(closes.containsKey(lb))
{
gen.loadThis();
gen.getField(objtype, lb.name, Type.getType(primc));
}
else if(lb.isArg)
gen.loadArg(lb.idx-argoff);
else
gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), lb.idx);
}
示例4: emitClearLocalsOld
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
void emitClearLocalsOld(GeneratorAdapter gen){
for(int i=0;i<argLocals.count();i++)
{
LocalBinding lb = (LocalBinding) argLocals.nth(i);
if(!localsUsedInCatchFinally.contains(lb.idx) && lb.getPrimitiveType() == null)
{
gen.visitInsn(Opcodes.ACONST_NULL);
gen.storeArg(lb.idx - 1);
}
}
// for(int i = 1; i < numParams() + 1; i++)
// {
// if(!localsUsedInCatchFinally.contains(i))
// {
// gen.visitInsn(Opcodes.ACONST_NULL);
// gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
// }
// }
for(int i = numParams() + 1; i < maxLocal + 1; i++)
{
if(!localsUsedInCatchFinally.contains(i))
{
LocalBinding b = (LocalBinding) RT.get(indexlocals, i);
if(b == null || maybePrimitiveType(b.init) == null)
{
gen.visitInsn(Opcodes.ACONST_NULL);
gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
}
}
}
}
示例5: redirectLocal
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
/**
* Pushes in the stack the value that should be redirected for the given local.
*/
protected void redirectLocal(GeneratorAdapter mv, int local, Type arg) {
mv.visitVarInsn(arg.getOpcode(Opcodes.ILOAD), local);
}
示例6: restore
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
@Override
protected void restore(GeneratorAdapter mv, List<Type> args) {
// At this point, init$args has been called and the result Object is on the stack.
// The value of that Object is Object[] with exactly n + 1 elements.
// The first element is a string with the qualified name of the constructor to call.
// The remaining elements are the constructtor arguments.
// Create a new local that holds the result of init$args call.
mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
int constructorArgs = mv.newLocal(Type.getType("[Ljava/lang/Object;"));
mv.storeLocal(constructorArgs);
// Reinstate local values
mv.loadLocal(locals);
int stackIndex = 0;
for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
Type arg = args.get(arrayIndex);
// Do not restore "this"
if (arrayIndex > 0) {
// duplicates the array
mv.dup();
// index in the array of objects to restore the boxed parameter.
mv.push(arrayIndex);
// get it from the array
mv.arrayLoad(Type.getType(Object.class));
// unbox the argument
ByteCodeUtils.unbox(mv, arg);
// restore the argument
mv.visitVarInsn(arg.getOpcode(Opcodes.ISTORE), stackIndex);
}
// stack index must progress according to the parameter type we just processed.
stackIndex += arg.getSize();
}
// pops the array
mv.pop();
// Push a null for the marker parameter.
mv.loadLocal(constructorArgs);
mv.visitInsn(Opcodes.ACONST_NULL);
// Invoke the constructor
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, thisClassName, "<init>", DISPATCHING_THIS_SIGNATURE, false);
mv.goTo(end.getLabel());
}
示例7: generateMethod
import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
/**
* 生成方法
* @param cw
* @param method
* @param exceptions
* @param interfaceClazz
*/
private static ClassWriter generateMethod(ClassWriter cw,java.lang.reflect.Method method,Class<Prepared> prepared){
org.objectweb.asm.commons.Method m = new org.objectweb.asm.commons.Method(method.getName(), Type.getMethodDescriptor(method));
GeneratorAdapter mv = new GeneratorAdapter(ACC_PUBLIC, m, null, null,cw);
mv.visitLdcInsn(method.getName()); // excute的第1参数
mv.visitLdcInsn(Type.getType(method).getDescriptor()); // excute的第2参数
// excute的第3参数(是可变参数)
Parameter[] parameters = method.getParameters();
mv = setIn(mv, parameters);
// excute的第4个参数
mv.visitVarInsn(ALOAD, 0);
// 调用Prepared中的excute方法
// INVOKESTATIC
mv.visitMethodInsn(INVOKESTATIC, Type.getType(prepared).getInternalName(), "excute", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lorg/fastquery/core/Repository;)Ljava/lang/Object;", false);
// 返回值处理
String internalName = Type.getInternalName(method.getReturnType());
int sort = Type.getReturnType(method).getSort();
if( sort == 0 ) { // 如果返回值是 Void
mv.visitInsn(POP);
mv.visitInsn(RETURN);
} else if( (1 <= sort) && (sort <= 8) ) { // 如果是基本类型 [1,8]
Object[] objs = TypeUtil.getTypeInfo(Type.getReturnType(method).getDescriptor());
String type = objs[0].toString();
mv.visitTypeInsn(CHECKCAST, type);
mv.visitMethodInsn(INVOKEVIRTUAL, type, objs[1].toString(), objs[2].toString(), false);
// Integer.parseInt(objs[3].toString()) 比 Integer.valueOf(objs[3].toString()).intValue()更优.
mv.visitInsn(Integer.parseInt(objs[3].toString()));
} else { //sort==9 表述数组类型int[]或Integer[], srot=10表示包装类型
mv.visitTypeInsn(CHECKCAST, internalName);
mv.visitInsn(ARETURN);
}
// mv.visitEnd()
mv.endMethod();
return cw;
}