1 #
   2 # Copyright (c) 2009, 2016, 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 # @test
  24 # @bug 4735126
  25 # @summary (cl) ClassLoader.loadClass locks all instances in chain
  26 #          when delegating
  27 #
  28 # @run shell TestOneWayDelegate.sh
  29 
  30 # if running by hand on windows, change TESTSRC and TESTCLASSES to "."
  31 if [ "${TESTSRC}" = "" ] ; then
  32     TESTSRC=`pwd`
  33 fi
  34 if [ "${TESTCLASSES}" = "" ] ; then
  35     TESTCLASSES=`pwd`
  36 fi
  37 
  38 # if running by hand on windows, change this to appropriate value
  39 if [ "${TESTJAVA}" = "" ] ; then
  40     echo "TESTJAVA not set.  Test cannot execute."
  41     echo "FAILED!!!"
  42     exit 1
  43 fi
  44 if [ "${COMPILEJAVA}" = "" ] ; then
  45     COMPILEJAVA="${TESTJAVA}"
  46 fi
  47 
  48 echo TESTSRC=${TESTSRC}
  49 echo TESTCLASSES=${TESTCLASSES}
  50 echo TESTJAVA=${TESTJAVA}
  51 echo COMPILEJAVA=${COMPILEJAVA}
  52 echo ""
  53 
  54 # set platform-specific variables
  55 OS=`uname -s`
  56 case "$OS" in
  57   SunOS )
  58     FS="/"
  59     ;;
  60   Linux )
  61     FS="/"
  62     ;;
  63   Darwin )
  64     FS="/"
  65     ;;
  66   AIX )
  67     FS="/"
  68     ;;
  69   Windows* | CYGWIN* )
  70     FS="\\"
  71     ;;
  72 esac
  73 
  74 # compile test
  75 ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
  76         -d ${TESTCLASSES} \
  77         ${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java
  78 
  79 STATUS=$?
  80 if [ ${STATUS} -ne 0 ]
  81 then
  82     exit ${STATUS}
  83 fi
  84 
  85 # set up test
  86 ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
  87         -d ${TESTCLASSES}${FS} \
  88         ${TESTSRC}${FS}Alice.java ${TESTSRC}${FS}SupBob.java \
  89         ${TESTSRC}${FS}Bob.java ${TESTSRC}${FS}SupAlice.java
  90 
  91 cd ${TESTCLASSES}
  92 DIRS="SA SB"
  93 for dir in $DIRS
  94 do
  95     if [ -d ${dir} ]; then
  96         rm -rf ${dir}
  97     fi
  98     mkdir ${dir}
  99     mv com${dir} ${dir}
 100 done
 101 
 102 # run test
 103 ${TESTJAVA}${FS}bin${FS}java \
 104         ${TESTVMOPTS} \
 105         --add-opens java.base/java.lang=ALL-UNNAMED \
 106         -verbose:class -Xlog:class+load -cp . \
 107         -Dtest.classes=${TESTCLASSES} \
 108         Starter one-way
 109 # -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \
 110 
 111 # save error status
 112 STATUS=$?
 113 
 114 # clean up
 115 rm -rf ${TESTCLASSES}${FS}SA ${TESTCLASSES}${FS}SB
 116 
 117 # return
 118 exit ${STATUS}