jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Huntwork <...@huntwork.net>
Subject Re: Create a pointer to an InstructionHandle
Date Mon, 19 Dec 2005 04:43:48 GMT
Here's how the line number attribute works:  when the MethodGen is created
from a Method (
the LineNumberTable Attribute (which knows about instruction indexes) get
converted into LineNumberGen objects which know about InstructionHandles and
implement InstructionTargeter.  Then when the MethodGen is turned back into
a method (
the LineNumberGen objects are turned into an updated LineNumberTable
object.  So the offsets  in the attribute are not kept up to date.  They are
only valid right after the MethodGen is created from the Method and right
after the Method is created from the MethodGen.

You'll probably want to mimic that code for your new attribute.  bcel is
open-source, so feel free to download the source and modify it for your
purposes.  you could even modify bcel to make Attributes pluggable.  then
you could submit that patch to bcel-dev, get it included, and probably not
have to maintain any bcel patches yourself.

if you don't want to modify bcel source, you could use aspectj to write some
"after returning" advice on MethodGen(Method m) and MethodGen.getMethod()
that updates your Attribute's properties.  failing that, it should even be
possible to manually update your Attribute when either of those methods is

On 12/18/05, email_ricevute_da-bcel@yahoo.it <
email_ricevute_da-bcel@yahoo.it> wrote:
> I have done so, but the problem is that when I delete/add some
> instructions this number becomes wrong.
>   I thinks that I have to implement the class InstructionTargeter,
> like  in the object LineNumber in the attribute LineNumberTable.
>   In that case there are two class: LineNumber and LineNumberGen.
>   Only the second one implements the class InstructionTargeter.
>   My attribute must save the positions of two instruction, an
> integer,  and a structure (both the reading and the writing). With my
> actual  implementation it save the two position like an integer. But when
> I  add/delete some instructions this number becomes wrong.
>   I tried to use the two LineNumber elements to save them, but they are
> not updated like happens in the LineNumberTable attribute.
>   Someone knows why this happens?
>   Thanks.
> Andrew Huntwork <ash@huntwork.net> ha scritto:   The InstructionTargeter
> interface may be what you want.  You may also want
> to make sure that when you serialize your attribute (in dump(), it would
> appear), InstructionHandle.getPosition is up to date.  You can use
> InstructionList.setPositions() for that purpose.
> On 12/15/05, Emanuele Debenedetti  wrote:
> >
> > I have created a new attribute using bcel.
> > This attribute should points at two instructions:
> > actually I record two integer, but if I delete one or
> > more instruction this interger become wrong.
> >
> > I think that I should create a pointer to an
> > InstructionHandle like the goto Instruction, but I
> > have non idea how to do this.
> >
> > Could you help me?
> >
> > Thanks.
> >
> >
> >
> >
> >
> >
> > ___________________________________
> > Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
> > http://mail.yahoo.it
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
> ---------------------------------
> Yahoo! Messenger: chiamate gratuite in tutto il mondo

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message