01: package gnu.bytecode;
02:
03: import java.io.*;
04:
05: /** Lists the number of bytes in named methods.
06: * Useful for regression testing of code generation and inlining.
07: */
08:
09: public class ListCodeSize {
10: public static void usage() {
11: System.err.println("Usage: class methodname ...");
12: System.exit(-1);
13: }
14:
15: static void print(Method method) {
16: System.out.print(method);
17: CodeAttr code = method.getCode();
18: if (code == null)
19: System.out.print(": no code");
20: else {
21: System.out.print(": ");
22: System.out.print(code.getPC());
23: System.out.print(" bytes");
24: }
25: System.out.println();
26: }
27:
28: public static final void main(String[] args) {
29: if (args.length == 0)
30: usage();
31: String filename = args[0];
32: try {
33: java.io.InputStream inp = new FileInputStream(filename);
34:
35: ClassType ctype = new ClassType();
36: new ClassFileInput(ctype, inp);
37:
38: if (args.length == 1) {
39: for (Method method = ctype.getMethods(); method != null; method = method
40: .getNext()) {
41: print(method);
42: }
43: } else {
44: for (int i = 1; i < args.length; i++) {
45: for (Method method = ctype.getMethods(); method != null; method = method
46: .getNext()) {
47: StringBuffer sbuf = new StringBuffer();
48: sbuf.append(method.getName());
49: method.listParameters(sbuf);
50: sbuf.append(method.getReturnType().getName());
51: if (sbuf.toString().startsWith(args[i]))
52: print(method);
53: }
54: }
55: }
56: } catch (java.io.FileNotFoundException e) {
57: System.err.println("File " + filename + " not found");
58: System.exit(-1);
59: } catch (java.io.IOException e) {
60: System.err.println(e);
61: e.printStackTrace();
62: System.exit(-1);
63: }
64: }
65: }
|