1 30 package org.objectweb.asm; 31 32 import java.io.InputStream ; 33 import java.lang.reflect.Modifier ; 34 35 import javassist.ClassPool; 36 import javassist.CtClass; 37 import javassist.CtField; 38 import javassist.CtMethod; 39 import javassist.bytecode.Bytecode; 40 import javassist.bytecode.CodeIterator; 41 import javassist.bytecode.MethodInfo; 42 import javassist.bytecode.Opcode; 43 44 47 public class JavassistPerfTest extends ALLPerfTest { 48 49 public static void main(final String args[]) throws Exception { 50 System.out.println("Javassist PERFORMANCES\n"); 51 new JavassistPerfTest().perfs(args); 52 } 53 54 ClassPool pool; 55 56 public JavassistPerfTest() { 57 pool = new ClassPool(null); 58 } 59 60 ALLPerfTest newInstance() { 61 return new JavassistPerfTest(); 62 } 63 64 byte[] nullAdaptClass(final InputStream is, final String name) 65 throws Exception 66 { 67 CtClass cc = pool.makeClass(is); 68 CtMethod[] ms = cc.getDeclaredMethods(); 69 for (int j = 0; j < ms.length; ++j) { 70 if (skipDebug) { 71 } 73 if (compute) { 74 } 76 } 77 return cc.toBytecode(); 78 } 79 80 byte[] counterAdaptClass(final InputStream is, final String name) 81 throws Exception 82 { 83 CtClass cc = pool.makeClass(is); 84 if (!cc.isInterface()) { 85 cc.addField(new CtField(CtClass.intType, "_counter", cc)); 86 } 87 CtMethod[] ms = cc.getDeclaredMethods(); 88 for (int j = 0; j < ms.length; ++j) { 89 CtMethod m = ms[j]; 90 int modifiers = m.getModifiers(); 91 if (!Modifier.isStatic(modifiers) 92 && !Modifier.isAbstract(modifiers) 93 && !Modifier.isNative(modifiers)) 94 { 95 if (!m.isEmpty()) { 96 MethodInfo info = m.getMethodInfo(); 97 Bytecode bc = new Bytecode(info.getConstPool(), 1, 0); 98 bc.addAload(0); 99 bc.addAload(0); 100 bc.addGetfield(cc, "_counter", "I"); 101 bc.add(Opcode.ICONST_1); 102 bc.add(Opcode.IADD); 103 bc.addPutfield(cc, "_counter", "I"); 104 CodeIterator iter = info.getCodeAttribute().iterator(); 105 iter.begin(); 106 iter.insert(bc.get()); 107 } 108 } 109 } 110 return cc.toBytecode(); 111 } 112 } 113 | Popular Tags |