Package org.hotswap.agent.util
Class HotswapTransformer
- java.lang.Object
-
- org.hotswap.agent.util.HotswapTransformer
-
- All Implemented Interfaces:
ClassFileTransformer
public class HotswapTransformer extends Object implements ClassFileTransformer
Java instrumentation transformer. The is the single instance of transformer registered by HotswapAgent. It will delegate to plugins to do the transformer work.- Author:
- Jiri Bubnik
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<ClassFileTransformer,ClassLoader>classLoaderTransformersprotected Map<String,org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord>otherTransformersprotected Map<String,org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord>redefinitionTransformersprotected Map<ClassLoader,Boolean>seenClassLoaders
-
Constructor Summary
Constructors Constructor Description HotswapTransformer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseClassLoader(ClassLoader classLoader)Remove all transformers registered with a classloaderprotected booleanensureClassLoaderInitialized(ClassLoader classLoader, ProtectionDomain protectionDomain)Every classloader should be initialized.List<Pattern>getExcludedClassLoaderPatterns()List<Pattern>getIncludedClassLoaderPatterns()protected StringnormalizeTypeRegexp(String registeredType)Transform type to ^regexp$ form - match only whole pattern.voidregisterTransformer(ClassLoader classLoader, String classNameRegexp, HaClassFileTransformer transformer)Register a transformer for a regexp matching class names.voidremoveTransformer(String classNameRegexp, HaClassFileTransformer transformer)Remove registered transformer.voidsetExcludedClassLoaderPatterns(List<Pattern> excludedClassLoaderPatterns)voidsetIncludedClassLoaderPatterns(List<Pattern> includedClassLoaderPatterns)byte[]transform(ClassLoader classLoader, String className, Class<?> redefiningClass, ProtectionDomain protectionDomain, byte[] bytes)Main transform method called by Java instrumentation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.instrument.ClassFileTransformer
transform
-
-
-
-
Field Detail
-
redefinitionTransformers
protected Map<String,org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord> redefinitionTransformers
-
otherTransformers
protected Map<String,org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord> otherTransformers
-
classLoaderTransformers
protected Map<ClassFileTransformer,ClassLoader> classLoaderTransformers
-
seenClassLoaders
protected Map<ClassLoader,Boolean> seenClassLoaders
-
-
Method Detail
-
setIncludedClassLoaderPatterns
public void setIncludedClassLoaderPatterns(List<Pattern> includedClassLoaderPatterns)
-
setExcludedClassLoaderPatterns
public void setExcludedClassLoaderPatterns(List<Pattern> excludedClassLoaderPatterns)
- Parameters:
excludedClassLoaderPatterns- the excludedClassLoaderPatterns to set
-
registerTransformer
public void registerTransformer(ClassLoader classLoader, String classNameRegexp, HaClassFileTransformer transformer)
Register a transformer for a regexp matching class names. Used byOnClassLoadEventannotation respectiveOnClassLoadedHandler.- Parameters:
classLoader- the classloader to which this transformation is associatedclassNameRegexp- regexp to match fully qualified class name. Because "." is any character in regexp, this will match / in the transform method as well (diffentence between java/lang/String and java.lang.String).transformer- the transformer to be called for each class matching regexp.
-
removeTransformer
public void removeTransformer(String classNameRegexp, HaClassFileTransformer transformer)
Remove registered transformer.- Parameters:
classNameRegexp- regexp to match fully qualified class name.transformer- currently registered transformer
-
closeClassLoader
public void closeClassLoader(ClassLoader classLoader)
Remove all transformers registered with a classloader- Parameters:
classLoader-
-
transform
public byte[] transform(ClassLoader classLoader, String className, Class<?> redefiningClass, ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException
Main transform method called by Java instrumentation.It does not do the instrumentation itself, instead iterates registered transformers and compares registration class regexp - if the regexp matches, the classloader is called.
Note that class bytes may be send to multiple transformers, but the order is not defined.
- Specified by:
transformin interfaceClassFileTransformer- Throws:
IllegalClassFormatException- See Also:
ClassFileTransformer.transform(ClassLoader, String, Class, java.security.ProtectionDomain, byte[])
-
ensureClassLoaderInitialized
protected boolean ensureClassLoaderInitialized(ClassLoader classLoader, ProtectionDomain protectionDomain)
Every classloader should be initialized. Usually if anything interesting happens, it is initialized during plugin initialization process. However, some plugins (e.g. Hotswapper) are triggered during classloader initialization process itself (@Init on static method). In this case, the plugin will be never invoked, until the classloader initialization is invoked from here. Schedule with some timeout to allow standard plugin initialization process to precede.- Parameters:
classLoader- the classloader to which this transformation is associatedprotectionDomain- associated protection domain (if any)
-
-