提交 96913396 编写于 作者: V valeriep

4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating

Summary: Added support for parallel-capable class loaders
Reviewed-by: alanb
上级 1497d82e
#
# Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 1997-2009 Sun Microsystems, Inc. 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
......@@ -135,7 +135,8 @@ SUNWprivate_1.1 {
Java_java_lang_ClassLoader_00024NativeLibrary_find;
Java_java_lang_ClassLoader_00024NativeLibrary_load;
Java_java_lang_ClassLoader_00024NativeLibrary_unload;
Java_java_lang_ClassLoader_registerNatives;
Java_java_lang_ClassLoader_getCaller;
Java_java_lang_ClassLoader_registerNatives;
Java_java_lang_Compiler_registerNatives;
Java_java_lang_Double_longBitsToDouble;
Java_java_lang_Double_doubleToRawLongBits;
......
/*
* Copyright 1994-2008 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1994-2009 Sun Microsystems, Inc. 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
......@@ -2846,14 +2846,14 @@ public final
if (loader == null)
return desiredAssertionStatus0(this);
synchronized(loader) {
// If the classloader has been initialized with
// the assertion directives, ask it. Otherwise,
// ask the VM.
return (loader.classAssertionStatus == null ?
desiredAssertionStatus0(this) :
loader.desiredAssertionStatus(getName()));
// If the classloader has been initialized with the assertion
// directives, ask it. Otherwise, ask the VM.
synchronized(loader.assertionLock) {
if (loader.classAssertionStatus != null) {
return loader.desiredAssertionStatus(getName());
}
}
return desiredAssertionStatus0(this);
}
// Retrieves the desired assertion status of this class from the VM
......
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2009 Sun Microsystems, Inc. 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
......@@ -74,10 +74,10 @@ import sun.security.util.SecurityConstants;
*/
public class URLClassLoader extends SecureClassLoader implements Closeable {
/* The search path for classes and resources */
URLClassPath ucp;
private final URLClassPath ucp;
/* The context to be used when loading classes and resources */
private AccessControlContext acc;
private final AccessControlContext acc;
/**
* Constructs a new URLClassLoader for the given URLs. The URLs will be
......@@ -105,7 +105,19 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
security.checkCreateClassLoader();
}
ucp = new URLClassPath(urls);
acc = AccessController.getContext();
this.acc = AccessController.getContext();
}
URLClassLoader(URL[] urls, ClassLoader parent,
AccessControlContext acc) {
super(parent);
// this is to make the stack depth consistent with 1.1
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkCreateClassLoader();
}
ucp = new URLClassPath(urls);
this.acc = acc;
}
/**
......@@ -136,7 +148,18 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
security.checkCreateClassLoader();
}
ucp = new URLClassPath(urls);
acc = AccessController.getContext();
this.acc = AccessController.getContext();
}
URLClassLoader(URL[] urls, AccessControlContext acc) {
super();
// this is to make the stack depth consistent with 1.1
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkCreateClassLoader();
}
ucp = new URLClassPath(urls);
this.acc = acc;
}
/**
......@@ -599,17 +622,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
public static URLClassLoader newInstance(final URL[] urls,
final ClassLoader parent) {
// Save the caller's context
AccessControlContext acc = AccessController.getContext();
final AccessControlContext acc = AccessController.getContext();
// Need a privileged block to create the class loader
URLClassLoader ucl = AccessController.doPrivileged(
new PrivilegedAction<URLClassLoader>() {
public URLClassLoader run() {
return new FactoryURLClassLoader(urls, parent);
return new FactoryURLClassLoader(urls, parent, acc);
}
});
// Now set the context on the loader using the one we saved,
// not the one inside the privileged block...
ucl.acc = acc;
return ucl;
}
......@@ -626,18 +646,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
*/
public static URLClassLoader newInstance(final URL[] urls) {
// Save the caller's context
AccessControlContext acc = AccessController.getContext();
final AccessControlContext acc = AccessController.getContext();
// Need a privileged block to create the class loader
URLClassLoader ucl = AccessController.doPrivileged(
new PrivilegedAction<URLClassLoader>() {
public URLClassLoader run() {
return new FactoryURLClassLoader(urls);
return new FactoryURLClassLoader(urls, acc);
}
});
// Now set the context on the loader using the one we saved,
// not the one inside the privileged block...
ucl.acc = acc;
return ucl;
}
......@@ -649,20 +665,26 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
}
}
);
ClassLoader.registerAsParallelCapable();
}
}
final class FactoryURLClassLoader extends URLClassLoader {
FactoryURLClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
static {
ClassLoader.registerAsParallelCapable();
}
FactoryURLClassLoader(URL[] urls, ClassLoader parent,
AccessControlContext acc) {
super(urls, parent, acc);
}
FactoryURLClassLoader(URL[] urls) {
super(urls);
FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
super(urls, acc);
}
public final synchronized Class loadClass(String name, boolean resolve)
public final Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// First check if we have permission to access the package. This
......
/*
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2009 Sun Microsystems, Inc. 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
......@@ -45,14 +45,19 @@ public class SecureClassLoader extends ClassLoader {
* succeed. Otherwise the object is not initialized and the object is
* useless.
*/
private boolean initialized = false;
private final boolean initialized;
// HashMap that maps CodeSource to ProtectionDomain
private HashMap<CodeSource, ProtectionDomain> pdcache =
// @GuardedBy("pdcache")
private final HashMap<CodeSource, ProtectionDomain> pdcache =
new HashMap<CodeSource, ProtectionDomain>(11);
private static final Debug debug = Debug.getInstance("scl");
static {
ClassLoader.registerAsParallelCapable();
}
/**
* Creates a new SecureClassLoader using the specified parent
* class loader for delegation.
......@@ -136,10 +141,7 @@ public class SecureClassLoader extends ClassLoader {
byte[] b, int off, int len,
CodeSource cs)
{
if (cs == null)
return defineClass(name, b, off, len);
else
return defineClass(name, b, off, len, getProtectionDomain(cs));
return defineClass(name, b, off, len, getProtectionDomain(cs));
}
/**
......@@ -172,10 +174,7 @@ public class SecureClassLoader extends ClassLoader {
protected final Class<?> defineClass(String name, java.nio.ByteBuffer b,
CodeSource cs)
{
if (cs == null)
return defineClass(name, b, (ProtectionDomain)null);
else
return defineClass(name, b, getProtectionDomain(cs));
return defineClass(name, b, getProtectionDomain(cs));
}
/**
......@@ -209,12 +208,10 @@ public class SecureClassLoader extends ClassLoader {
if (pd == null) {
PermissionCollection perms = getPermissions(cs);
pd = new ProtectionDomain(cs, perms, this, null);
if (pd != null) {
pdcache.put(cs, pd);
if (debug != null) {
debug.println(" getPermissions "+ pd);
debug.println("");
}
pdcache.put(cs, pd);
if (debug != null) {
debug.println(" getPermissions "+ pd);
debug.println("");
}
}
}
......
/*
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1998-2009 Sun Microsystems, Inc. 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
......@@ -120,7 +120,10 @@ public class Launcher {
* The class loader used for loading installed extensions.
*/
static class ExtClassLoader extends URLClassLoader {
private File[] dirs;
static {
ClassLoader.registerAsParallelCapable();
}
/**
* create an ExtClassLoader. The ExtClassLoader is created
......@@ -146,12 +149,12 @@ public class Launcher {
}
});
} catch (java.security.PrivilegedActionException e) {
throw (IOException) e.getException();
throw (IOException) e.getException();
}
}
void addExtURL(URL url) {
super.addURL(url);
super.addURL(url);
}
/*
......@@ -159,7 +162,6 @@ public class Launcher {
*/
public ExtClassLoader(File[] dirs) throws IOException {
super(getExtURLs(dirs), null, factory);
this.dirs = dirs;
}
private static File[] getExtDirs() {
......@@ -206,20 +208,27 @@ public class Launcher {
*/
public String findLibrary(String name) {
name = System.mapLibraryName(name);
for (int i = 0; i < dirs.length; i++) {
// Look in architecture-specific subdirectory first
String arch = System.getProperty("os.arch");
if (arch != null) {
File file = new File(new File(dirs[i], arch), name);
URL[] urls = super.getURLs();
File prevDir = null;
for (int i = 0; i < urls.length; i++) {
// Get the ext directory from the URL
File dir = new File(urls[i].getPath()).getParentFile();
if (dir != null && !dir.equals(prevDir)) {
// Look in architecture-specific subdirectory first
String arch = System.getProperty("os.arch");
if (arch != null) {
File file = new File(new File(dir, arch), name);
if (file.exists()) {
return file.getAbsolutePath();
}
}
// Then check the extension directory
File file = new File(dir, name);
if (file.exists()) {
return file.getAbsolutePath();
}
}
// Then check the extension directory
File file = new File(dirs[i], name);
if (file.exists()) {
return file.getAbsolutePath();
}
prevDir = dir;
}
return null;
}
......@@ -248,6 +257,10 @@ public class Launcher {
*/
static class AppClassLoader extends URLClassLoader {
static {
ClassLoader.registerAsParallelCapable();
}
public static ClassLoader getAppClassLoader(final ClassLoader extcl)
throws IOException
{
......@@ -281,7 +294,7 @@ public class Launcher {
/**
* Override loadClass so we can checkPackageAccess.
*/
public synchronized Class loadClass(String name, boolean resolve)
public Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
int i = name.lastIndexOf('.');
......
/*
* Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2009 Sun Microsystems, Inc. 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
......@@ -437,3 +437,21 @@ Java_java_lang_ClassLoader_00024NativeLibrary_find
(*env)->ReleaseStringUTFChars(env, name, cname);
return res;
}
JNIEXPORT jobject JNICALL
Java_java_lang_ClassLoader_getCaller(JNIEnv *env, jclass cls, jint index)
{
jobjectArray jcallerStack;
int len;
jcallerStack = JVM_GetClassContext(env);
if ((*env)->ExceptionCheck(env)) {
return NULL;
}
len = (*env)->GetArrayLength(env, jcallerStack);
if (index < len) {
return (*env)->GetObjectArrayElement(env, jcallerStack, index);
}
return NULL;
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
package comSA;
public class Alice extends comSB.SupAlice {
static {
System.out.println("comSA.Alice loaded");
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
package comSB;
public class Bob extends comSA.SupBob {
static {
System.out.println("comSB.Bob loaded");
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.*;
import java.lang.reflect.*;
public class DelegatingLoader extends URLClassLoader {
private DelegatingLoader delLoader;
private String[] delClasses;
static {
boolean supportParallel = false;
try {
Class c = Class.forName("java.lang.ClassLoader");
Method m = c.getDeclaredMethod("registerAsParallelCapable",
new Class[0]);
m.setAccessible(true);
Object result = (Boolean) m.invoke(null);
if (result instanceof Boolean) {
supportParallel = ((Boolean) result).booleanValue();
} else {
// Should never happen
System.out.println("Error: ClassLoader.registerAsParallelCapable() did not return a boolean!");
System.exit(1);
}
} catch (NoSuchMethodException nsme) {
System.out.println("No ClassLoader.registerAsParallelCapable() API");
} catch (NoSuchMethodError nsme2) {
System.out.println("No ClassLoader.registerAsParallelCapable() API");
} catch (Exception ex) {
ex.printStackTrace();
// Exit immediately to indicate an error
System.exit(1);
}
System.out.println("Parallel ClassLoader registration: " +
supportParallel);
}
public DelegatingLoader(URL urls[]) {
super(urls);
System.out.println("DelegatingLoader using URL " + urls[0]);
}
public void setDelegate(String[] delClasses, DelegatingLoader delLoader) {
this.delClasses = delClasses;
this.delLoader = delLoader;
}
public Class loadClass(String className, boolean resolve)
throws ClassNotFoundException {
for (int i = 0; i < delClasses.length; i++) {
if (delClasses[i].equals(className)) {
Starter.log("Delegating class loading for " + className);
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
return null;
}
return delLoader.loadClass(className, resolve);
}
}
Starter.log("Loading local class " + className);
// synchronized (getClassLoadingLock(className)) {
return super.loadClass(className, resolve);
// }
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
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");
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
package comSB;
public class SupAlice {
static {
System.out.println("comSB.SupAlice loaded");
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 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.
*/
package comSA;
public class SupBob {
static {
System.out.println("comSA.SupBob loaded");
}
}
#
# Copyright 2009 Sun Microsystems, Inc. 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 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.
#
# @test
# @bug 4735126
# @summary (cl) ClassLoader.loadClass locks all instances in chain
# when delegating
#
# @run shell/timeout=10 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
echo TESTSRC=${TESTSRC}
echo TESTCLASSES=${TESTCLASSES}
echo TESTJAVA=${TESTJAVA}
echo ""
# set platform-specific variables
OS=`uname -s`
case "$OS" in
SunOS )
FS="/"
;;
Linux )
FS="/"
;;
Windows* )
FS="\\"
;;
esac
# compile test
${TESTJAVA}${FS}bin${FS}javac \
-d ${TESTCLASSES} \
${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java
STATUS=$?
if [ ${STATUS} -ne 0 ]
then
exit ${STATUS}
fi
# set up test
${TESTJAVA}${FS}bin${FS}javac \
-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 \
-verbose:class -XX:+TraceClassLoading -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}
#
# Copyright 2009 Sun Microsystems, Inc. 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 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.
#
# @test
# @bug 4735126
# @summary (cl) ClassLoader.loadClass locks all instances in chain
# when delegating
#
# @run shell/timeout=10 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
echo TESTSRC=${TESTSRC}
echo TESTCLASSES=${TESTCLASSES}
echo TESTJAVA=${TESTJAVA}
echo ""
# set platform-specific variables
OS=`uname -s`
case "$OS" in
SunOS )
FS="/"
;;
Linux )
FS="/"
;;
Windows* )
FS="\\"
;;
esac
# compile test
${TESTJAVA}${FS}bin${FS}javac \
-d ${TESTCLASSES} \
${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java
STATUS=$?
if [ ${STATUS} -ne 0 ]
then
exit ${STATUS}
fi
# set up test
${TESTJAVA}${FS}bin${FS}javac \
-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 \
-verbose:class -XX:+TraceClassLoading -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}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册