TheDeveloperBlog.com


C# Activation Record: Call Stack

Activation records are used to implement method calls. At the lowest level of the machine, instructions are used exclusively. Activation records provide a layer of abstraction for the implementation of function calls.

Methods

Instructions: On the evaluation stack, these activation records are implemented with pure instruction sequences.


Example. 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.

Visual Studio

Next: In this example, the call stack of activation records will be Main, B, and C.

Visual Studio Debugging
C# program that creates the call stack in picture

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.


Records. 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 has an access link and a control link. These are used to access other code when the 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. We saw the call stack in Visual Studio and the C# language in the context of compiler theory. We explored stack allocation. Stack memory can be used to quickly call procedures. These are themselves an abstraction over raw instructions.

Compiler

Thus: The concept of the activation record provides a framework for modular and clear program development.