Native Code Optimization via Intermediate Representation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The existing Java Native Interface (JNI) introduces significant overhead due to time-consuming indirect calls and references when accessing native code methods and heap objects, particularly for methods performing minimal computational work.
Innovation Solution
A system that optimizes native code method calls by decompiling part of the native code into an intermediate representation, combining it with the virtual machine's intermediate representation, and generating optimized native code to reduce indirect calls and references, with a focus on frequently called methods that perform little work.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If the Java Native Interface (JNI) is used to enable Java applications to access native methods, then platform-independent applications can perform low-level system operations, but significant overhead is introduced due to time-consuming indirect calls and references
Solution Approach 1:
The patent creates a copy of the native method code in the form of byte code that mirrors the native method's functionality. This byte code copy is stored in the virtual machine and can be executed directly, eliminating the need for repeated indirect calls to the original native method. The copying principle resolves the contradiction by providing a local replica that executes faster while maintaining the same adaptability.
Solution Approach 2:
The patent performs preliminary compilation of native methods into byte code during virtual machine initialization or just-in-time compilation. This preliminary action converts the native method into an intermediate representation that can be executed without subsequent indirect calls. By preparing the byte code copy in advance, the system eliminates the time-consuming indirect call overhead while preserving the ability to access native functionality.
2Adaptability or versatility
If indirect calls and references are used in JNI to maintain platform independence, then native code can manipulate heap objects in a platform-independent way, but execution performance deteriorates due to the overhead of these indirect calls
Solution Approach 1:
The patent copies the native method implementation into byte code form that is platform-independent yet executes efficiently. The byte code copy preserves the platform-independent characteristics while eliminating the performance penalty of indirect calls. This copying approach maintains adaptability across platforms while significantly improving execution speed.
Solution Approach 2:
The patent introduces byte code as an intermediary representation between native code and the virtual machine execution environment. This intermediary layer allows the system to maintain platform independence through the virtual machine while providing direct execution paths that avoid the overhead of traditional indirect calls. The byte code intermediary resolves the contradiction by serving as a efficient bridge between platform independence and execution performance.
Data Source
AI summary
One embodiment of the present invention provides a system that reduces the overhead involved in executing a native code method in an application running on a virtual machine. During operation, the system selects a call to a native code method to be optimized within the virtual machine, decompiles at least part of the native code method into an intermediate representation, and obtains an intermediate representation associated with the application. Next, the system combines the intermediate representation for the native code method with the intermediate representation associated with the application running on the virtual machine to form a combined intermediate representation, and generates native code from the combined intermediate representation, wherein the native code generation process optimizes interactions between the application running on the virtual machine and the native code method. A variation on this embodiment involves optimizing callbacks by the native code method into the virtual machine.


