在代码库中搜索大型方法
默认情况下,HotSpot JIT 拒绝编译大于约 8k 字节码的方法 (1)。有没有什么可以扫描 jar 中的此类方法 (2)?
除非你传递
-XX:-DontCompileHugeMethods
Jon Masamitsu 描述了解释方法如何减慢垃圾收集速度,并指出重构是通常比
-XX:-DontCompileHugeMethods
By default the HotSpot JIT refuses to compile methods bigger than about 8k of bytecode (1). Is there anything that can scan a jar for such methods (2)?
unless you pass
-XX:-DontCompileHugeMethods
Jon Masamitsu describes how interpreted methods can slow down garbage collection and notes that refactoring is generally wiser than
-XX:-DontCompileHugeMethods
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 Peter Lawrey 对 ASM 的指导。该程序打印出 jar 中每个方法的大小:
Thanks to Peter Lawrey for the pointer to ASM. This program prints out the size of each method in a jar:
Checkstyle 可能对此很有用 - 它不适用于 8k 限制,但适用于一般而言,方法中的可执行语句。老实说,这是您在实践中想要的限制。
正如您已经指出的,
-XX:-DontCompileHugeMethods
通常是一个坏主意 - 它迫使 JVM 挖掘所有丑陋的代码并尝试用它做一些事情,这可能会对性能产生负面影响而不是积极的!重构,或者最好不要一开始就编写如此庞大的方法,这将是前进的方向。哦,如果如此巨大的方法最终是通过一些人为设计而不是自动生成的代码而结束的,那么您的团队中可能有人需要与......
Checkstyle would probably be good for this - it doesn't work on the 8k limit but the number of executable statements in a method in general. To be honest, this is a limit that you want in practice though.
As you already state,
-XX:-DontCompileHugeMethods
is generally a bad idea - it forces the JVM to dig through all that ugly code and try and do something with it, which can have a negative effect on performance rather than a positive one! Refactoring, or better still not writing methods that huge to start with would be the way forward.Oh, and if the methods that huge ended up there through some human design, and not auto-generated code, then there's probably some people on your team who need talking to...