You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by Shrinivas Joshi <sj...@cc.gatech.edu> on 2005/06/19 02:31:08 UTC

WRT - Incompatible field Types

Hi All,
  Sorry for the previous two mails. I was not popping off the objectref of
getfield instruction and that was causing problem.

Thanks
Shrinivas Joshi




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


Re: createInvoke method

Posted by David Foster <da...@earthlink.net>.
I personally would recommend using the Reflection API  
(java.lang.Class, java.lang.reflect.*) if you truly must determine  
the name of the invoked method at runtime (i.e., at the time the  
function is called).

- David

On Jul 2, 2005, at 2:24 AM, Shrinivas Joshi wrote:

> Hi All,
>   InstructionFactory.createInvoke method takes name of the called  
> class as
> it first parameter. Can this be used to create an invoke  
> instruction that
> decides the name of the class at run-time. This is especially  
> useful while
> creating invoke for some method call that is defined in super- 
> classes of
> the calling class and appropriate class's method needs to be called  
> based
> on the run-time type of the objectref.
> Kindly let me know about this.
>
> Thanks and Regards
> Shrinivas Joshi
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>
>


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


Re: createInvoke method

Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi All,
  I guess I am missing something over here. Probably it will work if I
just create invoke instruction with called class as the class C and JVM
will decide the class/method to be called based on the run-time type of
the objectref. Will try with it and post abt it.

Thanks and Regards
Shrinivas Joshi.



On Sat, 2 Jul 2005, Shrinivas Joshi wrote:

> Hi Torsten,
>  I want to know whether one can provide something like "this" reference as
> the called class to createInvoke method. Since the called class might vary
> depending on the run-time type of objectref used by invoke* instruction.
> for e.g if A is superclass of B is superclass of C and one wants to add a
> invoke in class C to some method defined in A as well as B class then the
> called class can either be A or B depending on the run-time type of this
> reference loaded using aload_0 prior to invoke* instruction.
> Hope this clarifies.
>
> Thanks and Regards
> Shrinivas Joshi.
>
>
>
> On Sat, 2 Jul 2005, Torsten Curdt wrote:
>
> > Shrinivas Joshi wrote:
> > > Hi All,
> > >   InstructionFactory.createInvoke method takes name of the called class as
> > > it first parameter. Can this be used to create an invoke instruction that
> > > decides the name of the class at run-time. This is especially useful while
> > > creating invoke for some method call that is defined in super-classes of
> > > the calling class and appropriate class's method needs to be called based
> > > on the run-time type of the objectref.
> > > Kindly let me know about this.
> >
> > Shrinivas,
> >
> > sorry but ...but what is the question? :)
> >
> > cheers
> > --
> > Torsten
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>
>

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


Re: createInvoke method

Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi Torsten,
 I want to know whether one can provide something like "this" reference as
the called class to createInvoke method. Since the called class might vary
depending on the run-time type of objectref used by invoke* instruction.
for e.g if A is superclass of B is superclass of C and one wants to add a
invoke in class C to some method defined in A as well as B class then the
called class can either be A or B depending on the run-time type of this
reference loaded using aload_0 prior to invoke* instruction.
Hope this clarifies.

Thanks and Regards
Shrinivas Joshi.



On Sat, 2 Jul 2005, Torsten Curdt wrote:

> Shrinivas Joshi wrote:
> > Hi All,
> >   InstructionFactory.createInvoke method takes name of the called class as
> > it first parameter. Can this be used to create an invoke instruction that
> > decides the name of the class at run-time. This is especially useful while
> > creating invoke for some method call that is defined in super-classes of
> > the calling class and appropriate class's method needs to be called based
> > on the run-time type of the objectref.
> > Kindly let me know about this.
>
> Shrinivas,
>
> sorry but ...but what is the question? :)
>
> cheers
> --
> Torsten
>

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


Re: createInvoke method

Posted by Torsten Curdt <tc...@apache.org>.
Shrinivas Joshi wrote:
> Hi All,
>   InstructionFactory.createInvoke method takes name of the called class as
> it first parameter. Can this be used to create an invoke instruction that
> decides the name of the class at run-time. This is especially useful while
> creating invoke for some method call that is defined in super-classes of
> the calling class and appropriate class's method needs to be called based
> on the run-time type of the objectref.
> Kindly let me know about this.

Shrinivas,

sorry but ...but what is the question? :)

cheers
--
Torsten

createInvoke method

Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi All,
  InstructionFactory.createInvoke method takes name of the called class as
it first parameter. Can this be used to create an invoke instruction that
decides the name of the class at run-time. This is especially useful while
creating invoke for some method call that is defined in super-classes of
the calling class and appropriate class's method needs to be called based
on the run-time type of the objectref.
Kindly let me know about this.

Thanks and Regards
Shrinivas Joshi




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


Re: Determining Caller class of a method

Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi Dave,

 Thanks very much for the information. I will try this out.

Regards
Shrinivas Joshi



On Tue, 21 Jun 2005, David Hovemeyer wrote:

> Shrinivas Joshi wrote:
>
> >Hi All,
> >  Is there any way by which one can determine the name/type of the class
> >that invokes a particular method of some other class. I need to do this
> >when the application control is within the method being called. I looked
> >at BCEL ControlFlowGraph, Frame and OperandStack classes but it seems that
> >they dont fetch any information related to caller class.
> >Kindly let me know if someone has worked on similar requirement.
> >
> >
>
> I am assuming you need to do this at runtime, since finding out the
> callers statically is generally impossible.
>
> One possible approach is to insert a call to a static instrumentation method
> into the method you are trying to capture the callers for.   The
> instrumentation
> method can create a stack trace as follows:
>
>     StackTraceElement[] trace = new Throwable().getStackTrace();
>
> Each stack trace element has the class name, method name, and line number
> of the call site.  You'll want to skip the top element, since it refers to
> the instrumentation method.
>
> Note that you will have to use the line number to figure out
> which version of the method is called if there are overloaded variants.
> (If the class doesn't have line number information, then you're out of
> luck.)
> However, since all you need is the class name, then this approach should
> do what you need.
>
> This works for 1.4 and later VMs.  On earlier VMs you can accomplish
> more or less the same thing using printStackTrace() and supplying a
> PrintWriter backed by a StringWriter or similar object, and manually parsing
> the printed stack trace.
>
> Hope this helps.
>
> -Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>
>

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


Re: Determining Caller class of a method

Posted by Stephen Kolaroff <xc...@netscape.net>.
A good way could be overriding ScurityManager and using its protected 
method getClassContext(), which " Returns the current execution stack as 
an array of classes" (See javadocs for details).
This also addresses the issue for a malicious code packed in class 
HarmlessClassName, but loaded from a different class loader.
Unfortunately, this will not give you the name of the method invoking you.

Best regards
Cheffo

daveho@cs.umd.edu wrote:

> Shrinivas Joshi wrote:
>
>> Hi All,
>>  Is there any way by which one can determine the name/type of the class
>> that invokes a particular method of some other class. I need to do this
>> when the application control is within the method being called. I looked
>> at BCEL ControlFlowGraph, Frame and OperandStack classes but it seems 
>> that
>> they dont fetch any information related to caller class.
>> Kindly let me know if someone has worked on similar requirement.
>>  
>>
>
> I am assuming you need to do this at runtime, since finding out the
> callers statically is generally impossible.
>
> One possible approach is to insert a call to a static instrumentation 
> method
> into the method you are trying to capture the callers for.   The 
> instrumentation
> method can create a stack trace as follows:
>
>    StackTraceElement[] trace = new Throwable().getStackTrace();
>
> Each stack trace element has the class name, method name, and line number
> of the call site.  You'll want to skip the top element, since it 
> refers to
> the instrumentation method.
>
> Note that you will have to use the line number to figure out
> which version of the method is called if there are overloaded variants.
> (If the class doesn't have line number information, then you're out of 
> luck.)
> However, since all you need is the class name, then this approach should
> do what you need.
>
> This works for 1.4 and later VMs.  On earlier VMs you can accomplish
> more or less the same thing using printStackTrace() and supplying a
> PrintWriter backed by a StringWriter or similar object, and manually 
> parsing
> the printed stack trace.
>
> Hope this helps.
>
> -Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>


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


Re: Determining Caller class of a method

Posted by David Hovemeyer <da...@cs.umd.edu>.
Shrinivas Joshi wrote:

>Hi All,
>  Is there any way by which one can determine the name/type of the class
>that invokes a particular method of some other class. I need to do this
>when the application control is within the method being called. I looked
>at BCEL ControlFlowGraph, Frame and OperandStack classes but it seems that
>they dont fetch any information related to caller class.
>Kindly let me know if someone has worked on similar requirement.
>  
>

I am assuming you need to do this at runtime, since finding out the
callers statically is generally impossible.

One possible approach is to insert a call to a static instrumentation method
into the method you are trying to capture the callers for.   The 
instrumentation
method can create a stack trace as follows:

    StackTraceElement[] trace = new Throwable().getStackTrace();

Each stack trace element has the class name, method name, and line number
of the call site.  You'll want to skip the top element, since it refers to
the instrumentation method.

Note that you will have to use the line number to figure out
which version of the method is called if there are overloaded variants.
(If the class doesn't have line number information, then you're out of 
luck.)
However, since all you need is the class name, then this approach should
do what you need.

This works for 1.4 and later VMs.  On earlier VMs you can accomplish
more or less the same thing using printStackTrace() and supplying a
PrintWriter backed by a StringWriter or similar object, and manually parsing
the printed stack trace.

Hope this helps.

-Dave


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


Determining Caller class of a method

Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi All,
  Is there any way by which one can determine the name/type of the class
that invokes a particular method of some other class. I need to do this
when the application control is within the method being called. I looked
at BCEL ControlFlowGraph, Frame and OperandStack classes but it seems that
they dont fetch any information related to caller class.
Kindly let me know if someone has worked on similar requirement.

Thanks and Regards
Shrinivas Joshi.




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