In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, dynamic recompilation is a feature of some
emulator
In computing, an emulator is Computer hardware, hardware or software that enables one computer system (called the ''host'') to behave like another computer system (called the ''guest''). An emulator typically enables the host system to run sof ...
s and
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
s, where the system may
recompile
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
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
In communications and information processing, code is a system of rules to convert information—such as a letter, word, sound, image, or gesture—into another form, sometimes shortened or secret, for communication through a communicati ...
by exploiting information that is not available to a traditional static
compiler
In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
.
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
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
or .NET
Common Language Runtime
The Common Language Runtime (CLR), the virtual machine component of Microsoft .NET Framework, manages the execution of .NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code) into machine instr ...
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
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
checking
* Providing an interface to virtualized support hardware, for example a
GPU
* Optimizing higher-level code structures to run efficiently on the target hardware (see below)
Applications
* Many
Java virtual machine
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
s feature dynamic recompilation.
* Apple's
Rosetta for
Mac OS X
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
on x86, allows
PowerPC
PowerPC (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
code to be run on the
x86 architecture
x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. T ...
.
* Later versions of the
Mac 68K emulator used in
classic Mac OS
Mac OS (originally System Software; retronym: Classic Mac OS) is the series of operating systems developed for the Mac (computer), Macintosh family of personal computers by Apple Computer, Inc. from 1984 to 2001, starting with System 1 and end ...
to run
680x0 code on the PowerPC hardware.
*
Psyco
Psyco is an unmaintained specializing just-in-time compiler for pre-2.7 Python originally developed by Armin Rigo and further maintained and developed by Christian Tismer. Development ceased in December, 2011.
Psyco ran on BSD-derived operat ...
, a
specializing compiler for
Python.
* The HP
Dynamo project, an example of a transparent binary dynamic
optimizer.
*
DynamoRIO, an
open-source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
successor to Dynamo that works with the
ARM,
x86-64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
and
IA-64
IA-64 (Intel Itanium architecture) is the instruction set architecture (ISA) of the discontinued Itanium family of 64-bit Intel microprocessors. The basic ISA specification originated at Hewlett-Packard (HP), and was subsequently implemented by ...
(Itanium) instruction sets.
* The
Vx32 virtual machine employs dynamic recompilation to create
OS-independent x86 architecture sandboxes for safe application
plugins.
*
Microsoft Virtual PC for Mac, used to run x86 code on PowerPC.
* FreeKEYB, an international DOS keyboard and console driver with many usability enhancements utilized
self-modifying code
In computer science, self-modifying code (SMC or SMoC) is source code, code that alters its own instruction (computer science), instructions while it is execution (computing), executing – usually to reduce the instruction path length and imp ...
and
dynamic dead code elimination to minimize its in-memory image based on its user configuration (selected features, languages, layouts) and actual runtime environment (OS variant and version, loaded drivers, underlying hardware), automatically resolving dependencies, dynamically relocating and recombining code sections on byte-level granularity and optimizing opstrings based on semantic information provided in the source code, relocation information generated by special tools during assembly and profile information obtained at load time.
* The backwards compatibility functionality of the
Xbox 360
The Xbox 360 is a home video game console developed by Microsoft. As the successor to the Xbox (console), original Xbox, it is the second console in the Xbox#Consoles, Xbox series. It was officially unveiled on MTV on May 12, 2005, with detail ...
(i.e. running games written for the original
Xbox
Xbox is a video gaming brand that consists of four main home video game console lines, as well as application software, applications (games), the streaming media, streaming service Xbox Cloud Gaming, and online services such as the Xbox networ ...
) is widely assumed to use dynamic recompilation.
* Apple's
Rosetta 2 for Apple silicon, permits many applications compiled for
x86-64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
-based processors to be translated for execution on Apple silicon.
*
QEMU
The Quick Emulator (QEMU) is a free and open-source emulator that uses dynamic binary translation to emulate a computer's processor; that is, it translates the emulated binary codes to an equivalent binary format which is executed by the mach ...
Emulators
*
PCSX2, a
PlayStation 2
The PlayStation 2 (PS2) is a home video game console developed and marketed by Sony Interactive Entertainment, Sony Computer Entertainment. It was first released in Japan on 4 March 2000, in North America on 26 October, in Europe on 24 Novembe ...
emulator, has a recompiler called "microVU", the successor of "SuperVU".
* GCemu, a
GameCube
The is a PowerPC-based home video game console developed and marketed by Nintendo. It was released in Japan on September 14, 2001, in North America on November 18, 2001, in Europe on May 3, 2002, and in Australia on May 17, 2002. It is the suc ...
emulator.
* GEM, a
Game Boy
The is a handheld game console developed by Nintendo, launched in the Japanese home market on April 21, 1989, followed by North America later that year and other territories from 1990 onwards. Following the success of the Game & Watch single-ga ...
emulator for
MSX
MSX is a standardized home computer architecture, announced by ASCII Corporation on June 16, 1983. It was initially conceived by Microsoft as a product for the Eastern sector, and jointly marketed by Kazuhiko Nishi, the director at ASCII Corpo ...
uses an optimizing dynamic recompiler.
* DeSmuME, a
Nintendo DS
The is a foldable handheld game console produced by Nintendo, released globally across 2004 and 2005. The DS, an initialism for "Developers' System" or "Dual Screen", introduced distinctive new features to handheld games: two LCD screens worki ...
emulator, has a dynarec option.
* Soywiz's Psp, a
PlayStation Portable
The PlayStation Portable (PSP) is a handheld game console developed and marketed by Sony Interactive Entertainment, Sony Computer Entertainment. It was first released in Japan on December 12, 2004, in North America on March 24, 2005, and in PA ...
emulator, has a dynarec option.
*
Mupen64Plus, a multi-platform Nintendo 64 emulator.
* Yabause, a multi-platform
Saturn
Saturn is the sixth planet from the Sun and the second largest in the Solar System, after Jupiter. It is a gas giant, with an average radius of about 9 times that of Earth. It has an eighth the average density of Earth, but is over 95 tim ...
emulator.
*
PPSSPP, a multi-platform
PlayStation Portable
The PlayStation Portable (PSP) is a handheld game console developed and marketed by Sony Interactive Entertainment, Sony Computer Entertainment. It was first released in Japan on December 12, 2004, in North America on March 24, 2005, and in PA ...
emulator, uses a
JIT dynamic recompiler by default.
*
PCem, a 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.
See also
*
Binary recompiler
*
Binary translation
In computing, binary translation is a form of binary recompilation where sequences of instruction (computer science), instructions are translated from a source instruction set (ISA) to the target instruction set with respect to the operating syste ...
*
Comparison of platform virtualization software
Platform virtualization software, specifically emulators and hypervisors, are software packages that emulate the whole physical computer machine, often providing multiple virtual machines on one physical platform. The table below compares basic ...
*
Just-in-time compilation
In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is compilation (of computer code) during execution of a program (at run time) rather than before execution. This may consist of source code transl ...
*
Instrumentation (computer programming)
In computer programming, instrumentation is the act of modifying software so that analysis can be performed on it.
Generally, instrumentation either modifies source code or binary code. Execution environments like the JVM provide separate interfa ...
References
External links
Dynamic recompiler tutorialat the
Wayback Machine
The Wayback Machine is a digital archive of the World Wide Web founded by Internet Archive, an American nonprofit organization based in San Francisco, California. Launched for public access in 2001, the service allows users to go "back in ...
(archived {{date, 2021-06-11, DMY).
Blog posts about writing a MIPS to PPC dynamic recompiler
Virtualization
Compiler construction
Emulation software