private TransformerManager findTransformerManager(ClassFileTransformer transformer) { if (mTransformerManager.includesTransformer(transformer)) { return mTransformerManager; } if (mRetransfomableTransformerManager != null && mRetransfomableTransformerManager.includesTransformer(transformer)) { return mRetransfomableTransformerManager; } return null; }
public synchronized boolean removeTransformer(ClassFileTransformer transformer) { if (transformer == null) { throw new NullPointerException("null passed as 'transformer' in removeTransformer"); } TransformerManager mgr = findTransformerManager(transformer); if (mgr != null) { mgr.removeTransformer(transformer); if (mgr.isRetransformable() && mgr.getTransformerCount() == 0) { setHasRetransformableTransformers(mNativeAgent, false); } return true; } return false; }
// WARNING: the native code knows the name & signature of this method private byte[] transform( ClassLoader loader, String classname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer, boolean isRetransformer) { TransformerManager mgr = isRetransformer ? mRetransfomableTransformerManager : mTransformerManager; if (mgr == null) { return null; // no manager, no transform } else { return mgr.transform( loader, classname, classBeingRedefined, protectionDomain, classfileBuffer); } }
public synchronized void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) { if (!isNativeMethodPrefixSupported()) { throw new UnsupportedOperationException( "setNativeMethodPrefix is not supported in this environment"); } if (transformer == null) { throw new NullPointerException("null passed as 'transformer' in setNativeMethodPrefix"); } TransformerManager mgr = findTransformerManager(transformer); if (mgr == null) { throw new IllegalArgumentException("transformer not registered in setNativeMethodPrefix"); } mgr.setNativeMethodPrefix(transformer, prefix); String[] prefixes = mgr.getNativeMethodPrefixes(); setNativeMethodPrefixes(mNativeAgent, prefixes, mgr.isRetransformable()); }
public synchronized void addTransformer( ClassFileTransformer transformer, boolean canRetransform) { if (transformer == null) { throw new NullPointerException("null passed as 'transformer' in addTransformer"); } if (canRetransform) { if (!isRetransformClassesSupported()) { throw new UnsupportedOperationException( "adding retransformable transformers is not supported in this environment"); } if (mRetransfomableTransformerManager == null) { mRetransfomableTransformerManager = new TransformerManager(true); } mRetransfomableTransformerManager.addTransformer(transformer); if (mRetransfomableTransformerManager.getTransformerCount() == 1) { setHasRetransformableTransformers(mNativeAgent, true); } } else { mTransformerManager.addTransformer(transformer); } }