LuciferYang commented on code in PR #43675:
URL: https://github.com/apache/spark/pull/43675#discussion_r1387860580
##########
core/src/main/scala/org/apache/spark/storage/StorageUtils.scala:
##########
@@ -197,13 +195,18 @@ private[spark] class StorageStatus(
/** Helper methods for storage-related objects. */
private[spark] object StorageUtils extends Logging {
- private val bufferCleaner: DirectBuffer => Unit = {
- val cleanerMethod =
- Utils.classForName("sun.misc.Unsafe").getMethod("invokeCleaner",
classOf[ByteBuffer])
- val unsafeField = classOf[Unsafe].getDeclaredField("theUnsafe")
- unsafeField.setAccessible(true)
- val unsafe = unsafeField.get(null).asInstanceOf[Unsafe]
- buffer: DirectBuffer => cleanerMethod.invoke(unsafe, buffer)
+ private val bufferCleaner: ByteBuffer => Unit = {
+ val cleanerClass = Utils.classForName("jdk.internal.ref.Cleaner")
+ val directBufferClass = Utils.classForName("sun.nio.ch.DirectBuffer")
+ val byteBufferLookup: MethodHandles.Lookup =
+ MethodHandles.privateLookupIn(directBufferClass, MethodHandles.lookup())
+ val cleanerMethod: MethodHandle = byteBufferLookup
+ .findVirtual(directBufferClass, "cleaner",
MethodType.methodType(cleanerClass))
+ val cleanerLookup: MethodHandles.Lookup =
+ MethodHandles.privateLookupIn(cleanerClass, MethodHandles.lookup())
+ val cleanMethod: MethodHandle =
+ cleanerLookup.findVirtual(cleanerClass, "clean",
MethodType.methodType(classOf[Unit]))
+ buffer: ByteBuffer => cleanMethod.invoke(cleanerMethod.invoke(buffer))
Review Comment:
Let me test several cpu models more and feedback later
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]