Path: blob/master/test/jdk/java/beans/XMLDecoder/8028054/TestMethodFinder.java
41153 views
/*1* Copyright (c) 2013, 2018, 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* @modules java.desktop/com.sun.beans.finder36* @compile -XDignore.symbol.file TestMethodFinder.java37* @run main TestMethodFinder38*/3940public class TestMethodFinder {41public static void main(String[] args) throws Exception {42List<Class<?>> classes = Task.getClasses(4000);43List<Method> methods = new ArrayList<>();44for (Class<?> type : classes) {45Collections.addAll(methods, type.getMethods());46}47Task.print("found " + methods.size() + " methods in " + classes.size() + " classes");4849List<Task> tasks = new ArrayList<>();50for (int i = 0; i < 50; i++) {51tasks.add(new Task<Method>(methods) {52@Override53protected void process(Method method) throws NoSuchMethodException {54MethodFinder.findMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes());55}56});57}58int alarm = 0;59while (true) {60int alive = 0;61int working = 0;62for (Task task : tasks) {63if (task.isWorking()) {64working++;65alive++;66} else if (task.isAlive()) {67alive++;68}69}70if (alive == 0) {71break;72}73Task.print(working + " out of " + alive + " threads are working");74if ((working == 0) && (++alarm == 10)) {75throw new RuntimeException("FAIL - DEADLOCK DETECTED");76}77Thread.sleep(1000);78}79}80}818283