author | rehn |
Fri, 07 Jul 2017 23:04:06 +0200 | |
changeset 46643 | cb5f289ba033 |
parent 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
1 |
/* |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
13603
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
4 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
8 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
14 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
18 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
21 |
* questions. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
22 |
*/ |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
23 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
24 |
/* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
25 |
* @test |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
26 |
* @bug 6963811 |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests deadlock in PropertyEditorManager |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
28 |
* @author Sergey Malenkov |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
13603
diff
changeset
|
29 |
* @modules java.desktop/com.sun.beans.editors |
13603
f87474d813e6
7183701: [TEST] closed/java/beans/security/TestClassFinder.java - compilation failed
malenkov
parents:
13602
diff
changeset
|
30 |
* @compile -XDignore.symbol.file Test6963811.java |
f87474d813e6
7183701: [TEST] closed/java/beans/security/TestClassFinder.java - compilation failed
malenkov
parents:
13602
diff
changeset
|
31 |
* @run main Test6963811 |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
32 |
*/ |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
33 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
34 |
import java.beans.PropertyEditorManager; |
13602
68fbb8be55ab
7162476: XMLDecoder security issue via ClassFinder
malenkov
parents:
5959
diff
changeset
|
35 |
import com.sun.beans.editors.StringEditor; |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
36 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
37 |
public class Test6963811 implements Runnable { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
38 |
private final long time; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
39 |
private final boolean sync; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
40 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
41 |
public Test6963811(long time, boolean sync) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
42 |
this.time = time; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
43 |
this.sync = sync; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
44 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
45 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
46 |
public void run() { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
47 |
try { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
48 |
Thread.sleep(this.time); // increase the chance of the deadlock |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
49 |
if (this.sync) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
50 |
synchronized (Test6963811.class) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
51 |
PropertyEditorManager.findEditor(Super.class); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
52 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
53 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
54 |
else { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
55 |
PropertyEditorManager.findEditor(Sub.class); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
56 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
57 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
58 |
catch (Exception exception) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
59 |
exception.printStackTrace(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
60 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
61 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
62 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
63 |
public static void main(String[] args) throws Exception { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
64 |
Thread[] threads = new Thread[2]; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
65 |
for (int i = 0; i < threads.length; i++) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
66 |
threads[i] = new Thread(new Test6963811(0L, i > 0)); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
67 |
threads[i].start(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
68 |
Thread.sleep(500L); // increase the chance of the deadlock |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
69 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
70 |
for (Thread thread : threads) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
71 |
thread.join(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
72 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
73 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
74 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
75 |
public static class Super { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
76 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
77 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
78 |
public static class Sub extends Super { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
79 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
80 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
81 |
public static class SubEditor extends StringEditor { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
82 |
public SubEditor() { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
83 |
new Test6963811(1000L, true).run(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
84 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
85 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
86 |
} |