Segmented Code Cache in java 9 - Non-method, Profiled code and non-profiled code



Contents of page >


1) Segmented Code Cache in java 9 >
Improve performance by dividing the code cache into distinct segments, each of which contains compiled code of a particular type.


2) What's the advantage of Segmented Code Cache in java 9 ?
  1. Separate following code areas >
    • Non-method (JVM internal) code,
    • Profiled code and
    • non-profiled code.
  2. Sweep times will be short because specialized iterators can skip non-method code.
  3. Decrease fragmentation of highly-optimized code.
  4. Reduced execution time for some compilation-intensive benchmarks.
  5. Better control of JVM memory footprint.
  6. Reduced number of >
    • iTLB and
    • iCache misses.
  7. Establish a base for future extensions
    • Possibility of fine-grained locking per code heap
    • Future separation of code and metadata

3) Why we need Segmented Code Cache in java 9 ?
If compiled code is organized and maintained properly that can be a significant gain in performance.


3.1) Code cache has become very important with the introduction of tiered compilation, as compared to non-tiered compilation.


3.2) Tiered compilation also introduces >
Profiled code - a new compiled code type instrumented compiled code.


3.3) Important difference in Profiled code and non-profiled code >
Profiled Code
Non-profiled code
Profiled code has predefined, limited lifetime.
While non-profiled code potentially remains in the code cache forever

The current code-cache is optimized to handle homogeneous code ( only one type of compiled code).


4) How is code cache organized ?
The code-cache is organized as a single heap data structure on top of a contiguous chunk of memory.
Therefore, profiled code (Profiled code has predefined, limited lifetime) when mixed with non-profiled code (non-profiled code potentially remains in the code cache forever), leads to problems like >
  • Performance and
  • design problems.


5) heap for different code areas >
As we read above that we will have different/separate code areas. Let’s learn about the heap for different code areas >


    • 5.1) Non-method (JVM internal) code >
      • non-method code heap - contains compiler buffers and bytecode interpreter. This code type will stay in the code cache forever.
        • This area has fixed size of 3 MB. And remaining code cache is distributed evenly amongst profiled and non-profiled code heap.
        • VM/JVM argument (command line) arguments >
-XX:NonMethodCodeHeapSize
It sets non-method code heap size in bytes.


    • 5.2) Profiled code >
      • profiled code heap - contains code which has predefined and limited lifetime and is lightly optimized.
        • VM/JVM argument (command line) arguments >
-XX:ProfiledCodeHeapSize
It sets profiled-method code heap size in bytes.


    • 5.3) non-profiled >.
      • non-profiled code heap - contains code potentially remains in the code cache forever and is fully optimized.
        • VM/JVM argument (command line) arguments >
-XX:NonProfiledCodeHeapSize
It sets non-profiled-method code heap size in bytes.

6) Code cache is a central component of the JVM, components affected by changes to code cache >
  • Code cache sweeper - Now only iterates over the method-code heaps.
  • Tiered compilation policy - It sets compilation thresholds according to free space in code heaps
  • Java Flight Recorder (JFR) - All the events related to the code cache.
  • Indirect references from following >
    • Jhelper.d - For resolving names of compiled Java methods.
    • Pstack support library (libjvm_db.c) - Stack tracing of compiled Java methods
    • Serviceability Agent - Java interface to code-cache internals

7) Problems in Segmented Code Cache in java 9>
Keeping fixed size per code heap leads to a potential waste of memory in case one code heap is full and there is space available in another code heap.


In case of very small code cache sizes it may happen that the compilers are shut off even when space is available. For solving this problem - An option will be added to turn off the segmentation for small code-cache sizes.

For avoiding memory wastes in future version >
  • Dynamic resizing or
  • Different allocation strategies may be implemented.

Summary >
In this java tutorial we learned about Segmented Code Cache in java 9 - Non-method, Profiled code and non-profiled code in java 9.


Improve performance by dividing the code cache into distinct segments, each of which contains compiled code of a particular type. Separate following code areas >
    • Non-method (JVM internal) code,
    • Profiled code and
    • non-profiled code.

Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

RELATED LINKS>

Improve Locking performance in java 9

JVM logging system in Java 9 - Levels, tags, output, rotation, decoration


varHandle (variable handle) in java 9

Labels: Java 9
eEdit
Must read for you :