FFM Bound up call stub keeps JNI Global Ref to bound parameter

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Affects Version/s: 25
    • Component/s: client-libs
    • 2d

      Fonts created via Font.createFont() and then used by OpenType Layout were not being collected.
      There turned out to be a few issues here notably https://bugs.openjdk.org/browse/JDK-8337853
      But even if that is fixed the FFM-based code path to invoke the native OpenType font layout library would not allow these fonts to be collected.

      The problem turns out to be that a "bound up call stub" - ie a method handle that has one of its parameters bound to a Font2D instance it needed, keeps a JNI global reference to the bound parameter because it needs to ensure it is not collected.

      This defeats the intentions of the layout code which avoided keeping a strong reference and installed a disposer/cleaner to free resources when it became unreachable.

      But it could never become unreachable because the referenced object has this JNI global reference which defeats GC.

      Fortunately, there's a solution : scoped values.
      For other upcalls we already use scoped values, because when layout is run on text we use these because they are explicit parameters to the layout call which returns synchronously.

      However in this case, we are binding the Font2D to a long-lived "face" object which is expensive to create because it requires reading font data, parsing it sanitizing it etc. So the up call needed to know what font it is associated with.

      Somewhat fortunately (and a little tenuously) the only time this up call is needed is when running layout on a font. And that layout call already stores the Font2D using ScopedValue.

      So we can remove the bound parameter and set a local var to hold the Font2D to use from the ScopedValue.

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

              Created:
              Updated: