You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InstrumentationRedefiner.java 1.1KB

12345678910111213141516171819202122232425262728293031
  1. package com.github.dcevm;
  2. import com.github.dcevm.agent.InstrumentationAgent;
  3. import java.io.IOException;
  4. import java.lang.instrument.ClassDefinition;
  5. import java.lang.instrument.Instrumentation;
  6. import java.lang.instrument.UnmodifiableClassException;
  7. import java.util.Map;
  8. public class InstrumentationRedefiner implements Redefiner {
  9. public void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException {
  10. Instrumentation instrumentation = InstrumentationAgent.INSTRUMENTATION;
  11. if (instrumentation == null) {
  12. throw new IllegalStateException("Instrumentation agent is not properly installed!");
  13. }
  14. ClassDefinition[] definitions = new ClassDefinition[classes.size()];
  15. int i = 0;
  16. for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) {
  17. definitions[i++] = new ClassDefinition(entry.getKey(), entry.getValue());
  18. }
  19. instrumentation.redefineClasses(definitions);
  20. }
  21. @Override
  22. public void close() throws IOException {
  23. // Do nothing.
  24. }
  25. }