Re: Re: Adding try/finally block

Nikolas Nehmer <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Organization FB Informatik, TU Kaiserslautern, GERMANY
Message-ID <6011238.1272989472002.OPEN-XCHANGE.WebMail.tomcat@groupmail.informatik.uni-kl.de>
Hi,

I have a follow up problem extending and creating try/catch/finally
blocks.

I'm trying to implement a try block depth counter on bytecode level. For
every try block entered the counter is incremented and for a try block
left the counter is decremented. Of course, there are 3 different use
cases.
1. try block is executed completely
2. try block is terminated by an exception that is caught by one of the
corresponding handlers
3. try block is terminated by an exception not caught by one of the
corresponding handlers

For cases where a complete try/catch/finally structure already exists in
the source code this apporach works perfectly. But I have serious
problems rebuilding the finally block structure by myself for the 3rd
case. By studying several simple try/catch/finally examples I came up
with the following "general" structure of try/catch/finally blocks:

try block start label
...
some code
...
try block end label
JumpInsn to normalExecutionFinallyBlockLabel

exception handler start label
exception handler code
cloned finally block code
JumpInsn to End of try block

exception handler start label
exception handler code
cloned finally block code
JumpInsn to End of try block

... continued for every exception handler

exceptionalExecutionFinallyBlock Label
FrameInsn
ASTORE
cloned finally block code
ALOAD
ATHROW

normalExecutionFinallyBlock Label
cloned finally block code

end of try block label

Assuming this structure is correct, I came up with a solution for the 3
cases mentioned above. The first two are quite simple to solve. I'm just
inserting my counter decrement behind the
normalExecutionFinallyBlockLabel and behind the
ExcetionHandlerBlockStartLabels. For the third case I would like to add
my counter decrement to the exceptionalExecutionFinallyBlockLabel. In
case the finally block structure already exists in the application code,
this works perfectly. BUT if I have to add the complete finally block
logic to the code (in case there ony exists a try/catch block within the
code) a java.lang.VerifyError (Inconsistent stack height 0 != 1) is
raised. In fact this exception is raised when I'm trying to add a new
TryCatchBlockNode specifying the corresponding finally block (for case
3).

Any help will be appreciated ;-)

Best regards
Nikolas
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.