Stack storage overview

Note: The term stack refers to the user stack, which is an independent area of stack storage that can be located above or below the 16 MB line, designed to be used by both library routines and compiled code. All references to stack storage and stack frame are to real storage allocation, as opposed to invocation stack, which refers to a conceptual stack.

Stack storage is the storage provided by Language Environment that is needed for routine linkage and any automatic storage. It is allocated on entry to a routine or block, and freed on the subsequent return. It is a contiguous area of storage obtained directly from the operating system. Stack storage is automatically provided at thread initialization and is available in the user stack.

The user stack is used by both library routines and, except for Fortran, compiled code. Stack storage is also available in the library stack, which is an independent area of stack storage, allocated below the 16 MB line, designed to be used only by library routines.

A storage stack is a data structure that supports procedure or block invocation (call and return). It is used to provide both the storage required for the application initialization and any automatic storage used by the called routine. Each thread has a separate and distinct stack.

The storage stack is divided into large segments of storage called stack segments, which are further divided into smaller segments called stack frames, also known as dynamic storage areas (DSAs). A stack frame, or DSA, is dynamically acquired storage composed of a register save area and an area available for dynamic storage allocation for items such as program variables. Stack frames are added to the user stack when a routine is entered, and removed upon exit in a last in, first out (LIFO) manner. Stack frame storage is acquired during the execution of a program and is allocated every time a procedure, function, or block is entered, as, for example, when a call is made to a Language Environment callable service, and is freed when the procedure or block returns control.

The first segment used for stack storage is called the initial stack segment. When the initial stack segment becomes full, a second segment, or stack increment is obtained from the operating system. As each succeeding stack increment becomes full, another is obtained from the operating system as needed. The size of the initial stack segment and the size of the increments are specified by the init_size and incr_size parameters of the STACK runtime option. For more information about the STACK runtime option, see z/OS Language Environment Programming Reference.

Figure 1 shows the standard Language Environment stack storage model. The XPLINK stack (see Figure 2) is structured differently. See Using Extra Performance Linkage (XPLINK) for information about XPLINK.

Figure 1. Language Environment stack storage model
The standard stack storage model is an upward-growing stack.