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