Re: How to wrap a function with a try finally block

Tronje Krop <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Organization TU-Darmstadt
Message-ID <[email protected]>
Have you thought about wrapping the whole function?

public int method1() {
  code....
}

to:

private void _wrapped_method1() {
  code....
}

public int method1() {
  StaticClass.enter_method();
  try {
    return this._wrapped_method1()
  } finally {
    StaticClass.exit_method();
  }
}

This is a very simple and clean way for transforming the class
and you can use the ASMifyer to help you generate the code
straight forward.

Best regards

Tronje

[email protected] wrote:
> I tried to write a tool to add a static method to every function and guarantee
> it is called before the method return, i wrote something in the MethodAdaptor
> like this:
>    public void visitInsn(int opcode)
>     {	  
>       if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode ==
> Opcodes.ATHROW)  {
> 	  mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, methodName,
> "()V");
>       }
>       
>       mv.visitInsn(opcode);
>     }	
> 
> It does not work when the method calls some other method and that guy throws a
> RuntimeException, then i tried to use try finally to wrap the whole method body
> like this:
> transfer
> private void method1()
> {
>   code....
>   ...
> } 
> to:
> private void method1()
> {
>   try {
>     code....
>     ...
>   } finally {
>     StaticClass.method();
>   }
> }
> 
> I wrote a small class and checked the binary code with both javap and
> ASMifierClassVisitor, then i realized that i have to figure out every posible
> branche that may jump into the finally block and do something with the
> exception table.
> 
> I have read the guild and have not got anything helpful. It's too hard or i
> just can't do this?
> 
> Thanks for your patience.
>
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.