Java Reference
In-Depth Information
10:dup
11:invokespecial #28;//Methodjava/lang/StringBuilder."<init>":()V
14:getstatic #19;//Fieldn:I
17:invokevirtual #32;//Methodjava/lang/StringBuilder.append:
(I)Ljava/lang/StringBuilder;
20:ldc #34;//String!=
22:invokevirtual #37;//Methodjava/lang/StringBuilder.append:
(Ljava/lang/String;)Ljava/lang/StringBuilder;
25:iload_1
26:invokestatic#13;//Methodfactorial:(I)I
29:invokevirtual #32;//Methodjava/lang/StringBuilder.append:
(I)Ljava/lang/StringBuilder;
32:invokevirtual #41;//Methodjava/lang/StringBuilder.toString:
()Ljava/lang/String;
35:invokevirtual #47;//Methodjava/io/PrintStream.println:
(Ljava/lang/String;)V
38:return
publicstatic{};
Code:
Stack=2,Locals=0,Args_size=0
0:iconst_5
1:putstatic#19;//Fieldn:I
4:return
}
We have removed the constant pool, but the comments contain the constants that the
program refers to. Notice the last method, static . That implements what is known as the
static block, where class initializations can go. Here, the static field n is initialized to 5. The
method that does this in the JVM code is <clinit> (for class initialization).
The following sections address the task of generating code for various j-- constructs.
5.2 Generating Code for Classes and Their Members
JCompilationUnit 's codegen() drives the generation of code for classes. For each type
(that is, class) declaration, it
Invokes codegen() on the JClassDeclaration for generating the code for that class,
Writes out the class to a class file in the destination directory, and
Adds the in-memory representation of the class to a list that stores such representa-
tions for all the classes within a compilation unit; this list is used in translating JVM
byte code to native (SPIM) code, in Chapter 6.
publicvoidcodegen(CLEmitteroutput){
for(JASTtypeDeclaration:typeDeclarations){
typeDeclaration.codegen(output);
output.write();
clFiles.add(output.clFile());
}
}
 
Search WWH ::




Custom Search