Java -XX:-TieredCompilation 到底做了什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38721235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly does -XX:-TieredCompilation do?
提问by Markus Weninger
Using java -XX:+PrintFlagsFinal
I found the TieredCompilation
flag, and I read about it a bit online.
使用java -XX:+PrintFlagsFinal
我找到了TieredCompilation
标志,我在网上阅读了一些关于它的信息。
Yet, I still don't know exactlywhat happens when setting it to false
.
然而,我仍然不知道究竟它设置时会发生什么false
。
I know that the compilation system supports 5 execution levels, basically splitted into interpreter, C1 and C2:
我知道编译系统支持5个执行级别,基本分为interpreter,C1和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
- 0 级 - 口译员
- 级别 1 - C1 完全优化(无分析)
- 级别 2 - 带有调用和后台计数器的 C1
- 级别 3 - C1 具有完整分析(级别 2 + MDO)
- 级别 4 - C2
来源: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?
(1) 通过设置-XX:-TieredCompilation
,是否只是禁用了某些级别?如果是,是哪个?
(2) Is there some flag to decide whether to disable C1 or C2, or to not compile at all?
(2) 是否有一些标志来决定是否禁用 C1 或 C2,或者根本不编译?
采纳答案by apangin
-XX:-TieredCompilation
disables intermediate compilation tiers (1, 2, 3), so that a method is either interpreted or compiled at the maximum optimization level (C2).
-XX:-TieredCompilation
禁用中间编译层 (1, 2, 3),以便在最大优化级别 (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
作为副作用TieredCompilation
标志还会更改编译器线程的数量、编译策略和默认代码缓存大小。请注意,与TieredCompilation
禁用
- 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
.
要禁用 C2 编译器并仅保留 C1 而没有额外开销,请设置-XX:TieredStopAtLevel=1
.
To disable all JIT compilers and to run everything in interpreter, use -Xint
.
要禁用所有 JIT 编译器并在解释器中运行所有内容,请使用-Xint
.
回答by AlBlue
There are different levels of JIT, as you've noticed (including not running the JIT at all).
正如您所注意到的,有不同级别的 JIT(包括根本不运行 JIT)。
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.
在旧版本的 Java 中,您过去必须首先选择它们(例如-Xint
, -client
, -server
)才能仅使用解释器、仅使用客户端 (C1) 编译器或仅使用服务器 (C2) 编译器运行。
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 7 中的分层编译意味着热点编译器可以在这些步骤之间无缝切换。那么会发生的情况是,经过一定的运行次数后,代码将使用 C1 进行编译,然后在多次运行后,将使用 C2 进行编译。这是在逐个方法的基础上,因此当应用程序运行时,很大一部分将仅在解释器下运行(用于冷代码),然后在代码运行很多(热)之后,它将被编译为性能更高。您可以通过运行看到不同的级别
$ 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).
在-XX:-TieredCompilation
本质上是TieredCompilation=false
其手段不这样做过渡,你必须选择前面是否使用客户端或服务器编译器。JVM 会根据您的 CPU 启发式地决定应用哪种模式;如果您有多个处理器或 64 位 VM,那么它将使用服务器 VM (C2),否则它将使用客户端 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
因此-Xint
将仅使用解释器(即无编译器)运行,您可以仅选择 C1 或 C2 with-client
或-server
,以及-XX:-TieredCompilation
回答by WENPIN1
As a Java 8 user, it's recommended to disable TieredComplilation
for production use with floating point.
作为 Java 8 用户,建议禁用TieredComplilation
浮点用于生产用途。
Oracle won't fix this issue on Java8. All hotspot JVM 8 w/ G1GC have the same issue.
Oracle 不会在 Java8 上修复这个问题。所有带有 G1GC 的热点 JVM 8 都有相同的问题。