Skip to content

Commit

Permalink
Merge pull request #41120 from gsmet/revert-parallel-classloader
Browse files Browse the repository at this point in the history
Revert "Improve loading of classes in RunnerClassLoader"
  • Loading branch information
gsmet authored Jun 11, 2024
2 parents b8994ac + 430fcb8 commit 5d49aba
Showing 1 changed file with 29 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
*/
public final class RunnerClassLoader extends ClassLoader {

static {
registerAsParallelCapable();
}

/**
* A map of resources by dir name. Root dir/default package is represented by the empty string
*/
Expand Down Expand Up @@ -107,55 +103,18 @@ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundExce
continue;
}
definePackage(packageName, resources);
return defineClass(name, data, resource);
}
}
return getParent().loadClass(name);
}

private void definePackage(String pkgName, ClassLoadingResource[] resources) {
if ((pkgName != null) && getDefinedPackage(pkgName) == null) {
for (ClassLoadingResource classPathElement : resources) {
ManifestInfo mf = classPathElement.getManifestInfo();
if (mf != null) {
try {
definePackage(pkgName, mf.getSpecTitle(),
mf.getSpecVersion(),
mf.getSpecVendor(),
mf.getImplTitle(),
mf.getImplVersion(),
mf.getImplVendor(), null);
} catch (IllegalArgumentException e) {
var loaded = getDefinedPackage(pkgName);
if (loaded == null) {
throw e;
}
try {
return defineClass(name, data, 0, data.length, resource.getProtectionDomain());
} catch (LinkageError e) {
loaded = findLoadedClass(name);
if (loaded != null) {
return loaded;
}
return;
}
}
try {
definePackage(pkgName, null, null, null, null, null, null, null);
} catch (IllegalArgumentException e) {
var loaded = getDefinedPackage(pkgName);
if (loaded == null) {
throw e;
}
}
}
}

private Class<?> defineClass(String name, byte[] data, ClassLoadingResource resource) {
Class<?> loaded;
try {
return defineClass(name, data, 0, data.length, resource.getProtectionDomain());
} catch (LinkageError e) {
loaded = findLoadedClass(name);
if (loaded != null) {
return loaded;
}
throw e;
}
return getParent().loadClass(name);
}

private void accessingResource(final ClassLoadingResource resource) {
Expand Down Expand Up @@ -262,6 +221,28 @@ protected Enumeration<URL> findResources(String name) {
return Collections.enumeration(urls);
}

private void definePackage(String pkgName, ClassLoadingResource[] resources) {
if ((pkgName != null) && getPackage(pkgName) == null) {
synchronized (getClassLoadingLock(pkgName)) {
if (getPackage(pkgName) == null) {
for (ClassLoadingResource classPathElement : resources) {
ManifestInfo mf = classPathElement.getManifestInfo();
if (mf != null) {
definePackage(pkgName, mf.getSpecTitle(),
mf.getSpecVersion(),
mf.getSpecVendor(),
mf.getImplTitle(),
mf.getImplVersion(),
mf.getImplVendor(), null);
return;
}
}
definePackage(pkgName, null, null, null, null, null, null, null);
}
}
}
}

private String getPackageNameFromClassName(String className) {
final int index = className.lastIndexOf('.');
if (index == -1) {
Expand Down

0 comments on commit 5d49aba

Please sign in to comment.