ClassUnloadTest.java revision 0
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
*
*
* Unit test for Instrumentation appendToSystemClassLoaderSearch. This
* test does the following:
*
* 1. Creates a class loader to load class Foo. Execute Foo.doSomething
* which references a missing class Bar. The doSomething method
* should fail with NoClassDefFoundError.
*
* 2. Add Bar.jar to the system class path. Bar.jar contains Bar.
*
* 3. Create another class loader to load Foo. Execute Foo.doSomething.
* doSomething will load Bar.
*
* 4. Re-execute the first Foo's doSomething - it should fail a second
* time because the attempt to resolve Bar must fail with the same
* error as the first attempt.
*
* 5. De-reference both class loaders and execute System.gc(). We can't
* assert that the Foo classes will be unloaded but it serves to
* exercise the unload code path in HotSpot.
*/
public class ClassUnloadTest {
static Instrumentation ins;
// This should fail as Bar is not available
if (result.booleanValue()) {
throw new RuntimeException("Test configuration error - doSomething should not succeed");
}
// put Bar on the system class path
// This should fail even though Bar is now available
if (result.booleanValue()) {
throw new RuntimeException("Test configuration error - doSomething should not succeed");
}
// This should succeed because this is a different Foo
if (!result.booleanValue()) {
throw new RuntimeException("Test configuration error - doSomething did not succeed");
}
// Exercise some class unloading
}
static class Invoker {
Method m;
{
}
{
}
}
ins = i;
}
}