gpt4 book ai didi

java - 关于HotSpot动态反优化

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:41:58 25 4
gpt4 key购买 nike

在看《Scala in depth》这本书的时候,提到HotSpot编译器有几个重要的特性,其中之一就是“Dynamic De-Optimization”:

It is the ability to determine if an optimization did not, in fact, improve performance and undo that optimization,allowing others to be applied

HotSpot 似乎会尝试各种“优化”,并从中选择最好的一个。

但是我不是很明白。这里的“优化”都是HotSpot提供的吗?我的意思是程序员经常尝试使用一些技巧来优化代码,HotSpot 会处理它们吗?

HotSpot 是否会尝试任何常见的“优化”?

最佳答案

Oracle 提供了一个 (rather concise) summary of this performance techniques applied by the JVM .它解释说:

Deoptimization is the process of changing an optimized stack frame to an unoptimized one. With respect to compiled methods, it is also the process of throwing away code with invalid optimistic optimizations, and replacing it by less-optimized, more robust code. A method may in principle be deoptimized dozens of times.

在这个总结中,去优化的原因罗列如下:

  1. The compiler may stub out an untaken branch and deoptimize if it is ever taken.
  2. Similarly for low-level safety checks that have historically never failed.
  3. If a call site or cast encounters an unexpected type, the compiler deoptimizes.
  4. If a class is loaded that invalidates an earlier class hierarchy analysis, any affected method activations, in any thread, are forced to a safepoint and deoptimized.
  5. Such indirect deoptimization is mediated by the dependency system. If the compiler makes an unchecked assumption, it must register a checkable dependency. (E.g., that class Foo has no subclasses, or method Foo.bar is has no overrides.)

就个人而言,我找到了this blog entry关于微基准测试非常可读,其中还涵盖了 HotSpot VM 上的优化和反优化主题。另外,我可以推荐reading through this presentation .

关于java - 关于HotSpot动态反优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20522870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com