1

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?

aaronm
  • 11
  • 2
  • Please do not change my original question. I did not ask how to update Java 8 code to compile on Java 11. I have a business limitation of requiring to support **running** on both Java 8 JVM as well as Java 11 JVM. I am asking if some specific Java 9+ features work on Java 8 compiled code. – aaronm Jul 19 '20 at 11:32
  • Just for clarification: You want to know if a jdk8 compiled application executed on jre9+ is able to use features (even if it's just one specific) introduced with java 9? – BeWu Jul 19 '20 at 11:44
  • Correct. It is understandable the many feature (especially in-code) require Java 9 compilation. But some outside features (like GC logging for example) may not be coupled to compilation. So while it would be great to have the answer per new feature - currently i am asking specifically about the new Segmented Code Cache. – aaronm Jul 19 '20 at 12:31

1 Answers1

0

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.
Dharman
  • 30,962
  • 25
  • 85
  • 135
BeWu
  • 1,941
  • 1
  • 16
  • 22