In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, dynamic recompilation is a feature of some
emulator
In computing, an emulator is 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 software or use peri ...
s and
virtual machine
In computing, a virtual machine (VM) is the virtualization/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized har ...
s, 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
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 that ...
.
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 (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
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 instruc ...
bytecodes. Full-speed debuggers also utilize dynamic recompilation to reduce the space overhead incurred in most
deoptimization
Adaptive optimization is a technique in computer science that performs dynamic recompilation of portions of a program based on the current execution profile. With a simple implementation, an adaptive optimizer may simply make a trade-off between ...
techniques, and other features such as dynamic
thread migration
In computing, process migration is a specialized form of process management whereby processes are moved from one computing environment to another. This originated in distributed computing, but is now used more widely. On multicore machines (multip ...
.
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 describ ...
s feature dynamic recompilation.
* Apple's
Rosetta
Rosetta or Rashid (; ar, رشيد ' ; french: Rosette ; cop, ϯⲣⲁϣⲓⲧ ''ti-Rashit'', Ancient Greek: Βολβιτίνη ''Bolbitinē'') is a port city of the Nile Delta, east of Alexandria, in Egypt's Beheira governorate. The ...
for
Mac OS X
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
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– IBM ...
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 Intel 8086 microprocessor and its 8088 variant. The 8086 was ...
.
* 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 Macintosh family of personal computers by Apple Computer from 1984 to 2001, starting with System 1 and ending with Mac OS 9. Th ...
to run
680x0 code on the PowerPC hardware.
*
Psyco, 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 the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
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 version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging ...
and
IA-64
IA-64 (Intel Itanium architecture) is the instruction set architecture (ISA) of the Itanium family of 64-bit Intel microprocessors. The basic ISA specification originated at Hewlett-Packard (HP), and was subsequently implemented by Intel in col ...
(Itanium) instruction sets.
* The
Vx32 virtual machine employs dynamic recompilation to create
OS-independent x86 architecture sandboxes for safe application
plugins
Plug-in, plug in or plugin may refer to:
* Plug-in (computing) is a software component that adds a specific feature to an existing computer program.
** Audio plug-in, adds audio signal processing features
** Photoshop plugin, a piece of software t ...
.
*
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) is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code ...
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 original Xbox, it is the second console in the Xbox series. It competed with Sony's PlayStation 3 and Nintendo's Wii as part of the seventh generati ...
(i.e. running games written for the original
Xbox
Xbox is a video gaming brand created and owned by Microsoft. The brand consists of five video game consoles, as well as applications (games), streaming services, an online service by the name of Xbox network, and the development arm by th ...
) is widely assumed to use dynamic recompilation.
* Apple's
Rosetta 2
Rosetta is a dynamic binary translator developed by Apple Inc. for macOS, an application compatibility layer between different instruction set architectures. It enables a transition to newer hardware, by automatically translating software. Th ...
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 version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging ...
-based processors to be translated for execution on Apple silicon.
Emulators
*
PCSX2
PCSX2 is a free and open-source PlayStation 2 emulator for Windows, Linux, and macOS that supports a wide range of PlayStation 2 video games with a high level of compatibility and functionality. Although PCSX2 can closely mirror the original ga ...
, a
Sony
, commonly stylized as SONY, is a Japanese multinational conglomerate corporation headquartered in Minato, Tokyo, Japan. As a major technology company, it operates as one of the world's largest manufacturers of consumer and professional ...
PlayStation 2 emulator, has a recompiler called "microVU", the successor of "SuperVU".
* GCemu, a
Nintendo GameCube
The is a home video game console developed and released by Nintendo in Japan on September 14, 2001, in North America on November 18, 2001, and in PAL territories in 2002. It is the successor to the Nintendo 64 (1996), and predecessor of the ...
emulator.
* GEM, a
Nintendo Game Boy emulator for
MSX uses an optimizing dynamic recompiler.
* DeSmuME, a
Nintendo DS emulator, has a dynarec option.
* Soywiz's Psp, a
Sony
, commonly stylized as SONY, is a Japanese multinational conglomerate corporation headquartered in Minato, Tokyo, Japan. As a major technology company, it operates as one of the world's largest manufacturers of consumer and professional ...
PlayStation Portable
The PlayStation Portable (PSP) is a handheld game console developed and marketed by Sony Computer Entertainment. It was first released in Japan on December 12, 2004, in North America on March 24, 2005, and in PAL regions on September 1, 200 ...
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 nine and a half times that of Earth. It has only one-eighth the average density of Earth; ...
emulator.
*
PPSSPP, a multi-platform
PlayStation Portable
The PlayStation Portable (PSP) is a handheld game console developed and marketed by Sony Computer Entertainment. It was first released in Japan on December 12, 2004, in North America on March 24, 2005, and in PAL regions on September 1, 200 ...
emulator, uses a
JIT dynamic recompiler by default.
See also
*
Binary recompiler
*
Binary translation
In computing, binary translation is a form of binary recompilation where sequences of instructions are translated from a ''source'' instruction set to the ''target'' instruction set. In some cases such as instruction set simulation, the target i ...
*
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 i ...
*
Just-in-time compilation
In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compiler, compilation during execution of a program (at run time (program lifecycle phase), run tim ...
*
Instrumentation (computer programming)
In the context of computer programming, instrumentation refers to the measure of a product's performance, in order to diagnose errors and to write trace information. Instrumentation can be of two types: source instrumentation and binary instrument ...
References
{{Reflist
External links
Dynamic recompiler tutorialBlog posts about writing a MIPS to PPC dynamic recompiler
Virtualization
Compiler construction
Emulation software