Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLDecoder/8028054/TestMethodFinder.java
38828 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import com.sun.beans.finder.MethodFinder;2425import java.lang.reflect.Method;26import java.util.ArrayList;27import java.util.Collections;28import java.util.List;2930/*31* @test32* @bug 802805433* @summary Tests that cached methods have synchronized access34* @author Sergey Malenkov35* @compile -XDignore.symbol.file TestMethodFinder.java36* @run main TestMethodFinder37*/3839public class TestMethodFinder {40public static void main(String[] args) throws Exception {41List<Class<?>> classes = Task.getClasses(4000);42List<Method> methods = new ArrayList<>();43for (Class<?> type : classes) {44Collections.addAll(methods, type.getMethods());45}46Task.print("found " + methods.size() + " methods in " + classes.size() + " classes");4748List<Task> tasks = new ArrayList<>();49for (int i = 0; i < 50; i++) {50tasks.add(new Task<Method>(methods) {51@Override52protected void process(Method method) throws NoSuchMethodException {53MethodFinder.findMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes());54}55});56}57int alarm = 0;58while (true) {59int alive = 0;60int working = 0;61for (Task task : tasks) {62if (task.isWorking()) {63working++;64alive++;65} else if (task.isAlive()) {66alive++;67}68}69if (alive == 0) {70break;71}72Task.print(working + " out of " + alive + " threads are working");73if ((working == 0) && (++alarm == 10)) {74Task.print("DEADLOCK DETECTED");75System.exit(100);76}77Thread.sleep(1000);78}79}80}818283