What exactly does -XX:-TieredCompilation do?
Asked Answered
T

3

84

Using java -XX:+PrintFlagsFinal I found the TieredCompilation flag, and I read about it a bit online.

Yet, I still don't know exactly what happens when setting it to false.

I know that the compilation system supports 5 execution levels, basically splitted into interpreter, C1 and C2:

  • level 0 - interpreter
  • level 1 - C1 with full optimization (no profiling)
  • level 2 - C1 with invocation and backedge counters
  • level 3 - C1 with full profiling (level 2 + MDO)
  • level 4 - C2

Source: http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/file/2b2511bd3cc8/src/share/vm/runtime/advancedThresholdPolicy.hpp#l34

Two questions:

(1) By setting -XX:-TieredCompilation, are some of this levels just disabled? If yes, which?

(2) Is there some flag to decide whether to disable C1 or C2, or to not compile at all?

Truckle answered 2/8, 2016 at 13:3 Comment(0)
H
94

-XX:-TieredCompilation disables intermediate compilation tiers (1, 2, 3), so that a method is either interpreted or compiled at the maximum optimization level (C2).

As a side effect TieredCompilation flag also changes the number of compiler threads, the compilation policy and the default code cache size. Note that with TieredCompilation disabled

  • there will be less compiler threads;
  • simple compilation policy (based on method invocation and backedge counters) will be chosen instead of advanced compilation policy;
  • default reserved code cache size will be 5 times smaller.

To disable C2 compiler and to leave only C1 with no extra overhead, set -XX:TieredStopAtLevel=1.

To disable all JIT compilers and to run everything in interpreter, use -Xint.

Henricks answered 2/8, 2016 at 13:34 Comment(3)
Thanks! Now I'm a bit confused, because I have different answers: Will setting -XX:-TieredCompilation now (1.) disable C1 and always compile to the max (C2) or (2.) lead the JVM to heuristically decide which compilation tiers to disable based on the CPU (as stated by @AlBlue)? It also makes it hard for me to decide, which to accept as correct answer :PTruckle
@MarkusWeninger I've commented under AlBlue's answer. It's not very accurate.Henricks
Thanks, I just saw it. In the second comment you mention TierXCompileThreshold and -XX:CompilationPolicyChoice=2, two new things I still don't know about, but I will read about them. :P But the first comment explains my question very well.Truckle
Y
28

There are different levels of JIT, as you've noticed (including not running the JIT at all).

In older versions of Java, you used to have to select them at first (e.g. -Xint, -client, -server) to run with just interpreter, with just the client (C1) compiler, or just the server (C2) compiler.

Tiered compilation, which came in with Java 7, meant that the hotspot compiler could shift between those steps seamlessly. So what happens is that after a certain amount of runs, the code will be compiled with C1, and then after more runs, it will be compiled with C2. This is on a method-by-method basis, so when an app is running a significant portion will just be running under interpreter (which is for cold code) and then after code is run a lot (hot) then it will be compiled to be more performant. You can see the different levels by running

$ java -XX:+PrintFlagsFinal -version | grep CompileThreshold
intx Tier2CompileThreshold                     = 0
intx Tier3CompileThreshold                     = 2000
intx Tier4CompileThreshold                     = 15000
openjdk version "1.8.0_92"
OpenJDK Runtime Environment (Zulu 8.15.0.1-macosx) (build 1.8.0_92-b15)
OpenJDK 64-Bit Server VM (Zulu 8.15.0.1-macosx) (build 25.92-b15, mixed mode)

The -XX:-TieredCompilation is essentially TieredCompilation=false which means don't do this transition, and you have to select up front whether to use the client or server compiler. The JVM heuristically decides which mode to apply based on your CPU; if you have multiple processors or a 64-bit VM then it will use a Server VM (C2), otherwise it will use a Client VM (C1).

So -Xint will run with just the interpreter (i.e. no compiler) and you can select either only C1 or C2 with -client or -server respectively, along with the -XX:-TieredCompilation

Yachting answered 2/8, 2016 at 13:13 Comment(5)
Thanks, -Xint, -client and -server were the flags I've been looking for.Truckle
I talked a little bit about the compilation levels in speakerdeck.com/alblue/hotspot-under-the-hood if you want to go deeper down the rabbit hole :)Yachting
Thanks, I will have a look at it! :)Truckle
@MarkusWeninger -client and -server flags are just ignored in modern versions of JDK. Use -XX:-TieredCompilation or -XX:TieredStopAtLevel=1 to disable C1 or C2 respectively.Henricks
TierXCompileThreshold flags are not used with Tiered Compilation unless SimpleThresholdPolicy is explicitly chosen with -XX:CompilationPolicyChoice=2.Henricks
D
5

As a Java 8 user, it's recommended to disable TieredComplilation for production use with floating point.

Oracle won't fix this issue on Java8. All hotspot JVM 8 w/ G1GC have the same issue.

(Bug1) (Bug2)

Donal answered 13/6, 2018 at 2:15 Comment(3)
Bugs are fixed as of Java 9.Admonish
And how does one disable tieredCompilation? -XX:-TieredCompilation and what do you use with floating point?Materialize
These bugs are fixed in 8u192 and 8u201, so it’s safe to use in Java 8 nowYachting

© 2022 - 2024 — McMap. All rights reserved.