Systems and methods for performing binary translation
Patent Information
- Application Number
- JP2024074501
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2021-06-09
- Filing Date
- 2024-05-01
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-06-10
AI Technical Summary
Existing methods for enabling applications written for one execution environment to run in another environment, such as through porting and rebuilding, are time and effort intensive and can introduce noticeable delays due to dynamic binary translation.
A system with a binary translator that includes a persistent translation cache and a runtime code module, managing transformations and just-in-time translations, allowing for efficient execution of applications across different instruction set architectures by caching and dynamically converting application binaries.
Facilitates seamless execution of applications across different execution environments with reduced delays and hardware overhead, maintaining application functionality and performance.
Abstract
Description
[Technical field]
[0001] FIELD OF THE DISCLOSURE Embodiments described herein relate to binary translations, and in particular to caching translated binaries in a translation cache for rapid retrieval by a system service that manages the cached translations. [Background technology]
[0002] A standard way for a developer to enable an application written for a first execution environment to run in a second execution environment is to port the application to the second execution environment, which involves rebuilding and recompiling the application for the second execution environment. Porting can take a lot of time and effort for large applications and may require a good working knowledge of the second execution environment and the correct tools to recompile for that execution environment. To bridge the gap while an application is rebuilt and recompiled, developers have often used emulators (e.g., interpreters and / or translators) to run code on a different execution environment. An interpreter typically iteratively reads application instructions in a first execution environment, or source execution environment, and performs operations in the source execution environment that are executed in a software environment in a second execution environment, or target execution environment. Other emulators operate similarly, but optimize the translation by utilizing some of the underlying hardware of the second environment. For example, an emulator may use the underlying memory as well as the underlying processor and system so that the application may appear to be running natively in the second environment, with the application running at a speed determined by the power of the underlying hardware and the performance of the interpreter. The binary translator translates the various instructions and code of the application from a first execution environment to a second execution environment.
[0003] Binary translators can typically be either static or dynamic. A static binary translator attempts to translate all application code from a first execution environment to a second execution environment without actually executing the code beforehand. Dynamic binary translation translates discrete blocks of code during execution and caches the translated blocks for use during execution of the application that contains that code. The Rosetta dynamic translation layer used to translate PowerPC applications to x86 is an example of a dynamic binary translator. Dynamic binary translators can be more accurate in that they can account for all of the code that requires translation, but they often result in greater hardware overhead during application execution due to the dynamic translation, which can cause the application to run more slowly with user-noticeable delays. Furthermore, if the application being translated includes just-in-time (JIT) compilation that requires translation, this will further include user-noticeable delays in the application as the application undergoes dynamic binary translation. Summary of the Invention
[0004] In one embodiment, the system may comprise a memory storing an operating system and one or more application binaries. The one or more application binaries may be written for execution in a first execution environment. The system may further comprise one or more processors configured to execute the application binaries in a second execution environment different from the first execution environment. The system may also comprise a binary translator comprising a system service executable in an address space separate from the application binaries and a runtime code module executable in an address space with the application binaries. The system service may be configured to manage translation of the application binaries, and the runtime code module may be configured to manage just-in-time (JIT) translation of application binaries for which the system service lacks a corresponding translation. In one embodiment, the system service may also manage library binaries (e.g., operating system provided libraries and / or user provided libraries). The system may further include a persistent translation cache stored in the memory. The persistent translation cache may store one or more translations, a given translation corresponding to at least a portion of the one or more application binaries. The one or more transformations may be for execution in a second execution environment, and the transformation of the one or more application binaries may include an object-level transformation of the one or more application binaries generated prior to execution of the one or more applications represented by the one or more application binaries, and the one or more processors may be configured to execute the cached transformation of the one or more application binaries in the runtime code module when the operating system requests execution of the one or more application binaries.
[0005] In one embodiment, the first execution environment can include a source instruction set and the second execution environment can include a target instruction set that is different from the source instruction set. In one embodiment, a code signature can be generated for each page that includes at least a portion of a transformation of one or more application binaries. A data structure that stores the code signature can be encrypted with a key that is unique to the system (e.g., a secure enclave processor and memory coupled to one or more processors can be configured to generate the unique key). In one embodiment, the object level transformation can include transformation of libraries used by one or more application binaries during execution. In one embodiment, the object level transformation can include transformation of plugins used by one or more application binaries during execution.
[0006] In one embodiment, a system service may be configured to generate a hash value based on information associated with one or more application binaries. The system service may store the generated hash value in an associative array in memory. The generated hash value may be used to determine whether the one or more application binaries are available in a persistent transform cache and to determine whether the one or more application binaries have been modified. When the one or more application binaries have been modified, the system may be configured to remove a transform for the one or more application binaries from the persistent transform cache and generate a new transform.
[0007] In one embodiment, the runtime code module may be configured to determine whether one or more application binaries corresponding to the executing translations have been made writable. When the one or more application binaries have been made writable, the system may be further configured to remove target addresses associated with the one or more application binaries from a global indirect branch table, unlink translations stored in a runtime translation cache that jump directly to the removed translations, advance a global counter, stop execution of threads associated with the one or more application binaries, force the threads associated with the one or more application binaries into a just-in-time (JIT) translation of the one or more application binaries performed by the runtime code module, and resume execution of the threads.
[0008] In one embodiment, if one or more application binaries include self-modifying code, the system may be configured to write-protect pages in memory in which the one or more application binaries are stored, trap writes to the protected pages in an exception handler, remove target addresses associated with the one or more application binaries from a global indirect branch table and jump directly to the removed translation, unlink translations stored in a runtime translation cache, advance a global counter, request a thread associated with the self-modifying code to process invalidations, perform a JIT translation of the self-modifying code, record the global counter value in metadata associated with the translation, update the execution thread to a new version of the global indirect branch table, clean the removed translation from a return stack associated with the execution thread, insert the target address of the branch into the translation via a lookup into the global indirect branch table, and release the translation when all threads have reached the global counter value.
[0009] In one embodiment, a system may include one or more processors configured to execute instructions defined in a first instruction set architecture and a non-transitory computer-accessible storage medium coupled to the one or more processors. The non-transitory computer-accessible storage medium may store one or more application binaries having instructions defined in a second instruction set architecture different from the first instruction set architecture, a persistent translation cache that stores one or more translated code sequences corresponding to one or more portions of the one or more application binaries, where the one or more translated code sequences, when executed, perform substantially the same operations as the one or more portions of the one or more application binaries perform, and a binary translator including a system service executable in an address space separate from the application binaries and a runtime code module executable in an address space together with the application binaries. The system service may be configured to manage the persistent translation cache and the runtime code module may be configured to manage just-in-time (JIT) translation of application binaries that do not have translated code sequences in the persistent translation cache.
[0010] In one embodiment, the system service may be configured to, in response to launching a given application binary of the one or more application binaries, check the persistent translation cache for a corresponding translated code sequence and provide the corresponding translated code sequence to the runtime code module based on finding the corresponding translated code sequence in the persistent translation cache. Similarly, a library used by the given application binary may have a translated sequence, and the system service may check the persistent translation cache for a translated library used by the launching application. The translated library may be provided for the launching application binary. Checking the persistent translation cache may be based on a hash value generated based on the given application / library binary. The hash value may differ from a previously generated hash value if the given application binary has been modified after the corresponding translated code sequence was generated. In one embodiment, a first translated code sequence of the one or more translated code sequences in the persistent translation cache is generated when the corresponding application binary is installed on the system. In one embodiment, a first translated code sequence of the one or more translated code sequences in the persistent translation cache is generated when the corresponding application binary is initially launched in the system. In one embodiment, a first translated code sequence of the one or more translated code sequences in the runtime translation cache is generated as a JIT translation of a corresponding application binary when the corresponding application binary was previously launched in the system.
[0011] In one embodiment, the method may include launching a first application binary for execution in a system. The first application binary may be written for a first execution environment, and one or more processors in the system may be configured to execute the application binary in a second execution environment different from the first execution environment. The method may further include determining whether a translated code sequence generated by a binary translator is stored in a persistent translation cache in the system. The binary translator may comprise a runtime code module executable in an address space of the application binary and a system service executable in a different process, and determining whether the translated code sequence is stored in the persistent translation cache may be performed by the system service. The method may further include performing a just-in-time translation of the first application binary by the runtime code module based on the translated code sequence not being cached in the translation cache. The method may further include executing the cached translated code sequence in the runtime code module based on the translated code sequence being cached in the translation cache. [Brief description of the drawings]
[0012] The following detailed description refers to the accompanying drawings, which are briefly described below.
[0013] [Figure 1] 1 is a system including a binary translator according to some embodiments.
[0014] [Diagram 2] FIG. 2 illustrates a binary conversion system within the disk storage of the system of FIG. 1 according to some embodiments.
[0015] [Diagram 3]FIG. 1 is a diagram of an embodiment of a binary conversion system in a running system memory in accordance with some embodiments.
[0016] [Figure 4] 1 is a flowchart illustrating a method for processing cached binary translations in accordance with some embodiments.
[0017] [Diagram 5] 1 is a flowchart illustrating a method for processing modifications to a binary associated with a cached transformation according to some embodiments.
[0018] [Figure 6] 1 is a flowchart illustrating a method for processing self-modifying code in accordance with some embodiments.
[0019] [Figure 7] 1 is a flowchart illustrating a method for processing modifications to an original binary corresponding to an ongoing cached transformation, according to some embodiments.
[0020] [Figure 8] 1 is a flow chart illustrating one embodiment of a method for handling exceptions or other interruptions (code stops) in translated code.
[0021] While the embodiments described in this disclosure may be susceptible to various modifications and alternative forms, specific embodiments thereof are shown by way of example in the drawings and described in detail herein. It should be understood, however, that the drawings and detailed description thereof are not intended to limit the embodiments to the particular forms disclosed, but rather, the intention is to cover all modifications, equivalents, and alternatives falling within the spirit and scope of the appended claims. The headings used herein are for organizational purposes only and are not intended to be used to limit the scope of the description. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0022] Figure 1 illustrates a system 100 including a binary translator, according to some embodiments. As illustrated in Figure 1, the system 100 includes a processor 102, a main memory 104, input / output (I / O) circuitry 106, a GPU 108, various peripherals 110, and disk storage 112. The processor 102, the system memory 104, the I / O 106, the GPU 108, the peripherals 110, and the disk storage 112 may be coupled to each other via a bus 114 such that the system components 102-112 are agents of the bus 114.
[0023] Processor 102 may include one or more cores 116-1 through 116-N and processor cache 118. In various embodiments, processor 102 may represent a general-purpose processor that performs computational operations. For example, processor 102 may be a central processing unit (CPU), such as a microprocessor, a microcontroller, an application specific integrated circuit (ASIC), or a field programmable gate array (FPGA). Processor 102 may be a stand-alone component or may be integrated on an integrated circuit with other components (e.g., other processors, or other components of a system-on-chip (SOC)). Processor 102 may be a component within a multi-chip module (MCM) with other components.
[0024] Consistent with some embodiments, the processor 102 may be configured to execute instructions defined in an execution environment, such as an instruction set architecture (ISA), implemented by the processor 102 and the processor cores 116-1-116-N. The ISA may include the original x86 ISA developed by Intel, and related x86-64 ISAs developed by AMD and Intel, the ARM and AArch64 ISAs from ARM Holdings, the Power ISA and PowerPC ISA from IBM / Motorola, the RISC-V ISA, and the like. An instruction is defined in an instruction set architecture, including its coding in memory, its operation, and its effect on registers, memory locations, and / or other processor state. A given implementation of an ISA may execute each instruction directly, although the form may be modified by decoding and other operations within the processor 102. Another implementation may decode at least some instructions into multiple instruction operations for execution by the cores 116-1-116-N. Some instructions may be microcoded, in some embodiments. Thus, the term "instruction operation" may be used herein to refer to an operation that cores 116-1 through 116-N are configured to execute as a single entity. An instruction may have a one-to-one correspondence with an instruction operation, and in some cases, an instruction operation may be an instruction. An instruction may also have a one-to-many (one-to-many) correspondence with an instruction operation. An instruction operation may be more simply referred to herein as an "op."
[0025] Cores 116-1-116-N may include various execution units, with each execution unit configured to perform various types of operations (e.g., integer, floating point, vector, multimedia, load / store, etc.). Cores 116-1-116-N may include different numbers of pipeline stages and various other performance enhancing features such as branch prediction. Cores 116-1-116-N may include one or more of an instruction decode unit, a scheduler or reservation station, a reordering buffer, a memory management unit, an I / O interface, etc.
[0026] The processor cache 118 may be a volatile or non-volatile memory. In some embodiments, the processor cache 118 may be a static random access memory (SRAM). Additional processor caches may include an instruction cache and a data cache. The processor cache 118 may be organized as a hierarchy of one or more cache levels, such as level 1 (L1), L2, L3, etc.
[0027] The processor 102 may also include a secure enclave processor (SEP) 119 in some embodiments. The SEP may be a self-contained system-on-chip (SOC) within the processor 102 that includes its own processor and one or more security peripherals. The SEP 119 may be isolated from the rest of the processor 102 such that access to the SEP 119 may be strictly controlled. For example, the processor 102 may only be able to communicate with the SEP 119 through a mailbox mechanism, where the processor 102 can write messages to the mailbox and the SEP 119 can read and respond to the messages via the mailbox.
[0028] In one embodiment, the SEP 119 can manage encryption keys for the system 100. In one embodiment, software running on the system 100 can request a key, and the system 100 can generate a "wrapped" key for the requesting software. The wrapped key is encrypted using the wrapping key, and the wrapping key is sent in hardware to the cryptographic hardware in the SEP 119. Using the wrapping key, the receiving cryptographic hardware in the SEP can decrypt the wrapped key provided by the software and obtain the actual key to be used. Insecure software may not have access to the actual key.
[0029] Disk storage 112 may include volatile and / or non-volatile memory and may function as a long-term storage device for system 100. Disk storage 112 may store one or more applications 120 that, when executed by processor 102, may cause system 100 to perform one or more steps, operations, or functions and may include software applications. Application 120 may comprise one or more binaries. Application 120 may be written for execution in a particular execution environment, such as a particular instruction set architecture. In some embodiments, the execution environment in which application 120 is written is a different execution environment than the execution environment in which processor 102 is designed to execute. In such embodiments, application 120 is considered to be written for a source execution environment, but the processor may execute in a target execution environment. As described throughout, system 100 may be capable of translating application binaries written for a first execution environment, or source execution environment, to application binaries written for a second execution environment, or target execution environment. Returning to FIG. 1, disk storage 112 may include a persistent translation cache 122 and an operating system 124. Operating system 124 may include instructions and frameworks for any well-known operating system, such as MacOS X.
[0030] More generally, the disk storage 112 and / or the main memory 104 may be examples of computer-accessible storage media. In general, computer-accessible storage media may include any storage media that is accessible by a computer when used to provide instructions and / or data to the computer. For example, computer-accessible storage media may include storage media such as magnetic or optical media, e.g., disks (fixed or removable), tapes, CD-ROMs, DVD-ROMs, CD-Rs, CD-RWs, DVD-Rs, DVD-RWs, or Blu-rays. Storage media may further include volatile or non-volatile memory media, such as RAM (e.g., Synchronous DRAM (SDRAM), Rambus DRAM (RDRAM), Static RAM (SRAM), etc.), ROM, or flash memory. Storage media may be physically installed within the computer to which it provides instructions / data. Alternatively, storage media may be connected to the computer. For example, storage media may be connected to the computer via a network or wireless link, such as network-attached storage. Storage media may be connected by a peripheral device interface, such as a universal serial bus (USB). In general, a computer-accessible storage medium may store data in a non-transitory manner, where non-transitory in this context may mean not conveying instructions / data over signals. For example, non-transitory storage may be volatile (stored instructions / data may be lost upon a power-down event) or non-volatile. A computer-accessible storage medium may store various components shown in FIG. 1, such as persistent translation cache 122, application 120, and / or operating system 124.
[0031] The I / O circuitry 106 and / or peripherals 110 may be any set of additional hardware functions included in the system 100. For example, the peripherals 110 may include video peripherals such as an image signal processor configured to process image capture data from a camera or other image sensor, a graphics processing unit (GPU) such as the GPU 108 shown in FIG. 1, a video encoder / decoder, a scaler, a rotator, a blender, a video display controller, a display such as a liquid crystal display (LCD) including a display integrated with touch sensing technology to function as an input device, a light emitting diode display (LED) such as an organic LED (OLED), a plasma display, etc. The peripherals may include audio peripherals such as a microphone, a speaker, an interface to a microphone and a speaker, an audio processor, a digital signal processor, a mixer, etc. The I / O circuitry 106 may include interface controllers for various interfaces external to the system including interfaces such as Universal Serial Bus (USB), Peripheral Component Interconnect (PCI) including PCI Express (PCIe), serial and parallel ports, etc. The peripherals may include network peripherals such as a media access controller (MAC). Any set of hardware may be included as peripherals 110 and / or I / O circuitry 106. Peripherals may include other user interface devices such as a keyboard, a mouse, or other pointing device.
[0032] Bus 114 may be an example of a communications fabric. In general, a communications fabric may be any communications interconnect and communication protocol for communicating between components of system 100. A communications fabric may be bus-based (e.g., bus 114), including shared bus configurations, crossbar configurations, and hierarchical buses with bridges. A communications fabric may also be packet-based, hierarchical with bridges, crossbar, point-to-point, or other interconnects.
[0033] The main memory 104 may include a memory controller and one or more memory devices. A memory controller may typically include circuitry for receiving memory operations from other components of the system 100 and accessing the memory devices to complete the memory operations. The memory controller may be configured to access any type of memory device. For example, the memory devices may be static random access memory (SRAM), dynamic RAM (DRAM), such as synchronous DRAM (SDRAM), including double data rate (DDR, DDR2, DDR3, DDR4, etc.) DRAM. Low power / mobile versions of DDR DRAM (e.g., LPDDR, mDDR, etc.) may be supported. The memory controller may include a queue of memory operations for ordering (and possibly reordering) the operations and presenting the operations to the memory devices. The memory controller may further include data buffers for storing write data waiting to be written to the memory devices and read data waiting to be sent back to the source of the memory operation. In some embodiments, the memory controller may include a memory cache for storing recently accessed memory data. In some cases, a memory cache may be referred to as a system cache, as opposed to a dedicated cache, such as processor cache 118, that serves only a particular component. Main memory 104 may store various code for execution, such as applications 120, corresponding translations retrieved from persistent translation cache 122, operating system 124, etc. In one embodiment, various runtime data structures may also reside in main memory 104. For example, main memory 104 may store a global indirect branch table 117.Global indirect branch table 117 may be a data structure managed by the binary translator to map indirect branch target addresses from application 120 to indirect branch target addresses in a corresponding translated code sequence.
[0034] In some embodiments, the persistent transformation cache 122 may include a translation of binaries developed or written for one execution environment to a second execution environment that is different from the first execution environment. The binaries may include executables, applications, linkers, libraries, etc. In some embodiments, the binaries may include Mach-O objects. In some embodiments, the translated binaries stored in the transformation cache may be signed using a key generated by the SEP 119 that is unique to the system 100, such that the translation is not available to the system 100 unless the translation is signed. Additionally, the persistent transformation cache 122 may reside in a read / write partition of the disk storage 112 along with the operating system 124. More specifically, the translation of a given binary, when performed by the processor 102, may cause the system 100 to perform substantially the same operations in the system 100 that the system would have performed in a system that implemented the first execution environment (e.g., ISA) in which the binary was written. Because the second execution environment is different from the first execution environment, there may be some differences in the operations. For example, in some cases, multiple instructions in an ISA implemented by processor 120 may be used to perform the same operation as a single instruction in the ISA in which the binary was written. Thus, the amount of time that elapses during execution of the binary may be different as compared to executing the original binary in its original execution environment. However, the functionality of the original binary may be maintained identical in, for example, the converted binary.
[0035] FIG. 2 illustrates a binary translation system 200 in the disk storage 112 of the system 100, according to some embodiments. As shown in FIG. 2, the binary translation system (or simply "binary translator") 200 includes a system service 202 and a runtime code module 204. In some embodiments, the runtime code module 204 is a runtime service that resides in an address space corresponding to the application 120 in the disk storage 112 and is where the translated application 120 executes in a second execution environment. The system service 202 can be responsible for managing access to the translations stored in the persistent translation cache 122 and for managing the coherency of the translations stored in the persistent translation cache 122 in the case of self-modifying or other dynamically modified code. The system service 202 can manage the scheduling of translations and can perform the translations when a cached translation does not exist or is invalidated. In particular, system service 202 may be responsible for handling calls to persistent translation cache 122, determining hash values associated with one or more binaries 206-1 through 206-N (hereafter referred to as binaries 206) of application 120, writing them to global hash table 208, and performing lookups therefrom. In some embodiments, system service 202 may handle requests to binary translator 202 via inter-process communication (IPC) calls from operating system 124. Runtime code module 204 may be responsible for handling just-in-time (JIT) translations, and may also be responsible for monitoring the state of registers updated by an application during execution (e.g., registers defined within the source ISA or execution environment in which application 120 was originally written).
[0036] 2, application 120 includes application binaries 206. As previously described, binaries 206 may include executables, applications, linkers, libraries, etc. In some embodiments, binaries 206 may include Mach-O objects. In some embodiments, disk storage may further include shared libraries and / or shared caches 210 that may store libraries and caches that may be utilized by multiple applications, services, and / or operating system 124 itself.
[0037] In some embodiments, the binaries 206 may be translated when they are installed on the system 100 via a standard or trusted installation process associated with the operating system 124. The translation process may be performed as part of the installation (e.g., the installation may not be complete until the translation is complete) or as a background process during and / or after installation. For other installations, such as via sideloading or removable disk media, the binary translator 200 may translate the binaries 206 upon first launch of the application 120 or first use of any binary 206. If a binary 206 cannot be translated due to a translation failure due to a misformation or misprediction, the runtime code module 204 includes a just-in-time (JIT) translation process that translates a smaller set of instructions associated with that binary 206 when the system 100 attempts to execute the application 120. When the operating system 124 is being updated, the system service 202 may delete all cached translations in the persistent translation cache 122 and initiate a background process to retranslate all previously cached binaries 206. Additionally, when the binary translator 200 is added to the system 100 , the binary translator 100 can translate the shared libraries and shared cache 210 associated with the operating system 124 .
[0038] To perform the conversion of the binary written for execution in the first execution environment for use in the second execution environment, the system services 202 may identify one or more entry points into the binary 206 to determine potential portions of the binary that may be code and require conversion. In some embodiments, the first execution environment may include support for variable size instructions and the second execution environment may only include support for fixed size instructions. In these embodiments, the system services 202 may not know the instruction boundaries based on the size of the instructions and may find potentially valid instructions for conversion at multiple steps along the way. The system services 202 may identify the entry points into the binary 206 using information provided by the static linker for the dynamic linker. In particular, in some embodiments, the operating system 124 may include a dynamic linker that links applications to the shared libraries 210 and places certain code at address points in the disk storage 112 where the application 120 is coded at link time, so that the application 120 can use machine specific calls or jump instructions to one of those address points when it needs to utilize the dynamic linker instead of interacting with the dynamic linker directly. System services 202 can utilize these specific address points as entry points to identify code that requires translation. Once the entry points have been identified and the code that requires translation has been identified, system services 202 can translate the identified code written for the first execution environment into code that is executable in the second execution environment. System services 202 can save the translation to a persistent translation cache 122 in disk storage 112 and update associative array 208 by performing a hash of application binary 206 and storing the hash in array 208.
[0039] 3 is a block diagram illustrating one embodiment of main memory 104 in operation. Various portions of the address space may be mapped by operating system 124 as system service space 320 and user (or non-privileged) space 322. For example, operating system 124 may define pages of memory as privileged space or user space 322 in a virtual to physical address translation mechanism as one of the page attributes in the translation. The privileged space may be the address space in which operating system 124 itself executes, or at least the kernel portion of operating system 124 in a kernel-based embodiment. User space 322 may be the space in which application 120 executes. System service space 320 may also be a user space, but separate from the address space in which translated applications execute (e.g., system services may be a different process than the translated application, but runtime code module 204 may execute in the address space of the translated application). In general, code executing within user space 322 may not be permitted to execute certain instructions that control critical processor state that operating system 124 reserves for itself.
[0040] As mentioned above, the system service 202 may execute in the system service space 320 and may maintain a persistent transformation cache 122. The persistent transformation cache 122. The persistent transformation cache 122 may be in the user space so that the transformed code may be executed by the processor 102, but access to the persistent transformation cache 122 may be controlled by the system service 202 (e.g., generating a hash and checking the transformation when a given application 120 is called for execution). Alternatively, a transformation from the persistent transformation cache 122 may be mapped into memory when the corresponding application is launched or when an entry point corresponding to the cached transformation is called. The transformation may be loaded into memory and a pointer to the transformation may be provided to the runtime code module 204. The transformation may be loaded into the address space of the application in the user space 322. If multiple threads are executing the same transformation, the transformation may be mapped into each thread's address space. Alternatively, the threads may share a common copy of the transformation. There may be other times when the transformation is loaded from the persistent transformation cache 122. For example, the dynamic linker can link various dynamically linked libraries to an application. If the dynamically linked libraries are being written for a first execution environment, the dynamic linker can request that the runtime code module 204 determine if there are any translations in the persistent translation cache 122. The runtime code module 204 can query a system service to determine if there are any translations and can determine the size of the translation. Alternatively, the dynamic linker can query the system service and provide the size to the runtime code module to allocate memory for the translated library. The dynamic linker can load the original library code and can request that the runtime code module 204 load the corresponding translations and provide a pointer to the translation.
[0041] As described above, the runtime code module 204 executes in user space 322 (or, more specifically, in the address space of the application 120 if the application 120 is written in an ISA different from the ISA of the processor 102). The runtime code module 204 may maintain a runtime translation cache 122 for JIT translations generated by the runtime code module 204 when a corresponding translation or portion thereof for the application 120 is not found in the persistent translation cache 122.
[0042] In one embodiment, the JIT transformations generated by the runtime code module 204 may also be installed as transformations in the persistent transformation cache 122. While the JIT transformations often cover small portions of the application 120 that are dynamically generated as the application is executed, if the JIT transformations begin to cover a sufficiently large portion (e.g., a threshold amount) of the overall application, the JIT transformations may be installed in the persistent transformation cache 122 by the system service 202 and retained for execution at a later time. In other embodiments, the JIT transformations may not be installed in the persistent transformation cache 122 and may thus be generated by the runtime code module 204 each time the corresponding application is invoked. In yet another embodiment, the generation of the JIT transformations may act as a hint to the binary translator 200 to consider the transformations to be installed in the persistent transformation cache 122. If the binary translator 200 determines that the transformations should be executed, the binary translator 200 may execute the transformations separately from the JIT transformations and install the separately generated transformations in the persistent transformation cache 122. Various factors can determine whether a JIT transformation causes a transformation of the persistent transformation cache 122 (e.g., how often the JIT transformation is used or generated over time during different runs of the application, whether the JIT transformation is due to self-modifying code such that the self-modifying code may not be installed in the persistent transformation cache 122, etc.).
[0043] The shared libraries / cache 210 may also be in a user space 322 or in a privileged space or combination of spaces (eg, the libraries 210 may be in a privileged space or in the user space 322 on a per library basis).
[0044] FIG. 4 is a flow chart illustrating a method 400 for processing cached binary translation, according to some embodiments. As shown in FIG. 4, when an application 120 is invoked (step 402), a check may be made to determine whether the application 120 was written for a first execution environment (step 404). In some embodiments, an application, such as application 120, may include one or more binaries 206 written for execution in a first execution environment, such as x86 or x86-64, which requires a processor capable of executing their instructions. If the application 120 is not written for the first execution environment, and instead is capable of running natively within a second execution environment, which may be, for example, ARM or AArch64, then the application 120 may run natively (step 406). If the application 120 is written for the first execution environment, then it may be passed to a system service 202 of the binary translation system 200 (step 408). In some embodiments, code for passing the application to the system service 202 may be part of the runtime code module 204. The system service 202 may calculate a hash value based on metadata associated with one or more binaries 206 of the application and / or the binaries 206 themselves, and compare the generated hash to one or more hash values in the associative array 208 to determine whether a cached translation exists in the persistent translation cache 122 or whether the expected cached translation is not available (step 410). If a match is found in the array 208, the cached translation may be used by granting (by the system service 202 to the runtime module 204) access to the cached translation. The cached translation may be mapped into memory (e.g., into the application's user address space 322 as shown in FIG. 3) using standard operating system calls (step 412).The translated application binary may then be executed in a second execution environment within the runtime code module 204 (step 414). If the hashes do not match, the application 120 may not have been previously translated. In this case, the system service 202 may initiate a background process to translate the application binary 206 (step 416) and install the resulting translation into the persistent translation cache 122. In parallel, the runtime code module 204 may generate a JIT translation of the code for the current execution. The JIT translation may be executed in a second execution environment within the runtime code module 204 (step 414).
[0045] FIG. 5 is a flow chart illustrating a method 500 for processing modifications to a binary associated with a cached translation, according to some embodiments. As shown in FIG. 5, when an application 120 is invoked (step 502), a check may be made to determine whether the application was written for a first execution environment (step 504) (e.g., similar to the embodiment of FIG. 4). In some embodiments, an application, such as application 120, may include one or more binaries 206 written for execution in a first execution environment, such as x86 or x86-64, which requires a processor capable of executing those instructions. If application 120 is not written for the first execution environment, but instead is capable of running natively within a second execution environment, which may be, for example, ARM or AArch64, then the application may run natively (step 506). If the application is written for the first execution environment, it may be passed by runtime code module 204 to system service 202 of binary translation system 200 (step 508). The system service 202 may calculate a hash value based on metadata associated with one or more binaries 206 of the application or the binaries 206 themselves, and compare the hash to one or more values in the associative array 208 to determine whether a cached translation exists in the persistent translation cache 122 or whether the application has been modified (step 510). If a match is found in the array 208, the cached translation may be used by granting access to the cached translation, which may then be mapped into memory for that particular application using standard operating system calls (step 512). The translation may be executed in the second execution environment using the runtime code module 204 (step 520). If the hashes do not match, the application 120 may have been modified and may require a new translation.In this case, the system service 202 may remove the cached translation (step 514), and the system service 202 may generate a new translation (step 516), which may then be sent to the runtime code module 204 (step 518) for execution within a second execution environment within the runtime code module 204 (step 520).
[0046] Consistent with some embodiments, the binary conversion system 200 may also manage multi-threaded resources. In some embodiments, the runtime code module 204 may use a particular time-based process to manage its resources, known as epoch-based reclamation. In epoch-based reclamation, each thread of execution on the system 100 may be associated with a current epoch that indicates when the thread last exited the runtime code module 204 and discarded any pointers to shared state. Threads may asynchronously request that other threads advance their epochs or perform one of a small number of tasks. When all threads have advanced to a sufficiently recent epoch, the shared resources may be deallocated.
[0047] FIG. 6 is a flow chart illustrating a method 600 for handling self-modifying code, according to some embodiments. Some execution environments, e.g., x86 and x86-64, allow applications to employ self-modifying code, and binary translation system 200 may also be capable of handling self-modifying code. In some embodiments, the first execution environment may actively maintain coherence between data and instruction caches, as well as between an instruction pipeline, which may invoke the self-modifying code as it is generated. To handle such self-modifying code, binary translation system 200 may first write-protect any code pages in memory of binaries 206 written for a first execution environment that have been translated into code written for a second execution environment (step 602). Then, if a write occurs, which may be either a store instruction, or an attempt to modify that page in memory via a system call, etc., system services 202 may trap the write to an exception handler in runtime code module 204 (step 604). The exception handler in the runtime code module 204 may then remove any branch targets to that page from the global indirect branch table 117 (step 606) and unlink any translations that jump directly to the affected translation (step 608). The exception handler may then advance a global epoch counter (step 610), asynchronously request that all other threads process this code invalidation (step 612), and record the advanced global epoch counter value in metadata for each of the affected translations (step 614). When processing the asynchronous requests, the other threads update to the latest version of the indirect branch table 117, clean the removed translations from their return stack caches (or simply clear the entire cache) (step 616), and enter the translated code by performing a new lookup from the indirect branch table 117 (step 618). The execution of the original thread may then continue with the trapping of the write.Once all other threads have reached the newly updated epoch, the affected transformations are released from the lock and can proceed to execution, step 620. Note that method 600, in one embodiment, may be processed by runtime code module 204 within the application's address space.
[0048] FIG. 7 is a flow chart illustrating a method 700 for processing modifications to an original binary corresponding to an executing cached translation, according to some embodiments. As shown in FIG. 6, when a cached translation is being executed within the runtime code module 204 (step 702), the runtime code module 204 may determine that the original binary corresponding to the currently executing cached translation has been made writable (step 704). In some examples, the application 120 corresponding to the cached translation may modify the binary 206 during execution by making the binary writable indicating that the binary is likely to be modified, thereby invalidating a previously cached translation of the binary 206. An exception handler within the runtime code module 204 may then remove any branch targets to that page from the global indirect branch table 117 (step 706) and unlink any translations that jump directly to the affected translation (step 708). In one embodiment, the binary translator 200 may maintain a mapping from the original (untranslated) code addresses that are translation entry points to the corresponding translations themselves. The mapping allows the binary translator 200 to efficiently execute ordered queries. When the affected translations are invalidated for writes to code in a given page, mappings for any addresses in that age can be invalidated. The exception handler can advance a global epoch counter (step 710). The runtime code module 204 can then send a message to the operating system 124 to stop all execution threads (step 712). The runtime code module 204 can then check whether any threads were executing cached translations, and if so, the runtime code module 204 forcibly redirects them to the JIT translations generated by the runtime code module 204 (step 714).For example, the thread-specific context of each thread may include a variable that indicates the last global epoch change that the thread observed. The variable may be atomically written by a thread and atomically read by other threads. The runtime code module may resume execution of all threads in a second execution environment within the runtime code module 204 (step 716). In some embodiments, the JIT transformations are not cached to disk storage 112, but are only temporarily stored within the writeable address space of the runtime code module 204.
[0049] In some embodiments, the binary translation system 200 can also handle indirect branches. In particular, indirect branch lookups can be performed using a global indirect branch table 117, where multiple threads can read the table without synchronization, but the writer takes a lock to modify the table. As the size of the table 117 grows, only threads that update their local table pointers to point to the latest version get the new version, which is done as needed when a thread returns from the runtime code module 204 to the translated code. In some embodiments, reuse of older table 117 versions (after the table has grown) is handled using epoch-based reuse. Since the table 117 is linearly probed, deletions may be handled in-place. There is a race condition where one thread may delete while another is reading, falsely detecting a cache miss. This can be handled by having the persistent translation cache 122 miss code path take the same lock used by the writer. A function return is a particular type of indirect branch that can be handled by using a software version of a return stack branch predictor. A pair of the program counter from the first execution environment and the translated program counter for the second execution environment is stored on the stack. On return, the return address is checked to see if it matches the stored address associated with the program counter of the first execution environment, and if so, the saved translated program counter is returned. Otherwise, the indirect branch operation is processed normally.
[0050] In some embodiments, when the system 100 is executing the translated application 120, the runtime code module 204 may improve the accuracy of the translation by monitoring the execution of the translated instructions to ensure that exceptions, traps, and other interruptions of instruction execution occur at instructions in the target execution environment that correspond to the start or end of an instruction in the source execution environment ("instruction boundaries"). That is, a given instruction in the source ISA may be translated into multiple instructions in the target ISA. If instruction execution in a translated instruction sequence is interrupted at one of the instructions that does not represent a source instruction boundary, the register state and / or other architectural state of the processor 102 may reflect partial execution of the source ISA instructions, which is not possible on a processor that natively executes the source ISA. For example, the operating system 124 may include various mechanisms for interrogating registers after stopping execution in a translated instruction sequence (e.g., for debugging purposes). The runtime code module 204 can monitor execution of the translated instructions to ensure that at every point of execution in the second execution environment, the runtime code module can fast-forward or rewind execution by a small number of instructions to generate the correct register state according to the first execution environment as if the binary was actually executing exactly with respect to the instruction boundaries observed in the first execution environment. In some embodiments, this process can enable execution of the translated instructions to appear to be executed atomically as if they were executed within the first execution environment instead of being executed in the second execution environment using instructions designed for the second execution environment.
[0051] 8 is a flow chart illustrating one embodiment of a method 800 for handling exceptions or other interruptions (code stops) in translated code. An exception may be a synchronous stop of code due to a condition detected with respect to an executing instruction. An interrupt may in some cases be asynchronous with instruction execution (e.g., an external interrupt sourced from a device, or an interrupt issued by another thread). An interrupt occurs when an instruction completes execution, but may be independent of the execution of that instruction. When exceptions and interrupts occur during execution of translated code, they occur between translated instructions, but may not occur at an instruction boundary of the corresponding source instruction, since there may be multiple translated instructions used to emulate the source instruction.
[0052] Thus, the translation is performed (step 802). If no code stall is detected (decision step 804, "no" branch), the translation execution can continue (step 802). On the other hand, if a code stall is detected (decision step 804, "yes" branch), the runtime code module 204 can inspect the code sequence to determine whether the code stall occurred at a source instruction boundary (step 806). For example, in one embodiment, the binary translator 200 can generate the translation according to a set of rules, such that by inspecting the code sequence (disassembling the instructions near the stall), the binary translator 200 can determine where the boundaries of a given source instruction are and what the progress of the source instructions was at the time of the stall. If the stall occurred at an instruction boundary (decision step 808, "yes" branch), the stall can be processed at the instruction boundary (step 816). If not (decision step 808, "no" branch), the runtime code module 204 may determine whether any architectural state of the source execution environment has been modified (and whether the modifications can be reversed to restore the state at the start of the source instruction) (decision step 810). If the architectural state has not been modified, or if the architectural state has been modified and reversal is possible and desirable rather than rolling forward (decision step 810, "no" branch), the runtime code module 204 may roll the state back to the beginning of the source instruction (step 820) or a halt may be processed (step 816). If the architectural state has been irreversibly modified, or if a rollback is undesirable (decision step 810, "yes" branch), the runtime code module may determine whether a roll forward is possible through the runtime code module 204 emulating the remainder of the source instruction execution and modifying the architectural state with the results of the instruction (decision step 812).If roll-forward is possible (decision step 812, "yes" branch), the runtime code module 204 may roll-forward to the next instruction boundary (block 814), and the stop may be processed at that instruction boundary (step 816). If roll-forward is not possible (decision step 812, "no" branch), execution of the translated code sequence may terminate (step 818).
[0053] The present disclosure includes references to "one embodiment" or groups of "embodiments" (e.g., "some embodiments" or "various embodiments"). Embodiments are different implementations or examples of the disclosed concepts. References to "an embodiment," "one embodiment," "a particular embodiment," etc. do not necessarily refer to the same embodiment. Numerous possible embodiments, including those specifically disclosed, are contemplated, as well as modifications or alternatives that are within the spirit or scope of the disclosure.
[0054] This disclosure may discuss potential advantages that may result from the disclosed embodiments. All implementations of these embodiments necessarily exhibit some or all of the potential advantages. Whether advantages are realized for a particular implementation depends on many factors, some of which are outside the scope of this disclosure. Indeed, there are many reasons why an implementation within the scope of the claims may not exhibit some or all of any disclosed advantages. For example, a particular implementation may include other circuitry outside the scope of this disclosure that, in conjunction with one of the disclosed embodiments, nullifies or reduces one or more of the disclosed advantages. Furthermore, suboptimal design practices of a particular implementation (e.g., implementation techniques or tools) may also nullify or reduce the disclosed advantages. Even assuming skilled execution, realization of advantages may still depend on other factors, such as the environmental conditions in which the implementation is deployed. For example, inputs provided to a particular implementation may prevent one or more of the problems addressed in this disclosure from occurring on a particular occasion, such that the benefits of the solution may not be realized. Given the existence of factors external to the present disclosure that may arise, it is expressly intended that any potential advantages described herein should not be construed as claim limitations that must be met in order to demonstrate infringement. Rather, the identification of such potential advantages is intended to illustrate the types of improvements available to a designer having the benefit of the present disclosure. The fact that such advantages are permissibly described (e.g., a statement that a particular advantage "may result") is not intended to convey any doubt as to whether such advantage may actually be realized, but rather is intended to recognize the technological reality that realization of such advantages often depends on additional factors.
[0055] Unless otherwise stated, the embodiments are non-limiting. That is, the disclosed embodiments are not intended to limit the scope of the claims made based on this disclosure, even if only a single example is described with respect to a particular feature. The disclosed embodiments are intended to be illustrative, not limiting, unless otherwise stated in the disclosure. The above description is intended to enable claims that cover not only the disclosed embodiments, but also alternatives, modifications, and equivalents that will be apparent to those skilled in the art having the benefit of this disclosure.
[0056] For example, features of the present application may be combined in any suitable manner. Accordingly, new claims may be formulated during prosecution of this application (or an application claiming priority to this application) for any such combination of features. In particular, with reference to the appended claims, features from dependent claims may be combined with features of other dependent claims, including claims that are dependent on other independent claims, as appropriate. Similarly, features from each independent claim may be combined as appropriate.
[0057] Thus, the accompanying dependent claims may each be drafted to be dependent on a single other claim, although additional dependencies are also contemplated. Any combination of features in the dependent claims consistent with this disclosure is contemplated and may be claimed in this or another application. In summary, combinations are not limited to those specifically recited in the accompanying claims.
[0058] Where appropriate, it is contemplated that a claim drafted in one format or statutory type (e.g., apparatus) is also intended to support a corresponding claim in another format or statutory type (e.g., method).
[0059] Because this disclosure is a legal document, various terms and phrases may be subject to administrative and judicial interpretation. The definitions provided in the following paragraphs, as well as throughout this disclosure, are hereby publicly advised to be used in interpreting any claims made based on this disclosure.
[0060] Reference to a singular item (i.e., a noun or noun phrase preceded by "a," "an," or "the") is intended to mean "one or more" unless the context clearly indicates otherwise. Thus, a reference to an "item" in a claim does not exclude additional instances of the item without the context requiring otherwise. A "plurality" of an item refers to a set of two or more items.
[0061] The word "may" is used herein in a permissive sense (i.e., having the possibility, being able to) and not in an obligatory sense (i.e., not required).
[0062] The terms "comprising" and "including" and their forms are open ended and mean "including, but not limited to."
[0063] When the term "or" is used in this disclosure in reference to a list of alternatives, it will generally be understood to be used in an inclusive sense unless the context clearly indicates otherwise. Thus, a list of "x or y" is equivalent to "x or y, or both," and thus encompasses 1) x but not y, 2) y but not x, and 3) both x and y. On the other hand, the phrase "either x or y, but not both" makes it clear that "or" is used in an exclusive sense.
[0064] The enumeration of "w, x, y, z, or any combination thereof," or "at least one of ... w, x, y, and z" is intended to cover all possibilities including a single element up to the total number of elements in the set. For example, for the set [w, x, y, z], these expressions cover any single element of the set (e.g., w but not x, y, or z), any two elements (e.g., w and x but not y or z), any three elements (e.g., w, x, and y but not z), and all four elements. Thus, the phrase "at least one of ... w, x, y, and z" refers to at least one element of the set [w, x, y, z], thereby covering all possible combinations in this list of elements. This phrase should not be interpreted as requiring that there be at least one instance of w, at least one instance of x, at least one instance of y, and at least one instance of z.
[0065] In this disclosure, various "labels" may precede a noun or noun phrase. Unless the context clearly indicates otherwise, the various labels used for a feature (e.g., "first circuit," "second circuit," "particular circuit," "given circuit," etc.) refer to different instances of the feature. Furthermore, when applied to features, the labels "first," "second," and "third" do not imply any type of ordering (e.g., spatial, temporal, logical, etc.) unless otherwise specified.
[0066] As used herein, the phrase "based on" is used to describe one or more factors that influence the determination. This term does not exclude the possibility that additional factors may influence the decision. That is, the decision may be based only on the specified factors or based on the specified factors as well as other unspecified factors. Consider the phrase "determining A based on B." This phrase specifies that B is a factor that is used to determine A or that influences the determination of A. This phrase does not exclude that the determination of A may also be based on some other factor, such as C. This phrase is intended to cover embodiments in which A is determined solely based on B. As used herein, the phrase "based on" is synonymous with the phrase "based at least in part on."
[0067] The phrases "in response to" and "in response to" recite one or more factors that trigger an effect. This phrase does not exclude the possibility that additional factors may affect or otherwise trigger the effect, either together with the particular factor or independent of the specified factor. That is, the effect may be in response only to these factors or to the specified factors as well as other unspecified factors. Consider the phrase "performing A in response to B." By this phrase, B is a factor that triggers the execution of A or triggers a particular outcome for A. This phrase does not exclude that the execution of A may also be in response to other factors, such as C. This phrase also does not exclude that the execution of A may be in response to both B and C. This phrase is intended to cover embodiments in which A is performed only in response to B. As used herein, the phrase "in response to" is synonymous with the phrase "at least partially in response to." Similarly, the phrase "in response to" is synonymous with the phrase "at least partially in response to."
[0068] Within this disclosure, various entities (which may be variously referred to as "units," "circuits," other components, etc.) may be described or claimed as being "configured" to perform one or more tasks or operations. The phrase "entity" configured to perform one or more tasks is used herein to refer to structures (i.e., physical things). More specifically, the phrase is used to indicate that the structure is arranged to perform one or more tasks during operation. A structure may be said to be "configured to perform" some task even if the structure is not currently operating. Thus, an entity described or explained as being "configured" to perform some task refers to a physical thing, such as a device, a circuit, a system having a processor unit and a memory that stores executable program instructions to perform the task. The phrase is not used herein to refer to intangible things.
[0069] In some cases, various units / circuits / components may be described herein as performing a set of tasks or operations, and even if not specifically described, it will be understood that those entities are "configured to" perform those tasks / operations.
[0070] The term "configured to" is not intended to mean "configurable to." For example, an unprogrammed FPGA is not considered to be "configured" to perform a particular function. However, this unprogrammed FPGA may be "configurable" to perform that function. After appropriate programming, the FPGA can then be said to be "configured" to perform a particular function.
[0071] For purposes of filing a U.S. patent application based on this disclosure, reciting a claim as a structure "configured to" perform one or more tasks is not expressly intended to invoke 35 U.S.C. §112(f) for that claim element. If an applicant wishes to invoke 35 U.S.C. §112(f) during prosecution of a U.S. patent application based on this disclosure, it would be to recite a claim element using "means for [performing a function]."
[0072] Various "circuits" may be described in this disclosure. These circuits or "circuitry" constitute hardware including various types of circuit elements such as combinational logic, clocked storage devices (e.g., flip-flops, registers, latches, etc.), finite state machines, memories (e.g., random access memory, embedded dynamic random access memory), programmable logic arrays, etc. Circuits may be custom designed or obtained from standard libraries. In various implementations, circuitry may include digital components, analog components, or a combination of both, as appropriate. Certain types of circuits may be generally referred to as "units" (e.g., decoding units, arithmetic logic units (ALUs), functional units, memory management units (MMUs), etc.). Such units may also be referred to as circuits or circuitry.
[0073] The disclosed circuits / units / components and other elements shown in the drawings and described herein include hardware elements such as those described in the preceding paragraphs. Often, the internal arrangement of hardware elements within a particular circuit may be specified by describing the function of that circuit. For example, a particular "decode unit" may be described as performing the function of "processing the opcode of an instruction and routing the instruction to one or more of a plurality of functional units," meaning that the decode unit is "configured" to perform this function. Description of this function is sufficient to suggest to one skilled in the computer arts a set of possible configurations of the circuit.
[0074] In various embodiments, as discussed in the previous paragraph, circuits, units, and other elements are defined by the functions or operations they are configured to perform. The arrangement of such circuits / units / components relative to one another and the way in which they interact creates a microarchitectural definition of the hardware that is ultimately fabricated in an integrated circuit or programmed into an FPGA to form the physical implementation of the microarchitectural definition. Thus, a microarchitectural definition is recognized by those skilled in the art as a structure from which many physical implementations can be derived, all of which belong to the broader structure described by the microarchitectural definition. That is, a person skilled in the art presented with a microarchitectural definition provided in accordance with this disclosure may, without undue experimentation, use ordinary skill to implement the structure by coding the description of the circuit / unit / component into a hardware description language (HDL), such as Verilog or VHDL. HDL descriptions are often expressed in a manner that appears to be functional. However, to those skilled in the art, this HDL description is the method used to translate the structure of the circuit, unit, or component into the next level of implementation details. Such HDL descriptions may take the form of behavioral code (typically not synthesizable), register transfer language (RTL) code (typically synthesizable, as opposed to behavioral code), or structural code (e.g., a netlist specifying logic gates and their connections). The HDL description may be synthesized against a library of cells designed for a given integrated circuit manufacturing technology, and modified for timing, power, and other reasons, resulting in a final design database that can be sent to a foundry to generate masks and ultimately manufacture the integrated circuit. Some hardware circuits, or portions thereof, may also be custom designed in a schematic editor and incorporated into the integrated circuit design along with the synthesized circuit. The integrated circuit may further include transistors and other circuit elements (e.g., passive elements such as capacitors, resistors, inductors, etc.), as well as interconnects between the transistors and the circuit elements.Some embodiments may implement multiple integrated circuits connected together to realize the hardware circuit, and / or some embodiments may use discrete elements. Alternatively, the HDL design may be integrated into and implemented in a programmable logic array, such as a field programmable gate array (FPGA). This decoupling between the design of circuits and the subsequent low-level implementation of those circuits typically results in a scenario where the circuit or logic designer does not specify any particular set of structures for the low-level implementation other than describing how the circuit is structured, since this process is performed at a different stage of the circuit implementation process.
[0075] The fact that many different low-level combinations of circuit elements can be used to implement the same specification for a circuit results in numerous equivalent structures for that circuit. As noted above, these low-level circuit implementations may vary depending on changes in manufacturing technology, the foundry selected to manufacture the integrated circuit, the libraries of cells provided for a particular project, etc. In many cases, the choices made by different design tools or methods to generate these different implementations may be arbitrary.
[0076] Furthermore, for a given embodiment, it is common for a single implementation of a particular functional specification of a circuit to include a large number of devices (e.g., millions of transistors). This absolute amount of information therefore makes it impractical to exhaustively enumerate the low-level structures used to implement a single embodiment, let alone the vast amount of equivalent possible implementations. For this reason, this disclosure describes the structure of a circuit using functional abbreviations used in the industry.
[0077] Numerous variations and modifications will become apparent to those skilled in the art once the above disclosure is fully appreciated, and it is intended that the following claims be interpreted to embrace all such variations and modifications.
Claims
1. A system comprising: a memory storing one or more application binaries, the one or more application binaries being written for execution in a first execution environment; one or more processors configured to execute application binaries in a second execution environment different from the first execution environment; 1. A binary translator, comprising: Managing the conversion of said application binaries; a binary translator configured to manage just-in-time (JIT) translation of the application binaries for which the binary translator lacks a corresponding translation; a transformation cache stored within the memory and configured to store one or more transformations, a given transformation corresponding to at least a portion of the one or more application binaries, the one or more transformations being for execution in the second execution environment; The binary translator is configured to determine whether the one or more application binaries corresponding to the translation have been made writable, and if the one or more application binaries have been made writable, the system: removing a translation associated with the one or more application binaries from a global indirect branch table; unlinking a transformation stored in the transformation cache that jumps directly to the removed transformation; Stopping the execution of threads associated with the one or more application binaries; forcing the thread associated with the one or more application binaries into JIT translation of the one or more application binaries; The system is further configured to resume the execution of the thread.
2. The system of claim 1, wherein when the one or more application binaries are made writable, the system is further configured to advance a global counter used to deallocate shared resources.
3. The binary translator is further configured to maintain a mapping of untranslated code addresses that are translation entry points to corresponding translations; 2. The system of claim 1, wherein when the one or more application binaries are made writable, the system is further configured to invalidate the mapping of untranslated code addresses associated with the one or more application binaries.
4. The system of claim 1, wherein after resuming the execution of the thread, the JIT translation of the thread is not stored in the translation cache.
5. The system of claim 1, wherein the one or more processors are configured to perform the cached translation of the one or more application binaries within a runtime code module of the binary translator that determines whether the one or more application binaries corresponding to the ongoing translation are made writable.
6. The system described in claim 5, wherein the exception handler of the runtime code module removes translations associated with the one or more application binaries from the global indirect branch table.
7. The binary translator system service comprises: generating a hash value based on information associated with the one or more application binaries; 2. The system of claim 1, configured to: store the generated hash value in an associative array in the memory, the generated hash value being used to determine whether the one or more application binaries are available in the translation cache and to determine whether the one or more application binaries have been modified.
8. The system of claim 1, wherein the transformation of the one or more application binaries is signed using a key unique to the system.
9. The system of claim 1, wherein the transformation of the one or more application binaries is encrypted with a key unique to the system.
10. A secure enclave processor coupled to the one or more processors and the memory, the secure enclave processor configured to generate the unique key. The system according to claim 8 or 9, further comprising:
11. The system of claim 1, wherein the conversion of the one or more application binaries includes an object-level conversion of the one or more application binaries generated prior to execution of one or more applications represented by the one or more application binaries.
12. The system of claim 11, wherein the object-level conversion includes conversion of libraries used by the one or more application binaries during execution.
13. A computer-implemented method, comprising: launching a first application binary for execution in a system, the first application binary being written for a first execution environment, and one or more processors in the system being configured to execute the application binary in a second execution environment different from the first execution environment; determining whether a translated code sequence produced by a binary translator is stored in a translation cache within the system; executing the cached transformed code sequence based on the transformed code sequence being cached in the transformation cache; In response to the binary translator determining that the first application binary has been made writable, removing a translation associated with the first application binary from a global indirect branch table; unlinking a transformation stored in the transformation cache that jumps directly to the removed transformation; Stopping the execution of a thread associated with the first application binary; forcing the thread associated with the first application binary into a just-in-time (JIT) translation of the first application binary; resuming the execution of the thread; and A method comprising:
14. In response to the binary translator determining that the first application binary has been made writable, advancing a global epoch counter. The method of claim 13 further comprising:
15. A method for implementing a translation-based method comprising: maintaining a mapping of untranslated code addresses that are translation entry points to corresponding translations; In response to the binary translator determining that the first application binary has been made writable, invalidating the mapping of untranslated code addresses associated with the first application binary; The method of claim 13 further comprising:
16. The method of claim 13, wherein determining whether the translated code sequence is stored in the translation cache is based on a hash value generated based on the first application binary.
17. The method of claim 13, wherein after resuming the execution of the thread, JIT translations for the thread are not stored in the translation cache.
18. The method of claim 13, wherein the converted code sequence is generated when the first application binary is initially installed on the system.
19. The method of claim 13, wherein the converted code sequence is generated when the first application binary is first launched on the system.
20. The method of claim 13, wherein the transformed code sequence is generated as a JIT transformation of a corresponding application binary when the corresponding application binary was previously launched on the system.
