Java中有多少字节的字节码有特定的方法? [英] How many bytes of bytecode has a particular method in Java?
问题描述
我最近在 Jon Masamitsu的Weblog 上看到了巨大的方法(8000字节的字节码)是不是用HotSpot编译JIT。
I recently read on Jon Masamitsu's Weblog that huge methods (8000 bytes of bytecode) are not JIT compiled with HotSpot.
所以我的问题是:我如何找出(作为程序员)特定方法有多少字节的字节码?
So my question is: how do I find out (as a programmer) how many bytes of bytecode a particular method has?
JIT编译器当然似乎知道。我可以从 .class
文件中提取这条信息吗?
The JIT compiler of course seems to know. Can I extract this piece of information from the .class
file?
推荐答案
您可以使用 javap -c mypackage.MyClass
转储类的字节码(并查看每种方法的大小)
You can use javap -c mypackage.MyClass
to dump the bytecode of your class (and see the size of each method)
一般来说,在达到此限制之前,您应该知道方法太大而无法阅读和理解。恕我直言,它生成的代码更多的问题。 BTW方法中存在65536字节的硬限制。
Generally speaking, you should know that a method is too large to read and understand before you hit this limit. IMHO its more a problem for generated code. BTW There is a hard limit of 65536 bytes in a method.
这篇关于Java中有多少字节的字节码有特定的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!