Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8168804

PhantomReference should not permit referent access

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd_major
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
      gc
    • CPU:
      generic
    • OS:
      generic

      Description

      The documentation for PhantomReference says

        "... the referent of a phantom reference may not be retrieved: The
        {@code get} method of a phantom reference always returns {@code null}."

      and the documentation for get() says

        "Returns this reference object's referent. Because the referent of
        a phantom reference is always inaccessible, this method always
        returns {@code null}."

      In other words, those do not merely say that PhantomReference.get() returns null. Rather, they say there is no access path to the referent and, as a consequence, get() returns null.

      However, the current implementation allows access to the referent of a PhantomReference by either reflection (ultimately, Unsafe_GetObject or Unsafe_GetObjectVolatile) or JNI (jni_GetObjectField). Neither of these access paths does anything to recognize the field being accessed is a PhantomReference referent and block the access.

      Note that these accessors already need to recognize referent accesses in order to provide the read barrier needed by G1.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kbarrett Kim Barrett
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: