You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Emanuele Debenedetti <em...@yahoo.it> on 2005/12/15 18:03:03 UTC

Create a pointer to an InstructionHandle

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


Re: Create a pointer to an InstructionHandle

Posted by em...@yahoo.it.
I will watch the class MethodGen.
Thanks for your help.


--- Andrew Huntwork <as...@huntwork.net> ha scritto: 

> Here's how the line number attribute works:  when
> the MethodGen is created
> from a Method (
>
http://jakarta.apache.org/bcel/xref/org/apache/bcel/generic/MethodGen.html#230),
> 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 (
>
http://jakarta.apache.org/bcel/xref/org/apache/bcel/generic/MethodGen.html#627),
> 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
> called.
> 
> 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 <as...@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
> >
> 



		
___________________________________ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.messenger.yahoo.com

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


Re: Create a pointer to an InstructionHandle

Posted by Andrew Huntwork <as...@huntwork.net>.
Here's how the line number attribute works:  when the MethodGen is created
from a Method (
http://jakarta.apache.org/bcel/xref/org/apache/bcel/generic/MethodGen.html#230),
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 (
http://jakarta.apache.org/bcel/xref/org/apache/bcel/generic/MethodGen.html#627),
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
called.

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 <as...@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
>

Re: Create a pointer to an InstructionHandle

Posted by Atam <at...@gmail.com>.
thanks,

i wil llook into it,

Atam


On 12/18/05, Andrew Huntwork <as...@huntwork.net> wrote:
>
> 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 <em...@yahoo.it> 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
> >
> >
>
>

Re: Create a pointer to an InstructionHandle

Posted by em...@yahoo.it.
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 <as...@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 

Re: Create a pointer to an InstructionHandle

Posted by Andrew Huntwork <as...@huntwork.net>.
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 <em...@yahoo.it> 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
>
>