當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratorAdapter.loadArgs方法代碼示例

本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.loadArgs方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.loadArgs方法的具體用法?Java GeneratorAdapter.loadArgs怎麽用?Java GeneratorAdapter.loadArgs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.commons.GeneratorAdapter的用法示例。


在下文中一共展示了GeneratorAdapter.loadArgs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: emitMethods

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
protected void emitMethods(ClassVisitor cv){
	for(ISeq s = RT.seq(methods); s != null; s = s.next())
		{
		ObjMethod method = (ObjMethod) s.first();
		method.emit(this, cv);
		}
	//emit bridge methods
	for(Map.Entry<IPersistentVector,Set<Class>> e : covariants.entrySet())
		{
		java.lang.reflect.Method m = mmap.get(e.getKey());
		Class[] params = m.getParameterTypes();
		Type[] argTypes = new Type[params.length];

		for(int i = 0; i < params.length; i++)
			{
			argTypes[i] = Type.getType(params[i]);
			}

		Method target = new Method(m.getName(), Type.getType(m.getReturnType()), argTypes);

		for(Class retType : e.getValue())
			{
		        Method meth = new Method(m.getName(), Type.getType(retType), argTypes);

			GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC + ACC_BRIDGE,
	                                            meth,
	                                            null,
	                                            //todo don't hardwire this
	                                            EXCEPTION_TYPES,
	                                            cv);
			gen.visitCode();
			gen.loadThis();
			gen.loadArgs();
			gen.invokeInterface(Type.getType(m.getDeclaringClass()),target);
			gen.returnValue();
			gen.endMethod();
			}
		}
}
 
開發者ID:mrange,項目名稱:fsharpadvent2016,代碼行數:40,代碼來源:Compiler.java

示例2: 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();
}
 
開發者ID:NekoCaffeine,項目名稱:Alchemy,代碼行數:68,代碼來源:TransformerProxy.java


注:本文中的org.objectweb.asm.commons.GeneratorAdapter.loadArgs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。