Optimized TomcatInstrumentableClassLoader implementation

Issue: SPR-10788
(cherry picked from commit d32a77a)
This commit is contained in:
Juergen Hoeller
2013-08-01 15:49:58 +02:00
parent dcf7813de8
commit f88f5ed011
2 changed files with 20 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,15 +98,14 @@ public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver {
this.classLoader = classLoader;
this.addTransformerMethod = ClassUtils.getMethodIfAvailable(
this.classLoader.getClass(), ADD_TRANSFORMER_METHOD_NAME,
new Class [] {ClassFileTransformer.class});
new Class[] {ClassFileTransformer.class});
if (this.addTransformerMethod == null) {
throw new IllegalStateException(
"ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide an " +
"'addTransformer(ClassFileTransformer)' method.");
}
this.getThrowawayClassLoaderMethod = ClassUtils.getMethodIfAvailable(
this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME,
new Class[0]);
this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME, new Class[0]);
// getThrowawayClassLoader method is optional
if (this.getThrowawayClassLoaderMethod == null) {
if (logger.isInfoEnabled()) {
@@ -120,7 +119,7 @@ public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver {
@Override
public void addTransformer(ClassFileTransformer transformer) {
Assert.notNull(transformer, "Transformer must not be null");
ReflectionUtils.invokeMethod(this.addTransformerMethod, this.classLoader, new Object[] {transformer});
ReflectionUtils.invokeMethod(this.addTransformerMethod, this.classLoader, transformer);
}
@Override
@@ -131,11 +130,11 @@ public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver {
@Override
public ClassLoader getThrowawayClassLoader() {
if (this.getThrowawayClassLoaderMethod != null) {
return (ClassLoader) ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader,
new Object[0]);
return (ClassLoader) ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader);
}
else {
return new SimpleThrowawayClassLoader(this.classLoader);
}
}
}