Java Reference
In-Depth Information
11.3.3 Static References
/
Visitor code for Marker 6
/
procedure
visit
(StaticReferencing n )
( n . getType(), n . getName())
call emit
S
tatic
R
eference
end
The StaticReferencingAST node represents an access to a global storage name
that is not associatedwith a particular instance of any class. Languages vary in
their treatment of static names, but somemechanismis typicallypresent to help
organize such names and to encapsulate them according to their intended use.
In Java, a static name is associatedwith a class type. For example, the Java class
java.lang.System contains the static field out to facilitate program output to
a standard-output stream. The declared type of out is java.io.PrintStream.
AST
JVM Instructions
StaticReferencing
getstatic
Ljava/io/PrintStream; java/lang/System/out
System.out
n
The code generated in the box above specifies the type and name of the static
field reference. As described in Figure 10.4 on page 400, an object type in
the JVM is prefixed by L and terminated by a semicolon. In a fully qualified
class name, the package and class components are separated by a forward
slash, even though a dot is used in the source language for that purpose.
Thus, for the static field java.lang.System.out, the name is actually specified
as java/lang/System/out. Its type is denoted as Ljava/io/PrintStream;,
which is the fully qualified name of the PrintStream class.
For some VMs, and for native code generation, a static field reference is
computed more directly as the address of the reference. Exercise 2 explores
this issue in more detail.
11.3.4 Expressions
/
Visitor code for Marker 7
/
procedure
visit
(Computing n )
visit
C
hildren
( n )
28
loc ← alloc
()
n . setResultLocal( loc )
L
ocal
29
call
emit
O
peration
( n )
30
end
 
 
 
Search WWH ::




Custom Search