Skip to the content ForoHackers
Log inJoin

Runtimes: start here

Runtimes
#3387 · · Quote · Report

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

  1. Write the same small program in a compiled and in an interpreted language, and compare startup and memory.
  2. Read the bytecode your language produces and run it by hand for a few lines.
  3. Implement a tiny stack-based virtual machine with a loop and a few instructions.
  4. Add a simple mark-and-sweep collector to it.
  5. 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

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply