Dynamic recompilation


In computer science, dynamic recompilation is a feature of some emulators and virtual machines, where the system may recompile some part of a program during execution. By compiling during execution, the system can tailor the generated code to reflect the program's run-time environment, and potentially produce more efficient code by exploiting information that is not available to a traditional static compiler.

Uses

Most dynamic recompilers are used to convert machine code between architectures at runtime. This is a task often needed in the emulation of legacy gaming platforms. In other cases, a system may employ dynamic recompilation as part of an adaptive optimization strategy to execute a portable program representation such as Java or.NET Common Language Runtime bytecodes. Full-speed debuggers also utilize dynamic recompilation to reduce the space overhead incurred in most deoptimization techniques, and other features such as dynamic thread migration.

Tasks

The main tasks a dynamic recompiler has to perform are:
  • Reading in machine code from the source platform
  • Emitting machine code for the target platform
A dynamic recompiler may also perform some auxiliary tasks:
  • Managing a cache of recompiled code
  • Updating of elapsed cycle counts on platforms with cycle count registers
  • Management of interrupt checking
  • Providing an interface to virtualized support hardware, for example a GPU
  • Optimizing higher-level code structures to run efficiently on the target hardware

Applications

Emulators

  • PCSX2, a PlayStation 2 emulator, has a recompiler called "microVU", the successor of "SuperVU".
  • GCemu, a GameCube emulator.
  • GEM, a Game Boy emulator for MSX uses an optimizing dynamic recompiler.
  • DeSmuME, a Nintendo DS emulator, has a dynarec option.
  • Soywiz's Psp, a PlayStation Portable emulator, has a dynarec option.
  • Mupen64Plus, a multi-platform Nintendo 64 emulator.
  • Yabause, a multi-platform Saturn emulator.
  • PPSSPP, a multi-platform PlayStation Portable emulator, uses a JIT dynamic recompiler by default.
  • PCem, an emulator for old pc platforms which can be used on Windows and Linux. It uses the recompiler to translate legacy cpu calls to modern cpu instructions and to gain some speed in emulation overall.
  • 86Box, a fork of PCem with the goal of a more accurate emulation. It is using the recompiler for the same purpose.