Skip to content

Instantly share code, notes, and snippets.

@heipacker
Created April 2, 2016 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heipacker/4be207245fc34938891966083d773c3c to your computer and use it in GitHub Desktop.
Save heipacker/4be207245fc34938891966083d773c3c to your computer and use it in GitHub Desktop.
addCode
private static void addCode(Instrumentation instrumentation) {
Class[] allLoadedClasses = instrumentation.getAllLoadedClasses();
System.out.println("all load classes length:" + allLoadedClasses.length);
System.out.println("object size:" + instrumentation.getObjectSize(new Object()));
instrumentation.addTransformer(new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (classBeingRedefined != null) return null;
System.out.println("class transform " + className);
return classfileBuffer;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment