ListCodeSize.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package gnu.bytecode;
  2. import java.io.*;
  3. /** Application that lists the number of bytes in named methods.
  4. * Useful for regression testing of code generation and inlining.
  5. */
  6. public class ListCodeSize
  7. {
  8. public static void usage()
  9. {
  10. System.err.println("Usage: class methodname ...");
  11. System.exit(-1);
  12. }
  13. static void print (Method method)
  14. {
  15. System.out.print(method);
  16. CodeAttr code = method.getCode();
  17. if (code == null)
  18. System.out.print(": no code");
  19. else
  20. {
  21. System.out.print(": ");
  22. System.out.print(code.getPC());
  23. System.out.print(" bytes");
  24. }
  25. System.out.println();
  26. }
  27. public static final void main (String[] args)
  28. {
  29. if (args.length == 0)
  30. usage();
  31. String filename = args[0];
  32. try
  33. {
  34. java.io.InputStream inp = new FileInputStream(filename);
  35. ClassType ctype = new ClassType();
  36. new ClassFileInput(ctype, inp);
  37. if (args.length == 1)
  38. {
  39. for (Method method = ctype.getMethods(); method != null;
  40. method = method.getNext())
  41. {
  42. print(method);
  43. }
  44. }
  45. else
  46. {
  47. for (int i = 1; i < args.length; i++)
  48. {
  49. for (Method method = ctype.getMethods(); method != null;
  50. method = method.getNext())
  51. {
  52. StringBuffer sbuf = new StringBuffer();
  53. sbuf.append(method.getName());
  54. method.listParameters(sbuf);
  55. sbuf.append(method.getReturnType().getName());
  56. String xname = sbuf.toString();
  57. String pat = args[i];
  58. if (xname.startsWith(pat)
  59. && (xname.indexOf("$check(") < 0
  60. || pat.endsWith("$check")))
  61. print(method);
  62. }
  63. }
  64. }
  65. }
  66. catch (java.io.FileNotFoundException e)
  67. {
  68. System.err.println("File "+filename+" not found");
  69. System.exit(-1);
  70. }
  71. catch (java.io.IOException e)
  72. {
  73. System.err.println(e);
  74. e.printStackTrace();
  75. System.exit(-1);
  76. }
  77. }
  78. }