本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.endMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.endMethod方法的具體用法?Java GeneratorAdapter.endMethod怎麽用?Java GeneratorAdapter.endMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.objectweb.asm.commons.GeneratorAdapter
的用法示例。
在下文中一共展示了GeneratorAdapter.endMethod方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitEnd
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void visitEnd() {
if (!done && found) {
done = true;
try {
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this);
Label start = mg.mark();
mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME)));
mg.returnValue();
Label end = mg.mark();
mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
mg.returnValue();
mg.endMethod();
} catch (NoSuchMethodException nsme) {
System.err.println("Unable to find Agent.rlogCallChain method");
System.err.println("M:"+nsme);
nsme.printStackTrace();
}
}
super.visitEnd();
}
示例2: visitEnd
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void visitEnd() {
if (!foundClinit && instrument()) {
// didn't find <clinit> so lets make one
try {
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this);
Label start = mg.mark();
mg.push(className);
mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class)));
Label end = mg.mark();
mg.returnValue();
mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
mg.returnValue();
mg.endMethod();
} catch (NoSuchMethodException nsme) {
System.out.println("Unable to find Agent.reportClass method");
}
}
super.visitEnd();
}
示例3: emitMethods
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
protected void emitMethods(ClassVisitor cv){
//override of invoke/doInvoke for each method
for(ISeq s = RT.seq(methods); s != null; s = s.next())
{
ObjMethod method = (ObjMethod) s.first();
method.emit(this, cv);
}
if(isVariadic())
{
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
Method.getMethod("int getRequiredArity()"),
null,
null,
cv);
gen.visitCode();
gen.push(variadicMethod.reqParms.count());
gen.returnValue();
gen.endMethod();
}
}
示例4: generateFailedMethod
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null -> fail")
static void generateFailedMethod(ClassVisitor cv, Method interfaceMethod, String errorMessage) {
String methodName = interfaceMethod.getName();
String methodDescriptor = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDescriptor);
adapter.visitCode();
/* Throw exception */
adapter.throwException(Type.getType(RuntimeException.class), errorMessage);
/* End method generation */
adapter.endMethod();
}
示例5: doEmit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void doEmit(ObjExpr fn, ClassVisitor cv){
Method m = new Method(getMethodName(), getReturnType(), getArgTypes());
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
m,
null,
//todo don't hardwire this
EXCEPTION_TYPES,
cv);
gen.visitCode();
Label loopLabel = gen.mark();
gen.visitLineNumber(line, loopLabel);
try
{
Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));
body.emit(C.RETURN, fn, gen);
Label end = gen.mark();
gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
{
LocalBinding lb = (LocalBinding) lbs.first();
gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
}
}
finally
{
Var.popThreadBindings();
}
gen.returnValue();
//gen.visitMaxs(1, 1);
gen.endMethod();
}
示例6: emit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emit(ObjExpr fn, ClassVisitor cv){
Method m = new Method(getMethodName(), getReturnType(), getArgTypes());
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
m,
null,
//todo don't hardwire this
EXCEPTION_TYPES,
cv);
gen.visitCode();
Label loopLabel = gen.mark();
gen.visitLineNumber(line, loopLabel);
try
{
Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));
body.emit(C.RETURN, fn, gen);
Label end = gen.mark();
gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
{
LocalBinding lb = (LocalBinding) lbs.first();
gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
}
}
finally
{
Var.popThreadBindings();
}
gen.returnValue();
//gen.visitMaxs(1, 1);
gen.endMethod();
}
示例7: generateMethodProxy
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, null, null, _, _ -> fail")
static void generateMethodProxy(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type interfaceClass,
String targetMethodName, Type[] targetParameters, Type targetReturnType,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
/* Load method parameters into stack */
loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor (invokeExact is polymorphic) */
String mhDescriptor = convertDesc(targetParameters,
((flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetReturnType : OBJECT),
(flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT) : null);
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
/* Figure out what opcode to use */
int opCode = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ?
((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEINTERFACE : INVOKESTATIC)
:
((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEVIRTUAL : INVOKESTATIC);
/* Build descriptor & select target class */
String targetDescriptor = convertDesc(targetParameters, targetReturnType, null);
String targetName = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ? interfaceClass.getInternalName() : targetClass.getInternalName();
/* Invoke method */
adapter.visitMethodInsn(opCode, targetName, targetMethodName, targetDescriptor, (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0);
}
/* Return */
handleReturn(adapter, interfaceMethod, targetReturnType);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例8: generateConstructorProxy
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, _, _ -> fail")
static void generateConstructorProxy(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass,
Type[] targetParameters,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
String targetClassName = targetClass.getInternalName();
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) == 0) {
adapter.visitTypeInsn(NEW, targetClassName);
adapter.visitInsn(DUP);
}
/* Load method parameters into stack */
loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.RETURN_TYPE_PUBLIC) != 0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = convertDesc(targetParameters,
(flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT, null);
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
/* Build target descriptor */
String targetDesc = convertDesc(targetParameters, Type.VOID_TYPE, null);
/* Invoke constructor */
adapter.visitMethodInsn(INVOKESPECIAL, targetClassName, "<init>", targetDesc, false);
}
/* Return */
handleReturn(adapter, interfaceMethod, (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例9: generateFieldReadMethod
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldReadMethod(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = newDescriptor()
.accepts((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor() : "")
.returns(fieldType.getDescriptor())
.toString();
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
adapter.getField(targetClass, fieldName, fieldType);
else
adapter.getStatic(targetClass, fieldName, fieldType);
}
/* Return */
handleReturn(adapter, interfaceMethod, fieldType);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例10: generateFieldWriteMethod
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldWriteMethod(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
/* Load method parameter into stack */
adapter.loadArg(0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = newDescriptor()
.accepts(((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ?
((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor(): "")
+ fieldType.getDescriptor())
.toString();
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
adapter.putField(targetClass, fieldName, fieldType);
else
adapter.putStatic(targetClass, fieldName, fieldType);
}
/* Return */
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例11: 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;
}
示例12: transform
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
@Unsafe(Unsafe.ASM_API)
public byte[] transform(String name, String transformedName, byte[] basicClass) {
String srgName = this.srgName;
if (!AlchemyEngine.isRuntimeDeobfuscationEnabled())
srgName = DeobfuscatingRemapper.instance().mapMethodName(transformedName, this.srgName, desc);
AlchemyTransformerManager.transform("<proxy>" + name + "|" + transformedName + "#" + proxyMethod.name + proxyMethod.signature
+ "\n-> " + target + "#" + srgName + desc);
ClassReader reader = new ClassReader(basicClass);
ClassWriter writer = ASMHelper.newClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
ClassNode node = new ClassNode(ASM5);
reader.accept(node, 0);
MethodNode oldMethod = null, newMethod = new MethodNode(proxyMethod.access, proxyMethod.name, proxyMethod.desc, proxyMethod.signature,
proxyMethod.exceptions.toArray(new String[proxyMethod.exceptions.size()]));
for (MethodNode method : node.methods)
if (method.name.equals(proxyMethod.name) && method.desc.equals(proxyMethod.desc)) {
oldMethod = method;
GeneratorAdapter adapter = new GeneratorAdapter(newMethod, method.access, method.name, method.desc);
Type owner = Type.getType(ASMHelper.getClassDesc(target));
Method targetMethod = new Method(srgName, desc);
switch (opcode) {
case INVOKESTATIC:
adapter.loadArgs();
adapter.invokeStatic(owner, targetMethod);
break;
case INVOKEVIRTUAL:
adapter.loadArgs();
adapter.invokeVirtual(owner, targetMethod);
break;
case INVOKESPECIAL:
adapter.invokeStatic(Type.getType(AlchemyEngine.class), new Method("lookup",
"()Ljava/lang/invoke/MethodHandles$Lookup;"));
adapter.push(srgName);
Type args[] = Type.getArgumentTypes(desc);
adapter.visitFieldInsn(GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;");
adapter.push(args.length);
adapter.newArray(Type.getType(Class.class));
for (Type arg : args) {
adapter.dup();
adapter.push(arg);
adapter.arrayStore(Type.getType(Class.class));
}
adapter.invokeStatic(Type.getType(MethodType.class), new Method("methodType",
"(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;"));
adapter.push(owner);
adapter.dupX2();
adapter.invokeVirtual(Type.getType(MethodHandles.Lookup.class), new Method("findSpecial",
"(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;"));
adapter.loadArgs();
adapter.invokeVirtual(Type.getType(MethodHandle.class), new Method("invoke", proxyMethod.desc));
break;
case INVOKEINTERFACE:
adapter.loadArgs();
adapter.invokeInterface(owner, targetMethod);
break;
default:
AlchemyRuntimeException.onException(new RuntimeException("Unsupported opcode: " + opcode));
}
adapter.returnValue();
adapter.endMethod();
break;
}
node.methods.remove(oldMethod);
node.methods.add(newMethod);
node.accept(writer);
return writer.toByteArray();
}