author | bchristi |
Thu, 19 May 2016 16:25:35 -0700 | |
changeset 38436 | 4676f6c9ebee |
parent 6882 | 637546039be3 |
child 40684 | 2e37c119dc2a |
permissions | -rw-r--r-- |
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
1 |
/* |
38436
4676f6c9ebee
8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents:
6882
diff
changeset
|
2 |
* Copyright (c) 2010, 2016 Oracle and/or its affiliates. All rights reserved. |
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
4 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
8 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
13 |
* accompanied this code). |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
14 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
18 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
21 |
* questions. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
22 |
*/ |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
23 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
24 |
import java.util.Properties; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
25 |
import java.util.concurrent.CyclicBarrier; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
26 |
import java.util.concurrent.BrokenBarrierException; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
27 |
import java.io.IOException; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
28 |
import java.net.URL; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
29 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
30 |
/* @test |
38436
4676f6c9ebee
8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents:
6882
diff
changeset
|
31 |
* @bug 6977738 8029891 |
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
32 |
* @summary Test ClassLoader.getResource() that should not deadlock |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
33 |
# if another thread is holding the system properties object |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
34 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
35 |
* @build GetResource |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
36 |
* @run main GetResource |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
37 |
*/ |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
38 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
39 |
public class GetResource { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
40 |
CyclicBarrier go = new CyclicBarrier(2); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
41 |
CyclicBarrier done = new CyclicBarrier(2); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
42 |
Thread t1, t2; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
43 |
public GetResource() { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
44 |
t1 = new Thread() { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
45 |
public void run() { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
46 |
Properties prop = System.getProperties(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
47 |
synchronized (prop) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
48 |
System.out.println("Thread 1 ready"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
49 |
try { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
50 |
go.await(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
51 |
prop.put("property", "value"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
52 |
prop.store(System.out, ""); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
53 |
done.await(); // keep holding the lock until t2 finishes |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
54 |
} catch (InterruptedException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
55 |
throw new RuntimeException(e); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
56 |
} catch (BrokenBarrierException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
57 |
throw new RuntimeException(e); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
58 |
} catch (IOException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
59 |
throw new RuntimeException(e); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
60 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
61 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
62 |
System.out.println("Thread 1 exits"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
63 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
64 |
}; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
65 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
66 |
t2 = new Thread() { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
67 |
public void run() { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
68 |
System.out.println("Thread 2 ready"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
69 |
try { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
70 |
go.await(); // wait until t1 holds the lock of the system properties |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
71 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
72 |
URL u1 = Thread.currentThread().getContextClassLoader().getResource("unknownresource"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
73 |
done.await(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
74 |
} catch (InterruptedException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
75 |
throw new RuntimeException(e); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
76 |
} catch (BrokenBarrierException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
77 |
throw new RuntimeException(e); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
78 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
79 |
System.out.println("Thread 2 exits"); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
80 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
81 |
}; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
82 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
83 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
84 |
public void run() throws Exception { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
85 |
t1.start(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
86 |
t2.start(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
87 |
try { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
88 |
t1.join(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
89 |
} catch (InterruptedException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
90 |
e.printStackTrace(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
91 |
throw e; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
92 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
93 |
try { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
94 |
t2.join(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
95 |
} catch (InterruptedException e) { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
96 |
e.printStackTrace(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
97 |
throw e; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
98 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
99 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
100 |
|
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
101 |
public static void main(String[] args) throws Exception { |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
102 |
new GetResource().run(); |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
103 |
} |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
diff
changeset
|
104 |
} |