List of usage examples for org.objectweb.asm.commons Method Method
public Method(final String name, final String descriptor)
From source file:com.github.stokito.gag.instrument.info.ClassInfo.java
License:Apache License
public MethodInfo getMethod(String name, String desc) { return methods.get(new Method(name, desc)); }
From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write * instance trampoline dispatchers for mangled method names to the * implementing method.//from ww w . ja v a 2s . c om */ private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in * WriteJsoImpl, however there are enough small differences between the * semantics of the dispatches that would make a common implementation far * more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the * same, but they're kept distinct to aid in clarity should the * dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor(), false); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }
From source file:com.google.web.bindery.requestfactory.server.RequestFactoryJarExtractor.java
License:Apache License
/** * Produce a rebased method declaration, also visiting referenced types. *///w ww .j av a 2s.c o m private Method processMethod(String sourceType, String name, String desc) { Method method = new Method(name, desc); Type[] argumentTypes = method.getArgumentTypes(); for (int i = 0, j = argumentTypes.length; i < j; i++) { argumentTypes[i] = processType(sourceType, argumentTypes[i]); } method = new Method(name, processType(sourceType, method.getReturnType()), argumentTypes); return method; }
From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline * dispatchers for mangled method names to the implementing method. *///from ww w. ja va 2 s . com private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however * there are enough small differences between the semantics of the dispatches that would make * a common implementation far more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the same, but * they're kept distinct to aid in clarity should the dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor()); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
/** * To each class, add the dispatch method called by the original code that acts as a trampoline to * invoke the changed methods.//from w w w . j a v a2s. c o m * <p/> * Pseudo code: * <code> * Object access$dispatch(String name, object[] args) { * if (name.equals( * "firstMethod.(L$type;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;")) { * return firstMethod(($type)arg[0], (String)arg[1], arg[2]); * } * if (name.equals("secondMethod.(L$type;Ljava/lang/String;I;)V")) { * secondMethod(($type)arg[0], (String)arg[1], (int)arg[2]); * return; * } * ... * StringBuilder $local1 = new StringBuilder(); * $local1.append("Method not found "); * $local1.append(name); * $local1.append(" in " + visitedClassName + * "$dispatch implementation, restart the application"); * throw new $package/InstantReloadException($local1.toString()); * } * </code> */ private void addDispatchMethod() { int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_VARARGS; Method m = new Method("access$dispatch", "(I[Ljava/lang/Object;)Ljava/lang/Object;"); MethodVisitor visitor = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); final GeneratorAdapter mv = new GeneratorAdapter(access, m, visitor); if (TRACING_ENABLED) { mv.push("Redirecting "); mv.loadArg(0); trace(mv, 2); } List<MethodNode> allMethods = new ArrayList(); // if we are disabled, do not generate any dispatch, the method will throw an exception // if invoked which should never happen. if (!instantRunDisabled) { //noinspection unchecked allMethods.addAll(classNode.methods); allMethods.addAll(addedMethods); } final Map<String, MethodNode> methods = new HashMap(); for (MethodNode methodNode : allMethods) { if (methodNode.name.equals("<clinit>") || methodNode.name.equals("<init>")) { continue; } if (!isAccessCompatibleWithInstantRun(methodNode.access)) { continue; } methods.put(methodNode.name + "." + methodNode.desc, methodNode); } new IntSwitch() { @Override void visitString() { mv.visitVarInsn(Opcodes.ALOAD, 1); } @Override void visitInt() { mv.visitVarInsn(Opcodes.ILOAD, 1); } @Override void visitCase(String methodName) { MethodNode methodNode = methods.get(methodName); String name = methodNode.name; boolean isStatic = (methodNode.access & Opcodes.ACC_STATIC) != 0; String newDesc = computeOverrideMethodDesc(methodNode.desc, isStatic); if (TRACING_ENABLED) { trace(mv, "M: " + name + " P:" + newDesc); } Type[] args = Type.getArgumentTypes(newDesc); int argc = 0; for (Type t : args) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.push(argc); mv.visitInsn(Opcodes.AALOAD); ByteCodeUtils.unbox(mv, t); argc++; } mv.visitMethodInsn(Opcodes.INVOKESTATIC, visitedClassName + "$override", isStatic ? computeOverrideMethodName(name, methodNode.desc) : name, newDesc, false); Type ret = Type.getReturnType(methodNode.desc); if (ret.getSort() == Type.VOID) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.box(ret); } mv.visitInsn(Opcodes.ARETURN); } @Override void visitDefault() { writeMissingMessageWithHash(mv, visitedClassName); } }.visit(mv, methods.keySet(), visitedClassName); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
public void addSupportMethod() { int access = Opcodes.ACC_PUBLIC; Method m = new Method("isSupport", "(I)Z"); MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); mv.visitCode();/*from w w w. j ava2s . c o m*/ mv.visitVarInsn(Opcodes.ALOAD, 1); // mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); int[] hashArray = new int[fixMtds.size()]; Label[] labelArray = new Label[fixMtds.size()]; Label l0 = new Label(); Label l1 = new Label(); for (int i = 0; i < fixMtds.size(); i++) { hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i)); labelArray[i] = l0; } mv.visitLookupSwitchInsn(l1, hashArray, labelArray); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 2); mv.visitEnd(); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:com.netease.hearttouch.hthotfix.inject.HackInitMethodVisitor.java
License:MIT License
protected void onMethodExit(int opcode) { Type targetType = Type.getObjectType(HackClassName); super.invokeStatic(targetType, new Method("mock", "()V")); }
From source file:de.bodden.tamiflex.playout.transformation.AbstractTransformation.java
License:Open Source License
public ClassVisitor getClassVisitor(String name, ClassVisitor parent) { if (!name.equals(Type.getInternalName(affectedClass))) return parent; return new ClassAdapter(parent) { @Override//www.j a v a2s . co m public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { final MethodVisitor parent = super.visitMethod(access, name, desc, signature, exceptions); if (!affectedMethods.contains(new Method(name, desc))) return parent; return getMethodVisitor(parent); } }; }
From source file:de.bodden.tamiflex.playout.transformation.array.ArrayMultiNewInstanceTransformation.java
License:Open Source License
public ArrayMultiNewInstanceTransformation() { super(new Method("newInstance", "(Ljava/lang/Class;[I)Ljava/lang/Object;")); }
From source file:de.bodden.tamiflex.playout.transformation.array.ArrayNewInstanceTransformation.java
License:Open Source License
public ArrayNewInstanceTransformation() { super(new Method("newInstance", "(Ljava/lang/Class;I)Ljava/lang/Object;")); }