ClassUnloadTest.sh revision 0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# This code is free software; you can redistribute it and/or modify it
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# under the terms of the GNU General Public License version 2 only, as
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# published by the Free Software Foundation.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# This code is distributed in the hope that it will be useful, but WITHOUT
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# version 2 for more details (a copy is included in the LICENSE file that
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# accompanied this code).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# You should have received a copy of the GNU General Public License version
27e52281f1522522b170cafc76b08b58aa70ccaand# 2 along with this work; if not, write to the Free Software Foundation,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4b5981e276e93df97c34e4da05ca5cf8bbd937dand# CA 95054 USA or visit www.sun.com if you need additional information or
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# have any questions.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# @test
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun# @bug 6173575
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# @summary Unit tests for appendToBootstrapClassLoaderSearch and
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# appendToSystemClasLoaderSearch methods.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim# @build ClassUnloadTest
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim# @run shell ClassUnloadTest.sh
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndif [ "${TESTSRC}" = "" ]
a78048ccbdb6256da15e6b0e7e95355e480c2301ndthen
a78048ccbdb6256da15e6b0e7e95355e480c2301nd echo "TESTSRC not set. Test cannot execute. Failed."
a78048ccbdb6256da15e6b0e7e95355e480c2301nd exit 1
a78048ccbdb6256da15e6b0e7e95355e480c2301ndfi
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd. ${TESTSRC}/CommonSetup.sh
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Create Foo and Bar
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Foo has a reference to Bar but we deleted Bar so that
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# a NoClassDefFoundError will be thrown when Foo tries to
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# resolve the reference to Bar
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndOTHERDIR="${TESTCLASSES}"/other
a78048ccbdb6256da15e6b0e7e95355e480c2301ndmkdir "${OTHERDIR}"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndFOO="${OTHERDIR}"/Foo.java
a78048ccbdb6256da15e6b0e7e95355e480c2301ndBAR="${OTHERDIR}"/Bar.java
a78048ccbdb6256da15e6b0e7e95355e480c2301ndrm -f "${FOO}" "${BAR}"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndcat << EOF > "${FOO}"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public class Foo {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public static boolean doSomething() {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd try {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Bar b = new Bar();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return true;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd } catch (NoClassDefFoundError x) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return false;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301ndEOF
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndecho "public class Bar { }" > "${BAR}"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd(cd "${OTHERDIR}"; \
a78048ccbdb6256da15e6b0e7e95355e480c2301nd $JAVAC Foo.java Bar.java; $JAR cf "${OTHERDIR}"/Bar.jar Bar.class; \
a78048ccbdb6256da15e6b0e7e95355e480c2301nd rm -f Bar.class)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Create the manifest
a78048ccbdb6256da15e6b0e7e95355e480c2301ndMANIFEST="${TESTCLASSES}"/agent.mf
a78048ccbdb6256da15e6b0e7e95355e480c2301ndrm -f "${MANIFEST}"
a78048ccbdb6256da15e6b0e7e95355e480c2301ndecho "Premain-Class: ClassUnloadTest" > "${MANIFEST}"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Setup test case as an agent
a78048ccbdb6256da15e6b0e7e95355e480c2301nd$JAR -cfm "${TESTCLASSES}"/ClassUnloadTest.jar "${MANIFEST}" \
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -C "${TESTCLASSES}" ClassUnloadTest.class
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd# Finally we run the test
a78048ccbdb6256da15e6b0e7e95355e480c2301nd(cd "${TESTCLASSES}"; \
a78048ccbdb6256da15e6b0e7e95355e480c2301nd $JAVA -Xverify:none -XX:+TraceClassUnloading -javaagent:ClassUnloadTest.jar \
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ClassUnloadTest "${OTHERDIR}" Bar.jar)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd