Dynamic recompilation

Dynamic recompilation

In computer science, dynamic recompilation (sometimes abbreviated to dynarec or the pseudo-acronym DRC) 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 perhaps produce more efficient code by exploiting information that is not available to a traditional static compiler.

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 could also utilize it to reduce the space overhead incurred in most deoptimization techniques, and many other features such as dynamic thread migration.

Contents

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 at a time, and must do so by first reading it from the source string into a register, 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 in the processor to increment A and B while it is still copying bytes).

Applications using dynamic recompilation

See also

External links

  • [5] HP Labs' technical report on Dynamo
  • [6] Dynamic recompiler tutorial

Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Dynamic compilation — is a process used by some programming language implementations to gain performance during program execution. Although the technique originated in the Self programming language,[citation needed] the best known language that uses this technique is… …   Wikipedia

  • Dynamic program analysis — is the analysis of computer software that is performed by executing programs built from that software system on a real or virtual processor. For dynamic program analysis to be effective, the target program must be executed with sufficient test… …   Wikipedia

  • Java (programming language) — infobox programming language name = Java paradigm = Object oriented, structured, imperative year = 1995 designer = Sun Microsystems latest release version = Java Standard Edition 6 (1.6.0) latest release date = latest test version = latest test… …   Wikipedia

  • 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… …   Wikipedia

  • Emulator — This article is about emulators in computer science. For a line of digital musical instruments, see E mu Emulator. For other uses, see Emulation (disambiguation). DOSBox emulates the command line interface of DOS. In computing, an emulator is… …   Wikipedia

  • Microsoft Virtual PC — Infobox Software name = Microsoft Virtual PC caption = Screenshot of Virtual PC 2007 for Windows with virtualized Windows 2000 developer = Microsoft Corporation latest release version = 2007 SP1 (Windows), 7.0.3 (Mac) latest release date = May 15 …   Wikipedia

  • Windows Virtual PC — This article is about the virtualization software by Microsoft. For the generic term, see Virtual machine. Windows Virtual PC Windows Virtual PC …   Wikipedia

  • Eric Traut — is an American software engineer and software emulation pioneer. Traut graduated from Stanford University in 1992. From 1993 to 1995 he worked for Apple Computer, creating a Mac 68K emulator to be used in PowerPC based Macintoshes.… …   Wikipedia

  • VMware Fusion — Infobox Software name = VMware Fusion caption = VMware Fusion running Windows Vista on Mac OS X developer = VMware, Inc. latest release version = 2.0 (build 116369) latest release date = release date|2008|09|16 latest preview version = latest… …   Wikipedia

  • 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.There is static binary translation, where an… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”