Closed 0-x-2-2 closed 1 year 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.
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.
Would be great if you could check with all the other JVMs before going in
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.
The test case that forced us to add reachabilityFence
is described here https://github.com/JetBrains/compose-jb/issues/124
Java 8 support is available in 0.109.0, I think we can close this issue.
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