jvm - 关于代码缓存区

jvm - About code cache area

这里有一些关于 JVM 中 缓存区 的问题: (for hotspot Java8)

请注意,这个问题的答案可能因实施而异:

Does all machine code that jvm could run stored in this area, or only some hot code is stored here?

代码缓存几乎总是用于缓存热门方法(或曾经被C1 + C2认为热门的方法(分层编译)

From some book, it says client compiler (C1) is more likely to run out of memory in cache area, while server compiler (C2) don't. I am a little confused about that. Is that because the server compiler only compile the hot part, and interrupt the other part? In that case, shouldn't the server compiler be slow?

C1 编译器编译一切。 C2 一直等到它找到一些可以应用的优化,然后应用这些优化并编译方法(并非总是如此,但大多数情况下)。

注意C1可以多次编译同一个方法

How many times the code is run before C1 & C2 would compile them respectively?

如果C1/C2发现需要很长时间运行,一个方法即使只调用一次也能编译通过运行。

您可以使用 JITWatch 查看 C1 和 C2 的运行情况。