HumbleUI / Skija

Java bindings for Skia
Apache License 2.0
498 stars 34 forks source link

Backport to Java 8 #21

Closed 0-x-2-2 closed 1 year ago

0-x-2-2 commented 2 years ago

There seems to only be only one Java 9+ feature used by this project currently and usage of Java 8 for legacy projects is still significant while they slowly transition to Java 11+.

Here is an example licensed under the MIT license for abstracting the cleaner API for both Java 8 and Java 9+ support: https://github.com/aikar/cleaner

0-x-2-2 commented 2 years ago

https://twitter.com/dbg_nsk/status/1061467605221982209

The usage of Reference#reachabilityFence can be abstracted and replaced with Objects#requireNonNull or a no-op function. Hotspots JIT will still function the same but it was not defined in the spec till Java 9+ with an addition of the function in the stdlib.

public static void reachabilityFence(Object ref) {
        // Does nothing. This method is annotated with @ForceInline to eliminate
        // most of the overhead that using @DontInline would cause with the
        // HotSpot JVM, when this fence is used in a wide variety of situations.
        // HotSpot JVM retains the ref and does not GC it before a call to
        // this method, because the JIT-compilers do not have GC-only safepoints.
    }

Creating an equivalent function such as defined in Java 9+ will have the same functionality on hotspot for Java 8 but using Objects#requireNonNull may work on other JVMs such as IBM JVM if they don't function the same but that is very unlikely.

0-x-2-2 commented 2 years ago

This does seem to be enough to get the shared java sources to compile with about 10 minutes of work. Multi-release jar files may also be useful but regular abstraction will work perfectly fine and maybe is the better solution to the problem.

tonsky commented 2 years ago

Would be great if you could check with all the other JVMs before going in

0-x-2-2 commented 2 years ago

There are only two major desktop JVMs that follow spec closely but the JVM that is the most used is Hotspot. The only real way to test this is by testing the example projects before and after but it may be possible that Skija in its current form may not even work with the IBM JVM or have horrible performance such as the case with LWJGL but that may have changed.

tonsky commented 2 years ago

The test case that forced us to add reachabilityFence is described here https://github.com/JetBrains/compose-jb/issues/124

Glavo commented 1 year ago

Java 8 support is available in 0.109.0, I think we can close this issue.