diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-21 10:20:04 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-21 10:20:04 -0800 |
commit | 8755f774ae286eefbe3826dab592f1a22d0f6b95 (patch) | |
tree | cdfbe8acbd5530538d0d933230f4db7f09516e92 /org.aspectj.matcher | |
parent | f6d0013eb2cddf9946ab07d0a4e129cc9c0869bb (diff) | |
download | aspectj-8755f774ae286eefbe3826dab592f1a22d0f6b95.tar.gz aspectj-8755f774ae286eefbe3826dab592f1a22d0f6b95.zip |
389678: Better support for overweaving
More testcases for overweaving and better handling of WeaverStateInfo
to avoid the dreaded problems deserialized the 'special key' used
to store diffs.
With these changes once a class is woven via overweaving we switch
the diff we store in the weaverstateinfo to 0 byte array (indicating
overweaving happened for later weavers that see it). We also stop
writing the special 'key' into the attribute and avoid looking-for
and attempting to replace it at the end of weaving.
Diffstat (limited to 'org.aspectj.matcher')
3 files changed, 36 insertions, 9 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverMessages.java b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverMessages.java index 736220cd2..5a64a77e8 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverMessages.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverMessages.java @@ -1,18 +1,19 @@ /******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. + * Copyright (c) 2004-2019 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://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation *******************************************************************************/ package org.aspectj.weaver; import java.text.MessageFormat; import java.util.ResourceBundle; +/** + * @author Andy Clement + * @author IBM + */ public class WeaverMessages { private static ResourceBundle bundle = ResourceBundle.getBundle("org.aspectj.weaver.weaver-messages"); @@ -183,6 +184,8 @@ public class WeaverMessages { public static final String HAS_MEMBER_NOT_ENABLED = "hasMemberNotEnabled"; + public static final String MUST_KEEP_OVERWEAVING_ONCE_START = "mustKeepOverweavingOnceStart"; + // @AspectJ public static final String RETURNING_FORMAL_NOT_DECLARED_IN_ADVICE = "returningFormalNotDeclaredInAdvice"; public static final String THROWN_FORMAL_NOT_DECLARED_IN_ADVICE = "thrownFormalNotDeclaredInAdvice"; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java index b9fc99da8..f0dcbf270 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2002-2019 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 @@ -38,6 +38,8 @@ import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; * themselves If we are reweavable then we also have: Short: Number of aspects that touched this type in some way when it was * previously woven <String> The fully qualified name of each type Int: Length of class file data (i.e. the unwovenclassfile) * Byte[]: The class file data, compressed if REWEAVABLE_COMPRESSION_BIT set. + * + * @author Andy Clement */ public class WeaverStateInfo { private List<Entry> typeMungers; @@ -230,6 +232,21 @@ public class WeaverStateInfo { } } + private final static byte[] NO_BYTES = new byte[0]; + + /** + * If the weaver is ever invoked in over weaving mode, we should + * not include the key when writing out, it won't be replaced later. + * If we turn off the reweaving flag that unfortunately removes + * the 'what aspects have been woven into this type' list which we + * want to keep as it helps overweaving avoid weaving an aspect in + * twice. + */ + public void markOverweavingInUse() { + reweavableDiffMode = false; + unwovenClassFile = NO_BYTES; + } + public void addConcreteMunger(ConcreteTypeMunger munger) { typeMungers.add(new Entry(munger.getAspectType(), munger.getMunger())); } @@ -258,6 +275,10 @@ public class WeaverStateInfo { return oldStyle; } + public byte[] getUnwovenClassFileData() { + return unwovenClassFile; + } + public byte[] getUnwovenClassFileData(byte wovenClassFile[]) { if (unwovenClassFileIsADiff) { unwovenClassFile = applyDiff(wovenClassFile, unwovenClassFile); @@ -334,10 +355,12 @@ public class WeaverStateInfo { } } else { classData = new byte[unwovenClassFileSize]; - int bytesread = s.read(classData); - if (bytesread != unwovenClassFileSize) { - throw new IOException("ERROR whilst reading reweavable data, expected " + unwovenClassFileSize - + " bytes, only found " + bytesread); + if (unwovenClassFileSize != 0) { + int bytesread = s.read(classData); + if (bytesread != unwovenClassFileSize) { + throw new IOException("ERROR whilst reading reweavable data, expected " + unwovenClassFileSize + + " bytes, only found " + bytesread); + } } } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/weaver-messages.properties b/org.aspectj.matcher/src/org/aspectj/weaver/weaver-messages.properties index f47b3e38b..2745ae9e7 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/weaver-messages.properties +++ b/org.aspectj.matcher/src/org/aspectj/weaver/weaver-messages.properties @@ -181,6 +181,7 @@ noParameterizedDeclaringTypesInCall=can't use parameterized type patterns for th noRawTypePointcutReferences=cannot use a raw type reference to refer to a pointcut in a generic type (use a parameterized reference instead) hasMemberNotEnabled=the type pattern {0} can only be used when the -XhasMember option is set +mustKeepOverweavingOnceStart=the type {0} was previously subject to overweaving and after that can only be woven again in overweaving mode # Java5 features used in pre-Java 5 environment atannotationNeedsJava5=the @annotation pointcut expression is only supported at Java 5 compliance level or above |