/**
* Initialization
*/
+ @Override
public void initialize() {
}
* @param loader
* @return woven bytes
*/
+ @Override
public byte[] preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain) {
// TODO AV needs to doc that
if (loader == null || className == null || loader.getClass().getName().equals(deleLoader)) {
return instance;
}
+ @Override
public boolean equals(Object obj) {
if (!(obj instanceof AdaptorKey)) {
return false;
&& loaderClass.equals(other.loaderClass);
}
+ @Override
public int hashCode() {
return hashValue;
}
if (loader.equals(myClassLoader)){
adaptor = myClassLoaderAdaptor;
} else {
- adaptor = (ExplicitlyInitializedClassLoaderWeavingAdaptor) weavingAdaptors.get(adaptorKey);
+ adaptor = weavingAdaptors.get(adaptorKey);
}
if (adaptor == null) {
// create it and put it back in the weavingAdaptors map but avoid any kind of instantiation
((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClasses();
}
+ @Override
+ public void prepareForRedefinition(ClassLoader loader, String className) {
+ ((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClassesFor(className);
+ }
+
}
\ No newline at end of file
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
*
* @deprecated
*/
+ @Deprecated
public ClassLoaderWeavingAdaptor(final ClassLoader deprecatedLoader, final IWeavingContext deprecatedContext) {
super();
if (trace.isTraceEnabled()) {
* Callback when we need to define a Closure in the JVM
*
*/
+ @Override
public void acceptClass (String name, byte[] originalBytes, byte[] wovenBytes) {
try {
if (shouldDump(name.replace('/', '.'), false)) {
generatedClasses = new HashMap<String, IUnwovenClassFile>();
}
+ /**
+ * Remove generated classes based on the supplied className. This will
+ * remove any entries related to this name - so the class itself plus
+ * and inner classes.
+ * @param className a slashed classname (e.g. com/foo/Bar)
+ */
+ public void flushGeneratedClassesFor(String className) {
+ try {
+ String dottedClassName = className.replace('/', '.');
+ String dottedClassNameDollar = dottedClassName+"$"; // to pickup inner classes
+ Iterator<Map.Entry<String, IUnwovenClassFile>> iter = generatedClasses.entrySet().iterator();
+ while (iter.hasNext()) {
+ Entry<String, IUnwovenClassFile> next = iter.next();
+ String existingGeneratedName = next.getKey();
+ if (existingGeneratedName.equals(dottedClassName) ||
+ existingGeneratedName.startsWith(dottedClassNameDollar)) {
+ iter.remove();
+ }
+ }
+ } catch (Throwable t) {
+ new RuntimeException("Unexpected problem tidying up generated classes for "+className,t).printStackTrace();
+ }
+ }
+
private Unsafe unsafe;
private Unsafe getUnsafe() throws NoSuchFieldException, IllegalAccessException {
trace.exit("defineClass", clazz);
}
}
+
}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2005 Contributors.
+ * Copyright (c) 2005,2018 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Vasseur initial implementation
*******************************************************************************/
package org.aspectj.weaver.loadtime;
* further use on Java 1.3 / 1.4
*
* @author Alexandre Vasseur
+ * @author Andy Clement
*/
public interface ClassPreProcessor {
*/
void initialize();
- /**
- * Weave
- *
- * @param className
- * @param bytes
- * @param classLoader
- * @param a protection domain that may be used for defining extraneous classes generated as part of modifying the one passed in
- * @return
- */
byte[] preProcess(String className, byte[] bytes, ClassLoader classLoader, ProtectionDomain protectionDomain);
+
+ void prepareForRedefinition(ClassLoader loader, String className);
}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2005 Contributors.
+ * Copyright (c) 2005,2018 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Vasseur initial implementation
*******************************************************************************/
package org.aspectj.weaver.loadtime;
/**
* Java 1.5 adapter for class pre processor
*
- * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
+ * @author Alexandre Vasseur
+ * @author Andy Clement
*/
public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
- /**
- * Concrete preprocessor.
- */
- private static ClassPreProcessor s_preProcessor;
+ private static ClassPreProcessor classPreProcessor;
static {
try {
- s_preProcessor = new Aj();
- s_preProcessor.initialize();
+ classPreProcessor = new Aj();
+ classPreProcessor.initialize();
} catch (Exception e) {
throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
}
* @param bytes the incoming bytes (before weaving)
* @return the woven bytes
*/
+ @Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
byte[] bytes) throws IllegalClassFormatException {
if (classBeingRedefined != null) {
System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'");
+ classPreProcessor.prepareForRedefinition(loader, className);
}
- return s_preProcessor.preProcess(className, bytes, loader, protectionDomain);
+ return classPreProcessor.preProcess(className, bytes, loader, protectionDomain);
}
}