String s = e.getName();
if (s.endsWith(".class")) {
s = s.substring(0, s.length() - 6).replace('/', '.');
if (clazz == null || s.indexOf(clazz) != -1) {
InputStream is = zip.getInputStream(e);
classes.add(new ClassReader(is).b);
}
}
}
long[] times = new long[15];
for (int i = 0; i < times.length; ++i) {
times[i] = Long.MAX_VALUE;
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
new ClassReader(b).accept(new EmptyVisitor(), 0);
}
t = System.currentTimeMillis() - t;
times[0] = Math.min(t, times[0]);
System.out.println("Time to deserialize " + classes.size()
+ " classes = " + t + " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
new ClassReader(b).accept(cw, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[1] = Math.min(t, times[1]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes = " + t + " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassReader cr = new ClassReader(b);
ClassWriter cw = new ClassWriter(cr, 0);
cr.accept(cw, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[2] = Math.min(t, times[2]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes with copyPool = " + t + " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
ClassVisitor cv = new AddTimerAdapter(cw);
new ClassReader(b).accept(cv, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[3] = Math.min(t, times[3]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes with AddTimerAdapter = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassReader cr = new ClassReader(b);
ClassWriter cw = new ClassWriter(cr, 0);
ClassVisitor cv = new AddTimerAdapter(cw);
cr.accept(cv, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[4] = Math.min(t, times[4]);
System.out
.println("Time to deserialize and reserialize "
+ classes.size()
+ " classes with AddTimerAdapter and copyPool = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
ClassVisitor cv = new ClassAdapter(cw) {
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new RemoveGetFieldPutFieldAdapter(cv.visitMethod(
access, name, desc, signature, exceptions));
}
};
new ClassReader(b).accept(cv, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[5] = Math.min(t, times[5]);
System.out.println("Time to deserialize and reserialize "
+ classes.size()
+ " classes with RemoveGetFieldPutFieldAdapter = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassReader cr = new ClassReader(b);
ClassWriter cw = new ClassWriter(cr, 0);
ClassVisitor cv = new ClassAdapter(cw) {
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new RemoveGetFieldPutFieldAdapter(cv.visitMethod(
access, name, desc, signature, exceptions));
}
};
cr.accept(cv, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[6] = Math.min(t, times[6]);
System.out
.println("Time to deserialize and reserialize "
+ classes.size()
+ " classes with RemoveGetFieldPutFieldAdapter and copyPool = "
+ t + " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
new ClassReader(b).accept(cw, 0);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[7] = Math.min(t, times[7]);
System.out
.println("Time to deserialize and reserialize "
+ classes.size() + " classes with computeMaxs = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
int errors = 0;
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
try {
new ClassReader(b).accept(cw, 0);
} catch (Throwable e) {
++errors;
}
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[8] = Math.min(t, times[8]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes with computeFrames = " + t
+ " ms (" + errors + " errors)");
}
System.out.println();
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
new ClassReader(b).accept(new ClassNode(), 0);
}
t = System.currentTimeMillis() - t;
times[9] = Math.min(t, times[9]);
System.out.println("Time to deserialize " + classes.size()
+ " classes with tree package = " + t + " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
ClassNode cn = new ClassNode();
new ClassReader(b).accept(cn, 0);
cn.accept(cw);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[10] = Math.min(t, times[10]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes with tree package = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
ClassNode cn = new ClassNode();
new ClassReader(b).accept(cn, 0);
new AddTimerTransformer(null).transform(cn);
cn.accept(cw);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[11] = Math.min(t, times[11]);
System.out.println("Time to deserialize and reserialize "
+ classes.size() + " classes with AddTimerTransformer = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size(); ++j) {
byte[] b = (byte[]) classes.get(j);
ClassWriter cw = new ClassWriter(0);
ClassNode cn = new ClassNode();
new ClassReader(b).accept(cn, 0);
Iterator it = cn.methods.iterator();
while (it.hasNext()) {
MethodNode mn = (MethodNode) it.next();
new RemoveGetFieldPutFieldTransformer(null).transform(mn);
}
cn.accept(cw);
cw.toByteArray();
}
t = System.currentTimeMillis() - t;
times[12] = Math.min(t, times[12]);
System.out.println("Time to deserialize and reserialize "
+ classes.size()
+ " classes with RemoveGetFieldPutFieldTransformer = " + t
+ " ms");
}
for (int i = 0; i < 10; ++i) {
int errors = 0;
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size() / 10; ++j) {
byte[] b = (byte[]) classes.get(j);
ClassReader cr = new ClassReader(b);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
List methods = cn.methods;
for (int k = 0; k < methods.size(); ++k) {
MethodNode method = (MethodNode) methods.get(k);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new BasicInterpreter());
try {
a.analyze(cn.name, method);
} catch (Throwable th) {
++errors;
}
}
}
}
t = System.currentTimeMillis() - t;
times[13] = Math.min(t, times[13]);
System.out.println("Time to analyze " + classes.size() / 10
+ " classes with BasicInterpreter = " + t + " ms (" + errors
+ " errors)");
}
for (int i = 0; i < 10; ++i) {
int errors = 0;
long t = System.currentTimeMillis();
for (int j = 0; j < classes.size() / 10; ++j) {
byte[] b = (byte[]) classes.get(j);
ClassReader cr = new ClassReader(b);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
List methods = cn.methods;
for (int k = 0; k < methods.size(); ++k) {
MethodNode method = (MethodNode) methods.get(k);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());