In
computer scienceComputer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems. It is frequently described as the systematic study of algorithmic processes that create, describe and transform...
,
dynamic recompilation (sometimes abbreviated to
dynarec or the
pseudo-acronymA pseudo-acronym is an apparent acronym or other abbreviation which doesn't stand for anything, or cannot be officially expanded to some meaning. An orphan acronym is a pseudo-acronym that was once a true acronym or initialism...
DRC) is a feature of some
emulatorAn emulator in computer sciences duplicates the functions of one system using a different system, so that the second system behaves like the first system...
s and
virtual machineA virtual machine is a software implementation of a machine that executes programs like a physical machine.-Definitions:...
s, where the system may
recompileCompile may refer to:* Compile , a Japanese video game company founded in 1983 that specialized in shoot 'em up and computer puzzle game genres...
some part of a
programComputer programs are instructions for a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute the instructions...
during execution. By compiling during execution, the system can tailor the generated code to reflect the program's run-time environment, and perhaps produce more efficient
codeIn communications, a code is a rule for converting a piece of information into another form or representation , not necessarily of the same type. In communications and information processing, encoding is the process by which information from a source is converted into symbols to be communicated...
by exploiting information that is not available to a traditional static
compilerA compiler is a computer program that transforms source code written in a computer language into another computer language...
.
In other cases, a system may employ dynamic recompilation as part of an
adaptive optimizationAdaptive 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 Just-in-time compilation and interpreting instructions...
strategy to execute a portable program
representation such as
JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
or .NET
Common Language RuntimeThe Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...
bytecodes.
In
computer scienceComputer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems. It is frequently described as the systematic study of algorithmic processes that create, describe and transform...
,
dynamic recompilation (sometimes abbreviated to
dynarec or the
pseudo-acronymA pseudo-acronym is an apparent acronym or other abbreviation which doesn't stand for anything, or cannot be officially expanded to some meaning. An orphan acronym is a pseudo-acronym that was once a true acronym or initialism...
DRC) is a feature of some
emulatorAn emulator in computer sciences duplicates the functions of one system using a different system, so that the second system behaves like the first system...
s and
virtual machineA virtual machine is a software implementation of a machine that executes programs like a physical machine.-Definitions:...
s, where the system may
recompileCompile may refer to:* Compile , a Japanese video game company founded in 1983 that specialized in shoot 'em up and computer puzzle game genres...
some part of a
programComputer programs are instructions for a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute the instructions...
during execution. By compiling during execution, the system can tailor the generated code to reflect the program's run-time environment, and perhaps produce more efficient
codeIn communications, a code is a rule for converting a piece of information into another form or representation , not necessarily of the same type. In communications and information processing, encoding is the process by which information from a source is converted into symbols to be communicated...
by exploiting information that is not available to a traditional static
compilerA compiler is a computer program that transforms source code written in a computer language into another computer language...
.
In other cases, a system may employ dynamic recompilation as part of an
adaptive optimizationAdaptive 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 Just-in-time compilation and interpreting instructions...
strategy to execute a portable program
representation such as
JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
or .NET
Common Language RuntimeThe Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...
bytecodes. Full-speed debuggers could also utilize it to reduce the space overhead incurred in most deoptimization techniques, and many other features such as dynamic thread migration.
Example
Suppose a program is being run in an emulator and needs to copy a null-terminated string. The program is compiled originally for a very simple processor. This processor can only copy a
byteA byte is a unit of information storage representing the smallest addressable element for a given computer architecture. It often designates a sequence of bits whose length is determined by the architecture...
at a time, and must do so by first reading it from the source string into a
registerIn computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere. Most, but not all, modern computers adopt the so-called load-store architecture...
, then writing it from that register into the destination string. The original program might look something like this:
beginning:
mov A,[first string pointer] ; Put location of first character of source string
; in register A
mov B,[second string pointer] ; Put location of first character of destination string
; in register B
loop:
mov C,[A] ; Copy byte at address in register A to register C
mov [B],C ; Copy byte in register C to the address in register B
cmp C,#0 ; Compare the data we just copied to 0 (string end marker)
inc A ; Increment the address in register A to point to
; the next byte
inc B ; Increment the address in register B to point to
; the next byte
jnz loop ; If it wasn't 0 then we have more to copy, so go back
; and copy the next byte
end: ; If we didn't loop then we must have finished,
; so carry on with something else.
The emulator might be running on a processor which is similar, but extremely good at copying strings, and the emulator knows it can take advantage of this.
It might recognize the string copy sequence of instructions and decide to rewrite them more efficiently just before execution, to speed up the emulation.
Say there is an instruction on our new processor called
movs, specifically designed to copy strings efficiently. Our theoretical movs instruction copies 16 bytes at a time, without having to load them into register C in between,
but will stop if it copies a 0 byte (which marks the end of a string) and set the zero flag. It also knows that the addresses of the strings will be in registers A and B, so it increments A and B by 16 every time it executes, ready for the next copy.
Our new recompiled code might look something like this:
beginning:
mov A,[first string pointer] ; Put location of first character of source string
; in register A
mov B,[second string pointer] ; Put location of first character of destination string
; in register B
loop:
movs [B],[A] ; Copy 16 bytes at address in register A to address
; in register B, then increment A and B by 16
jnz loop ; If the zero flag isn't set then we haven't reached
; the end of the string, so go back and copy some more.
end: ; If we didn't loop then we must have finished,
; so carry on with something else.
There is an immediate speed benefit simply because the processor doesn't have to load so many instructions to do the same task, but also because the movs instruction is likely to be optimized by the processor designer to be more efficient than the sequence used in the first example (for example it may make better use of
parallel executionParallel computing is a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently . There are several different forms of parallel computing: bit-level,...
in the processor to increment A and B while it is still copying bytes).
Products using dynamic recompilation
- Many Java virtual machines
A Java Virtual Machine is a set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts. The model used by a JVM accepts a form of computer intermediate language commonly referred to as Java bytecode...
feature dynamic recompilation.
- Apple's Rosetta
Rosetta is a lightweight dynamic translator for Mac OS X distributed by Apple. It enables applications compiled for the PowerPC family of processors to run on Apple systems that use Intel processors...
for Mac OS XMac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems...
on x86, allows PowerPCPowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM. Originally intended for personal computers, PowerPC CPUs have since become popular embedded and high-performance processors...
code to be run on the x86 architectureThe term x86 refers to a family of instruction set architectures based on the Intel 8086. The term derived from the fact that many early processors backward compatible with the 8086 also had names ending in "86". Many additions and extensions have been added to the x86 instruction set over the...
.
- Later versions of the Mac 68K emulator
The Mac 68K emulator was a software emulator built into all versions of the Mac OS for PowerPC. This emulator permitted the running of applications and system code that were originally written for the 680x0 based Macintosh models. The emulator was completely seamless for users, and reasonably...
used in Mac OSMac OS is the trademarked name for a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems. The Macintosh user experience is credited with popularizing the graphical user interface...
to run 680x0 code on the PowerPC hardware.
- Psyco
Psyco is a specializing just-in-time compiler for Python originally developed by Armin Rigo and further maintained and developed by Christian Tismer....
, a specializing compiler for PythonPython is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
.
- The HP Dynamo project, an example of a transparent binary dynamic optimizer
Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attribute of an executable computer program. The most common requirement is to minimize the time taken to execute a program; a less common one is to minimize the amount of memory occupied...
.
- The VX32 virtual machine
The VX32 virtual extension environment is an application-level virtual machine implemented as an ordinary user-mode library and designed to run native x86 code...
employs dynamic recompilation to create OSAn operating system is an interface between hardware and user which is responsible for the management and coordination of activities and the sharing of the resources of the computer that acts as a host for computing applications run on the machine. As a host, one of the purposes of an operating...
-independent x86 architecture sandboxes for safe application pluginIn computing, a plug-in consists of a computer program that interacts with a host application to provide a certain, usually very specific, function "on demand"...
s.
- Microsoft Virtual PC
Microsoft Virtual PC is a virtualization program for Microsoft Windows operating systems, and an emulation program for Mac OS X on PowerPC-based systems. The software was originally developed by Connectix, and was subsequently acquired by Microsoft. In July 2006 Microsoft released the...
for Mac, used to run x86 code on PowerPC.
- QEMU
QEMU is a processor emulator that relies on dynamic binary translation to achieve a reasonable speed while being easy to port on new host CPU architectures....
, an open-source full system emulator.
- The backwards compatibility functionality of the Xbox 360
The Xbox 360 is the second video game console produced by Microsoft, and the successor to the Xbox. The Xbox 360 competes with Sony's PlayStation 3 and Nintendo's Wii as part of the seventh generation of video game consoles....
(i.e. running games written for the original XboxThe Xbox is a video game console produced by Microsoft. It was Microsoft's first foray into the gaming console market, and competed with Sony's PlayStation 2, Sega's Dreamcast, and Nintendo's GameCube...
) is widely assumed to use dynamic recompilation.
- PSEmu Pro, a Sony
is a multinational conglomerate corporation headquartered in Minato, Tokyo, Japan, and one of the world's largest media conglomerates with revenue exceeding ¥ 7.730.0 trillion, or $78.88 billion U.S. . Sony is one of the leading manufacturers of electronics, video, communications, video game...
PlaystationThe PlayStation is a 32-bit fifth generation video game console released by Sony Computer Entertainment in December ....
emulator.
- Ultrahle
UltraHLE is an emulator allowing games for the Nintendo 64 game console to be run on a computer. It was hailed as a massive step forward in emulation technology upon its release in 1999...
, the first Nintendo 64The , often abbreviated as N64, is Nintendo's third home video game console for the international market. Named for its 64-bit CPU, it was released on June 23, 1996 in Japan, September 29, 1996 in North America, March 1, 1997 in Europe and Australia, September 1, 1997 in France and December 10,...
emulator to fully run commercial games.
- PCSX2
PCSX2 is a PlayStation 2 emulator for the Microsoft Windows and Linux operating systems. With the most recent versions, many PS2 games are playable , and several games are claimed to have full functionality...
http://www.pcsx2.net, a Sonyis a multinational conglomerate corporation headquartered in Minato, Tokyo, Japan, and one of the world's largest media conglomerates with revenue exceeding ¥ 7.730.0 trillion, or $78.88 billion U.S. . Sony is one of the leading manufacturers of electronics, video, communications, video game...
Playstation 2The PlayStation 2 is a sixth-generation video game console manufactured by Sony. The PS2 console is the sequel to the original PlayStation console. The successor to the PlayStation, and the predecessor to the PlayStation 3, the PlayStation 2 forms part of the PlayStation series of video game...
emulator, now uses a recompiler called "SuperVU", and a new one called "microVU" is in development.
- Dolphin
Dolphin is an open-source Nintendo GameCube and Wii emulator for Microsoft Windows, Linux and Mac OS X , it is the first emulator to successfully run commercial Nintendo GameCube and Wii games. It is currently the only emulator capable of running commercial Wii games and it is free software under...
, a Nintendo GameCubeThe is Nintendo's fourth home video game console with Wii being fifth, and is part of the sixth generation console era. It is the successor to the Nintendo 64 and predecessor to Nintendo's Wii....
and WiiThe is a home video game console released by Nintendo. As a seventh-generation console, the Wii primarily competes with Microsoft's Xbox 360 and Sony's PlayStation 3. Nintendo states that its console targets a broader demographic than that of both...
emulator, has a dynarec option.
- GCemu, a Nintendo GameCube
The is Nintendo's fourth home video game console with Wii being fifth, and is part of the sixth generation console era. It is the successor to the Nintendo 64 and predecessor to Nintendo's Wii....
emulator.
- OVPsim
OVPsim is a multiprocessor platform emulator that uses dynamic binary translation technology to achieve high simulation speeds. It has public APIs allowing users to create their own processor, peripheral and platform models. Various models are available as source. OVPsim is a key component of the...
http://www.ovpworld.org, a freely-available full system emulator.
- VirtualBox
VirtualBox is an x86 virtualization software package, originally created by German software company Innotek, now developed by Sun Microsystems as part of its Sun xVM virtualization platform...
uses dynamic recompilation
- Valgrind
Valgrind is a programming tool for memory debugging, memory leak detection, and profiling. The name Valgrind comes from the name of the main entrance to Valhalla in Norse mythology....
, a a programming tool for memory debugging, memory leak detection, and profiling, uses dynamic recompilation.
External links