< prev index next >

src/jdk.unsupported/share/classes/sun/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


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.misc;
  27 
  28 import jdk.internal.vm.annotation.ForceInline;
  29 import jdk.internal.misc.VM;
  30 import jdk.internal.ref.Cleaner;
  31 import jdk.internal.reflect.CallerSensitive;
  32 import jdk.internal.reflect.Reflection;
  33 import sun.nio.ch.DirectBuffer;
  34 
  35 import java.lang.reflect.Field;
  36 
  37 
  38 /**
  39  * A collection of methods for performing low-level, unsafe operations.
  40  * Although the class and all methods are public, use of this class is
  41  * limited because only trusted code can obtain instances of it.
  42  *
  43  * <em>Note:</em> It is the resposibility of the caller to make sure
  44  * arguments are checked before methods of this class are
  45  * called. While some rudimentary checks are performed on the input,
  46  * the checks are best effort and when performance is an overriding
  47  * priority, as when methods of this class are optimized by the
  48  * runtime compiler, some or all checks (if any) may be elided. Hence,
  49  * the caller must not rely on the checks and corresponding
  50  * exceptions!
  51  *
  52  * @author John R. Rose
  53  * @see #getUnsafe


1216      */
1217     @ForceInline
1218     public void fullFence() {
1219         theInternalUnsafe.fullFence();
1220     }
1221 
1222     /**
1223      * Invokes the given direct byte buffer's cleaner, if any.
1224      *
1225      * @param directBuffer a direct byte buffer
1226      * @throws NullPointerException if {@code directBuffer} is null
1227      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
1228      * or is a {@link java.nio.Buffer#slice slice}, or is a
1229      * {@link java.nio.Buffer#duplicate duplicate}
1230      * @since 9
1231      */
1232     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
1233         if (!directBuffer.isDirect())
1234             throw new IllegalArgumentException("buffer is non-direct");
1235 
1236         DirectBuffer db = (DirectBuffer)directBuffer;
1237         if (db.attachment() != null)
1238             throw new IllegalArgumentException("duplicate or slice");
1239 
1240         Cleaner cleaner = db.cleaner();
1241         if (cleaner != null) {
1242             cleaner.clean();
1243         }
1244     }
1245 }


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.misc;
  27 
  28 import jdk.internal.vm.annotation.ForceInline;
  29 import jdk.internal.misc.VM;

  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.Reflection;

  32 
  33 import java.lang.reflect.Field;
  34 
  35 
  36 /**
  37  * A collection of methods for performing low-level, unsafe operations.
  38  * Although the class and all methods are public, use of this class is
  39  * limited because only trusted code can obtain instances of it.
  40  *
  41  * <em>Note:</em> It is the resposibility of the caller to make sure
  42  * arguments are checked before methods of this class are
  43  * called. While some rudimentary checks are performed on the input,
  44  * the checks are best effort and when performance is an overriding
  45  * priority, as when methods of this class are optimized by the
  46  * runtime compiler, some or all checks (if any) may be elided. Hence,
  47  * the caller must not rely on the checks and corresponding
  48  * exceptions!
  49  *
  50  * @author John R. Rose
  51  * @see #getUnsafe


1214      */
1215     @ForceInline
1216     public void fullFence() {
1217         theInternalUnsafe.fullFence();
1218     }
1219 
1220     /**
1221      * Invokes the given direct byte buffer's cleaner, if any.
1222      *
1223      * @param directBuffer a direct byte buffer
1224      * @throws NullPointerException if {@code directBuffer} is null
1225      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
1226      * or is a {@link java.nio.Buffer#slice slice}, or is a
1227      * {@link java.nio.Buffer#duplicate duplicate}
1228      * @since 9
1229      */
1230     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
1231         if (!directBuffer.isDirect())
1232             throw new IllegalArgumentException("buffer is non-direct");
1233 
1234         theInternalUnsafe.invokeCleaner(directBuffer);







1235     }
1236 }
< prev index next >