List of usage examples for org.objectweb.asm.commons LocalVariablesSorter LocalVariablesSorter
public LocalVariablesSorter(final int access, final String descriptor, final MethodVisitor methodVisitor)
From source file:cc.adf.metrics.agent.visitor.MetricsClassVisitor.java
@Override public MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions) {/*from www . ja v a2 s .c o m*/ //System.out.println("Visiting Method " + name); MethodVisitor mv = cv.visitMethod(access, methodName, desc, signature, exceptions); boolean isInterface = (access & ACC_INTERFACE) != 0; if (!isInterface && mv != null && (methodName.equals("passivateState") || methodName.equals("create"))) { System.out.println("Visiting Method " + methodName); System.out.println("Pre Enter MetricsMethodVisitor"); MetricsMethodVisitor newMv = new MetricsMethodVisitor(mv, this.className, methodName, desc); System.out.println("this.name = " + this.className + ", desc = " + desc); //newMv.analyzerAdapter = new AnalyzerAdapter(this.name, access, name, desc, newMv); //newMv.localVariablesSorter = new LocalVariablesSorter(access, desc, newMv.analyzerAdapter); newMv.localVariablesSorter = new LocalVariablesSorter(access, desc, newMv); return newMv.localVariablesSorter; //return newMv; } return mv; //return new MetricsMethodVisitor(access, desc, // cv.visitMethod(access, name, desc, signature, exceptions) //); }
From source file:com.github.malamut2.low.AllocationClassAdapter.java
License:Apache License
/** * For each method in the class being instrumented, <code>visitMethod</code> * is called and the returned MethodVisitor is used to visit the method. * Note that a new MethodVisitor is constructed for each method. *///from www.j a v a2 s . com @Override public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions); if (mv != null) { // We need to compute stackmaps (see // AllocationInstrumenter#instrument). This can't really be // done for old bytecode that contains JSR and RET instructions. // So, we remove JSRs and RETs. JSRInlinerAdapter jsria = new JSRInlinerAdapter(mv, access, base, desc, signature, exceptions); AllocationMethodAdapter aimv = new AllocationMethodAdapter(jsria, recorderClass, recorderMethod); LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, aimv); aimv.lvs = lvs; mv = lvs; } return mv; }
From source file:com.google.monitoring.runtime.instrumentation.adapters.AllocationClassAdapter.java
License:Apache License
/** * For each method in the class being instrumented, <code>visitMethod</code> * is called and the returned MethodVisitor is used to visit the method. * Note that a new MethodVisitor is constructed for each method. *//*from w w w.j a va 2 s.co m*/ @Override public MethodVisitor visitMethod(final int access, final String base, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions); if (mv != null) { // We need to compute stackmaps (see // AllocationInstrumenter#instrument). This can't really be // done for old bytecode that contains JSR and RET instructions. // So, we remove JSRs and RETs. final JSRInlinerAdapter jsria = new JSRInlinerAdapter(mv, access, base, desc, signature, exceptions); final AllocationMethodAdapter aimv = new AllocationMethodAdapter(jsria, recorderClass, recorderMethod); final LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, aimv); aimv.lvs = lvs; mv = lvs; } return mv; }
From source file:com.toolazydogs.maiden.agent.asm.BeginEndMethodVisitor.java
License:Apache License
public BeginEndMethodVisitor(MethodVisitor visitor, int access, String name, String desc, String signature, String[] exceptions) {//w ww . j av a2s.co m assert visitor != null; assert name != null; assert desc != null; if (LOGGER.isLoggable(Level.CONFIG)) { LOGGER.config("visitor: " + visitor); LOGGER.config("access: " + access); LOGGER.config("name: " + name); LOGGER.config("desc: " + desc); LOGGER.config("signature: " + signature); for (String exception : exceptions) LOGGER.config("exception: " + exception); } this.visitor = visitor; // this MethodNode instance is used to fill in hte gaps of frames and maxes methodNode = new MethodNode(access, name, desc, signature, exceptions); // We use this instance to keep track of local variables that may need to be created. lvs = new LocalVariablesSorter(access, desc, methodNode); }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.MethodSplitter.java
License:Open Source License
@Override public InsnList optimize(final InsnList original, final MethodNode methodNode) throws JBOPClassException { LocalVariablesSorter sorter = new LocalVariablesSorter(methodNode.access, methodNode.desc, new EmptyMethodVisitor(Opcodes.ASM5)); methodNode.accept(sorter);/*from w ww. j av a2 s. c o m*/ if (getLength(methodNode) < maxInsns) { return clean(original); } final List<Block> blocks = getBlocks(original, methodNode); final String baseName = methodNode.name; final String[] exceptions = getExceptions(methodNode); final InsnList returnList = new InsnList(); InsnList list = returnList; Block block = blocks.get(0); block.renameInsns(block.getVarMap()); final String name = baseName + "__split__part__"; final Type endType = Type.getReturnType(methodNode.desc); for (int i = 1; i < blocks.size(); ++i) { final Map<Integer, Integer> paramRenameMap = block.getVarMap(); add(list, block.getInstructions(), original); block = blocks.get(i); block.renameInsns(paramRenameMap); final String methodDescriptor = block.getDescriptor(); final String newMethodName = name + block.getBlockNumber(); final MethodNode splitMethod = new MethodNode(Opcodes.ASM5, ACCESS, newMethodName, methodDescriptor, null, exceptions); additionalMethods.add(splitMethod); list.add(new VarInsnNode(Opcodes.ALOAD, 0)); list.add(block.getPushParameters()); list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.name, splitMethod.name, methodDescriptor)); list.add(new InsnNode(endType.getOpcode(IRETURN))); sorter = new LocalVariablesSorter(splitMethod.access, splitMethod.desc, new EmptyMethodVisitor(Opcodes.ASM5)); splitMethod.accept(sorter); list = splitMethod.instructions; } add(list, block.getInstructions(), original); return returnList; }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (name.equals("<clinit>")) { hasClinit = true;//from w ww .j a va 2 s . c o m } // TODO-RS: Remove me - avoiding a race condition in ZipFileInflaterInputStream... if (name.equals("finalize")) { return null; } if (name.equals("<init>")) { // Add the implicit mirror argument desc = addMirrorParam(desc); } // toString() is a special case - it's defined in java.lang.Object, which this class must ultimately // extend, so we have to return a real String rather than a hologram. boolean isToString = name.equals("toString") && desc.equals(Type.getMethodDescriptor(getHologramType(Type.getType(String.class)))); if (isToString) { desc = Type.getMethodDescriptor(Type.getType(String.class)); } if (name.equals("equals") && desc.equals(Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Hologram.class)))) { desc = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)); } boolean isGetStackTrace = this.name.equals(hologramThrowableType.getInternalName()) && name.equals("getStackTrace") && desc.equals(Type.getMethodDescriptor(getHologramType(Type.getType(StackTraceElement[].class)))); if (isGetStackTrace) { desc = Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)); } if (name.equals("fillInStackTrace") && this.name.equals(hologramThrowableType.getInternalName())) { // Omit this - we'll use the Throwable superclass version return null; } // Take off the native keyword if it's there - we're going to fill in an actual // method (even if it's a stub that throws an exception). int hologramAccess = ~Opcodes.ACC_NATIVE & access; // Mild hack: generated method accessors are defined using ClassDefiner and Unsafe, // allowing them to make illegal access to this package-private constructor. if (this.name.equals("hologram/sun/reflect/MethodAccessorImpl") && name.equals("<init>")) { hologramAccess = forcePublic(hologramAccess); } MethodVisitor superVisitor = super.visitMethod(hologramAccess, name, desc, signature, exceptions); HologramMethodGenerator generator = new HologramMethodGenerator(this.name, hologramAccess, name, desc, superVisitor, isToString, isGetStackTrace); LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, generator); generator.setLocalVariablesSorter(lvs); boolean needsThunk = (Opcodes.ACC_NATIVE & access) != 0; if (!needsThunk && !name.startsWith("<")) { if ((Opcodes.ACC_ABSTRACT & access) == 0) { MethodMirror method; try { method = Reflection.getDeclaredMethod(classMirror, name, getOriginalType(Type.getMethodType(desc))); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } MirrorInvocationHandler handler = ClassHolograph.getMethodHandler(method); if (handler != null) { needsThunk = true; } } } if (needsThunk) { generator.generateNativeThunk(); return null; } return lvs; }
From source file:net.sourceforge.cobertura.instrument.pass3.InjectCodeClassInstrumenter.java
License:GNU General Public License
/** * <p>Instrumenting a code in a single method. Special conditions for processing 'static initialization block'.</p> * <p/>//from w w w. jav a2s . co m * <p>This method also uses {@link ShiftVariableMethodAdapter} that is used firstly to calculate the index of internal * variable injected to store information about last 'processed' jump or switch in runtime ( {@link ShiftVariableMethodAdapter#calculateFirstStackVariable(int, String)} ), * and then is used to inject code responsible for keeping the variable and shifting (+1) all previously seen variables. */ @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (ignoredMethods.contains(name + desc)) { return mv; } if ((access & Opcodes.ACC_STATIC) != 0) { mv = new GenerateCallCoberturaInitMethodVisitor(mv, classMap.getClassName()); if ("<clinit>".equals(name)) { wasStaticInitMethodVisited = true; } } FindTouchPointsMethodAdapter instrumenter = new FindTouchPointsMethodAdapter(mv, classMap.getClassName(), name, desc, eventIdGenerator, duplicatedLinesMap, lineIdGenerator); instrumenter.setTouchPointListener(touchPointListener); instrumenter.setIgnoreRegexp(getIgnoreRegexp()); LocalVariablesSorter sorter = new LocalVariablesSorter(access, desc, instrumenter); int variable = sorter.newLocal(Type.INT_TYPE); touchPointListener.setLastJumpIdVariableIndex(variable); return sorter; //return new ShiftVariableMethodAdapter(instrumenter, access, desc, 1); }
From source file:org.glassfish.pfl.tf.tools.enhancer.ClassTracer.java
License:Open Source License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String sig, final String[] exceptions) { info(2, "visitMethod: " + name + desc); // Enhance the class first (part 1). // - Modify all of the @InfoMethod methods with extra arguments // - Modify all calls to @InfoMethod methods to add the extra arguments // or to flag an error if NOT called from an MM method. final String fullDesc = util.getFullMethodDescriptor(name, desc); final EnhancedClassData.MethodType mtype = ecd.classifyMethod(fullDesc); MethodVisitor mv = super.visitMethod(access, name, desc, sig, exceptions); if (util.getDebug()) { mv = new SimpleMethodTracer(mv, util); }//w ww. ja v a 2 s . c o m switch (mtype) { case STATIC_INITIALIZER: case INFO_METHOD: case NORMAL_METHOD: return mv; case MONITORED_METHOD: final MonitoredMethodEnhancer mme = new MonitoredMethodEnhancer(access, name, desc, mv); // AnalyzerAdapter aa = new AnalyzerAdapter( ecd.getClassName(), // access, name, desc, mme ) ; final LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, mme); mme.setLocalVariablesSorter(lvs); return lvs; } return null; }
From source file:org.jtsan.Agent.java
License:Apache License
private ClassAdapter newMethodTransformAdapter(final Agent myself, ClassWriter cw, final String className, final CodePos codePos, final Set<String> volatiles) { return new ClassAdapter(cw) { private String source; private final Set<String> volatileFields = volatiles; /*// w w w . java2 s . co m * Compose a chain of visitors: * MethodTransformer -> LocalVariablesSorter -> CodeSizeLimiter -> MethodVisitor */ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); String signatureStr = (null == signature ? "" : signature); int pos = className.lastIndexOf("/"); String fullSourcePath = className.substring(0, pos + 1) + (source == null ? "" : source); String fullMethodName = className.substring(pos + 1) + "." + name + signatureStr; String fullClassName = "L" + className + ";"; CodeSizeLimiter csl = new CodeSizeLimiter(mv, name); LocalVariablesSorter sorter = new LocalVariablesSorter(access, desc, csl); MethodTransformer transformer = new MethodTransformer(myself, sorter, access, name, fullMethodName, desc, fullSourcePath, fullClassName, syncMethods, codePos, volatileFields); transformer.setLocalVarsSorter(sorter); return transformer; } @Override public void visitSource(String source, String debug) { this.source = source; } @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((access & Opcodes.ACC_VOLATILE) != 0) { volatileFields.add(className + "." + name); } return super.visitField(access, name, desc, signature, value); } }; }
From source file:org.sonar.plugins.monitor.agent.transform.OpenInterceptionAdapter.java
License:Open Source License
public OpenInterceptionAdapter(MethodVisitor base, int access, String desc) { super(null);/*from w w w .j a v a2 s . co m*/ lvs = new LocalVariablesSorter(access, desc, base); mv = lvs; this.base = base; }