mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8183503: Update hotspot tests to allow for unique test classes directory
Reviewed-by: iklam
This commit is contained in:
parent
0a79d06e97
commit
ce9501e66a
3 changed files with 43 additions and 10 deletions
|
@ -108,8 +108,8 @@ public class TestAnonymousClassUnloading {
|
||||||
*/
|
*/
|
||||||
static public void main(String[] args) throws Exception {
|
static public void main(String[] args) throws Exception {
|
||||||
// (1) Load an anonymous version of this class using the corresponding Unsafe method
|
// (1) Load an anonymous version of this class using the corresponding Unsafe method
|
||||||
URL classUrl = TestAnonymousClassUnloading.class.getResource(
|
String rn = TestAnonymousClassUnloading.class.getSimpleName() + ".class";
|
||||||
TestAnonymousClassUnloading.class.getName().replace('.', '/') + ".class");
|
URL classUrl = TestAnonymousClassUnloading.class.getResource(rn);
|
||||||
URLConnection connection = classUrl.openConnection();
|
URLConnection connection = classUrl.openConnection();
|
||||||
|
|
||||||
int length = connection.getContentLength();
|
int length = connection.getContentLength();
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class ClassLoadUnloadTest {
|
||||||
List<String> argsList = new ArrayList<>();
|
List<String> argsList = new ArrayList<>();
|
||||||
Collections.addAll(argsList, args);
|
Collections.addAll(argsList, args);
|
||||||
Collections.addAll(argsList, "-Xmn8m");
|
Collections.addAll(argsList, "-Xmn8m");
|
||||||
Collections.addAll(argsList, "-Dtest.classes=" + System.getProperty("test.classes","."));
|
Collections.addAll(argsList, "-Dtest.class.path=" + System.getProperty("test.class.path", "."));
|
||||||
Collections.addAll(argsList, ClassUnloadTestMain.class.getName());
|
Collections.addAll(argsList, ClassUnloadTestMain.class.getName());
|
||||||
return ProcessTools.createJavaProcessBuilder(argsList.toArray(new String[argsList.size()]));
|
return ProcessTools.createJavaProcessBuilder(argsList.toArray(new String[argsList.size()]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,10 @@ import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ClassUnloadCommon {
|
public class ClassUnloadCommon {
|
||||||
public static class TestFailure extends RuntimeException {
|
public static class TestFailure extends RuntimeException {
|
||||||
|
@ -61,14 +63,45 @@ public class ClassUnloadCommon {
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a class loader that loads classes from {@code ${test.class.path}}
|
||||||
|
* before delegating to the system class loader.
|
||||||
|
*/
|
||||||
public static ClassLoader newClassLoader() {
|
public static ClassLoader newClassLoader() {
|
||||||
|
String cp = System.getProperty("test.class.path", ".");
|
||||||
|
URL[] urls = Stream.of(cp.split(File.pathSeparator))
|
||||||
|
.map(Paths::get)
|
||||||
|
.map(ClassUnloadCommon::toURL)
|
||||||
|
.toArray(URL[]::new);
|
||||||
|
return new URLClassLoader(urls) {
|
||||||
|
@Override
|
||||||
|
public Class<?> loadClass(String cn, boolean resolve)
|
||||||
|
throws ClassNotFoundException
|
||||||
|
{
|
||||||
|
synchronized (getClassLoadingLock(cn)) {
|
||||||
|
Class<?> c = findLoadedClass(cn);
|
||||||
|
if (c == null) {
|
||||||
try {
|
try {
|
||||||
return new URLClassLoader(new URL[] {
|
c = findClass(cn);
|
||||||
Paths.get(System.getProperty("test.classes",".") + File.separatorChar + "classes").toUri().toURL(),
|
} catch (ClassNotFoundException e) {
|
||||||
}, null);
|
c = getParent().loadClass(cn);
|
||||||
} catch (MalformedURLException e){
|
|
||||||
throw new RuntimeException("Unexpected URL conversion failure", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (resolve) {
|
||||||
|
resolveClass(c);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static URL toURL(Path path) {
|
||||||
|
try {
|
||||||
|
return path.toUri().toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue