Runtime Function Modification via JIT Code Injection
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Current techniques for runtime code modification in computing environments often alter the call stack and functionality of programs, making it difficult to modify functions without unintended side effects, especially when using just-in-time compilation and intermediate language manipulation.
Innovation Solution
The proposed solution involves using a just-in-time compilation service within a common language infrastructure to inject arbitrary code from a separate file, utilizing an event-based profiling agent to detect and modify user-selected functions at runtime, while ensuring that the injected code runs in the same stack frame as the original code, thereby mitigating changes to the call stack and functionality.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If code modification is injected into an existing program before compiling, then code coverage testing can be performed, but unintentional side effects occur such as additional calls and parameters that add overhead
Solution Approach 1:
The patent applies preliminary action by injecting the modification code at compile time rather than runtime. The modification code is prepared and integrated into the program code before execution, allowing code coverage testing to be set up in advance without adding runtime overhead. This resolves the contradiction by performing the modification work beforehand, so no additional calls or parameters are needed during program execution.
2Adaptability or versatility
If code modification is performed at runtime using JIT compilation, then functions can be modified immediately prior to execution, but the call stack and program functionality are altered
Solution Approach 1:
The patent uses an intermediary approach by introducing a modification code that acts as a bridge between the original program code and the runtime execution environment. This modification code is injected in a way that allows runtime function modification while preserving the original call stack structure. The intermediary code handles the adaptation needs without disrupting the integrity of the call stack, thus resolving the contradiction between adaptability and reliability.
3Adaptability or versatility
If arbitrary code is injected from a separate file, then function modification flexibility is increased, but the complexity of code injection and integration increases
Solution Approach 1:
The patent applies segmentation by dividing the code modification process into distinct components: the original program code, the modification code from a separate file, and the integration mechanism. This segmentation allows arbitrary code to be injected from external files while managing complexity through structured integration. The modification code is treated as a separate module that can be independently developed, tested, and integrated, reducing the overall complexity of the code injection process.
Data Source
AI summary
Modifying computer program code can be performed at or immediately prior to runtime of the computer code in a runtime environment of a common language infrastructure of a language-neutral framework for developing and executing computer applications. A function in a computer program can be modified at runtime by injecting arbitrary code, while mitigating an alteration of a program's call stack. A just-in-time compilation service is used to compile and execute intermediate language code of the program, and the runtime environment sends callback functions to an event-based profiling agent (profiler) attached to the runtime environment. The profiler can trap desired functions, as determined by configuration data, and inject modification code from stub methods in a stub assembly file. The modified code can be sent back to the runtime environment to be executed by the just-in-time compilation service.


