1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.gcclass;
8 import java.util.zip.*;
10 import org.apache.bcel.util.*;
11 import org.apache.bcel.classfile.*;
13 // This code is hideous... it is just a quick hack
15 public class SizeCheck {
16 public static void main(String[] args) throws Exception {
18 System.err.println("Usage SizeCheck classpath class1 ... [class n]");
21 String classpath = ClassPath.SYSTEM_CLASS_PATH + File.pathSeparator + args[0];
22 Repository repo = SyntheticRepository.getInstance(new ClassPath(classpath));
24 List all= new ArrayList();
26 for(int j=1;j<args.length;j++) {
28 if(s.endsWith(".class")) s = s.substring(0,s.length()-6).replace('/','.');
29 while(s.startsWith(".")) s = s.substring(1);
30 JavaClass c = repo.loadClass(s);
31 List stuff = new ArrayList();
32 ByteArrayOutputStream baos;
33 GZIPOutputStream gzos;
36 baos = new ByteArrayOutputStream();
37 gzos = new GZIPOutputStream(baos);
38 dos = new DataOutputStream(gzos);
39 c.getConstantPool().dump(dos);
42 stuff.add(new Stuff(baos.size(),"Constant Pool"));
43 Method[] methods = c.getMethods();
44 for(int i=0;i<methods.length;i++) {
45 baos = new ByteArrayOutputStream();
46 gzos = new GZIPOutputStream(baos);
47 dos = new DataOutputStream(gzos);
50 stuff.add(new Stuff(baos.size(),methods[i].getName()));
53 stuff.add(new Stuff(total,"Total"));
54 StringBuffer sb = new StringBuffer(s + ":\n");
55 Collections.sort(stuff);
56 for(int i=0;i<stuff.size();i++) {
57 Stuff st = (Stuff) stuff.get(i);
58 sb.append("\t" + st.size + (st.size < 1000 ? "\t\t" : "\t") + st.desc + "\n");
60 all.add(new Stuff(total,sb.toString()));
63 Collections.sort(all);
64 for(int i=0;i<all.size();i++) {
65 Stuff st = (Stuff) all.get(i);
66 System.out.println(st.size + ": " + st.desc);
68 System.out.println("Total: " + alltotal);
71 public static class Stuff implements Comparable {
74 public int compareTo(Object o_) {
76 return desc.equals("Total") ? 1 : o.desc.equals("Total") ? -1 : -(size - o.size); }
77 public Stuff(int size, String desc) { this.size = size; this.desc = desc; }