From d72870bfb6b09927e10944bdd129ce18dfcf7366 Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 31 Aug 2011 10:29:34 +0000 Subject: JvstTest test case. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@589 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/test/javassist/ClassPoolBench.java | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/javassist/ClassPoolBench.java (limited to 'src/test/javassist/ClassPoolBench.java') diff --git a/src/test/javassist/ClassPoolBench.java b/src/test/javassist/ClassPoolBench.java new file mode 100644 index 00000000..d3cb6b2d --- /dev/null +++ b/src/test/javassist/ClassPoolBench.java @@ -0,0 +1,57 @@ +package javassist; + +import java.util.Enumeration; +import java.util.zip.*; + +public class ClassPoolBench { + static ClassPool cp; + static boolean mod = false, detach = false, readonly = false; + + public static void accessClass(String name) throws Exception { + CtClass cc = cp.get(name); + System.out.println(cc.getName()); + cc.getSuperclass(); + if (mod) + cc.getClassFile(); + + if (detach) + cc.stopPruning(true); + + if (!readonly) + cc.toBytecode(); + + if (detach) + cc.detach(); + } + + public static void accessAll(String filename) throws Exception { + ZipFile zip = new ZipFile(filename); + Enumeration files = zip.entries(); + while (files.hasMoreElements()) { + ZipEntry z = (ZipEntry)files.nextElement(); + String name = z.getName(); + if (name.endsWith(".class")) { + name = name.substring(0, name.length() - 6) + .replace('/', '.'); + accessClass(name); + } + } + + zip.close(); + } + + public static void main(String[] args) throws Exception { + cp = ClassPool.getDefault(); + cp.appendClassPath(args[0]); + if (args[1].equals("true")) + mod = true; + else if (args[1].equals("detach")) + mod = detach = true; + else if (args[1].equals("read")) + readonly = true; + + System.err.println("mod: " + mod + " detach: " + detach + + " readonly: " + readonly); + accessAll(args[0]); + } +} -- cgit v1.2.3