The reminiscence entry strategies of Java’s solar.misc.Unsafe
class could be deprecated for elimination in a future launch of the platform, underneath a JEP (JDK Enhancement Proposal) afoot within the OpenJDK group. Of the category’s 87 strategies, 79 could be eliminated.
These unsupported strategies have had supported replacements since JDK 9, for accessing on-heap reminiscence, and JDK 22, for accessing off-heap reminiscence, the proposal states. Library builders are strongly inspired emigrate from solar.misc.Unsafe
to those supported replacements. Objectives of the proposal embody making ready for the elimination of those reminiscence entry strategies in a future Java launch and serving to builders know when their functions depend on them. It’s not a objective of the proposal to take away the solar.misc.Unsafe
class fully, as a small variety of its strategies will not be used for reminiscence entry and can stay undeprecated.
The proposal doesn’t cite a selected launch of Java that will deprecate the strategies. The subsequent model of ordinary Java, JDK 22, due in March, already has its characteristic set frozen. However JDK 23, more likely to be launched in September, may very well be a doable goal.
Previously, unsafe code was considered as required for low-level programming. The solar.misc.Unsafe
class was launched in 2002 as a method for Java lessons within the JDK to carry out low-level operations. Its reminiscence entry strategies, because the identify of the category suggests, are unsafe and may result in undefined habits, so that they weren’t uncovered as a normal API. They have been launched with the belief that they have been completely to be used inside the JDK, that callers inside the JDK would carry out exhaustive security checks earlier than utilizing them, and that protected customary APIs for the performance could be added to the Java platform, the proposal says.
However with no method in 2002 to forestall solar.misc.Unsafe
from getting used outdoors the JDK, its reminiscence entry strategies turned a “Swiss Military knife” for library builders who wished extra energy and efficiency than customary APIs may present. Sadly, not all libraries carry out security checks earlier than calling these strategies, thus presenting a danger of failures and crashes in functions.
Throughout the previous a number of years, two customary APIs have been launched as replacements for the reminiscence entry strategies in solar.misc.Unsafe
. These are java.lang.invoke
from JDK 9 and java.lang.international
from JDK 22.
Copyright © 2024 IDG Communications, Inc.