Java Reference
In-Depth Information
code is statically allocated, any execution order can be accommodated. Java
and C
allow classes to be dynamically loaded or compiled; but once program
code is made executable, it is static.
Conceptually, we can bind static objects to absolute memory addresses.
Thus, if we generate an assembly language translation of a program, a global
variable or program statement can be given a symbolic label that denotes a
fixed memory address. It is often preferable to address a static data object
as a pair ( DataArea , O ff set ). O ff set is fixed at compile-time, but the address of
DataArea can be deferred to link- or runtime. In Fortran, for example, DataArea
can be the start of one of many common blocks. In C, DataArea can be the start
of a block of storage for the variables local to a module (a “.c”file). InJava,
DataArea can be the start of a block of storage for the static fields of a class.
Typically these addresses are bound when the program is linked. Address
binding must be deferred until link-time or runtime because subroutines and
classes may be compiled independently, making it impossible for the compiler
to know about all the data areas in a program.
Alternatively, the address of DataArea can be loaded into a register (the
global pointer ), which allows a static data item to be addressed as ( Register ,
O ff set ). This addressing form is available on almost every machine. The
advantage of addressing a piece of static data with a global pointer is that
we can load or store a global value in one instruction. Since global addresses
occupy 32 (or 64) bits, they normally “don't fit” in a single instruction on
machines in which an instruction is the same number of bits as an address, like
MIPS R
,andSparc TM . If a global pointer is not available, global
addresses must be formed in several steps, first loading the high-order bits,
and then masking in the remaining low-order bits.
,PowerPC R
12.2 Stack Allocation
Almost all modern programming languages allow recursive subprograms .
Recursion requires dynamic memory allocation . Each recursive call requires
the allocation of memory for a new copy of a routine's local variables; thus
the number of memory allocations required during program execution is not
known at compile-time. To implement recursion, all of the data space required
for a routine (a procedure, function, or method) is treated as a data area that,
because of the special way it is handled, is called a frame or activation record .
A frame holds local data for a subprogram activation, and is accessible
only for the duration of that activation. In mainstream languages like C, C
++
,
C
, and Java, subprogramactivations obey a stack discipline: the most recently
called subprogram must be the first to return. In terms of implementation, a
frame will be pushed onto a runtime stack when a routine is called (activated).
When the routine returns, the frame is popped from the stack, freeing the
 
 
Search WWH ::




Custom Search