1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import com.sun.beans.finder.ConstructorFinder;
25
26 import java.lang.reflect.Constructor;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31 /*
32 * @test
33 * @bug 8028054
34 * @summary Tests that cached constructors have synchronized access
35 * @author Sergey Malenkov
36 * @compile -XDignore.symbol.file TestConstructorFinder.java
37 * @run main TestConstructorFinder
38 */
39
40 public class TestConstructorFinder {
41 public static void main(String[] args) throws Exception {
42 List<Class<?>> classes = Task.getClasses(Integer.MAX_VALUE);
43 List<Constructor> constructors = new ArrayList<>();
44 for (Class<?> type : classes) {
45 Collections.addAll(constructors, type.getConstructors());
46 }
47 Task.print("found " + constructors.size() + " constructors in " + classes.size() + " classes");
48
49 List<Task> tasks = new ArrayList<>();
50 for (int i = 0; i < 50; i++) {
51 tasks.add(new Task<Constructor>(constructors) {
52 @Override
53 protected void process(Constructor constructor) throws NoSuchMethodException {
54 ConstructorFinder.findConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes());
55 }
|
1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import com.sun.beans.finder.ConstructorFinder;
25
26 import java.lang.reflect.Constructor;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31 /*
32 * @test
33 * @bug 8028054
34 * @summary Tests that cached constructors have synchronized access
35 * @author Sergey Malenkov
36 * @modules java.desktop/com.sun.beans.finder
37 * @compile -XDignore.symbol.file TestConstructorFinder.java
38 * @run main TestConstructorFinder
39 */
40
41 public class TestConstructorFinder {
42 public static void main(String[] args) throws Exception {
43 List<Class<?>> classes = Task.getClasses(Integer.MAX_VALUE);
44 List<Constructor> constructors = new ArrayList<>();
45 for (Class<?> type : classes) {
46 Collections.addAll(constructors, type.getConstructors());
47 }
48 Task.print("found " + constructors.size() + " constructors in " + classes.size() + " classes");
49
50 List<Task> tasks = new ArrayList<>();
51 for (int i = 0; i < 50; i++) {
52 tasks.add(new Task<Constructor>(constructors) {
53 @Override
54 protected void process(Constructor constructor) throws NoSuchMethodException {
55 ConstructorFinder.findConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes());
56 }
|