Recent from talks
Nothing was collected or created yet.
Dynamic recompilation
View on WikipediaThis article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|
| Program execution |
|---|
| General concepts |
| Types of code |
| Compilation strategies |
| Notable runtimes |
|
| Notable compilers & toolchains |
|
In computer science, dynamic recompilation 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 potentially produce more efficient code by exploiting information that is not available to a traditional static compiler.
Uses
[edit]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 or .NET Common Language Runtime 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
[edit]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 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
[edit]- Many Java virtual machines feature dynamic recompilation.
- Apple's Rosetta for Mac OS X on x86, allows PowerPC code to be run on the x86 architecture.
- Later versions of the Mac 68K emulator used in classic Mac OS 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.[1]
- DynamoRIO, an open-source successor to Dynamo that works with the ARM, x86-64 and IA-64 (Itanium) instruction sets.[2][3]
- 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 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.[4]
- The backwards compatibility functionality of the Xbox 360 (i.e. running games written for the original Xbox) is widely assumed to use dynamic recompilation.
- Apple's Rosetta 2 for Apple silicon, permits many applications compiled for x86-64-based processors to be translated for execution on Apple silicon.
- QEMU
Emulators
[edit]- PCSX2,[5] a PlayStation 2 emulator, has a recompiler called "microVU", the successor of "SuperVU".
- GCemu,[6] a GameCube emulator.
- GEM,[7] a Game Boy emulator for MSX uses an optimizing dynamic recompiler.
- DeSmuME,[8] a Nintendo DS emulator, has a dynarec option.
- Soywiz's Psp,[9] a PlayStation Portable emulator, has a dynarec option.
- Mupen64Plus, a multi-platform Nintendo 64 emulator.[10]
- Yabause, a multi-platform Saturn emulator.[11]
- PPSSPP, a multi-platform PlayStation Portable emulator, uses a JIT dynamic recompiler by default.[12]
- PCem, an 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
[edit]References
[edit]- ^ "HP Labs' technical report on Dynamo". Archived from the original on 2008-07-07. Retrieved 2006-01-22.
- ^ "DynamoRIO Dynamic Instrumentation Tool Platform". Archived from the original on 2019-09-05. Retrieved 2016-04-12.
- ^ "DynamoRIO". GitHub. 2021-10-15.
- ^ Paul, Matthias R.; Frinke, Axel C. (1997-10-13) [first published 1991], FreeKEYB - Enhanced DOS keyboard and console driver (User Manual) (v6.5 ed.)
- ^ "PCSX 2". Archived from the original on 2005-10-29. Retrieved 2009-04-15.
- ^ petebernert (2015-10-03). "GCemu". SourceForge.
- ^ "Gameboy Emulator for MSX | The New Image". GEM. Retrieved 2014-01-12.
- ^ "DeSmuME v0.9.9".
- ^ Publicado por Carlos Ballesteros Velasco (2013-07-28). "Soywiz's PSP Emulator: Release : Soywiz's Psp Emulator 2013-07-28 (r525)". Pspemu.soywiz.com. Retrieved 2014-01-12.
- ^ Mupen64Plus
- ^ "SH2".
- ^ "PPSSPP - PPSSPP - PSP emulator for Android, Windows, Linux, iOS, MacOSX". ppsspp.org. Retrieved 2021-11-17.
External links
[edit]- Dynamic recompiler tutorial. Archive at the Wayback Machine (archived 11 June 2021).
- Blog posts about writing a MIPS to PPC dynamic recompiler.
Dynamic recompilation
View on GrokipediaFundamentals
Definition and Principles
Dynamic recompilation, also known as dynamic binary translation, is a runtime technique that translates and recompiles executable code from a source instruction set architecture (ISA) into optimized machine code for the host architecture during program execution.[6] This process enables software designed for one processor to run efficiently on another without prior static conversion, addressing compatibility across heterogeneous systems.[7] The core principles of dynamic recompilation revolve around on-the-fly translation, where blocks of guest code are dynamically decoded and mapped to equivalent host instructions as execution progresses.[6] To mitigate repeated translation overhead, recompiled code blocks are cached in memory, allowing direct execution of native code upon subsequent encounters of the same guest instructions.[7] Architectural differences, such as varying instruction sets, register counts, and endianness, are handled through mapping mechanisms that allocate host resources to emulate guest behaviors accurately, often using temporary registers or memory for state preservation.[6] At a high level, the workflow begins with detecting and fetching a block of guest code from the program's execution stream, followed by disassembly into individual instructions.[7] These are then analyzed for dependencies and control flow, after which native code stubs are generated to replicate the semantics, incorporating any necessary emulation for host-guest mismatches.[6] Unlike interpretation, which simulates each guest instruction step-by-step via a software loop, dynamic recompilation produces fully executable host code that runs directly on the processor, yielding superior performance for frequently executed paths while incurring initial translation costs.[7] This technique finds prominent use in emulators, where it facilitates the simulation of legacy hardware on modern platforms.[6]Comparison to Static Recompilation
Static recompilation, often referred to as static binary translation, involves translating an entire program's binary code from a source instruction set architecture to a target one prior to execution, typically offline or ahead-of-time.[8] This approach enables thorough analysis, such as reconstructing control flow and optimizing the full codebase, without incurring translation costs during runtime.[9] Dynamic recompilation differs fundamentally by performing translation incrementally at runtime, recompiling code blocks as they are encountered and executed.[8] While static methods provide seamless runtime performance for predictable code, they struggle with variability like conditional branches or data-dependent execution paths that only reveal themselves during program flow.[10] Dynamic approaches address this by adapting translations on-the-fly but introduce overhead from repeated recompilation and cache management, potentially slowing initial execution phases.[11] The trade-offs between these paradigms are evident in their suitability for different scenarios:| Aspect | Static Recompilation | Dynamic Recompilation |
|---|---|---|
| Execution Timing | Pre-execution translation; no runtime pauses for translation. | Runtime translation; spreads overhead but may cause minor execution interruptions. |
| Flexibility | Best for static, fully known binaries with minimal changes; limited handling of dynamic elements. | Excels in environments with runtime variability, such as branches or loaded modules. |
| Performance | Faster overall runtime due to optimized, fixed code; upfront compilation time can be lengthy for large programs. | Initial overhead from translation, but enables runtime optimizations based on execution profiles. |
| Use Cases | Ideal for batch processing or environments with low code variability. | Preferred for interactive systems or code with unpredictable behaviors. |
