synchronized boolean includesTransformer(ClassFileTransformer transformer) { for (TransformerInfo info : mTransformerList) { if (info.transformer() == transformer) { return true; } } return false; }
String[] getNativeMethodPrefixes() { TransformerInfo[] transformerList = getSnapshotTransformerList(); String[] prefixes = new String[transformerList.length]; for (int x = 0; x < transformerList.length; x++) { TransformerInfo transformerInfo = transformerList[x]; prefixes[x] = transformerInfo.getPrefix(); } return prefixes; }
boolean setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) { TransformerInfo[] transformerList = getSnapshotTransformerList(); for (int x = 0; x < transformerList.length; x++) { TransformerInfo transformerInfo = transformerList[x]; ClassFileTransformer aTransformer = transformerInfo.transformer(); if (aTransformer == transformer) { transformerInfo.setPrefix(prefix); return true; } } return false; }
public byte[] transform( ClassLoader loader, String classname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { boolean someoneTouchedTheBytecode = false; TransformerInfo[] transformerList = getSnapshotTransformerList(); byte[] bufferToUse = classfileBuffer; // order matters, gotta run 'em in the order they were added for (int x = 0; x < transformerList.length; x++) { TransformerInfo transformerInfo = transformerList[x]; ClassFileTransformer transformer = transformerInfo.transformer(); byte[] transformedBytes = null; try { transformedBytes = transformer.transform( loader, classname, classBeingRedefined, protectionDomain, bufferToUse); } catch (Throwable t) { // don't let any one transformer mess it up for the others. // This is where we need to put some logging. What should go here? FIXME } if (transformedBytes != null) { someoneTouchedTheBytecode = true; bufferToUse = transformedBytes; } } // if someone modified it, return the modified buffer. // otherwise return null to mean "no transforms occurred" byte[] result; if (someoneTouchedTheBytecode) { result = bufferToUse; } else { result = null; } return result; }