What is Introspection?

Introspection is the ability for a program to observe and reason about its own state. This is useful for numerous software analysis tasks, to query not only the run-time state of a software system but also its source code.

This works by providing a reflective API to query the run-time system. In Smalltalk, this is done by reifying metaobjects of the runtime so they can be queried.

Some examples of metaobjects are:

Smalltalk, a Facade for interacting with the running image.

— The core classes of the Smalltalk system, such as Behavior Object subclass: #Behavior instanceVariableNames: 'superclass methodDict format layout' classVariableNames: 'ClassProperties ObsoleteSubclasses' package: 'Kernel-Classes' , Class ClassDescription subclass: #Class instanceVariableNames: 'subclasses name classPool sharedPools environment category' classVariableNames: '' package: 'Kernel-Classes' and Metaclass ClassDescription subclass: #Metaclass instanceVariableNames: 'thisClass' classVariableNames: '' package: 'Kernel-Classes'

— Any class

We will have a closer look at concrete examples in three parts:

Querying objects — shows examples of querying an object's reference, state and class.

Querying classes and methods — shows how to reflectively query classes and methods using numerous APIs.

Querying the runtime — shows how to query the run-time stack of execution contexts