java中如何计算调用接口方法的count参数?
我正在使用 javassist,并在加载时/运行时生成接口和其他内容。
要调用接口的方法(使用字节码 invokeinterface),我们必须提供几个参数:indexbyte1、indexbyte2、count 和 0(来自 http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html)。
已经有了我想要调用的抽象方法 (CtMethod),如何计算其计数?
例如,http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html 他们说“invokeinterface 指令的计数操作数记录参数值数量的度量,其中 long 或 double 类型的参数值为计数值贡献两个单位,任何其他类型的参数为计数值贡献一个单位。此信息也可以从所选方法的描述符中导出。冗余是历史性的。”
但也要说“计数操作数是一个不得为零的无符号字节。”
如果我要调用的抽象方法没有参数,它的计数将为0!?但count不能为0。该方法的描述符是()V。
有什么建议吗?
I'm using javassist and I generate interfaces and other stuff at loadtime/runtime.
To call an interface's method (with the bytecode invokeinterface) we have to provide several parameters: indexbyte1, indexbyte2, count, and 0 (from http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html).
Already having the abstract method (CtMethod) that I want to call, how do I calculate its count?
For example in http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html they say that "The count operand of the invokeinterface instruction records a measure of the number of argument values, where an argument value of type long or type double contributes two units to the count value and an argument of any other type contributes one unit. This information can also be derived from the descriptor of the selected method. The redundancy is historical."
But also say that "The count operand is an unsigned byte that must not be zero."
If the abstract method I want to call does not have parameters, it will have count 0!? But count cannot be 0. The descriptor of the method is ()V.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 javaassist 的细节,但我假设计数是调用该方法所需的堆栈空间的大小。如果是这种情况,那么您需要为“this”变量指定空间,该变量在任何参数之前被推入堆栈(因为您正在执行调用接口)。如果是这种情况,那么对于不带参数的方法,计数将为 1。
I don't know the particulars of javaassist, but I'm assuming that the count is the size of stack space needed to call the method. If this is the case, then you need to specify space for the 'this' variable that gets pushed onto the stack before any parameters (since you are doing an invokeinterface). If this is the case, then the count will be 1 for a method w/o parameters.
实例方法本质上消耗调用主题的堆栈字。
An instance method inherently consumes a stack word for the subject of the invoke.