author | malenkov |
Tue, 26 Nov 2013 13:30:44 +0400 | |
changeset 21793 | 561ed508292b |
child 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
21793
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
1 |
/* |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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.MethodFinder; |
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.Method; |
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 methods 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 |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
36 |
* @compile -XDignore.symbol.file TestMethodFinder.java |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
37 |
* @run main TestMethodFinder |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
38 |
*/ |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
39 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
40 |
public class TestMethodFinder { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
41 |
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
|
42 |
List<Class<?>> classes = Task.getClasses(4000); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
43 |
List<Method> methods = new ArrayList<>(); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
44 |
for (Class<?> type : classes) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
45 |
Collections.addAll(methods, type.getMethods()); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
46 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
47 |
Task.print("found " + methods.size() + " methods in " + classes.size() + " classes"); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
48 |
|
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
49 |
List<Task> tasks = new ArrayList<>(); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
50 |
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
|
51 |
tasks.add(new Task<Method>(methods) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
52 |
@Override |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
53 |
protected void process(Method method) throws NoSuchMethodException { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
54 |
MethodFinder.findMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes()); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
55 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
56 |
}); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
57 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
58 |
int alarm = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
59 |
while (true) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
60 |
int alive = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
61 |
int working = 0; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
62 |
for (Task task : tasks) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
63 |
if (task.isWorking()) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
64 |
working++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
65 |
alive++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
66 |
} else if (task.isAlive()) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
67 |
alive++; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
68 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
69 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
70 |
if (alive == 0) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
71 |
break; |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
72 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
73 |
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
|
74 |
if ((working == 0) && (++alarm == 10)) { |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
75 |
Task.print("DEADLOCK DETECTED"); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
76 |
System.exit(100); |
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 |
Thread.sleep(1000); |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
79 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
80 |
} |
561ed508292b
8028054: com.sun.beans.finder.MethodFinder has unsynchronized access to a static Map
malenkov
parents:
diff
changeset
|
81 |
} |