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 a开发者_如何转开发n 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?
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.
精彩评论