You may also use the ConstantPoolGen.lookupMethodref() method, which will tell you whether a certain method/field is being used within another class.

vicki kozel wrote:

Thanks a lot for the response, Toby! It is very helpful. I hope you can answer these couple of question about your comments:
1) "you can look for the putfield and putstatic instructions"
Q. I was going to look for ALOAD instructions to spot where variables get loaded onto stack - you suggest "putfield" and "putstatic" instead of that ?
2)"but that won't catch any modifications that occur through reflection."
Q. So, is there any way at all to find instructions related to modification of variables through reflection?


This is somthing kind of difficult to do ...
You could look in the ConstantPoolGen for a String entry with the method name , and another one with the method signature ..
Then look further for the usage of the invoke() method ...
And finally figure out where exaclty the code is being made, and make sure this is the one you are expecting.


This "algorithm" only works if the method invoked is hardcoded in the code ... If it is being computed, I don't think there is any static way to find that out !

Simon.

3) Can you suggest some code examples or open source tools that do something similar to what my task is? - I am trying to modify classfile, but not at the run time.

Thanks a lot!
Vicki

[EMAIL PROTECTED] wrote:
First, you don't necessarily know what local variables are, unless the original compiler included the line number information in the class file. If it did, you could try to scan for store instructions.


Second, you can look for the putfield and putstatic instructions to see when instance and static variables are modified, but that won't catch any modifications that occur through reflection.

God bless,
-Toby Reyelts


I also was working on a simple BCEL based tool that will allow me to track all variables, global and LOCAL, at the moment when they are changed. I just want to insert instructions into the Method of profiled class to printout name and the value of a variable - local variables too! - when they are changed. Any suggestions??
thanks!!
Vicki



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



[EMAIL PROTECTED]
415-668-6967 home
415-806-9093 cell

---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software


Reply via email to