[ 
https://issues.apache.org/jira/browse/SPARK-24421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16680355#comment-16680355
 ] 

Alan commented on SPARK-24421:
------------------------------

The comment that sun.misc.Unsafe is private and not accessible in JDK 9 or 
newer releases is not correct. When compiling or running code on the class path 
then sun.misc.Unsafe works as it did in JDK 8 and older releases. Yes, you need 
to use core reflection to get the Unsafe instance but this is no different to 
JDK 8 and older. If developing a module then the module should `requires 
jdk.unsupported` as per the description. The jdk.unsupported module opens the 
sun.misc package so you can use reflection to get at the Unsafe instances in 
the same way as code on the class path.

As regards freeing the memory underlying of a reachable direct buffer then this 
is always a very dangerous as further access to the buffer will lead to a crash 
and security issues. So anything doing this needs to be really careful and 
immediately discard all references to the Buffer object. There is no need to 
hack private fields to get at Cleaner objects with JDK 9 or newer, instead look 
at the Unsafe invokeCleaner method which will do what you want. The comment 
(from Kris Mo?) suggests that sun.misc.Cleaner still exists in JDK 9 - that 
isn't so, it was removed in JDK 9 as part of clearing out sun.misc. So I 
suspect Kris may be looking at a JDK 8 or older build instead. The Unsafe 
invokeCleaner API works the same in the OpenJDK builds from jdk.net as it does 
with Oracle JDK builds, there are no differences.

 

 

> sun.misc.Unsafe in JDK11
> ------------------------
>
>                 Key: SPARK-24421
>                 URL: https://issues.apache.org/jira/browse/SPARK-24421
>             Project: Spark
>          Issue Type: Sub-task
>          Components: Build
>    Affects Versions: 2.3.0
>            Reporter: DB Tsai
>            Priority: Major
>
> Many internal APIs such as unsafe are encapsulated in JDK9+, see 
> http://openjdk.java.net/jeps/260 for detail.
> To use Unsafe, we need to add *jdk.unsupported* to our code’s module 
> declaration:
> {code:java}
> module java9unsafe {
>     requires jdk.unsupported;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to