< prev index next >

src/java.base/share/classes/jdk/internal/misc/Unsafe.java

Print this page
rev 51958 : 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
Reviewed-by: alanb, dfuchs, kvn
rev 51959 : resolve JDK-8211122

*** 3724,3729 **** --- 3724,3752 ---- private native int addressSize0(); private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches); private native int getLoadAverage0(double[] loadavg, int nelems); private native boolean unalignedAccess0(); private native boolean isBigEndian0(); + + /** + * Invokes the given direct byte buffer's cleaner, if any. + * + * @param directBuffer a direct byte buffer + * @throws NullPointerException if {@code directBuffer} is null + * @throws IllegalArgumentException if {@code directBuffer} is non-direct, + * or is a {@link java.nio.Buffer#slice slice}, or is a + * {@link java.nio.Buffer#duplicate duplicate} + */ + public void invokeCleaner(java.nio.ByteBuffer directBuffer) { + if (!directBuffer.isDirect()) + throw new IllegalArgumentException("buffer is non-direct"); + + DirectBuffer db = (DirectBuffer) directBuffer; + if (db.attachment() != null) + throw new IllegalArgumentException("duplicate or slice"); + + Cleaner cleaner = db.cleaner(); + if (cleaner != null) { + cleaner.clean(); + } + } }
< prev index next >