Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / July 2007

Tip: Looking for answers? Try searching our database.

Weird entry in the exception table for monitorenter/monitorexit

Thread view: 
Douwe - 18 Jul 2007 13:16 GMT
I've created a simple test class with one method:

public class TestClass {

    int a = 0;

    public void test() {
        synchronized(TestClass.class) {
            a = 1;
        }
    }

}

After opening the generated class file with Eclipse I got the next
result (I've removed the parts that are irrelevant)

 public void test();
    0  ldc <Class TestClass> [1]
    2  dup
    3  astore_1
    4  monitorenter
    5  aload_0 [this]
    6  iconst_1
    7  putfield TestClass.a : int [12]
   10  aload_1
   11  monitorexit
   12  goto 18
   15  aload_1
   16  monitorexit
   17  athrow
   18  return
     Exception Table:
       [pc: 5, pc: 12] -> 15 when : any
       [pc: 15, pc: 17] -> 15 when : any

I do understand that after the monitor is entered it is very important
that it leaves it again with the instruction monitorexit. In normal
case where no exceptions occur it will call monitorexit at the address
11. But if an exception occurs it has to make sure monitorexit is
called and therefore the exception table defines in the first entry
that on any exception the VM jumps to address 15. Until here
everything is understandable, but what is the second entry in the
exception table telling me? if an exception occurs betweern 15 and 17
then jump to 15 ... doesn't this cause an endless loop?
Roedy Green - 19 Jul 2007 01:53 GMT
>result (I've removed the parts that are irrelevant)
>
[quoted text clipped - 26 lines]
>exception table telling me? if an exception occurs betweern 15 and 17
>then jump to 15 ... doesn't this cause an endless loop?

I will make a guess that the implementation of exception propagation
checks for a "in monitor" bit and deals with it.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.