634 * Therefore, code which will be ported to such JVMs on 64-bit platforms
635 * must preserve all bits of static field offsets.
636 *
637 * @deprecated The guarantee that a field will always have the same offset
638 * and base may not be true in a future release. The ability to provide an
639 * offset and object reference to a heap memory accessor will be removed
640 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
641 *
642 * @see #getInt(Object, long)
643 */
644 @Deprecated(since="18")
645 @ForceInline
646 public long objectFieldOffset(Field f) {
647 if (f == null) {
648 throw new NullPointerException();
649 }
650 Class<?> declaringClass = f.getDeclaringClass();
651 if (declaringClass.isHidden()) {
652 throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
653 }
654 if (declaringClass.isRecord()) {
655 throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
656 }
657 return theInternalUnsafe.objectFieldOffset(f);
658 }
659
660 /**
661 * Reports the location of a given static field, in conjunction with {@link
662 * #staticFieldBase}.
663 * <p>Do not expect to perform any sort of arithmetic on this offset;
664 * it is just a cookie which is passed to the unsafe heap memory accessors.
665 *
666 * <p>Any given field will always have the same offset, and no two distinct
667 * fields of the same class will ever have the same offset.
668 *
669 * <p>As of 1.4.1, offsets for fields are represented as long values,
670 * although the Sun JVM does not use the most significant 32 bits.
671 * It is hard to imagine a JVM technology which needs more than
672 * a few bits to encode an offset within a non-array object,
673 * However, for consistency with other methods in this class,
674 * this method reports its result as a long value.
675 *
676 * @deprecated The guarantee that a field will always have the same offset
677 * and base may not be true in a future release. The ability to provide an
678 * offset and object reference to a heap memory accessor will be removed
679 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
680 *
681 * @see #getInt(Object, long)
682 */
683 @Deprecated(since="18")
684 @ForceInline
685 public long staticFieldOffset(Field f) {
686 if (f == null) {
687 throw new NullPointerException();
688 }
689 Class<?> declaringClass = f.getDeclaringClass();
690 if (declaringClass.isHidden()) {
691 throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
692 }
693 if (declaringClass.isRecord()) {
694 throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
695 }
696 return theInternalUnsafe.staticFieldOffset(f);
697 }
698
699 /**
700 * Reports the location of a given static field, in conjunction with {@link
701 * #staticFieldOffset}.
702 * <p>Fetch the base "Object", if any, with which static fields of the
703 * given class can be accessed via methods like {@link #getInt(Object,
704 * long)}. This value may be null. This value may refer to an object
705 * which is a "cookie", not guaranteed to be a real Object, and it should
706 * not be used in any way except as argument to the get and put routines in
707 * this class.
708 *
709 * @deprecated The guarantee that a field will always have the same offset
710 * and base may not be true in a future release. The ability to provide an
711 * offset and object reference to a heap memory accessor will be removed
712 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
713 */
714 @Deprecated(since="18")
715 @ForceInline
716 public Object staticFieldBase(Field f) {
717 if (f == null) {
718 throw new NullPointerException();
719 }
720 Class<?> declaringClass = f.getDeclaringClass();
721 if (declaringClass.isHidden()) {
722 throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
723 }
724 if (declaringClass.isRecord()) {
725 throw new UnsupportedOperationException("can't get base address on a record class: " + f);
726 }
727 return theInternalUnsafe.staticFieldBase(f);
728 }
729
730 /**
731 * Detects if the given class may need to be initialized. This is often
732 * needed in conjunction with obtaining the static field base of a
733 * class.
734 *
735 * @deprecated No replacement API for this method. As multiple threads
736 * may be trying to initialize the same class or interface at the same time.
737 * The only reliable result returned by this method is {@code false}
738 * indicating that the given class has been initialized. Instead, simply
739 * call {@link java.lang.invoke.MethodHandles.Lookup#ensureInitialized(Class)}
740 * that does nothing if the given class has already been initialized.
741 * This method is subject to removal in a future version of JDK.
742 *
743 * @return false only if a call to {@code ensureClassInitialized} would have no effect
|
634 * Therefore, code which will be ported to such JVMs on 64-bit platforms
635 * must preserve all bits of static field offsets.
636 *
637 * @deprecated The guarantee that a field will always have the same offset
638 * and base may not be true in a future release. The ability to provide an
639 * offset and object reference to a heap memory accessor will be removed
640 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
641 *
642 * @see #getInt(Object, long)
643 */
644 @Deprecated(since="18")
645 @ForceInline
646 public long objectFieldOffset(Field f) {
647 if (f == null) {
648 throw new NullPointerException();
649 }
650 Class<?> declaringClass = f.getDeclaringClass();
651 if (declaringClass.isHidden()) {
652 throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
653 }
654 if (f.getDeclaringClass().isPrimitiveClass()) {
655 throw new UnsupportedOperationException("can't get field offset on an inline class: " + f);
656 }
657 if (declaringClass.isRecord()) {
658 throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
659 }
660 return theInternalUnsafe.objectFieldOffset(f);
661 }
662
663 /**
664 * Reports the location of a given static field, in conjunction with {@link
665 * #staticFieldBase}.
666 * <p>Do not expect to perform any sort of arithmetic on this offset;
667 * it is just a cookie which is passed to the unsafe heap memory accessors.
668 *
669 * <p>Any given field will always have the same offset, and no two distinct
670 * fields of the same class will ever have the same offset.
671 *
672 * <p>As of 1.4.1, offsets for fields are represented as long values,
673 * although the Sun JVM does not use the most significant 32 bits.
674 * It is hard to imagine a JVM technology which needs more than
675 * a few bits to encode an offset within a non-array object,
676 * However, for consistency with other methods in this class,
677 * this method reports its result as a long value.
678 *
679 * @deprecated The guarantee that a field will always have the same offset
680 * and base may not be true in a future release. The ability to provide an
681 * offset and object reference to a heap memory accessor will be removed
682 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
683 *
684 * @see #getInt(Object, long)
685 */
686 @Deprecated(since="18")
687 @ForceInline
688 public long staticFieldOffset(Field f) {
689 if (f == null) {
690 throw new NullPointerException();
691 }
692 Class<?> declaringClass = f.getDeclaringClass();
693 if (declaringClass.isHidden()) {
694 throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
695 }
696 if (f.getDeclaringClass().isPrimitiveClass()) {
697 throw new UnsupportedOperationException("can't get static field offset on an inline class: " + f);
698 }
699 if (declaringClass.isRecord()) {
700 throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
701 }
702 return theInternalUnsafe.staticFieldOffset(f);
703 }
704
705 /**
706 * Reports the location of a given static field, in conjunction with {@link
707 * #staticFieldOffset}.
708 * <p>Fetch the base "Object", if any, with which static fields of the
709 * given class can be accessed via methods like {@link #getInt(Object,
710 * long)}. This value may be null. This value may refer to an object
711 * which is a "cookie", not guaranteed to be a real Object, and it should
712 * not be used in any way except as argument to the get and put routines in
713 * this class.
714 *
715 * @deprecated The guarantee that a field will always have the same offset
716 * and base may not be true in a future release. The ability to provide an
717 * offset and object reference to a heap memory accessor will be removed
718 * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
719 */
720 @Deprecated(since="18")
721 @ForceInline
722 public Object staticFieldBase(Field f) {
723 if (f == null) {
724 throw new NullPointerException();
725 }
726 Class<?> declaringClass = f.getDeclaringClass();
727 if (declaringClass.isHidden()) {
728 throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
729 }
730 if (f.getDeclaringClass().isPrimitiveClass()) {
731 throw new UnsupportedOperationException("can't get base address on an inline class: " + f);
732 }
733 if (declaringClass.isRecord()) {
734 throw new UnsupportedOperationException("can't get base address on a record class: " + f);
735 }
736 return theInternalUnsafe.staticFieldBase(f);
737 }
738
739 /**
740 * Detects if the given class may need to be initialized. This is often
741 * needed in conjunction with obtaining the static field base of a
742 * class.
743 *
744 * @deprecated No replacement API for this method. As multiple threads
745 * may be trying to initialize the same class or interface at the same time.
746 * The only reliable result returned by this method is {@code false}
747 * indicating that the given class has been initialized. Instead, simply
748 * call {@link java.lang.invoke.MethodHandles.Lookup#ensureInitialized(Class)}
749 * that does nothing if the given class has already been initialized.
750 * This method is subject to removal in a future version of JDK.
751 *
752 * @return false only if a call to {@code ensureClassInitialized} would have no effect
|