7

Run-Time Environment

What you will learn in this chapter

  • What is a Run-Time environment for a program?
  • What is the basic CPU and Memory environment?
  • What are different methods of storage allocation?
  • What is an Activation Record?
  • What are different types of Activation Records?
  • What are different methods of passing parameters to a subroutine?
  • How is memory allocation managed for a block-structured language?
  • How are the scope and visibility of a variable determined?
  • How is a running program controlled by an Operating System?
  • What are System Calls?
  • What is a Language library?
  • How does one create an application-specific library?
  • What are system environmental parameters?
  • How are the command-line invocation parameters passed?

Key Words

run-time, memory organization, static, stack-based and dynamic run-times, activation record, parameter passing, heap allocation, block-structured languages, variable scope and visibility, process, system calls, language library, system environmental parameters, command-line parameters

We have been discussing till now the front-end of a compiler and something about how semantic analysis, i.e. finding the “meaning”, of a program is done. We also considered certain essential semantic checks, known as type checking. We have to now consider how the target language code is generated, but before that we should know the environment which our program experience when it is running. The details of generated code depend heavily on this environment, although the general principles of code generation steps are the same. Some of the code optimization that a good compiler attempts also depend upon the run-time environment. That is why we discuss in this chapter the runtime environment – the background canvass on which the picture of running programs will be painted.

One should really consider the total run-time environment under which a program will have to run. For example, the environments under which a program running on a desktop computer, an application running on a personal digital assistant (PDA), an application being executed on a cloud computer or a program running on a supercomputer are quite different. Figure 7.1 shows the overall environment in which a translated program executes. The total environment consists of the following:

 

Run-time environment of a translated program, apart from the basic environment that is the CPU

 

Fig. 7.1 Run-time environment of a translated program, apart from the basic environment that is the CPU

 

Hardware: It includes CPU, memory, I/O devices, communication network, etc. It – especially the processor and the memory – provides the basic environment, on which we will concentrate.

Operating system: Concerned with resource management. It provides services through System Call Interface (SCI).

Language library: It provides functions for doing the jobs which the basic hardware is not directly capable of doing. For example, in C language if we write as

short i;
int j;
j = j + i ;

we expect that the short value on the RHS will be promoted to int and assigned to j. On machines where this cannot be done via an instruction, the compiler has to generate a call to a C language library to do this work. A slightly more involved example is the cast facility provided in C. On machines which do not have floating-point processor, the library will be used to do the floating-point computations.

System environmental parameters: System-wide and user-specific environmental values, such as – absolute paths to essential software (compiler, libraries, utilities), Terminal type, users home directory, user name, user group, default permissions for newly created files, prompt strings, machine type, O/S version, last console command executed, etc. These parameters are available in a C program by a third argument in the main(), like:

int main(int argc, char *argv[], char *env[]){ … }

Also, C library functions getenv() and putenv() can be used to obtain and set value of an individual environment parameter.

Invocation (command-line) parameters: The command-line arguments which are accessible via the second argument in the main().

Specialized libraries: A particular program may require and depend upon a special functions library, for example graphics library.

The most basic environment – the CPU plus memory pair – is not shown in Fig. 7.1 separately, but we concentrate on it more, as it is immediately related to our language translation tasks.

As an aside, we note that the source of power and thermal states is also part of the total environment, especially in portable equipment, but we simply ignore them here. However, there are situations where a program or application to be run on an embedded or portable system needs to be adjusted for minimum power consumption or thermal output.

Processor and memory technology has evolved over the years and their evolution has enabled computer scientists and engineers to provide more and more sophisticated language facilities. Figure 7.2 shows a three-dimensional space of processor (P), memory (M) and instruction set (I) in which past and present day CPU hardware exists.

 

Growth of the three dimensions of the basic environment – processor facilities, memory sophistication and instruction set capabilities

 

Fig. 7.2 Growth of the three dimensions of the basic environment – processor facilities, memory sophistication and instruction set capabilities

 

For example, it was the availability of hardware stack which allowed economic implementation of recursive functions. Virtual memory (VM) made the programmer free from program and data size limitations for normal programs.

It also provided much simpler target language generation. Interrupt system, DMA, virtual memory, indivisible read/update instructions and memory protection allowed building reliable multi-tasking environments.

Out of all the environmental factors which happen to be a resource, one that is always in short supply is the main memory. The amount of memory available and the way it is used in a system determine not only the sophistication of the language that can be used to program the system, but also the efficiency of execution. Hence, we start our discussion with the memory allocation during run-time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.184.102