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

Use Reference.reachabilityFence in sun.java2d.Disposer.addRecord

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • client-libs
    • None
    • 2d

      sun.java2d.Disposer has been in use for 22 years and was introduced in JDK 1.4.1 and implemented under
      https://bugs.openjdk.org/browse/JDK-4525841 : RAS: (2D) should attempt to reduce or eliminate use of finalizers

      It is widely used in the desktop module to ensure release of native resources which in most cases cannot adopt a try-with-resources approach so must use a cleaner/finalize solution.

      Disposer predates java.lang.ref.Cleaner (JDK 9) by some 15 years and is very similar to it in concept and usage, except the 2D Disposer is used only internally by the desktop module.

      Disposer continues to work well and there have been no problems with it, and usage increases as we try to continue reducing reliance on finalize.

      It has been noted that under certain circumstances the Object that needs to make use of a cleaner could become unreachable even whilst under construction, and that consequently even a Disposer added in the constructor may never be enqueued for disposal because the disposer target (referent) is then also already unreachable.
       Cleaner uses reachabilityFence : https://bugs.openjdk.org/browse/JDK-8145459
      However it was further observed that it may not be in the most safe place :
      https://bugs.openjdk.org/browse/JDK-4525841

      There's no observed problem with Disposer, but adding something like this in this one location could help in some rare extreme case and give more confidence that missed clean up won't be a problem.


            prr Philip Race
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: