Executable References for Dynamic Java Native Interoperability

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

The Java Native Interface (JNI) requires static declaration and compilation of native functions, limiting its use with non-native data types like structs and pointers, and necessitates knowledge of native languages, making it cumbersome for inter-language interactions, especially when invoking native functions from Java.

Innovation Solution

The system employs a MethodHandle object to create an executable reference for native functions, allowing dynamic linking and invocation with type-safe transformations of arguments, enabling the use of native functions across different programming languages, including support for structs and pointers through memory addresses and function descriptors.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If JNI is used to invoke native functions, then interoperability between Java and native code is achieved, but the process becomes complex requiring static declaration, separate compilation, and knowledge of native languages

Engineering Contradiction:
Improveinteroperability between Java and native codeVSAvoidcomplexity of native function invocation process
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent introduces MethodHandle as an intermediary object that mediates between Java code and native functions. Instead of directly using JNI with its complex static declaration and compilation requirements, Java code creates MethodHandle objects that encapsulate the native function invocation logic. This intermediary layer simplifies the interface while maintaining the ability to call native code, thus resolving the contradiction between interoperability and complexity.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent creates executable references (MethodHandle objects) that are copies or representations of native function entries. These MethodHandle objects contain the necessary information to invoke native functions without requiring the original complex JNI setup process. By working with these copied references rather than direct native function pointers, the system achieves simpler Java-to-native integration while maintaining full interoperability capabilities.

Inventive Principle:
Principle #26Copying

2Reliability

If JNI is used with native data types, then native function calling works, but support for non-native data types like structs and pointers is limited

Engineering Contradiction:
Improvenative function calling capabilityVSAvoidsupport for non-native data types
Core Design Contradiction:
ReliabilityVSAdaptability or versatility

Solution Approach 1:

The patent transforms the parameters and data types between Java and native representations through MethodHandle. Instead of being constrained to native data types only, the system allows Java objects to be converted into appropriate native representations dynamically. This parameter transformation capability enables structs and pointers to be handled seamlessly, resolving the contradiction between reliable native function calling and support for diverse data types.

Inventive Principle:
Principle #35Parameter changes

3Ease of manufacture

If static declaration of native functions is required, then compilation is possible, but dynamic invocation and flexibility are reduced

Engineering Contradiction:
Improvecompilation capabilityVSAvoiddynamic invocation capability
Core Design Contradiction:
Ease of manufactureVSExtent of automation

Solution Approach 1:

The patent introduces dynamic MethodHandle objects that can be created and configured at runtime rather than requiring static declarations. These handles can be obtained through various means including reflection and dynamic loading, allowing the system to adapt to different native functions without recompilation. This dynamic approach maintains compilation capability while significantly enhancing runtime flexibility and automation, resolving the contradiction between static compilation requirements and dynamic invocation needs.

Inventive Principle:
Principle #15Dynamics

Data Source

PatentUS12008351B2Modeling foreign functions using executable references
Publication Date: 2024.06.11 ORACLE INT CORP
  • US12008351B2 patent drawing
  • US12008351B2 patent drawing
  • US12008351B2 patent drawing

AI summary

Techniques for representing a native function using an executable reference are disclosed. The system receives an instruction to create an executable reference for a native function, including a method type comprising a method signature corresponding to the executable reference, and a function description including (a) a memory layout corresponding to data returned by the function and (b) memory layouts corresponding to parameters required by the function. The system selects an application binary interface (ABI). The system generates code that, for each parameter, of the one or more parameters required by the function, converts the parameter from a value formatted for use by a Java Virtual machine to a value formatted for use in the native function, based on the selected ABI. Responsive to invocation of the executable reference, the generated code and the native function may be executed.