A runtime is the support code that runs alongside your program: it starts it, manages its memory, schedules its threads and connects it to the system. Some languages ship a small one, such as C's library; others a large virtual machine with a garbage collector and a just-in-time compiler. Knowing what the runtime does explains most surprising behaviour.
Key concepts
- Execution models: native code, bytecode on a virtual machine, or an interpreter reading source.
- Garbage collection: the runtime finds unreachable objects and reclaims them, trading pauses and memory for safety.
- Just-in-time compilation: hot code is compiled while the program runs, using what it has observed.
- Concurrency support: threads, event loops, green threads or lightweight tasks, with their own scheduler.
- Foreign interfaces: how managed code calls native libraries, and the cost and risk at that border.
Vocabulary
- Virtual machine: a program that executes a portable instruction format.
- Bytecode: the compact instruction set a virtual machine runs.
- Warm-up: the time a runtime needs before just-in-time compilation reaches full speed.
- Stop-the-world pause: a moment when a collector halts the program.
What to study, in order
- Write the same small program in a compiled and in an interpreted language, and compare startup and memory.
- Read the bytecode your language produces and run it by hand for a few lines.
- Implement a tiny stack-based virtual machine with a loop and a few instructions.
- Add a simple mark-and-sweep collector to it.
- Measure a program's garbage collection behaviour with the runtime's own tools and change one setting.
Related tags
#interpreters #compilers #memory-management #java #webassembly