Defined SUPPORT_CONST_ASTORE and SUPPORT_ONLY_ZERO_ASTORE.
[cacao.git] / tests / kaffe / TestUnlock.java
1 /**
2  * Test that locks taken in synchronized methods are properly unlocked
3  * when an exception occurs.  Note that different mechanisms are used in
4  * compiler & interpreter.
5  *
6  * @author Godmar Back <gback@cs.utah.edu>
7  */
8 public class TestUnlock {
9     synchronized void throwException() throws Exception {
10         throw new Exception();
11     }
12
13     synchronized void success() {
14         System.out.println("Success.");
15     }
16
17     public static void main(String av[]) throws Exception {
18         final TestUnlock me = new TestUnlock();
19
20         new Thread() {
21             public void run() {
22                 try {
23                     Thread.sleep(9000);
24                 } catch (Exception _) { }
25                 System.out.println("Time out.  Failure.");
26                 System.exit(-1);
27             }
28         }.start();
29
30         Thread t = new Thread() {
31             public void run() {
32                 try {
33                     me.throwException();
34                 } catch (Exception _) {
35                 }
36             }
37         };
38         t.start();
39         t.join();
40
41         Thread t2 = new Thread() {
42             public void run() {
43                 me.success();
44             }
45         };
46         t2.start();
47         t2.join();
48         System.exit(0);
49     }
50 }
51
52 /* Expected Output:
53 Success.
54 */