Dynamic recompilation
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, dynamic recompilation (sometimes abbreviated to dynarec or the pseudo-acronym DRC) is a feature of some emulator
Emulator
In computing, an emulator is hardware or software or both that duplicates the functions of a first computer system in a different second computer system, so that the behavior of the second system closely resembles the behavior of the first system...

s and virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

s, where the system may recompile
Compile
Compile 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 program
Computer program
A computer program is a sequence of instructions written to perform a specified task with 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...

 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 code
Code
A code is a rule for converting a piece of information into another form or representation , not necessarily of the same type....

 by exploiting information that is not available to a traditional static compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

.

In other cases, a system may employ dynamic recompilation as part of an adaptive optimization
Adaptive optimization
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 Just-in-time compilation and interpreting instructions...

 strategy to execute a portable program
representation such as Java
Java (programming language)
Java 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 Runtime
Common Language Runtime
The Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...

 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 byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 at a time, and must do so by first reading it from the source string into a register
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...

, 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
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
cmp C,#0 ; Compare the data we just copied to 0 (string end marker)
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 execution
Parallel computing
Parallel 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).

Applications using dynamic recompilation

  • Many Java virtual machines
    Java Virtual Machine
    A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...

     feature dynamic recompilation.
  • MAME
    MAME
    MAME is an emulator application designed to recreate the hardware of arcade game systems in software on modern personal computers and other platforms. The intention is to preserve gaming history by preventing vintage games from being lost or forgotten...

     uses dynamic recompilation in its CPU emulators for MIPS, SuperH, PowerPC and even the Voodoo graphics processing units.
  • 1964
    1964 (emulator)
    1964 is a Nintendo 64 emulator for Microsoft Windows, written in C and released as free software. It is one of the oldest and most popular N64 emulators, supporting many commercial N64 games...

    , a Nintendo 64
    Nintendo 64
    The , often referred to as N64, was Nintendo′s third home video game console for the international market. Named for its 64-bit CPU, it was released in June 1996 in Japan, September 1996 in North America, March 1997 in Europe and Australia, September 1997 in France and December 1997 in Brazil...

     emulator for x86 hardware.
  • Apple's Rosetta
    Rosetta (software)
    Rosetta was a lightweight and dynamic binary translator for Mac OS X which Apple released in 2006 when it transitioned the Macintosh from PowerPC to Intel processors. It allowed pre-existing software to run on the new systems without modification....

     for Mac OS X
    Mac OS X
    Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

     on x86, allows PowerPC
    PowerPC
    PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...

     code to be run on the x86 architecture
    X86 architecture
    The term x86 refers to a family of instruction set architectures based on the Intel 8086 CPU. The 8086 was launched in 1978 as a fully 16-bit extension of Intel's 8-bit based 8080 microprocessor and also introduced segmentation to overcome the 16-bit addressing barrier of such designs...

    .
  • Later versions of the Mac 68K emulator
    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 OS
    Mac OS
    Mac OS is 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
    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 Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose 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
    Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attributes 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
    VX32
    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 OS
    Operating system
    An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

    -independent x86 architecture sandboxes for safe application plugins.
  • Microsoft Virtual PC
    Microsoft Virtual PC
    Windows Virtual PC is a virtualization program for Microsoft Windows. In July 2006 Microsoft released the Windows-hosted version as a free product...

     for Mac, used to run x86 code on PowerPC.
  • NullDC
    NullDC
    nullDC is an open source Sega Dreamcast and NAOMI videogame systems emulator for Microsoft Windows.After not being updated for almost two years, the project's author drk||Raziel announced his decision to release the source code with his newest build....

    , a Sega
    Sega
    , usually styled as SEGA, is a multinational video game software developer and an arcade software and hardware development company headquartered in Ōta, Tokyo, Japan, with various offices around the world...

     Dreamcast emulator for x86.
  • QEMU
    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
    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 Xbox
    Xbox
    The Xbox is a sixth-generation video game console manufactured by Microsoft. It was released on November 15, 2001 in North America, February 22, 2002 in Japan, and March 14, 2002 in Australia and Europe and is the predecessor to the Xbox 360. It was Microsoft's first foray into the gaming console...

    ) is widely assumed to use dynamic recompilation.
  • PSEmu Pro, a Sony
    Sony
    , commonly referred to as Sony, is a Japanese multinational conglomerate corporation headquartered in Minato, Tokyo, Japan and the world's fifth largest media conglomerate measured by revenues....

     PlayStation
    PlayStation
    The is a 32-bit fifth-generation video game console first released by Sony Computer Entertainment in Japan on December 3, .The PlayStation was the first of the PlayStation series of consoles and handheld game devices. The PlayStation 2 was the console's successor in 2000...

     emulator.
  • Ultrahle
    UltraHLE
    UltraHLE was an emulator for the Nintendo 64. It was hailed as a massive step forward in emulation technology at its 1999 release. Emulating the N64 made it the first of the N64 emulators to run commercial titles at a playable frame rate on the hardware of the time.-The HLE technique:Earlier...

    , the first Nintendo 64
    Nintendo 64
    The , often referred to as N64, was Nintendo′s third home video game console for the international market. Named for its 64-bit CPU, it was released in June 1996 in Japan, September 1996 in North America, March 1997 in Europe and Australia, September 1997 in France and December 1997 in Brazil...

     emulator to fully run commercial games.
  • PCSX2
    PCSX2
    PCSX2 is an open-source PlayStation 2 emulator for the Microsoft Windows and Linux operating systems. In its latest stable release, many PS2 games are playable, and several games have full functionality. The main bottleneck in PS2 emulation is emulating the multi-processor PS2 on a PC x86...

     http://www.pcsx2.net, a Sony
    Sony
    , commonly referred to as Sony, is a Japanese multinational conglomerate corporation headquartered in Minato, Tokyo, Japan and the world's fifth largest media conglomerate measured by revenues....

     PlayStation 2
    PlayStation 2
    The PlayStation 2 is a sixth-generation video game console manufactured by Sony as part of the PlayStation series. Its development was announced in March 1999 and it was first released on March 4, 2000, in Japan...

     emulator, has a recompiler called "microVU", the successor of "SuperVU".
  • Dolphin
    Dolphin (emulator)
    Dolphin is an open-source Nintendo GameCube, Wii, and Triforce emulator for Microsoft Windows, Linux, and Mac OS X . It is the first emulator to successfully run commercial Nintendo GameCube and Wii games and is the only emulator capable of running commercial Wii games...

    , a Nintendo GameCube
    Nintendo GameCube
    The , officially abbreviated to NGC in Japan and GCN in other regions, is a sixth generation video game console released by Nintendo on September 15, 2001 in Japan, November 18, 2001 in North America, May 3, 2002 in Europe, and May 17, 2002 in Australia...

     and Wii
    Wii
    The Wii is a home video game console released by Nintendo on November 19, 2006. 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 the two others...

     emulator, has a dynarec option.
  • GCemu, a Nintendo GameCube
    Nintendo GameCube
    The , officially abbreviated to NGC in Japan and GCN in other regions, is a sixth generation video game console released by Nintendo on September 15, 2001 in Japan, November 18, 2001 in North America, May 3, 2002 in Europe, and May 17, 2002 in Australia...

     emulator.
  • OVPsim
    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
    Oracle VM VirtualBox is an x86 virtualization software package, originally created by software company Innotek GmbH, purchased by Sun Microsystems, and now developed by Oracle Corporation as part of its family of virtualization products...

     uses dynamic recompilation
  • Valgrind
    Valgrind
    Valgrind is a GPL licensed programming tool for memory debugging, memory leak detection, and profiling. The name valgrind comes from the main entrance to Valhalla in Norse mythology....

    , a programming tool for memory debugging, memory leak detection, and profiling, uses dynamic recompilation.
  • Wii64, a Nintendo 64
    Nintendo 64
    The , often referred to as N64, was Nintendo′s third home video game console for the international market. Named for its 64-bit CPU, it was released in June 1996 in Japan, September 1996 in North America, March 1997 in Europe and Australia, September 1997 in France and December 1997 in Brazil...

     emulator for the Wii.
  • WiiSX, a SONY PlayStation emulator for the Nintendo Wii.
  • Mupen64Plus
    Mupen64Plus
    Mupen64Plus is a cross-platform Nintendo 64 emulator, written in C and released as free software...

    , a multi-platform Nintendo 64 emulator.http://pandorawiki.org/Mupen64plus_dynamic_recompiler
  • Yabause, a multi-platform Saturn
    Sega Saturn
    The is a 32-bit fifth-generation video game console that was first released by Sega on November 22, 1994 in Japan, May 11, 1995 in North America, and July 8, 1995 in Europe...

     emulator.http://wiki.yabause.org/index.php5?title=SH2_dynamic_recompiler

See also

  • Comparison of platform virtual machines
  • Binary translation
    Binary translation
    In computing, binary translation is the emulation of one instruction set by another through translation of code. Sequences of instructions are translated from the source to the target instruction set...

  • Just-in-time compilation
    Just-in-time compilation
    In computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK