PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/sandmark-3.4/doc/tools.tex

https://gitlab.com/essere.lab.public/qualitas.class-corpus
LaTeX | 134 lines | 114 code | 20 blank | 0 comment | 0 complexity | 48a26a3b79bf16d8ac82c146e310a066 MD5 | raw file
  1. \section{Examining Java Classfiles}
  2. There are a number of tools that are helpful for
  3. viewing Java classfiles.
  4. \subsection{javap}
  5. {\tt javap} lists the contents of a Java classfile.
  6. It's particularly bad at displaying corrupted
  7. classfiles.
  8. Normally, we call {\tt javap} like this:
  9. \begin{verbatim}
  10. javap -c -s -verbose -l TTTApplication
  11. \end{verbatim}
  12. These are the available options:
  13. \begin{verbatim}
  14. Usage: javap <options> <classes>...
  15. where options include:
  16. -b Backward compatibility with javap in JDK 1.1
  17. -c Disassemble the code
  18. -classpath <pathlist> Specify where to find user class files
  19. -extdirs <dirs> Override location of installed extensions
  20. -help Print this usage message
  21. -J<flag> Pass <flag> directly to the runtime system
  22. -l Print line number and local variable tables
  23. -public Show only public classes and members
  24. -protected Show protected/public classes and members
  25. -package Show package/protected/public classes
  26. and members (default)
  27. -private Show all classes and members
  28. -s Print internal type signatures
  29. -bootclasspath <pathlist> Override location of class files loaded
  30. by the bootstrap class loader
  31. -verbose Print stack size, number of locals and args for methods
  32. If verifying, print reasons for failure
  33. \end{verbatim}
  34. \subsection{Jasmin}
  35. {\tt Jasmin} is a Java bytecode assembler. It reads
  36. a text file containing Java bytecode instructions and
  37. generates a classfile. It can be found here:
  38. \url{http://mrl.nyu.edu/~meyer/jasmin/about.html}.
  39. Here's is a simple class {\tt hello.j} in the {\tt Jasmin}
  40. assembler syntax:
  41. \begin{listing}{1}
  42. .class public HelloWorld
  43. .super java/lang/Object
  44. ;
  45. ; standard initializer (calls java.lang.Object's initializer)
  46. ;
  47. .method public <init>()V
  48. aload_0
  49. invokenonvirtual java/lang/Object/<init>()V
  50. return
  51. .end method
  52. ;
  53. ; main() - prints out Hello World
  54. ;
  55. .method public static main([Ljava/lang/String;)V
  56. .limit stack 2 ; up to two items can be pushed
  57. ; push System.out onto the stack
  58. getstatic java/lang/System/out Ljava/io/PrintStream;
  59. ; push a string onto the stack
  60. ldc "Hello World!"
  61. ; call the PrintStream.println() method.
  62. invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
  63. ; done
  64. return
  65. .end method
  66. \end{listing}
  67. Call {\tt Jasmin} like this:
  68. \begin{verbatim}
  69. java -classpath smextern/jasmin.jar jasmin.Main hello.j
  70. \end{verbatim}
  71. which will produce a class file {\tt HelloWorld.class}.
  72. \subsection{BCEL's Class Construction Kit}
  73. {\tt cck} is an interactive viewer and editor of Java classfiles.
  74. It is built on {\tt BCEL}. Call it like this:
  75. \begin{verbatim}
  76. java -classpath .:smextern/BCEL.jar -jar smextern/cck.jar
  77. \end{verbatim}
  78. and open a classfile from the {\tt file}-menu.
  79. \subsection{BCEL's listclass}
  80. {\tt listclass} comes with the BCEL package. It's
  81. a replacement for {\tt javap}, and very useful
  82. in cases when {\tt javap} crashes. Call it like
  83. this:
  84. \begin{verbatim}
  85. java -classpath smextern/BCEL.jar listclass -code TTTApplication
  86. \end{verbatim}
  87. The following options are available:
  88. \begin{verbatim}
  89. java listclass [-constants] [-code] [-brief] [-dependencies] \
  90. [-nocontents] [-recurse] class... [-exclude <list>]
  91. \end{verbatim}
  92. \begin{description}
  93. \item[{\tt -code}:]
  94. List byte code of methods.
  95. \item[{\tt -brief}:]
  96. List byte codes briefly
  97. \item[{\tt -constants}:]
  98. Print constants table (constant pool)
  99. \item[{\tt -recurse}:]
  100. Usually intended to be used along with
  101. \item[{\tt -dependencies:}]
  102. When this flag is set, listclass will also print i
  103. \end{description}
  104. \subsection{BCEL's JustIce}
  105. {\tt JustIce} verifies classfiles. Call it like this:
  106. \begin{verbatim}
  107. java -classpath .:smextern/BCEL.jar:smextern/JustIce.jar \
  108. org.apache.bcel.verifier.GraphicalVerifier
  109. \end{verbatim}
  110. or like this:
  111. \begin{verbatim}
  112. java -classpath .:smextern/BCEL.jar:smextern/JustIce.jar \
  113. org.apache.bcel.verifier.Verifier TTTApplication.class
  114. \end{verbatim}