1 8 package org.codehaus.aspectwerkz.hook; 9 10 import org.codehaus.aspectwerkz.transform.inlining.deployer.Redefiner; 11 import org.codehaus.aspectwerkz.transform.inlining.deployer.ChangeSet; 12 import org.codehaus.aspectwerkz.transform.inlining.compiler.JoinPointFactory; 13 import org.codehaus.aspectwerkz.exception.WrappedRuntimeException; 14 15 import java.util.Iterator ; 16 import java.lang.instrument.ClassDefinition ; 17 18 23 public class JVMTIRedefiner implements Redefiner { 24 25 public JVMTIRedefiner() { 26 if (!Agent.getInstrumentation().isRedefineClassesSupported()) { 27 throw new UnsupportedOperationException ("This Java 5 does not support JVMTI redefine()"); 28 } 29 } 30 31 36 public void redefine(final ChangeSet changeSet) { 37 if (! Agent.getInstrumentation().isRedefineClassesSupported()) { 38 return; 40 } 41 ClassDefinition [] changes = new ClassDefinition [changeSet.getElements().size()]; 42 int index = 0; 43 for (Iterator it = changeSet.getElements().iterator(); it.hasNext(); index++) { 44 ChangeSet.Element changeSetElement = (ChangeSet.Element) it.next(); 45 final byte[] bytecode = JoinPointFactory.redefineJoinPoint(changeSetElement.getCompilationInfo()); 46 changes[index] = new ClassDefinition (changeSetElement.getJoinPointInfo().getJoinPointClass(), bytecode); 47 } 48 try { 49 Agent.getInstrumentation().redefineClasses(changes); 50 } catch (Exception e) { 51 throw new WrappedRuntimeException(e); 52 } 53 } 54 } 55 | Popular Tags |