Class DelegatingClassLoader
- Direct Known Subclasses:
ExistenceCheckingClassLoader
,MaskingClassLoader
,PluginManager.UberClassLoader
ClassLoader
that does not define any classes itself but delegates class loading to
other class loaders to avoid the JDK's per-class-name locking and lock retention.
This class first attempts to load classes via its ClassLoader.getParent()
class loader,
then falls back to ClassLoader.findClass(java.lang.String)
to allow for custom delegation logic.
In a parallel-capable ClassLoader
, the JDK maintains a per-name lock object
indefinitely. In Jenkins, many class loading misses across many loaders can accumulate hundreds
of thousands of such locks, retaining significant memory. This loader never defines classes and
bypasses ClassLoader
's default loadClass
locking; it delegates to the parent
first and then to findClass
for custom delegation.
The actual defining loader (parent or a delegate) still performs the necessary synchronization
and class definition. A runtime guard (verify(java.lang.Class<?>)
) throws if this loader ever becomes the
defining loader.
Subclasses must not call defineClass
; implement delegation in findClass
if
needed and do not mark subclasses as parallel-capable.
- Author:
- Dmytro Ukhlov
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDelegatingClassLoader
(ClassLoader parent) protected
DelegatingClassLoader
(String name, ClassLoader parent) -
Method Summary
Modifier and TypeMethodDescriptionprotected Class
<?> Parent-first delegation without synchronizing onClassLoader.getClassLoadingLock(String)
.Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
DelegatingClassLoader
-
DelegatingClassLoader
-
-
Method Details
-
loadClass
Parent-first delegation without synchronizing onClassLoader.getClassLoadingLock(String)
. This prevents creation/retention of per-name lock objects in a loader that does not define classes. The defining loader downstream still serializes class definition as required.- Overrides:
loadClass
in classClassLoader
- Parameters:
name
- The binary name of the classresolve
- Iftrue
then resolve the class- Returns:
- The resulting
Class
object - Throws:
ClassNotFoundException
- If the class could not be found
-