Stack storage overview

Note: The term stack refers to the user stack, which is an independent area of stack storage that is located above the 2 GB bar, 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 a contiguous area of storage obtained directly from the operating system. Stack storage is automatically provided at thread initialization.

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 smaller segments called stack frames, which are 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 stack is allocated as one large area of contiguous storage, the size of which is specified by the maximum size parameter of the STACK64 runtime option. Only a portion of the stack is initially available to the application, the amount specified in the initial size parameter of the STACK64 runtime option. The rest of the stack storage is "guarded," which prevents the application from storing into it. When the initial stack area becomes full, a stack increment is created by the operating system by unguarding additional storage contiguous to the currently available stack area. The amount of storage to unguard is specified by the increment size parameter of the STACK64 runtime option.

See z/OS Language Environment Programming Reference for more information about using the STACK64 runtime option.

You can use the PAGEFRAMESIZE64 runtime option to request large page frames for stack storage. Large pages are a special-purpose feature to improve performance; therefore, using large pages is not recommended for all types of workloads. For more information about large pages, see z/OS MVS Programming: Assembler Services Guide.

The following figure shows the standard 64-bit stack storage model.

Figure 1. Stack storage model for Language Environment®
The stack storage model shows the difference between the initial segment and the subsequent segment.