author | serb |
Sat, 21 May 2016 02:53:37 +0300 | |
changeset 38989 | 49fb02b3e95b |
parent 33865 | d5d2d1a08a71 |
child 40261 | 86a49ba76f52 |
permissions | -rw-r--r-- |
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
1 |
/* |
38989 | 2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
4 |
* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
8 |
* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
14 |
* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
18 |
* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
21 |
* questions. |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
22 |
*/ |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
23 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
24 |
import com.sun.beans.finder.ConstructorFinder; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
25 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
26 |
import java.lang.reflect.Constructor; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
27 |
import java.util.ArrayList; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
28 |
import java.util.Collections; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
29 |
import java.util.List; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
30 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
31 |
/* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
32 |
* @test |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
33 |
* @bug 8028054 |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
34 |
* @summary Tests that cached constructors have synchronized access |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
35 |
* @author Sergey Malenkov |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
21793
diff
changeset
|
36 |
* @modules java.desktop/com.sun.beans.finder |
38989 | 37 |
* java.activation |
38 |
* java.transaction |
|
39 |
* java.corba |
|
40 |
* java.xml.bind |
|
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
41 |
* @compile -XDignore.symbol.file TestConstructorFinder.java |
38989 | 42 |
* @run main/othervm -addmods java.activation -addmods java.transaction -addmods java.corba -addmods java.xml.bind TestConstructorFinder |
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
43 |
*/ |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
44 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
45 |
public class TestConstructorFinder { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
47 |
List<Class<?>> classes = Task.getClasses(Integer.MAX_VALUE); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
48 |
List<Constructor> constructors = new ArrayList<>(); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
49 |
for (Class<?> type : classes) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
50 |
Collections.addAll(constructors, type.getConstructors()); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
51 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
52 |
Task.print("found " + constructors.size() + " constructors in " + classes.size() + " classes"); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
53 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
54 |
List<Task> tasks = new ArrayList<>(); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
55 |
for (int i = 0; i < 50; i++) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
56 |
tasks.add(new Task<Constructor>(constructors) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
57 |
@Override |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
58 |
protected void process(Constructor constructor) throws NoSuchMethodException { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
59 |
ConstructorFinder.findConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes()); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
60 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
61 |
}); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
62 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
63 |
int alarm = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
64 |
while (true) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
65 |
int alive = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
66 |
int working = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
67 |
for (Task task : tasks) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
68 |
if (task.isWorking()) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
69 |
working++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
70 |
alive++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
71 |
} else if (task.isAlive()) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
72 |
alive++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
73 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
74 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
75 |
if (alive == 0) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
76 |
break; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
77 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
78 |
Task.print(working + " out of " + alive + " threads are working"); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
79 |
if ((working == 0) && (++alarm == 10)) { |
33865
d5d2d1a08a71
8137113: [TEST_BUG] Two java.beans tests need to be updated to work with JDK 9 modularized filesystem
yan
parents:
31448
diff
changeset
|
80 |
throw new RuntimeException("FAIL - DEADLOCK DETECTED"); |
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
81 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
82 |
Thread.sleep(1000); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
83 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
84 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
85 |
} |