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

(ref) Reference.clear may extend the lifetime of the referent

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b26

      Description

      Reference.clear is presently implemented as just a simple assignment:

        this.referent = null;

      There is a similar assignment in Reference.enqueue.

      For some collectors (notably G1 and Shenandoah, which are SATB collectors), this may unintentionally and undesirably extend the lifetime of the referent, even though the referent object is otherwise unreachable.

      One way to address this would be to make the interpreter, compilers, unsafe, &etc have special knowledge about writes to the referent field, just as they already have special knowledge of reads of that field.

      However, a much simpler to implement solution would be to use a native method to implement clearing the referent. This native method can use the Access API, which provides a GC-agnostic way to perform assignments of such weak references without unnecessarily keeping the object being overwritten alive for longer than needed.

      Neither Reference.clear nor Reference.enqueue seem like performance critical functions, but if necessary the clearing could be intrinsified, using the compiler's Access API mechanisms.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: