使用java命令运行java程序时,可以使用-verbose指定verbose选项,以便检查何时加载类。例如:
java -verbose Test | grep "file:"
[Loaded Test from file:/Users... ]
[Loaded C1 from file:/Users... ]
[Loaded A1 from file:/Users... ]
[Loaded B1 from file:/Users...]
[Loaded C2 from file:/Users...]
有没有办法了解验证阶段何时发生?在加载类之后,不一定要直接验证类。例如,这样的事情是理想的:
java -verbose Test | grep "file:"
[Loaded Test from file:/Users... ]
[Loaded C1 from file:/Users... ]
[Loaded A1 from file:/Users... ]
[Loaded B1 from file:/Users...]
[Verified C1]
[Loaded C2 from file:/Users...]
[Verified C2]
等
对于那些“你不需要这个”,“你为什么要这样做”答案。它只是纯粹的兴趣,仍然值得一个问题。
答案 0 :(得分:0)
正如@Antimony建议的那样,要查看何时验证类,需要在重新编译之前修改正在使用的JVM的源。
Oracles HotSpot vm源已经有许多日志记录行来指示不同的验证阶段,可以通过更改来启用它们
ClassVerifier::_verify_verbose;
中的为真
/openjdk/hotspot/src/share/vm/classfile/verifier.cpp