gpt4 book ai didi

java - JMH 就像禁用方法内联 - 它是如何完成的?

转载 作者:行者123 更新时间:2023-12-01 22:21:22 25 4
gpt4 key购买 nike

我刚刚了解了 JMH 微基准测试框架 ( http://openjdk.java.net/projects/code-tools/jmh/ )。我只是想知道他们是如何实现@CompileControl注解功能的。他们从源代码中将指令(提示)列表简单地写入单个文本文件中的编译器。

我只是想知道是否可以找到一些有关底层机制的附加文档,它仅适用于 OpenJDK。

最佳答案

JMH 使用 HotSpot 特定的 CompilerOracle,它控制 JIT 编译器。这显然适用于任何基于 HotSpot 的 VM,包括普通 OpenJDK 和 Oracle JDK 版本。运行 OpenJDK:

$ java -XX:CompileCommand=help
CompileCommand and the CompilerOracle allows simple control over
what's allowed to be compiled. The standard supported directives
are exclude and compileonly. The exclude directive stops a method
from being compiled and compileonly excludes all methods except for
the ones mentioned by compileonly directives. The basic form of
all commands is a command name followed by the name of the method
in one of two forms: the standard class file format as in
class/name.methodName or the PrintCompilation format
class.name::methodName. The method name can optionally be followed
by a space then the signature of the method in the class file
format. Otherwise the directive applies to all methods with the
same name and class regardless of signature. Leading and trailing
*'s in the class and/or method name allows a small amount of
wildcarding.

Examples:

exclude java/lang/StringBuffer.append
compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;
exclude java/lang/String*.*
exclude *.toString

您在生成的CompilerHints资源文件中看到的基本上是逐字逐句的CompilerOracle命令;这些通过 -XX:CompileCommandFile=... 传递到 VM。 JMH @CompilerControl 工具只是声明 CompileOracle 命令的便捷方法,而不会弄乱原始命令行选项。

关于java - JMH 就像禁用方法内联 - 它是如何完成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29714607/

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