1 #
   2 # Copyright (c) 2005, 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 # @test
  25 # @bug 6173575
  26 # @summary Unit tests for appendToBootstrapClassLoaderSearch and
  27 #   appendToSystemClasLoaderSearch methods.
  28 #
  29 # @modules java.instrument
  30 # @build ClassUnloadTest
  31 # @run shell ClassUnloadTest.sh
  32 
  33 if [ "${TESTSRC}" = "" ]
  34 then
  35   echo "TESTSRC not set.  Test cannot execute.  Failed."
  36   exit 1
  37 fi
  38 
  39 . ${TESTSRC}/CommonSetup.sh
  40 
  41 # Create Foo and Bar
  42 # Foo has a reference to Bar but we deleted Bar so that
  43 # a NoClassDefFoundError will be thrown when Foo tries to
  44 # resolve the reference to Bar
  45 
  46 OTHERDIR="${TESTCLASSES}"/other
  47 mkdir "${OTHERDIR}"
  48 
  49 FOO="${OTHERDIR}"/Foo.java
  50 BAR="${OTHERDIR}"/Bar.java
  51 rm -f "${FOO}" "${BAR}"
  52 
  53 cat << EOF > "${FOO}"
  54   public class Foo {
  55       public static boolean doSomething() {
  56           try {
  57               Bar b = new Bar();
  58               return true;
  59           } catch (NoClassDefFoundError x) {
  60               return false;
  61           }
  62       }
  63   }
  64 EOF
  65 
  66 echo "public class Bar { }" > "${BAR}"
  67 
  68 (cd "${OTHERDIR}"; \
  69   $JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} Foo.java Bar.java; \
  70   $JAR ${TESTTOOLVMOPTS} cf "${OTHERDIR}"/Bar.jar Bar.class; \
  71   rm -f Bar.class)
  72 
  73 # Create the manifest
  74 MANIFEST="${TESTCLASSES}"/agent.mf
  75 rm -f "${MANIFEST}"
  76 echo "Premain-Class: ClassUnloadTest" > "${MANIFEST}"
  77 
  78 # Setup test case as an agent
  79 $JAR ${TESTTOOLVMOPTS} -cfm "${TESTCLASSES}"/ClassUnloadTest.jar "${MANIFEST}" \
  80   -C "${TESTCLASSES}" ClassUnloadTest.class
  81 
  82 # Finally we run the test
  83 (cd "${TESTCLASSES}"; \
  84   $JAVA ${TESTVMOPTS} -Xverify:none -XX:+TraceClassUnloading \
  85     -javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)