OpenJDK Plan Aims to Limit JNI Usage

OpenJDK Plan Aims to Limit JNI Usage

The latest Java enhancement proposal aims to maintain the Java Native Interface (JNI) as a key method for interacting with native code, but with a major shift: it will soon restrict such interactions by default.

The proposal, initially drafted in May 2023 and updated on July 16, outlines a plan to “Prepare to Restrict the Use of JNI,” and is set to be included in JDK 24, expected around March 2025. This JDK enhancement proposal (JEP) advocates for introducing warnings regarding JNI usage and making adjustments to the Foreign Function & Memory (FFM) API to ensure consistent warning messages. The intent is to alert developers about a future JDK release where JNI and FFM interactions will be disabled by default, requiring explicit activation by developers.

The proposal also aims to streamline the transition between JNI and FFM API usage, allowing library maintainers to switch from one to the other without needing to adjust command-line parameters. However, it does not aim to deprecate or remove JNI, nor does it seek to restrict how native code behaves when accessed via JNI. Native JNI functions will continue to be available as usual.

JNI was first introduced in JDK 1.1 back in February 1997 as the principal method for Java code to interface with native code, often written in C. This interface allows Java programs to invoke native methods (known as downcalls) and enables native code to call Java methods (known as upcalls). Despite its utility, JNI interactions pose potential risks to application and platform integrity. To uphold the principle of integrity by default, any JDK feature that might compromise this integrity must receive explicit developer approval.

Leave a Reply

Your email address will not be published. Required fields are marked *