Java Reference
In-Depth Information
Space for e[2]
through e[9]
Space for d and e[1]
Space for c and e[0]
Space for b
Space for a
Control Information
Figure 12.8: An Example of a Procedure-Level Frame
links, even in Java or C, because blocks can nest. Further, execution of a block
would become a bit costly, since frames would need to be pushed and popped,
display registers or static links updated, and so forth.
To avoid this overhead, we can choose to use frames only for true sub-
programs, even if blocks within a subprogram have local declarations. This
technique is called procedure-level frame allocation , as contrastedwith block-
level frame allocation , which allocates a frame for each block that has local
declarations.
The central idea of procedure-level frame allocation is that the relative
location of variables in individual blocks within a procedure can be computed
and fixed at compile-time. This works because blocks are entered and exited
in a strictly textual order. Consider the following procedure:
void p(int a) {
int b;
if (a > 0)
{float c, d;
// Body of block 1 }
else
{int e[10];
// Body of block 2 }
}
Parameter a and local variable b are visible throughout the procedure. How-
ever, the then and else parts of the if statement are mutually exclusive. Thus,
variables in block 1 and block 2 can overlay each other. That is, c and d are
allocated just beyond b as is array e. This overlay is safe because variables in
both blocks can never be accessed at the same time. The layout of the frame is
illustrated in Figure 12.8.
O
ff
sets for variables within a block are assigned just after the last variable
 
Search WWH ::




Custom Search