< 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


   9  * by Oracle in the LICENSE file that accompanied this code.
  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 jdk.internal.misc;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;

  29 import jdk.internal.vm.annotation.ForceInline;

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


3707     private native long allocateMemory0(long bytes);
3708     private native long reallocateMemory0(long address, long bytes);
3709     private native void freeMemory0(long address);
3710     private native void setMemory0(Object o, long offset, long bytes, byte value);
3711     @HotSpotIntrinsicCandidate
3712     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3713     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3714     private native long objectFieldOffset0(Field f);
3715     private native long objectFieldOffset1(Class<?> c, String name);
3716     private native long staticFieldOffset0(Field f);
3717     private native Object staticFieldBase0(Field f);
3718     private native boolean shouldBeInitialized0(Class<?> c);
3719     private native void ensureClassInitialized0(Class<?> c);
3720     private native int arrayBaseOffset0(Class<?> arrayClass);
3721     private native int arrayIndexScale0(Class<?> arrayClass);
3722     private native int addressSize0();
3723     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
3724     private native int getLoadAverage0(double[] loadavg, int nelems);
3725     private native boolean unalignedAccess0();
3726     private native boolean isBigEndian0();























3727 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  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 jdk.internal.misc;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.ref.Cleaner;
  30 import jdk.internal.vm.annotation.ForceInline;
  31 import sun.nio.ch.DirectBuffer;
  32 
  33 import java.lang.reflect.Field;
  34 import java.security.ProtectionDomain;
  35 
  36 
  37 /**
  38  * A collection of methods for performing low-level, unsafe operations.
  39  * Although the class and all methods are public, use of this class is
  40  * limited because only trusted code can obtain instances of it.
  41  *
  42  * <em>Note:</em> It is the resposibility of the caller to make sure
  43  * arguments are checked before methods of this class are
  44  * called. While some rudimentary checks are performed on the input,
  45  * the checks are best effort and when performance is an overriding
  46  * priority, as when methods of this class are optimized by the
  47  * runtime compiler, some or all checks (if any) may be elided. Hence,
  48  * the caller must not rely on the checks and corresponding
  49  * exceptions!
  50  *
  51  * @author John R. Rose


3709     private native long allocateMemory0(long bytes);
3710     private native long reallocateMemory0(long address, long bytes);
3711     private native void freeMemory0(long address);
3712     private native void setMemory0(Object o, long offset, long bytes, byte value);
3713     @HotSpotIntrinsicCandidate
3714     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3715     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3716     private native long objectFieldOffset0(Field f);
3717     private native long objectFieldOffset1(Class<?> c, String name);
3718     private native long staticFieldOffset0(Field f);
3719     private native Object staticFieldBase0(Field f);
3720     private native boolean shouldBeInitialized0(Class<?> c);
3721     private native void ensureClassInitialized0(Class<?> c);
3722     private native int arrayBaseOffset0(Class<?> arrayClass);
3723     private native int arrayIndexScale0(Class<?> arrayClass);
3724     private native int addressSize0();
3725     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
3726     private native int getLoadAverage0(double[] loadavg, int nelems);
3727     private native boolean unalignedAccess0();
3728     private native boolean isBigEndian0();
3729 
3730     /**
3731      * Invokes the given direct byte buffer's cleaner, if any.
3732      *
3733      * @param directBuffer a direct byte buffer
3734      * @throws NullPointerException     if {@code directBuffer} is null
3735      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
3736      *                                  or is a {@link java.nio.Buffer#slice slice}, or is a
3737      *                                  {@link java.nio.Buffer#duplicate duplicate}
3738      */
3739     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
3740         if (!directBuffer.isDirect())
3741             throw new IllegalArgumentException("buffer is non-direct");
3742 
3743         DirectBuffer db = (DirectBuffer) directBuffer;
3744         if (db.attachment() != null)
3745             throw new IllegalArgumentException("duplicate or slice");
3746 
3747         Cleaner cleaner = db.cleaner();
3748         if (cleaner != null) {
3749             cleaner.clean();
3750         }
3751     }
3752 }
< prev index next >