Torsten Curdt wrote:

Joseph Ryan wrote:

Torsten Curdt wrote:

If have an "invokevirtual" Instruction. How can I
obtain the information which method is actually
being called?

 InstructionList il = mg.getInstructionList();
 InstructionHandle[] ihs = il.getInstructionHandles();

 for (int j = 1; j < ihs.length; j++) {
   Instruction in = ihs[j].getInstruction();

if (in.getOpcode() == 182) {
// invoke virtual
// if (in invokes "mymethod") ...
System.out.println(in);
}
}
il.dispose();




Thats no good; try:


you mean "no good" because of the direct opcode
comparison, right? :)


Yep.  Even though the JVM spec isn't likely to change anytime soon, it
isn't exactly an open standard (as in, its controlled by a proprietery
company), so its better to be a bit more... abstract in your code.
Besides, unless the reader has the JVM spec memorized, he'll probably
have to look up which opcode 182 is, which would be annoying.

import org.apache.bcel.generic.INVOKEVIRTUAL;

// ...
if (in instanceof INVOKEVIRTUAL) {
INVOKEVIRTUAL invv = (INVOKEVIRTUAL) in.getInstruction()
ConstantPoolGen cp = mg.getConstantPool();
// for more accurate results, check the object on which the method is
// being called's class to see if the object is a subclass of the class
// that you want
if ( invv.getClassName().equals("...")
&& invv.getMethodName(cp).equals(mymethod)
) {


ah... this what I was looking for :)


Cool.

- Joe


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to