--- old/test/java/lang/ClassLoader/deadlock/DelegatingLoader.java 2017-07-13 14:25:39.000000000 +0800 +++ new/test/java/lang/ClassLoader/deadlock/DelegatingLoader.java 2017-07-13 14:25:38.000000000 +0800 @@ -75,7 +75,7 @@ throws ClassNotFoundException { for (int i = 0; i < delClasses.length; i++) { if (delClasses[i].equals(className)) { - Starter.log("Delegating class loading for " + className); + DelegateTest.log("Delegating class loading for " + className); try { Thread.sleep(500); } catch (InterruptedException ie) { @@ -85,7 +85,7 @@ } } - Starter.log("Loading local class " + className); + DelegateTest.log("Loading local class " + className); // synchronized (getClassLoadingLock(className)) { return super.loadClass(className, resolve); // } --- old/test/java/lang/ClassLoader/deadlock/Starter.java 2017-07-13 14:25:40.000000000 +0800 +++ /dev/null 2017-07-13 14:25:40.000000000 +0800 @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.net.MalformedURLException; -import java.net.URL; - -public class Starter implements Runnable { - - private String id; - private DelegatingLoader dl; - private String startClass; - - private static DelegatingLoader saLoader, sbLoader; - - public static void log(String line) { - System.out.println(line); - } - - public static void main(String[] args) { - URL[] urlsa = new URL[1]; - URL[] urlsb = new URL[1]; - try { - String testDir = System.getProperty("test.classes", "."); - String sep = System.getProperty("file.separator"); - urlsa[0] = new URL("file://" + testDir + sep + "SA" + sep); - urlsb[0] = new URL("file://" + testDir + sep + "SB" + sep); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - // Set up Classloader delegation hierarchy - saLoader = new DelegatingLoader(urlsa); - sbLoader = new DelegatingLoader(urlsb); - - String[] saClasses = { "comSA.SupBob", "comSA.Alice" }; - String[] sbClasses = { "comSB.SupAlice", "comSB.Bob" }; - - saLoader.setDelegate(sbClasses, sbLoader); - sbLoader.setDelegate(saClasses, saLoader); - - // test one-way delegate - String testType = args[0]; - if (testType.equals("one-way")) { - test("comSA.Alice", "comSA.SupBob"); - } else if (testType.equals("cross")) { - // test cross delegate - test("comSA.Alice", "comSB.Bob"); - } else { - System.out.println("ERROR: unsupported - " + testType); - } - } - - private static void test(String clsForSA, String clsForSB) { - Starter ia = new Starter("SA", saLoader, clsForSA); - Starter ib = new Starter("SB", sbLoader, clsForSB); - new Thread(ia).start(); - new Thread(ib).start(); - } - - public static void sleep() { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - e.printStackTrace(); - log("Thread interrupted"); - } - } - - private Starter(String id, DelegatingLoader dl, String startClass) { - this.id = id; - this.dl = dl; - this.startClass = startClass; - } - - public void run() { - log("Spawned thread " + id + " running"); - try { - // To mirror the WAS deadlock, need to ensure class load - // is routed via the VM. - Class.forName(startClass, true, dl); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - log("Thread " + id + " terminating"); - } -} --- /dev/null 2017-07-13 14:25:40.000000000 +0800 +++ new/test/java/lang/ClassLoader/deadlock/DelegateTest.java 2017-07-13 14:25:39.000000000 +0800 @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4735126 + * @summary (cl) ClassLoader.loadClass locks all instances in chain when delegating + * @modules java.base/java.lang:open + * @build Alice Bob SupAlice SupBob + * @run driver SetupLoader + * @run main/othervm -Xlog:class+load DelegateTest one-way + * @run main/othervm -Xlog:class+load DelegateTest cross + */ + +import java.net.MalformedURLException; +import java.net.URL; + +public class DelegateTest implements Runnable { + + private String id; + private DelegatingLoader dl; + private String startClass; + + private static DelegatingLoader saLoader, sbLoader; + + public static void log(String line) { + System.out.println(line); + } + + public static void main(String[] args) throws Exception { + URL[] urlsa = new URL[1]; + URL[] urlsb = new URL[1]; + try { + String testDir = System.getProperty("user.dir", "."); + String sep = System.getProperty("file.separator"); + urlsa[0] = new URL("file://" + testDir + sep + "SA" + sep); + urlsb[0] = new URL("file://" + testDir + sep + "SB" + sep); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + // Set up Classloader delegation hierarchy + saLoader = new DelegatingLoader(urlsa); + sbLoader = new DelegatingLoader(urlsb); + + String[] saClasses = { "comSA.SupBob", "comSA.Alice" }; + String[] sbClasses = { "comSB.SupAlice", "comSB.Bob" }; + + saLoader.setDelegate(sbClasses, sbLoader); + sbLoader.setDelegate(saClasses, saLoader); + + // test one-way delegate + String testType = args[0]; + if (testType.equals("one-way")) { + test("comSA.Alice", "comSA.SupBob"); + } else if (testType.equals("cross")) { + // test cross delegate + test("comSA.Alice", "comSB.Bob"); + } else { + System.out.println("ERROR: unsupported - " + testType); + } + } + + private static void test(String clsForSA, String clsForSB) throws InterruptedException { + DelegateTest ia = new DelegateTest("SA", saLoader, clsForSA); + DelegateTest ib = new DelegateTest("SB", sbLoader, clsForSB); + Thread ta = new Thread(ia); + Thread tb = new Thread(ib); + ta.start(); + tb.start(); + ta.join(); + tb.join(); + } + + public static void sleep() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + log("Thread interrupted"); + } + } + + private DelegateTest(String id, DelegatingLoader dl, String startClass) { + this.id = id; + this.dl = dl; + this.startClass = startClass; + } + + public void run() { + log("Spawned thread " + id + " running"); + try { + // To mirror the WAS deadlock, need to ensure class load + // is routed via the VM. + Class.forName(startClass, true, dl); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + log("Thread " + id + " terminating"); + } +} --- /dev/null 2017-07-13 14:25:41.000000000 +0800 +++ new/test/java/lang/ClassLoader/deadlock/SetupLoader.java 2017-07-13 14:25:40.000000000 +0800 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class SetupLoader { + + public static void main(String args[]) throws Exception { + String userDir = System.getProperty("user.dir", "."); + Path classes = Paths.get(System.getProperty("test.classes")); + move(classes.resolve("comSA"), Paths.get(userDir, "SA", "comSA")); + move(classes.resolve("comSB"), Paths.get(userDir, "SB", "comSB")); + } + + private static void move(Path from, Path to) throws IOException { + System.out.printf("Files.move(\"%s\", \"%s\")%n", + from.toString(), to.toString()); + Files.createDirectories(to); + Files.move(from, to, StandardCopyOption.REPLACE_EXISTING); + } +} --- old/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh 2017-07-13 14:25:41.000000000 +0800 +++ /dev/null 2017-07-13 14:25:41.000000000 +0800 @@ -1,122 +0,0 @@ -# -# Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# -# @test -# @bug 4735126 -# @summary (cl) ClassLoader.loadClass locks all instances in chain -# when delegating -# -# @run shell/timeout=300 TestCrossDelegate.sh - -# if running by hand on windows, change TESTSRC and TESTCLASSES to "." -if [ "${TESTSRC}" = "" ] ; then - TESTSRC=`pwd` -fi -if [ "${TESTCLASSES}" = "" ] ; then - TESTCLASSES=`pwd` -fi - -# if running by hand on windows, change this to appropriate value -if [ "${TESTJAVA}" = "" ] ; then - echo "TESTJAVA not set. Test cannot execute." - echo "FAILED!!!" - exit 1 -fi - -if [ "${COMPILEJAVA}" = "" ] ; then - COMPILEJAVA="${TESTJAVA}" -fi - -# set platform-specific variables -OS=`uname -s` -case "$OS" in - SunOS ) - FS="/" - ;; - Linux ) - FS="/" - ;; - Darwin ) - FS="/" - ;; - AIX ) - FS="/" - ;; - Windows*) - FS="\\" - ;; - CYGWIN* ) - FS="\\" - TESTCLASSES=`/usr/bin/cygpath -a -s -m ${TESTCLASSES}` - ;; -esac - -echo TESTSRC=${TESTSRC} -echo TESTCLASSES=${TESTCLASSES} -echo TESTJAVA=${TESTJAVA} -echo "" - -# compile test -${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ - -d ${TESTCLASSES} \ - ${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java - -STATUS=$? -if [ ${STATUS} -ne 0 ] -then - exit ${STATUS} -fi - -# set up test -${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ - -d ${TESTCLASSES}${FS} \ - ${TESTSRC}${FS}Alice.java ${TESTSRC}${FS}SupBob.java \ - ${TESTSRC}${FS}Bob.java ${TESTSRC}${FS}SupAlice.java - -cd ${TESTCLASSES} -DIRS="SA SB" -for dir in $DIRS -do - if [ -d ${dir} ]; then - rm -rf ${dir} - fi - mkdir ${dir} - mv com${dir} ${dir} -done - -# run test -${TESTJAVA}${FS}bin${FS}java \ - ${TESTVMOPTS} \ - --add-opens java.base/java.lang=ALL-UNNAMED \ - -verbose:class -Xlog:class+load -cp . \ - -Dtest.classes=${TESTCLASSES} \ - Starter cross -# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \ - -# save error status -STATUS=$? - -# clean up -rm -rf ${TESTCLASSES}${FS}SA ${TESTCLASSES}${FS}SB - -# return -exit ${STATUS} --- old/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh 2017-07-13 14:25:42.000000000 +0800 +++ /dev/null 2017-07-13 14:25:42.000000000 +0800 @@ -1,118 +0,0 @@ -# -# Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# -# @test -# @bug 4735126 -# @summary (cl) ClassLoader.loadClass locks all instances in chain -# when delegating -# -# @run shell TestOneWayDelegate.sh - -# if running by hand on windows, change TESTSRC and TESTCLASSES to "." -if [ "${TESTSRC}" = "" ] ; then - TESTSRC=`pwd` -fi -if [ "${TESTCLASSES}" = "" ] ; then - TESTCLASSES=`pwd` -fi - -# if running by hand on windows, change this to appropriate value -if [ "${TESTJAVA}" = "" ] ; then - echo "TESTJAVA not set. Test cannot execute." - echo "FAILED!!!" - exit 1 -fi -if [ "${COMPILEJAVA}" = "" ] ; then - COMPILEJAVA="${TESTJAVA}" -fi - -echo TESTSRC=${TESTSRC} -echo TESTCLASSES=${TESTCLASSES} -echo TESTJAVA=${TESTJAVA} -echo COMPILEJAVA=${COMPILEJAVA} -echo "" - -# set platform-specific variables -OS=`uname -s` -case "$OS" in - SunOS ) - FS="/" - ;; - Linux ) - FS="/" - ;; - Darwin ) - FS="/" - ;; - AIX ) - FS="/" - ;; - Windows* | CYGWIN* ) - FS="\\" - ;; -esac - -# compile test -${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ - -d ${TESTCLASSES} \ - ${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java - -STATUS=$? -if [ ${STATUS} -ne 0 ] -then - exit ${STATUS} -fi - -# set up test -${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ - -d ${TESTCLASSES}${FS} \ - ${TESTSRC}${FS}Alice.java ${TESTSRC}${FS}SupBob.java \ - ${TESTSRC}${FS}Bob.java ${TESTSRC}${FS}SupAlice.java - -cd ${TESTCLASSES} -DIRS="SA SB" -for dir in $DIRS -do - if [ -d ${dir} ]; then - rm -rf ${dir} - fi - mkdir ${dir} - mv com${dir} ${dir} -done - -# run test -${TESTJAVA}${FS}bin${FS}java \ - ${TESTVMOPTS} \ - --add-opens java.base/java.lang=ALL-UNNAMED \ - -verbose:class -Xlog:class+load -cp . \ - -Dtest.classes=${TESTCLASSES} \ - Starter one-way -# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \ - -# save error status -STATUS=$? - -# clean up -rm -rf ${TESTCLASSES}${FS}SA ${TESTCLASSES}${FS}SB - -# return -exit ${STATUS}