< prev index next >
src/java.base/share/classes/jdk/internal/misc/Unsafe.java
Print this page
*** 24,36 ****
--- 24,39 ----
*/
package jdk.internal.misc;
import jdk.internal.HotSpotIntrinsicCandidate;
+ import jdk.internal.ref.Cleaner;
import jdk.internal.vm.annotation.ForceInline;
+ import sun.nio.ch.DirectBuffer;
import java.lang.reflect.Field;
+ import java.nio.ByteBuffer;
import java.security.ProtectionDomain;
/**
* A collection of methods for performing low-level, unsafe operations.
*** 3249,3258 ****
--- 3252,3280 ----
} while (!weakCompareAndSwapLongAcquire(o, offset,
current, current ^ mask));
return current;
}
+ /**
+ * Deallocates the underlying memory, if any, associated with the given
+ * direct byte buffer.
+ *
+ * @param directBuffer a direct byte buffer
+ * @throws NullPointerException if {@code directBuffer} is null
+ * @throws IllegalArgumentException if {@code directBuffer} is non-direct
+ * @since 9
+ */
+ public void deallocate(ByteBuffer directBuffer) {
+ if (!directBuffer.isDirect())
+ throw new IllegalArgumentException("buffer is non-direct");
+
+ Cleaner cleaner = ((DirectBuffer)directBuffer).cleaner();
+ if (cleaner != null) {
+ cleaner.clean();
+ }
+ }
+
/**
* Ensures that loads before the fence will not be reordered with loads and
* stores after the fence; a "LoadLoad plus LoadStore barrier".
< prev index next >