C# Activation Record: Call Stack

Activation records are used to implement method calls. While at the lowest level of the machine, instructions are used exclusively, activation records provide a layer of abstraction for the implementation of function calls. On the evaluation stack, these activation records are implemented with pure instruction sequences.

Call stack

This article describes activation records in C# programs. Compiler theory is discussed.

Example

Note

First, another term for a sequence of activation records is the call stack. In Visual Studio, you can see the call stack in debug mode at any point by clicking in the margin on the left side of an executable source code line. In this example, the call stack of activation records will be Main, B, and C.

Program that creates the call stack in picture [C#]

using System;

class Program
{
    static void Main()
    {
	B();
    }

    static void B()
    {
	C();
    }

    static void C()
    {
	// Insert breakpoint here.
    }
}

Notes
    Insert breakpoint in Visual Studio to see call stack when executed.

Parts

Note (please read)

Each activation record has several memory locations where important data is stored. In compiler theory, you will find that local variables and data, the arguments, and a space for the return value will be allocated. Also, the activation record will contain an access link and a control link, which can be used to access other executable code when the method call is complete.

These links can be encoded as relative offsets: this makes it possible for a single compiled method to be called from two different methods. In each, the relative offset will return control to the calling method.

Summary

The C# programming language

We saw the call stack in Visual Studio and the C# language in the context of compiler theory and an understanding of stack allocation. Stack memory can be used to quickly call procedures, which are themselves an abstraction over raw instructions. While the computer can only execute instructions, the concept of the activation record provides a framework for modular and clear program development.

Visual Studio Tips
.NET