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 << #Behavior slots: { #superclass . #methodDict . #format . #layout }; sharedVariables: { #ClassProperties . #ObsoleteSubclasses }; tag: 'Classes'; package: 'Kernel-CodeModel' , Class ClassDescription << #Class slots: { #subclasses . #name . #classPool . #sharedPools . #environment . #commentSourcePointer . #packageTag }; sharedVariables: { #ObsoleteClasses }; tag: 'Classes'; package: 'Kernel-CodeModel' and Metaclass ClassDescription << #Metaclass slots: { #thisClass }; tag: 'Classes'; package: 'Kernel-CodeModel'

— 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