sun.misc.Unsafe是否在JDK9中公开? [英] Is sun.misc.Unsafe become public in JDK9?

查看:76
本文介绍了sun.misc.Unsafe是否在JDK9中公开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚尝试了JDK9,发现sun.misc.Unsafe现在不包含本机方法,而是将它们委托给某些jdk.internal.misc.Unsafe,例如:

I just tried JDK9 and found out that sun.misc.Unsafe is now containing not a native method, but delegates them to some jdk.internal.misc.Unsafe, for example:

@ForceInline
public int getInt(Object o, long offset) {
    return theInternalUnsafe.getInt(o, offset);
}

最新的实际上看起来像旧的sun.misc.Unsafe,但是现在这些方法都带有一些注释:

The latest, in turn, looks actually like the old sun.misc.Unsafe, but now the methods are annotated with some annotation:

@HotSpotIntrinsicCandidate
public native void putObject(Object o, long offset, Object x);

那么,使用Unsafe启动JDK9是否安全"?现在是公开的官方API吗?

So, is it "safe" to use Unsafe starting JDK9? Is it a public official API now?

推荐答案

以下是一个很好的解释:

Here is a good explanation:

https://adtmag.com/blogs/watersworks/2015/08/java-9-hack.aspx

在Java 9中如何处理sun.misc.Unsafe?一侧说这很简单 应当摆脱过去糟糕的过去;这 另一方则表示,大量使用Java导致了Java的兴起 基础架构空间和流行工具仍然需要它.问题 是的,双方都是正确的. ...

What to do with sun.misc.Unsafe in Java 9? One side says it's simply an awful hack from the bad old days that should be gotten rid of; the other side says its heavy use is responsible for the rise of Java in the infrastructure space and popular tools still need it. The problem is, both sides are right. ...

Reinhold在OpenJDK邮件列表中写道,建议封装 模块内不受支持的内部API,包括sun.misc.Unsafe 定义和使用它们.该建议现在是正式的Java 增强建议(JEP).本周发布的JEP 260(封装 大多数内部API")旨在制作大部分JDK的内部API 默认情况下无法访问,但保留了一些关键的,广泛使用的 内部API可以访问,直到所有版本都支持受支持的替换 或它们的大多数功能."

Writing on the OpenJDK mailing list, Reinhold proposed encapsulating unsupported, internal APIs, including sun.misc.Unsafe, within modules that define and use them. That proposal is now a formal Java Enhancement Proposals (JEP). Posted this week, JEP 260 ("Encapsulate Most Internal APIs") aims to "make most of the JDK's internal APIs inaccessible by default, but leave a few critical, widely used internal APIs accessible, until supported replacements exist for all or most of their functionality."

简短的回答:您不应在从头开始开发的任何新应用程序中使用它.

Short answer: you should NOT use it in any new application you're developing from scratch.

这篇关于sun.misc.Unsafe是否在JDK9中公开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆