This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcj/104: gcj does not handle synchronized methods properly



>Number:         104
>Category:       gcj
>Synopsis:       gcj does not handle synchronized methods properly
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    apbianco
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 16 14:30:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Godmar Back
>Release:        CVS October
>Organization:
>Environment:
RH 5.2, Linux 2.2.12, glibc 2.0.7
both gcj and libgcj configured with --enable-threads=posix
>Description:
gcj doesn't compile proper exception handling code.

>How-To-Repeat:
/**
 * Test that locks taken in synchronized methods are properly unlocked
 * when an exception occurs.  Note that different mechanisms are used in
 * compiler & interpreter.
 *
 * @author Godmar Back <gback@cs.utah.edu>
 */
public class TestUnlock {
    synchronized void throwException() throws Exception {
        throw new Exception();
    }

    synchronized void success() {
        System.out.println("Success.");
    }

    public static void main(String av[]) throws Exception {
        final TestUnlock me = new TestUnlock();

        new Thread() {
            public void run() {
               try {
                   Thread.sleep(2000);
               } catch (Exception _) { }
               System.out.println("Time out.  Failure.");
               System.exit(-1);
            }
        }.start();

        Thread t = new Thread() {
            public void run() {
               try {
                   me.throwException();
               } catch (Exception _) {
               }
            }
        };
        t.start();
        t.join();

        Thread t2 = new Thread() {
            public void run() {
               me.success();
            }
        };
        t2.start();
        t2.join();
        System.exit(0);
    }
}

/* Expected Output:
Success.
*/
>Fix:
Not sure.
Wrap whole function body of a synchronized method
in try/finally?
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]