Does Java 9+ Segmented Code Cache Require Java 9+Compilation?

353 views Asked by At

Our software is still supporting clients with JVM 8 deployments, and so we are still compiling with Java 8. I am trying to find out if the Segmented Code Cache JEP197 introduced in Java 9 works on older compilations - or requires the source code to also be compiled on Java 9+.

A lot of online sources describe how great it is, but I could not find a clear defalcation whether Java 8 code can capitalize on this capability.

Does Segmented Code Cache work on Java 8 compiled code?

1

There are 1 answers

0
BeWu On

Disclaimer: I have neither real life experience for my answer nor have I tested it. It is just my assumption after reading further into the matter of Segmented Code Cache.

My conclusion: Segmented Code Caches should be used if you run a jdk8 compiled application in jre9 and jre10. But i don't know if it delivers the promised performance improvements, since I don't know if jdk9 adds hints for the jit compiler in the bytecode.

What leads me to my conclusion is the fact that the Code Cache itself is used as storage of the compiled native code. Therefore it is an integral part of the jre as is stated here:

Segmented Code Cache The code cache is the area of memory where the Java Virtual Machine stores generated native code. It is organized as a single heap data structure on top of a contiguous chunk of memory.

Instead of having a single code heap, the code cache is divided into segments, each containing compiled code of a particular type. This segmentation provides better control of the JVM memory footprint, shortens scanning time of compiled methods, significantly decreases the fragmentation of code cache, and improves performance.

Source: https://docs.oracle.com/en/java/javase/11/vm/java-hotspot-virtual-machine-performance-enhancements.html

Since the nature of the answer is rather vague I strongly advise anyone from taking it as truth. Instead i see two options:

  1. Build the application with jdk9 and target 1.8 to keep it compatible with java 8.
  2. Do the same as in the first option but use it to compare the performances and monitor code cache of the jdk8 and jdk9 compiled applications on jre9. Otherwise you can't be sure if it really uses JEP 197.