Java Reference
In-Depth Information
Top of Stack
Space for b
Object Pointer
Control Information
Space for a
Frame Pointer
Object Obj
Rest of Stack
Figure 12.5: Accessing Local and Member data in Java
subclasses of Object.
Of course, the converse cannot be allowed. An instance of C may not be
used where an instance of D is expected, since D's fields are not present in C.
12.2.4 Handling Multiple Scopes
Older languages like Ada, Pascal, and Algol 60, as well as currently popular
languages like Python, ML, and Scheme, allow subprogram declarations to
nest. Java and C
allow classes to nest (see Exercise 7). Subprogram nesting
can be very useful, allowing, for example, a private utility subprogram to
directly access another routine's locals and parameters. However, runtime
data structures are complicated because multiple frames, corresponding to
nested subprogramdeclarations, may need to be accessed. To see the problem,
assume that functions can nest in Java or C, and consider the following code
fragment:
int p(int a){
int q(int b){
if (b < 0)
q(-b);
else
return a+b;
}
return q(-10);
}
When q executes, it can access not only its own frame, but also that of p,in
which it is nested. If the depth of nesting is unlimited, so is the number of
frames that must bemade accessible. In practice, the level of procedure nesting
actually seen is modest, usually no greater than two or three.
Two approaches are commonly used to support access to multiple frames.
One approach generalizes the idea of dynamic links introduced earlier. Along
with a dynamic link, we will also include a static link in the frame's control
 
 
Search WWH ::




Custom Search