Virtual Machine Native Method Handle Register Bypass
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The Java Native Interface (JNI) requires static declaration and compilation of native functions, limiting its flexibility with struct or pointer arguments, and necessitates knowledge of native languages, making it inefficient for invoking native functions using MethodHandle objects.
Innovation Solution
A reduced overhead methodology that stores arguments directly into physical registers from memory accessible by the virtual machine, using a function descriptor and Application Binary Interface (ABI) to move arguments directly into CPU registers, eliminating the need for intermediate buffers and preprocessing each argument serially based on the function descriptor and ABI.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If an intermediate buffer is used to pass arguments from Java code to native function, then flexibility with different native functions is improved, but processing overhead increases
Solution Approach 1:
The patent uses an intermediate buffer as a mediator between Java arguments and native function parameters. The buffer serves as a temporary storage location where Java arguments are placed before being moved to machine registers by assembly routines. This intermediary approach enables flexible invocation of different native functions through a generic protocol while managing the trade-off of additional processing steps.
Solution Approach 2:
The argument passing process is segmented into distinct phases: Java code places arguments in buffer slots, assembly routines move arguments from buffer to registers, and native functions execute with registered parameters. This segmentation allows for systematic handling of different argument types and enables optimization of each phase independently.
2Adaptability or versatility
If JNI is used to invoke native functions, then ability to call native code is improved, but complexity of implementation increases
Solution Approach 1:
The patent creates a universal MethodHandle-based interface that can invoke different native functions through a single generic protocol. Instead of requiring separate JNI declarations for each native function, the system uses a unified MethodHandle object that can be configured to call various native functions, reducing implementation complexity while maintaining versatility.
Solution Approach 2:
The system copies the functionality of traditional JNI into the MethodHandle framework, allowing native function invocation capabilities to be replicated through a different, more flexible mechanism. This copying approach enables the same native code calling capability to be achieved without the complexity of traditional JNI static declarations.
3Adaptability or versatility
If assembly routines are used to move arguments from buffer to registers, then ability to pass complex arguments is improved, but processing overhead increases
Solution Approach 1:
The patent replaces high-level Java argument passing mechanisms with low-level assembly routines that directly manipulate machine registers. This substitution enables precise control over argument transmission, allowing complex arguments including structs and pointers to be efficiently passed to native functions by bypassing Java's type system limitations.
Data Source
AI summary
Techniques for reducing overhead in native function calls are disclosed. The system may receive a method invocation instruction for invoking a particular method. The method invocation instruction includes a function descriptor, a method type, and an application binary interface (ABI) descriptor. The function descriptor includes a memory layout corresponding to any data returned by the function and memory layouts corresponding to each argument for the particular method. The system can select an ABI for processing the particular method based on the received ABI descriptor. The system can further associate each argument with a corresponding particular physical register into which the argument is to be loaded. The particular register is selected based on at least the selected ABI and the function descriptor. The system can cause a virtual machine to move each argument into the corresponding associated physical register.


