本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitMethodInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitMethodInsn方法的具体用法?Java MethodVisitor.visitMethodInsn怎么用?Java MethodVisitor.visitMethodInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitMethodInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke_methodhandle
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public Container invoke_methodhandle(TMethodHandle mh_type) throws CompileException {
MethodVisitor mv = getClosestFunContext().getMethodVisitor();
Container loaded_obj = null;
LOG.debug("Method Handle Call : " + mh_type);
FuncSignatureDesc funcsig = mh_type.getFuncSignatureDesc();
Debug.assertion(funcsig != null, "fucsig should be valid");
LOG.info("INVOKEVIRTUAL java/lang/invoke/MethodHandle/invoke");
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", funcsig.getMthdDscStr(),
false);
AbsType rettype = funcsig.getReturnType();
Debug.assertion(rettype != null, "rettype should be valid");
loaded_obj = new Container("anonymous", Container.FORM_OPSTACK_VAR, true, false);
loaded_obj.initializeType(rettype);
return loaded_obj;
}
示例2: loadDataItem
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void loadDataItem(MethodVisitor mv, int var, Class<?> type) throws CompilerException {
if(type != TemplateData.class) {
throw new CompilerException("Can't parse a data item that is not a template data");
}
if(!vars.isEmpty()) {
// TODO
// d = new ScopedData(data, d);
mv.visitTypeInsn(NEW, SCOPED_DATA.getInternalName());
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, vars.getLast());
mv.visitVarInsn(ALOAD, var);
mv.visitMethodInsn(INVOKESPECIAL, SCOPED_DATA.getInternalName(), "<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, DATA, DATA), false);
mv.visitVarInsn(ASTORE, var);
}
vars.add(var);
}
示例3: hookMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* (none-javadoc)
*
* @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
*/
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
if ("lookup".equals(name) && desc.startsWith("(Ljava/lang/String;)")) {
return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
@Override
public void onMethodExit(int opcode) {
if (opcode == Opcodes.ARETURN) {
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/ProxyDirContextHook", "checkResourceCacheEntry",
"(Ljava/lang/Object;)V", false);
}
super.onMethodExit(opcode);
}
};
}
return mv;
}
示例4: generateUpdateMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdateMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
String argsClassInternalName,
String constDesc, Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "update", "()Lio/primeval/reflex/arguments/Arguments;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitTypeInsn(NEW, argsClassInternalName);
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
}
mv.visitMethodInsn(INVOKESPECIAL, argsClassInternalName, "<init>", constDesc, false);
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例5: insertStringGetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void insertStringGetter(MethodVisitor mv, int var, String key, boolean escaped) throws CompilerException {
Class<?> type = insertGetter(mv, var, key, true).clazz;
// String.valueOf(...)
if(type.isPrimitive()) {
mv.visitMethodInsn(INVOKESTATIC, STRING.getInternalName(), "valueOf",
Type.getMethodDescriptor(STRING, Type.getType(type)), false);
} else if(!String.class.isAssignableFrom(type)) {
mv.visitMethodInsn(INVOKESTATIC, STRING.getInternalName(), "valueOf",
Type.getMethodDescriptor(STRING, OBJECT), false);
}
// TemplateUtils.escapeString(...)
if(escaped) {
mv.visitMethodInsn(INVOKESTATIC, UTILS.getInternalName(), "escapeString",
Type.getMethodDescriptor(STRING, STRING), false);
}
}
示例6: generateClass
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static byte[] generateClass(Class<? extends TileEntity> baseClass, String className, String contentId)
{
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(baseClass), null);
// Constructor
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(contentId);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(baseClass), "<init>", "(Ljava/lang/String;)V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
return cw.toByteArray();
}
示例7: apply
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void apply(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "insertToDB", "(Lcom/lhh/lkdb/ILKDBModel;)Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例8: insertNewInstance
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static void insertNewInstance(ClassWriter cw, String classNameInternal) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newInstance", "()Ljava/lang/Object;", null, null);
mv.visitCode();
mv.visitTypeInsn(NEW, classNameInternal);
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "()V");
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
示例9: apply
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void apply(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "updateToDBWithTableName", "(Lcom/lhh/lkdb/ILKDBModel;Ljava/lang/String;Ljava/lang/Object;)Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(3, 3);
mv.visitEnd();
}
示例10: throwExceptionBecauseCalledOnItself
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void throwExceptionBecauseCalledOnItself(MethodVisitor methodVisitor) {
String exceptionInternalName = Type.getInternalName(UnsupportedOperationException.class);
methodVisitor.visitTypeInsn(NEW, exceptionInternalName);
methodVisitor.visitInsn(DUP);
putConstantOnStack(methodVisitor, "Calling setters of a managed type on itself is not allowed");
String constructorDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, STRING_TYPE);
methodVisitor.visitMethodInsn(INVOKESPECIAL, exceptionInternalName, CONSTRUCTOR_NAME, constructorDescriptor, false);
methodVisitor.visitInsn(ATHROW);
}
示例11: createDoubleObj
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createDoubleObj(MethodVisitor mv, int argsPostion) {
mv.visitTypeInsn(Opcodes.NEW, "java/lang/Double");
mv.visitInsn(Opcodes.DUP);
mv.visitVarInsn(Opcodes.DLOAD, argsPostion);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Double", "<init>", "(D)V");
mv.visitInsn(Opcodes.AASTORE);
}
示例12: apply
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void apply(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "insertWhenNotExists", "(Lcom/lhh/lkdb/ILKDBModel;)Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例13: 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 + ")");
}
}
}
示例14: insertGetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private MemberType insertGetter(MethodVisitor mv, Class<?> clazz, int var, String key, boolean basicType) {
Member[] members = findPath(clazz, key);
if(members == null || members.length == 0) {
return null;
}
mv.visitVarInsn(ALOAD, var);
for(int i = 0; i < members.length; i++) {
Member member = members[i];
boolean last = i == members.length - 1;
if(member instanceof Method) {
Method method = (Method)member;
Class<?> returnClass = method.getReturnType();
Class<?> declaringClass = method.getDeclaringClass();
Type returnType = Type.getType(returnClass);
boolean itf = declaringClass.isInterface();
mv.visitMethodInsn(itf ? INVOKEINTERFACE : INVOKEVIRTUAL, Type.getInternalName(declaringClass),
method.getName(), Type.getMethodDescriptor(returnType), itf);
if(last) {
return basicType ? new MemberType(returnClass, returnType) : new MemberType(method, returnType);
}
} else if(member instanceof Field) {
Field field = (Field)member;
Class<?> fieldClass = field.getType();
Type fieldType = Type.getType(fieldClass);
mv.visitFieldInsn(GETFIELD, Type.getInternalName(field.getDeclaringClass()),
field.getName(), fieldType.getDescriptor());
if(last) {
return basicType ? new MemberType(fieldClass, fieldType) : new MemberType(field, fieldType);
}
}
}
// The code should never reach here
return null;
}
示例15: findClass
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals(POISON_IMPL_NAME)) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, POISON_IMPL_NAME.replace('.', '/'), null, Type.getInternalName(Pill.class), null);
// constructor
MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
constructor.visitCode();
constructor.visitVarInsn(Opcodes.ALOAD, 0);
constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Pill.class), "<init>", "()V", false);
constructor.visitInsn(Opcodes.RETURN);
constructor.visitMaxs(0, 0);
constructor.visitEnd();
MethodVisitor setList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setField", "()V", null, null);
setList.visitCode();
setList.visitVarInsn(Opcodes.ALOAD, 0);
setList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
setList.visitInsn(Opcodes.DUP);
setList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
setList.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(Pill.class), "field", Type.getDescriptor(TestInterface.class));
setList.visitInsn(Opcodes.RETURN);
setList.visitMaxs(0, 0);
setList.visitEnd();
MethodVisitor setStaticList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setStaticField", "()V", null, null);
setStaticList.visitCode();
setStaticList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
setStaticList.visitInsn(Opcodes.DUP);
setStaticList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
setStaticList.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(Pill.class), "staticField", Type.getDescriptor(TestInterface.class));
setStaticList.visitInsn(Opcodes.RETURN);
setStaticList.visitMaxs(0, 0);
setStaticList.visitEnd();
MethodVisitor callMe = cw.visitMethod(Opcodes.ACC_PUBLIC, "callMe", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(CallBack.class)), null, null);
callMe.visitCode();
callMe.visitVarInsn(Opcodes.ALOAD, 1);
callMe.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
callMe.visitInsn(Opcodes.DUP);
callMe.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
callMe.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(CallBack.class), "callBack", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(TestInterface.class)), true);
callMe.visitInsn(Opcodes.IRETURN);
callMe.visitMaxs(0, 0);
callMe.visitEnd();
MethodVisitor getList = cw.visitMethod(Opcodes.ACC_PUBLIC, "get", Type.getMethodDescriptor(Type.getType(TestInterface.class)), null, null);
getList.visitCode();
getList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
getList.visitInsn(Opcodes.DUP);
getList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
getList.visitInsn(Opcodes.ARETURN);
getList.visitMaxs(0, 0);
getList.visitEnd();
cw.visitEnd();
byte[] bytes = cw.toByteArray();
return defineClass(name, bytes, 0, bytes.length);
}
return super.findClass(name);
}