< prev index next >

src/jdk.unsupported/share/classes/sun/misc/Unsafe.java

Print this page

 878      * two distinct fields of the same class will ever have the same offset
 879      * and base.
 880      *
 881      * <p>As of 1.4.1, offsets for fields are represented as long values,
 882      * although the Sun JVM does not use the most significant 32 bits.
 883      * However, JVM implementations which store static fields at absolute
 884      * addresses can use long offsets and null base pointers to express
 885      * the field locations in a form usable by {@link #getInt(Object,long)}.
 886      * Therefore, code which will be ported to such JVMs on 64-bit platforms
 887      * must preserve all bits of static field offsets.
 888      *
 889      * @deprecated The guarantee that a field will always have the same offset
 890      * and base may not be true in a future release. The ability to provide an
 891      * offset and object reference to a heap memory accessor will be removed
 892      * in a future release. Use {@link VarHandle} instead.
 893      *
 894      * @see #getInt(Object, long)
 895      */
 896     @Deprecated(since="18", forRemoval=true)
 897     @ForceInline

 898     public long objectFieldOffset(Field f) {
 899         if (f == null) {
 900             throw new NullPointerException();
 901         }
 902         Class<?> declaringClass = f.getDeclaringClass();
 903         if (declaringClass.isHidden()) {
 904             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 905         }
 906         if (declaringClass.isRecord()) {
 907             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 908         }



 909         beforeMemoryAccess();
 910         return theInternalUnsafe.objectFieldOffset(f);
 911     }
 912 
 913     /**
 914      * Reports the location of a given static field, in conjunction with {@link
 915      * #staticFieldBase}.
 916      * <p>Do not expect to perform any sort of arithmetic on this offset;
 917      * it is just a cookie which is passed to the unsafe heap memory accessors.
 918      *
 919      * <p>Any given field will always have the same offset, and no two distinct
 920      * fields of the same class will ever have the same offset.
 921      *
 922      * <p>As of 1.4.1, offsets for fields are represented as long values,
 923      * although the Sun JVM does not use the most significant 32 bits.
 924      * It is hard to imagine a JVM technology which needs more than
 925      * a few bits to encode an offset within a non-array object,
 926      * However, for consistency with other methods in this class,
 927      * this method reports its result as a long value.
 928      *
 929      * @deprecated The guarantee that a field will always have the same offset
 930      * and base may not be true in a future release. The ability to provide an
 931      * offset and object reference to a heap memory accessor will be removed
 932      * in a future release. Use {@link VarHandle} instead.
 933      *
 934      * @see #getInt(Object, long)
 935      */
 936     @Deprecated(since="18", forRemoval=true)
 937     @ForceInline

 938     public long staticFieldOffset(Field f) {
 939         if (f == null) {
 940             throw new NullPointerException();
 941         }
 942         Class<?> declaringClass = f.getDeclaringClass();
 943         if (declaringClass.isHidden()) {
 944             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 945         }
 946         if (declaringClass.isRecord()) {
 947             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 948         }



 949         beforeMemoryAccess();
 950         return theInternalUnsafe.staticFieldOffset(f);
 951     }
 952 
 953     /**
 954      * Reports the location of a given static field, in conjunction with {@link
 955      * #staticFieldOffset}.
 956      * <p>Fetch the base "Object", if any, with which static fields of the
 957      * given class can be accessed via methods like {@link #getInt(Object,
 958      * long)}.  This value may be null.  This value may refer to an object
 959      * which is a "cookie", not guaranteed to be a real Object, and it should
 960      * not be used in any way except as argument to the get and put routines in
 961      * this class.
 962      *
 963      * @deprecated The guarantee that a field will always have the same offset
 964      * and base may not be true in a future release. The ability to provide an
 965      * offset and object reference to a heap memory accessor will be removed
 966      * in a future release. Use {@link VarHandle} instead.
 967      */
 968     @Deprecated(since="18", forRemoval=true)
 969     @ForceInline

 970     public Object staticFieldBase(Field f) {
 971         if (f == null) {
 972             throw new NullPointerException();
 973         }
 974         Class<?> declaringClass = f.getDeclaringClass();
 975         if (declaringClass.isHidden()) {
 976             throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
 977         }
 978         if (declaringClass.isRecord()) {
 979             throw new UnsupportedOperationException("can't get base address on a record class: " + f);
 980         }



 981         beforeMemoryAccess();
 982         return theInternalUnsafe.staticFieldBase(f);
 983     }
 984 
 985     /**
 986      * Reports the offset of the first element in the storage allocation of a
 987      * given array class.  If {@link #arrayIndexScale} returns a non-zero value
 988      * for the same class, you may use that scale factor, together with this
 989      * base offset, to form new offsets to access elements of arrays of the
 990      * given class.
 991      *
 992      * @deprecated Not needed when using {@link VarHandle} or {@link java.lang.foreign}.
 993      *
 994      * @see #getInt(Object, long)
 995      * @see #putInt(Object, long, int)
 996      */
 997     @Deprecated(since="23", forRemoval=true)
 998     @ForceInline
 999     public int arrayBaseOffset(Class<?> arrayClass) {
1000         beforeMemoryAccess();

 878      * two distinct fields of the same class will ever have the same offset
 879      * and base.
 880      *
 881      * <p>As of 1.4.1, offsets for fields are represented as long values,
 882      * although the Sun JVM does not use the most significant 32 bits.
 883      * However, JVM implementations which store static fields at absolute
 884      * addresses can use long offsets and null base pointers to express
 885      * the field locations in a form usable by {@link #getInt(Object,long)}.
 886      * Therefore, code which will be ported to such JVMs on 64-bit platforms
 887      * must preserve all bits of static field offsets.
 888      *
 889      * @deprecated The guarantee that a field will always have the same offset
 890      * and base may not be true in a future release. The ability to provide an
 891      * offset and object reference to a heap memory accessor will be removed
 892      * in a future release. Use {@link VarHandle} instead.
 893      *
 894      * @see #getInt(Object, long)
 895      */
 896     @Deprecated(since="18", forRemoval=true)
 897     @ForceInline
 898     @SuppressWarnings("preview")
 899     public long objectFieldOffset(Field f) {
 900         if (f == null) {
 901             throw new NullPointerException();
 902         }
 903         Class<?> declaringClass = f.getDeclaringClass();
 904         if (declaringClass.isHidden()) {
 905             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 906         }
 907         if (declaringClass.isRecord()) {
 908             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 909         }
 910         if (declaringClass.isValue()) {
 911             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 912         }
 913         beforeMemoryAccess();
 914         return theInternalUnsafe.objectFieldOffset(f);
 915     }
 916 
 917     /**
 918      * Reports the location of a given static field, in conjunction with {@link
 919      * #staticFieldBase}.
 920      * <p>Do not expect to perform any sort of arithmetic on this offset;
 921      * it is just a cookie which is passed to the unsafe heap memory accessors.
 922      *
 923      * <p>Any given field will always have the same offset, and no two distinct
 924      * fields of the same class will ever have the same offset.
 925      *
 926      * <p>As of 1.4.1, offsets for fields are represented as long values,
 927      * although the Sun JVM does not use the most significant 32 bits.
 928      * It is hard to imagine a JVM technology which needs more than
 929      * a few bits to encode an offset within a non-array object,
 930      * However, for consistency with other methods in this class,
 931      * this method reports its result as a long value.
 932      *
 933      * @deprecated The guarantee that a field will always have the same offset
 934      * and base may not be true in a future release. The ability to provide an
 935      * offset and object reference to a heap memory accessor will be removed
 936      * in a future release. Use {@link VarHandle} instead.
 937      *
 938      * @see #getInt(Object, long)
 939      */
 940     @Deprecated(since="18", forRemoval=true)
 941     @ForceInline
 942     @SuppressWarnings("preview")
 943     public long staticFieldOffset(Field f) {
 944         if (f == null) {
 945             throw new NullPointerException();
 946         }
 947         Class<?> declaringClass = f.getDeclaringClass();
 948         if (declaringClass.isHidden()) {
 949             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 950         }
 951         if (declaringClass.isRecord()) {
 952             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 953         }
 954         if (declaringClass.isValue()) {
 955             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 956         }
 957         beforeMemoryAccess();
 958         return theInternalUnsafe.staticFieldOffset(f);
 959     }
 960 
 961     /**
 962      * Reports the location of a given static field, in conjunction with {@link
 963      * #staticFieldOffset}.
 964      * <p>Fetch the base "Object", if any, with which static fields of the
 965      * given class can be accessed via methods like {@link #getInt(Object,
 966      * long)}.  This value may be null.  This value may refer to an object
 967      * which is a "cookie", not guaranteed to be a real Object, and it should
 968      * not be used in any way except as argument to the get and put routines in
 969      * this class.
 970      *
 971      * @deprecated The guarantee that a field will always have the same offset
 972      * and base may not be true in a future release. The ability to provide an
 973      * offset and object reference to a heap memory accessor will be removed
 974      * in a future release. Use {@link VarHandle} instead.
 975      */
 976     @Deprecated(since="18", forRemoval=true)
 977     @ForceInline
 978     @SuppressWarnings("preview")
 979     public Object staticFieldBase(Field f) {
 980         if (f == null) {
 981             throw new NullPointerException();
 982         }
 983         Class<?> declaringClass = f.getDeclaringClass();
 984         if (declaringClass.isHidden()) {
 985             throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
 986         }
 987         if (declaringClass.isRecord()) {
 988             throw new UnsupportedOperationException("can't get base address on a record class: " + f);
 989         }
 990         if (declaringClass.isValue()) {
 991             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 992         }
 993         beforeMemoryAccess();
 994         return theInternalUnsafe.staticFieldBase(f);
 995     }
 996 
 997     /**
 998      * Reports the offset of the first element in the storage allocation of a
 999      * given array class.  If {@link #arrayIndexScale} returns a non-zero value
1000      * for the same class, you may use that scale factor, together with this
1001      * base offset, to form new offsets to access elements of arrays of the
1002      * given class.
1003      *
1004      * @deprecated Not needed when using {@link VarHandle} or {@link java.lang.foreign}.
1005      *
1006      * @see #getInt(Object, long)
1007      * @see #putInt(Object, long, int)
1008      */
1009     @Deprecated(since="23", forRemoval=true)
1010     @ForceInline
1011     public int arrayBaseOffset(Class<?> arrayClass) {
1012         beforeMemoryAccess();
< prev index next >