jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent Martelli <laur...@bearteam.org>
Subject Re: Retrieving References of Methods in Methods
Date Mon, 09 Sep 2002 18:31:45 GMT
>>>>> "Huw" == Huw Evans <huw@dcs.gla.ac.uk> writes:

  >> For my purposes, I only need to know if a value is the this
  >> pointer, a field of an object or an argument. In fact I want to
  >> detect which methods are getters, setters, adders or
  >> removers. And a few other things, such as replacing java.util.*
  >> collections with my own versions that I can modify at load time.

  Huw> Hello, I've noticed the above on the bcel mailing list.

  Huw> In the general case, how are you going to notice a method goes
  Huw> a get, set, add or remove?

  Huw> If a programmer has written good OO code, you could possibly
  Huw> spot this, but in less well written code this would be hard.
  Huw> For example a method may do a combination of set and get, for
  Huw> example, e.g., hashtables put method that puts a value under
  Huw> the specific key, returning the old value (if any).

I do not have a proof that my system work on 100% of the cases. My
technique is to simulate bytecode execution and build a pseudo stack
which only contains the information that I need. For instance, when I
see aload_0, I know there's the this pointer pushed on the stack. And
if I encounter a getfield while this on the top of the stack, the
method is considered a getter for that field.

In order to detect adders, I also need to know a value on the stack is
the value of field. Everytime I see a getfield, I know it pushes the
value of a field on the stack. Then when I find an invokevirtual of
java.util.Vector.add() (for instance) on the a value, it's an adder.

I've commited my stuff into JAC's cvs, so you can have a look at it if
you like:

http://jac.aopsys.com/cgi-bin/viewcvs.cgi/jac/src/jac/core/translators/

See the VMStack class, and WrappeeTranslator_BCEL.fillRTTI()

Regards,
Laurent

-- 
Laurent Martelli                        http://jac.aopsys.com/
laurent@bearteam.org                    http://www.bearteam.org/~laurent/


--
To unsubscribe, e-mail:   <mailto:bcel-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:bcel-user-help@jakarta.apache.org>


Mime
View raw message