Java Reference
In-Depth Information
Chapter5
JVMCodeGeneration
5.1 Introduction
Once the AST has been fully analyzed, all variables and expressions have been typed and
any necessary tree rewriting has been done. Also a certain amount of setup needed for code
generation has been accomplished. The compiler is now ready to traverse the AST one more
time to generate the Java Virtual Machine (JVM) code, that is, build the class file for the
program.
For example, consider the following very simple program:
publicclassSquare{
publicintsquare(intx){
returnx*x;
}
}
Compiling this with our j-- compiler,
>$j/j--/bin/j--Square.java
produces a class file, Square.class . If we run the javap program on this, that is
>javap-verboseSquare
we get the following symbolic representation of the class file:
publicclassSquareextendsjava.lang.Object
minorversion:0
majorversion:49
Constantpool:
const#1=Asciz Square;
const#2=class #1;// Square
const#3=Asciz java/lang/Object;
const#4=class #3;// java/lang/Object
const#5=Asciz <init>;
const#6=Asciz ()V;
const#7=NameAndType #5:#6;// "<init>":()V
const#8=Method #4.#7; // java/lang/Object."<init>":()V
const#9=Asciz Code;
const#10=Asciz square;
const#11=Asciz (I)I;
{
publicSquare();
Code:
Stack=1,Locals=1,Args_size=1
0:aload_0
1:invokespecial#8;//Methodjava/lang/Object."<init>":()V
4:return
171
 
Search WWH ::




Custom Search