Dynamic Machine Code Generation Buffering Strategy
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
In dynamic compiling environments using Just-In-Time (JIT) compilers, the intertwining of instructions and data leads to inefficient cache performance due to the need for branch instructions, which increases execution time and memory usage, as the fixed-length instruction format limits memory access and requires additional space for branch object addresses.
Innovation Solution
A method and apparatus for dynamically generating machine code that involves storing instructions and data in separate buffers and flushing them to executable code when the offset range is reached, allowing for the conversion of load-based branch instructions to PC-relative branch instructions, thereby reducing the number of branch instructions and improving cache locality.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If load-based branch instructions are used to enable branching to all memory areas, then branching versatility is improved, but memory usage and execution time increase due to additional space needed for storing branching object addresses
Solution Approach 1:
The patent segments the code generation process into two phases: instruction generation phase and memory allocation phase. During instruction generation, load-based branch instructions are temporarily used without immediate memory allocation. After memory allocation, PC-relative branch instructions are substituted where applicable. This segmentation allows versatile branching capability during code generation while optimizing memory usage after compilation.
Solution Approach 2:
The patent performs preliminary action by generating load-based branch instructions first, which provide full branching capability without immediate memory constraints. Then, after memory allocation is completed, it performs substitution with PC-relative branch instructions to optimize memory usage. This preliminary action ensures versatility is maintained during the critical code generation phase.
2Quantity of substance
If instructions and data are intertwined in executable code to maximize memory space utilization, then memory efficiency is improved, but cache performance deteriorates due to reduced locality
Solution Approach 1:
The patent applies dynamics by making the arrangement of instructions and data flexible rather than fixed. During the instruction generation phase, instructions and data can be intertwined to maximize memory space utilization. After memory allocation, the code is optimized to improve cache locality. This dynamic approach allows the system to adapt the code layout based on the execution phase and performance requirements.
3Ease of operation
If branch instructions are inserted frequently to connect code areas separated by data areas, then code connectivity is improved, but execution time increases due to additional branch operations
Solution Approach 1:
The patent changes the parameter of branch instruction type based on the execution phase. During code generation, load-based branch instructions are used which provide full connectivity. After memory allocation, the parameter is changed to use PC-relative branch instructions where possible, reducing execution time while maintaining code connectivity. This parameter change optimizes the balance between connectivity and performance.
4Quantity of substance
If PC-relative branch instructions are used to save memory space and reduce execution time, then memory efficiency and speed are improved, but branching versatility is limited to PC-relative offset range
Solution Approach 1:
The patent performs preliminary action by using load-based branch instructions during the code generation phase, which provide full branching versatility without memory constraints. After memory allocation is completed, it substitutes with PC-relative branch instructions to optimize memory efficiency. This preliminary use of versatile instructions ensures that all branching requirements can be satisfied during code generation.
Data Source
AI summary
A method and an apparatus for dynamically generating a machine code is provided, including: sequentially storing generated instructions in a first buffer; sequentially storing data in a second buffer, when the generated instructions reference data; and flushing the first buffer and the second buffer to executable code when a distance between an instruction referencing the data and the data has reached a limit of an offset range of the data-referencing instruction.


