aclement 14 роки тому
джерело
коміт
65ed8e4b72

+ 255
- 197
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java Переглянути файл

@@ -139,8 +139,8 @@ class BcelClassWeaver implements IClassWeaver {
*/
private final List<BcelShadow> initializationShadows = new ArrayList<BcelShadow>();

private BcelClassWeaver(BcelWorld world, LazyClassGen clazz, List shadowMungers, List<ConcreteTypeMunger> typeMungers,
List lateTypeMungers) {
private BcelClassWeaver(BcelWorld world, LazyClassGen clazz, List<ShadowMunger> shadowMungers,
List<ConcreteTypeMunger> typeMungers, List lateTypeMungers) {
super();
// assert world == clazz.getType().getWorld()
this.world = world;
@@ -160,34 +160,34 @@ class BcelClassWeaver implements IClassWeaver {
if (p != null) {
String s = p.getProperty(World.xsetCAPTURE_ALL_CONTEXT, "false");
captureLowLevelContext = s.equalsIgnoreCase("true");
if (captureLowLevelContext)
if (captureLowLevelContext) {
world.getMessageHandler().handleMessage(
MessageUtil.info("[" + World.xsetCAPTURE_ALL_CONTEXT
+ "=true] Enabling collection of low level context for debug/crash messages"));
}
}
checkedXsetForLowLevelContextCapturing = true;
}
}

private List[] perKindShadowMungers;
private List<ShadowMunger>[] perKindShadowMungers;
private boolean canMatchBodyShadows = false;

// private boolean canMatchInitialization = false;
private void fastMatchShadowMungers(List shadowMungers) {
private void fastMatchShadowMungers(List<ShadowMunger> shadowMungers) {
// beware the annoying property that SHADOW_KINDS[i].getKey == (i+1) !

perKindShadowMungers = new List[Shadow.MAX_SHADOW_KIND + 1];
for (int i = 0; i < perKindShadowMungers.length; i++) {
perKindShadowMungers[i] = new ArrayList(0);
perKindShadowMungers[i] = new ArrayList<ShadowMunger>(0);
}
for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
ShadowMunger munger = (ShadowMunger) iter.next();

for (ShadowMunger munger : shadowMungers) {
int couldMatchKinds = munger.getPointcut().couldMatchKinds();
for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) {
Shadow.Kind kind = Shadow.SHADOW_KINDS[i];
if (kind.isSet(couldMatchKinds))
if (kind.isSet(couldMatchKinds)) {
perKindShadowMungers[kind.getKey()].add(munger);
}
}

// Set couldMatchKinds = munger.getPointcut().couldMatchKinds();
@@ -240,11 +240,13 @@ class BcelClassWeaver implements IClassWeaver {
}

private boolean addSuperInitializer(ResolvedType onType) {
if (onType.isRawType() || onType.isParameterizedType())
if (onType.isRawType() || onType.isParameterizedType()) {
onType = onType.getGenericType();
}
IfaceInitList l = addedSuperInitializers.get(onType);
if (l != null)
if (l != null) {
return false;
}
l = new IfaceInitList(onType);
addedSuperInitializers.put(onType, l);
return true;
@@ -253,8 +255,9 @@ class BcelClassWeaver implements IClassWeaver {
public void addInitializer(ConcreteTypeMunger cm) {
NewFieldTypeMunger m = (NewFieldTypeMunger) cm.getMunger();
ResolvedType onType = m.getSignature().getDeclaringType().resolve(world);
if (onType.isRawType())
if (onType.isRawType()) {
onType = onType.getGenericType();
}

if (m.getSignature().isStatic()) {
addedClassInitializers.add(cm);
@@ -278,12 +281,13 @@ class BcelClassWeaver implements IClassWeaver {

public int compareTo(Object other) {
IfaceInitList o = (IfaceInitList) other;
if (onType.isAssignableFrom(o.onType))
if (onType.isAssignableFrom(o.onType)) {
return +1;
else if (o.onType.isAssignableFrom(onType))
} else if (o.onType.isAssignableFrom(onType)) {
return -1;
else
} else {
return 0;
}
}

public int fallbackCompareTo(Object other) {
@@ -301,8 +305,9 @@ class BcelClassWeaver implements IClassWeaver {
}

public void addOrReplaceLazyMethodGen(LazyMethodGen mg) {
if (alreadyDefined(clazz, mg))
if (alreadyDefined(clazz, mg)) {
return;
}

for (Iterator i = addedLazyMethodGens.iterator(); i.hasNext();) {
LazyMethodGen existing = (LazyMethodGen) i.next();
@@ -348,8 +353,9 @@ class BcelClassWeaver implements IClassWeaver {

// remove abstract modifier
int mods = member.getModifiers();
if (Modifier.isAbstract(mods))
if (Modifier.isAbstract(mods)) {
mods = mods - Modifier.ABSTRACT;
}

LazyMethodGen ret = new LazyMethodGen(mods, BcelWorld.makeBcelType(member.getReturnType()), member.getName(), BcelWorld
.makeBcelTypes(member.getParameterTypes()), UnresolvedType.getNames(member.getExceptions()), gen);
@@ -398,8 +404,9 @@ class BcelClassWeaver implements IClassWeaver {
Type paramType = paramTypes[i];
body.append(InstructionFactory.createLoad(paramType, pos));
if (!newParamTypes[i].equals(paramTypes[i])) {
if (world.forDEBUG_bridgingCode)
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging: Cast " + newParamTypes[i] + " from " + paramTypes[i]);
}
body.append(fact.createCast(paramTypes[i], newParamTypes[i]));
}
pos += paramType.getSize();
@@ -427,8 +434,9 @@ class BcelClassWeaver implements IClassWeaver {
boolean isChanged = false;

// we want to "touch" all aspects
if (clazz.getType().isAspect())
if (clazz.getType().isAspect()) {
isChanged = true;
}

// start by munging all typeMungers
for (ConcreteTypeMunger o : typeMungers) {
@@ -440,8 +448,9 @@ class BcelClassWeaver implements IClassWeaver {
boolean typeMungerAffectedType = munger.munge(this);
if (typeMungerAffectedType) {
isChanged = true;
if (inReweavableMode || clazz.getType().isAspect())
if (inReweavableMode || clazz.getType().isAspect()) {
aspectsAffectingType.add(munger.getAspectType().getName());
}
}
}

@@ -490,8 +499,9 @@ class BcelClassWeaver implements IClassWeaver {
// now we weave all but the initialization shadows
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
if (!mg.hasBody())
if (!mg.hasBody()) {
continue;
}
implement(mg);
}

@@ -500,8 +510,9 @@ class BcelClassWeaver implements IClassWeaver {
// Repeat next step until nothing left to inline...cant go on
// infinetly as compiler will have detected and reported
// "Recursive constructor invocation"
while (inlineSelfConstructors(methodGens))
while (inlineSelfConstructors(methodGens)) {
;
}
positionAndImplement(initializationShadows);
}

@@ -513,8 +524,9 @@ class BcelClassWeaver implements IClassWeaver {
boolean typeMungerAffectedType = munger.munge(this);
if (typeMungerAffectedType) {
isChanged = true;
if (inReweavableMode || clazz.getType().isAspect())
if (inReweavableMode || clazz.getType().isAspect()) {
aspectsAffectingType.add(munger.getAspectType().getName());
}
}
}
}
@@ -546,8 +558,9 @@ class BcelClassWeaver implements IClassWeaver {
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
BcelMethod bM = mg.getMemberView();
if (bM != null)
if (bM != null) {
bM.wipeJoinpointSignatures();
}
}

return isChanged;
@@ -669,17 +682,21 @@ class BcelClassWeaver implements IClassWeaver {
* @return true if there is an overrides rather than a 'hides' relationship
*/
static boolean isVisibilityOverride(int methodMods, ResolvedMember inheritedMethod, boolean inSamePackage) {
if (inheritedMethod.isStatic())
if (inheritedMethod.isStatic()) {
return false;
if (methodMods == inheritedMethod.getModifiers())
}
if (methodMods == inheritedMethod.getModifiers()) {
return true;
}

if (inheritedMethod.isPrivate())
if (inheritedMethod.isPrivate()) {
return false;
}

boolean isPackageVisible = !inheritedMethod.isPrivate() && !inheritedMethod.isProtected() && !inheritedMethod.isPublic();
if (isPackageVisible && !inSamePackage)
if (isPackageVisible && !inSamePackage) {
return false;
}

return true;
}
@@ -692,17 +709,21 @@ class BcelClassWeaver implements IClassWeaver {
public static ResolvedMember checkForOverride(ResolvedType typeToCheck, String mname, String mparams, String mrettype,
int mmods, String mpkg, UnresolvedType[] methodParamsArray) {

if (typeToCheck == null)
if (typeToCheck == null) {
return null;
if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature)
}
if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature) {
return null; // we just can't tell !
}

if (typeToCheck.getWorld().forDEBUG_bridgingCode)
if (typeToCheck.getWorld().forDEBUG_bridgingCode) {
System.err.println(" Bridging:checking for override of " + mname + " in " + typeToCheck);
}

String packageName = typeToCheck.getPackageName();
if (packageName == null)
if (packageName == null) {
packageName = "";
}
boolean inSamePackage = packageName.equals(mpkg); // used when looking
// at visibility
// rules
@@ -718,8 +739,9 @@ class BcelClassWeaver implements IClassWeaver {
// check
ResolvedMember isOverriding = isOverriding(typeToCheck, methodThatMightBeGettingOverridden, mname, mrettype, mmods,
inSamePackage, methodParamsArray);
if (isOverriding != null)
if (isOverriding != null) {
return isOverriding;
}
}
// was: List l = typeToCheck.getInterTypeMungers();
List l = (typeToCheck.isRawType() ? typeToCheck.getGenericType().getInterTypeMungers() : typeToCheck.getInterTypeMungers());
@@ -730,31 +752,36 @@ class BcelClassWeaver implements IClassWeaver {
if (o instanceof BcelTypeMunger) {
BcelTypeMunger element = (BcelTypeMunger) o;
if (element.getMunger() instanceof NewMethodTypeMunger) {
if (typeToCheck.getWorld().forDEBUG_bridgingCode)
if (typeToCheck.getWorld().forDEBUG_bridgingCode) {
System.err.println("Possible ITD candidate " + element);
}
ResolvedMember aMethod = element.getSignature();
ResolvedMember isOverriding = isOverriding(typeToCheck, aMethod, mname, mrettype, mmods, inSamePackage,
methodParamsArray);
if (isOverriding != null)
if (isOverriding != null) {
return isOverriding;
}
}
}
}

if (typeToCheck.equals(UnresolvedType.OBJECT))
if (typeToCheck.equals(UnresolvedType.OBJECT)) {
return null;
}

ResolvedType superclass = typeToCheck.getSuperclass();
ResolvedMember overriddenMethod = checkForOverride(superclass, mname, mparams, mrettype, mmods, mpkg, methodParamsArray);
if (overriddenMethod != null)
if (overriddenMethod != null) {
return overriddenMethod;
}

ResolvedType[] interfaces = typeToCheck.getDeclaredInterfaces();
for (int i = 0; i < interfaces.length; i++) {
ResolvedType anInterface = interfaces[i];
overriddenMethod = checkForOverride(anInterface, mname, mparams, mrettype, mmods, mpkg, methodParamsArray);
if (overriddenMethod != null)
if (overriddenMethod != null) {
return overriddenMethod;
}
}
return null;
}
@@ -768,11 +795,13 @@ class BcelClassWeaver implements IClassWeaver {
*/
public static boolean calculateAnyRequiredBridgeMethods(BcelWorld world, LazyClassGen clazz) {
world.ensureAdvancedConfigurationProcessed();
if (!world.isInJava5Mode())
if (!world.isInJava5Mode()) {
return false; // just double check... the caller should have already
}
// verified this
if (clazz.isInterface())
if (clazz.isInterface()) {
return false; // dont bother if we're an interface
}
boolean didSomething = false; // set if we build any bridge methods

// So what methods do we have right now in this class?
@@ -793,21 +822,25 @@ class BcelClassWeaver implements IClassWeaver {

// This is the local method that we *might* have to bridge to
LazyMethodGen bridgeToCandidate = (LazyMethodGen) methods.get(i);
if (bridgeToCandidate.isBridgeMethod())
if (bridgeToCandidate.isBridgeMethod()) {
continue; // Doh!
}
String name = bridgeToCandidate.getName();
String psig = bridgeToCandidate.getParameterSignature();
String rsig = bridgeToCandidate.getReturnType().getSignature();

// if (bridgeToCandidate.isAbstract()) continue;
if (bridgeToCandidate.isStatic())
if (bridgeToCandidate.isStatic()) {
continue; // ignore static methods
if (name.endsWith("init>"))
}
if (name.endsWith("init>")) {
continue; // Skip constructors and static initializers
}

if (world.forDEBUG_bridgingCode)
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging: Determining if we have to bridge to " + clazz.getName() + "." + name + ""
+ bridgeToCandidate.getSignature());
}

// Let's take a look at the superclass
ResolvedType theSuperclass = clazz.getSuperClass();
@@ -836,8 +869,9 @@ class BcelClassWeaver implements IClassWeaver {
// Check superinterfaces
String[] interfaces = clazz.getInterfaceNames();
for (int j = 0; j < interfaces.length; j++) {
if (world.forDEBUG_bridgingCode)
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:checking superinterface " + interfaces[j]);
}
ResolvedType interfaceType = world.resolve(interfaces[j]);
overriddenMethod = checkForOverride(interfaceType, name, psig, rsig, bridgeToCandidate.getAccessFlags(), clazz
.getPackageName(), bm);
@@ -850,8 +884,9 @@ class BcelClassWeaver implements IClassWeaver {
createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
methodsSet.add(key);
didSomething = true;
if (world.forDEBUG_bridgingCode)
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:bridging to " + overriddenMethod);
}
continue; // look at the next method
}
}
@@ -889,8 +924,9 @@ class BcelClassWeaver implements IClassWeaver {
// deal with all the other methods...
List<LazyMethodGen> members = clazz.getMethodGens();
List<DeclareAnnotation> decaMs = getMatchingSubset(allDecams, clazz.getType());
if (decaMs.isEmpty())
if (decaMs.isEmpty()) {
return false; // nothing to do
}
if (!members.isEmpty()) {
Set<DeclareAnnotation> unusedDecams = new HashSet<DeclareAnnotation>();
unusedDecams.addAll(decaMs);
@@ -929,12 +965,13 @@ class BcelClassWeaver implements IClassWeaver {
// against it
unusedDecams.remove(decaM);
} else {
if (!decaM.isStarredAnnotationPattern())
if (!decaM.isStarredAnnotationPattern()) {
worthRetrying.add(decaM); // an annotation is
// specified that
// might be put on
// by a subsequent
// decaf
// specified that
// might be put on
// by a subsequent
// decaf
}
}
}

@@ -999,11 +1036,13 @@ class BcelClassWeaver implements IClassWeaver {
for (int i = 0; i < paramTypes.length; i++) {
UnresolvedType type = paramTypes[i];
String s = org.aspectj.apache.bcel.classfile.Utility.signatureToString(type.getSignature());
if (s.lastIndexOf('.') != -1)
if (s.lastIndexOf('.') != -1) {
s = s.substring(s.lastIndexOf('.') + 1);
}
parmString.append(s);
if ((i + 1) < paramTypes.length)
if ((i + 1) < paramTypes.length) {
parmString.append(",");
}
}
parmString.append(")");
String methodName = member.getName();
@@ -1114,8 +1153,9 @@ class BcelClassWeaver implements IClassWeaver {

if (decaF.matches(itdIsActually, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger);
if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors))
if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors)) {
continue; // skip this one...
}
annotationHolder.addAnnotation(decaF.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(world.getModelAsAsmManager(), decaF
.getSourceLocation(), itdIsActually.getSourceLocation());
@@ -1123,10 +1163,11 @@ class BcelClassWeaver implements IClassWeaver {
modificationOccured = true;

} else {
if (!decaF.isStarredAnnotationPattern())
if (!decaF.isStarredAnnotationPattern()) {
worthRetrying.add(decaF); // an annotation is specified
// that might be put on by a
// subsequent decaf
// that might be put on by a
// subsequent decaf
}
}
}

@@ -1137,8 +1178,9 @@ class BcelClassWeaver implements IClassWeaver {
DeclareAnnotation decaF = (DeclareAnnotation) iter2.next();
if (decaF.matches(itdIsActually, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger);
if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors))
if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors)) {
continue; // skip this one...
}
annotationHolder.addAnnotation(decaF.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(world.getModelAsAsmManager(), decaF
.getSourceLocation(), itdIsActually.getSourceLocation());
@@ -1197,8 +1239,9 @@ class BcelClassWeaver implements IClassWeaver {
DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next();
if (decaMC.matches(unMangledInterMethod, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, methodctorMunger);
if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors))
if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors)) {
continue; // skip this one...
}
annotationHolder.addAnnotation(decaMC.getAnnotation());
unMangledInterMethod.addAnnotation(decaMC.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(asmManager, decaMC.getSourceLocation(),
@@ -1259,8 +1302,9 @@ class BcelClassWeaver implements IClassWeaver {
}

List<DeclareAnnotation> decaFs = getMatchingSubset(allDecafs, clazz.getType());
if (decaFs.isEmpty())
if (decaFs.isEmpty()) {
return false; // nothing more to do
}
List<BcelField> fields = clazz.getFieldGens();
if (fields != null) {
Set<DeclareAnnotation> unusedDecafs = new HashSet<DeclareAnnotation>();
@@ -1332,12 +1376,13 @@ class BcelClassWeaver implements IClassWeaver {
// against it
unusedDecafs.remove(decaF);
} else {
if (!decaF.isStarredAnnotationPattern())
if (!decaF.isStarredAnnotationPattern()) {
worthRetrying.add(decaF); // an annotation is
// specified that
// might be put on
// by a subsequent
// decaf
// specified that
// might be put on
// by a subsequent
// decaf
}
}
}

@@ -1500,8 +1545,9 @@ class BcelClassWeaver implements IClassWeaver {
boolean inlinedSomething = false;
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
if (!mg.getName().equals("<init>"))
if (!mg.getName().equals("<init>")) {
continue;
}
InstructionHandle ih = findSuperOrThisCall(mg);
if (ih != null && isThisCall(ih)) {
LazyMethodGen donor = getCalledMethod(ih);
@@ -1597,8 +1643,9 @@ class BcelClassWeaver implements IClassWeaver {
* some duplication that can be removed.
*/
public static void transformSynchronizedMethod(LazyMethodGen synchronizedMethod) {
if (trace.isTraceEnabled())
if (trace.isTraceEnabled()) {
trace.enter("transformSynchronizedMethod", synchronizedMethod);
}
// System.err.println("DEBUG: Transforming synchronized method: "+
// synchronizedMethod.getName());
final InstructionFactory fact = synchronizedMethod.getEnclosingClass().getFactory();
@@ -1686,28 +1733,23 @@ class BcelClassWeaver implements IClassWeaver {

// now move the targeters from the RET to the start of
// the monitorexit block
InstructionTargeter[] targeters = element.getTargetersArray();
if (targeters != null) {
for (int i = 0; i < targeters.length; i++) {

InstructionTargeter targeter = targeters[i];
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof
// InstructionBranch &&
// ((InstructionBranch)targeter).isGoto()) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
for (InstructionTargeter targeter : element.getTargetersCopy()) {
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof
// InstructionBranch &&
// ((InstructionBranch)targeter).isGoto()) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
@@ -1895,27 +1937,22 @@ class BcelClassWeaver implements IClassWeaver {

// now move the targeters from the RET to the start of
// the monitorexit block
InstructionTargeter[] targeters = element.getTargetersArray();
if (targeters != null) {
for (int i = 0; i < targeters.length; i++) {

InstructionTargeter targeter = targeters[i];
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof GOTO ||
// targeter instanceof GOTO_W) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
for (InstructionTargeter targeter : element.getTargetersCopy()) {
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof GOTO ||
// targeter instanceof GOTO_W) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
@@ -2018,27 +2055,22 @@ class BcelClassWeaver implements IClassWeaver {

// now move the targeters from the RET to the start of the
// monitorexit block
InstructionTargeter[] targeters = element.getTargetersArray();
if (targeters != null) {
for (int i = 0; i < targeters.length; i++) {

InstructionTargeter targeter = targeters[i];
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof GOTO ||
// targeter instanceof GOTO_W) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
for (InstructionTargeter targeter : element.getTargetersCopy()) {
// what kinds are there?
if (targeter instanceof LocalVariableTag) {
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
// } else if (targeter instanceof GOTO ||
// targeter instanceof GOTO_W) {
// // move it...
// targeter.updateTarget(element,
// monitorExitBlockStart);
} else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
@@ -2066,8 +2098,9 @@ class BcelClassWeaver implements IClassWeaver {
// a variable,
// going to add a new variable for the this var

if (trace.isTraceEnabled())
if (trace.isTraceEnabled()) {
trace.exit("transformSynchronizedMethod");
}
}

/**
@@ -2226,8 +2259,9 @@ class BcelClassWeaver implements IClassWeaver {
}
}
}
if (!keepReturns)
if (!keepReturns) {
ret.append(footer);
}
return ret;
}

@@ -2424,8 +2458,9 @@ class BcelClassWeaver implements IClassWeaver {
LazyMethodGen aa = (LazyMethodGen) a;
LazyMethodGen bb = (LazyMethodGen) b;
int i = aa.getName().compareTo(bb.getName());
if (i != 0)
if (i != 0) {
return i;
}
return aa.getSignature().compareTo(bb.getSignature());
}
});
@@ -2460,14 +2495,16 @@ class BcelClassWeaver implements IClassWeaver {
int depth = 1;
InstructionHandle start = mg.getBody().getStart();
while (true) {
if (start == null)
if (start == null) {
return null;
}

Instruction inst = start.getInstruction();
if (inst.opcode == Constants.INVOKESPECIAL && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
depth--;
if (depth == 0)
if (depth == 0) {
return start;
}
} else if (inst.opcode == Constants.NEW) {
depth++;
}
@@ -2540,8 +2577,9 @@ class BcelClassWeaver implements IClassWeaver {
InstructionHandle superOrThisCall = findSuperOrThisCall(mg);

// we don't walk bodies of things where it's a wrong constructor thingie
if (superOrThisCall == null)
if (superOrThisCall == null) {
return false;
}

enclosingShadow = BcelShadow.makeConstructorExecution(world, mg, superOrThisCall);
if (mg.getEffectiveSignature() != null) {
@@ -2560,8 +2598,9 @@ class BcelClassWeaver implements IClassWeaver {
match(mg, h, beforeSuperOrThisCall ? null : enclosingShadow, shadowAccumulator);
}
}
if (canMatch(Shadow.ConstructorExecution))
if (canMatch(Shadow.ConstructorExecution)) {
match(enclosingShadow, shadowAccumulator);
}
}

// XXX we don't do pre-inits of interfaces
@@ -2602,13 +2641,16 @@ class BcelClassWeaver implements IClassWeaver {
}

private boolean shouldWeaveBody(LazyMethodGen mg) {
if (mg.isBridgeMethod())
if (mg.isBridgeMethod()) {
return false;
if (mg.isAjSynthetic())
}
if (mg.isAjSynthetic()) {
return mg.getName().equals("<clinit>");
}
AjAttribute.EffectiveSignatureAttribute a = mg.getEffectiveSignature();
if (a != null)
if (a != null) {
return a.isWeaveBody();
}
return true;
}

@@ -2627,8 +2669,9 @@ class BcelClassWeaver implements IClassWeaver {
ConcreteTypeMunger cmunger = (ConcreteTypeMunger) i.next();
NewFieldTypeMunger munger = (NewFieldTypeMunger) cmunger.getMunger();
ResolvedMember initMethod = munger.getInitMethod(cmunger.getAspectType());
if (!isStatic)
if (!isStatic) {
ret.append(InstructionConstants.ALOAD_0);
}
ret.append(Utility.createInvoke(fact, world, initMethod));
}
return ret;
@@ -2639,44 +2682,43 @@ class BcelClassWeaver implements IClassWeaver {

// Exception handlers (pr230817)
if (canMatch(Shadow.ExceptionHandler) && !Range.isRangeHandle(ih)) {
InstructionTargeter[] targeters = ih.getTargetersArray();
if (targeters != null) {
for (int j = 0; j < targeters.length; j++) {
InstructionTargeter t = targeters[j];
if (t instanceof ExceptionRange) {
// assert t.getHandler() == ih
ExceptionRange er = (ExceptionRange) t;
if (er.getCatchType() == null)
continue;
if (isInitFailureHandler(ih))
return;

if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
// If using cobertura, the catch block stats with
// INVOKESTATIC rather than ASTORE, in order that
// the
// ranges
// for the methodcall and exceptionhandler shadows
// that occur at this same
// line, we need to modify the instruction list to
// split them - adding a
// NOP before the invokestatic that gets all the
// targeters
// that were aimed at the INVOKESTATIC
mg.getBody().insert(ih, InstructionConstants.NOP);
InstructionHandle newNOP = ih.getPrev();
// what about a try..catch that starts at the start
// of the exception handler? need to only include
// certain targeters really.
er.updateTarget(ih, newNOP, mg.getBody());
for (int ii = 0; ii < targeters.length; ii++) {
newNOP.addTargeter(targeters[ii]);
}
ih.removeAllTargeters();
match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
} else {
match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
Set<InstructionTargeter> targeters = ih.getTargetersCopy();
for (InstructionTargeter t : targeters) {
if (t instanceof ExceptionRange) {
// assert t.getHandler() == ih
ExceptionRange er = (ExceptionRange) t;
if (er.getCatchType() == null) {
continue;
}
if (isInitFailureHandler(ih)) {
return;
}

if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
// If using cobertura, the catch block stats with
// INVOKESTATIC rather than ASTORE, in order that
// the
// ranges
// for the methodcall and exceptionhandler shadows
// that occur at this same
// line, we need to modify the instruction list to
// split them - adding a
// NOP before the invokestatic that gets all the
// targeters
// that were aimed at the INVOKESTATIC
mg.getBody().insert(ih, InstructionConstants.NOP);
InstructionHandle newNOP = ih.getPrev();
// what about a try..catch that starts at the start
// of the exception handler? need to only include
// certain targeters really.
er.updateTarget(ih, newNOP, mg.getBody());
for (InstructionTargeter t2 : targeters) {
newNOP.addTargeter(t2);
}
ih.removeAllTargeters();
match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
} else {
match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
}
}
}
@@ -2706,22 +2748,26 @@ class BcelClassWeaver implements IClassWeaver {
// it's
// not a join point according to 1.0.6 and 1.1.
} else {
if (canMatch(Shadow.FieldSet))
if (canMatch(Shadow.FieldSet)) {
matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
}
}
} else {
if (canMatch(Shadow.FieldSet))
if (canMatch(Shadow.FieldSet)) {
matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
}
}
} else {
if (canMatch(Shadow.FieldGet))
if (canMatch(Shadow.FieldGet)) {
matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
}
}
} else if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
if (canMatch(Shadow.ConstructorCall))
if (canMatch(Shadow.ConstructorCall)) {
match(BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow), shadowAccumulator);
}
} else if (ii.opcode == Constants.INVOKESPECIAL) {
String onTypeName = ii.getClassName(cpg);
if (onTypeName.equals(mg.getEnclosingClass().getName())) {
@@ -2785,8 +2831,9 @@ class BcelClassWeaver implements IClassWeaver {
InstructionHandle twoInstructionsAway = ih.getNext().getNext();
if (twoInstructionsAway.getInstruction().opcode == Constants.PUTSTATIC) {
String name = ((FieldInstruction) twoInstructionsAway.getInstruction()).getFieldName(cpg);
if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME))
if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME)) {
return true;
}
}
return false;
}
@@ -2796,8 +2843,9 @@ class BcelClassWeaver implements IClassWeaver {
Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi);

// synthetic fields are never join points
if (field.getName().startsWith(NameMangler.PREFIX))
if (field.getName().startsWith(NameMangler.PREFIX)) {
return;
}

ResolvedMember resolvedField = field.resolve(world);
if (resolvedField == null) {
@@ -2827,8 +2875,9 @@ class BcelClassWeaver implements IClassWeaver {
Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi);

// synthetic fields are never join points
if (field.getName().startsWith(NameMangler.PREFIX))
if (field.getName().startsWith(NameMangler.PREFIX)) {
return;
}

ResolvedMember resolvedField = field.resolve(world);
if (resolvedField == null) {
@@ -2855,8 +2904,9 @@ class BcelClassWeaver implements IClassWeaver {
ResolvedMember[] allMethods = type.getDeclaredMethods();
for (int i = 0; i < allMethods.length; i++) {
ResolvedMember member = allMethods[i];
if (member.getName().equals(methodName))
if (member.getName().equals(methodName)) {
return member;
}
}
return null;
}
@@ -2948,8 +2998,9 @@ class BcelClassWeaver implements IClassWeaver {
}
annotations = resolvedDooberry.getAnnotationTypes();
}
if (annotations == null)
if (annotations == null) {
annotations = new ResolvedType[0];
}
mapToAnnotations.put(rm, annotations);
}
rm.setAnnotationTypes(annotations);
@@ -2969,8 +3020,9 @@ class BcelClassWeaver implements IClassWeaver {
Member jpSig = world.makeJoinPointSignatureForMethodInvocation(clazz, invoke);
ResolvedMember declaredSig = jpSig.resolve(world);
// System.err.println(method + ", declaredSig: " +declaredSig);
if (declaredSig == null)
if (declaredSig == null) {
return;
}

if (declaredSig.getKind() == Member.FIELD) {
Shadow.Kind kind;
@@ -2980,28 +3032,33 @@ class BcelClassWeaver implements IClassWeaver {
kind = Shadow.FieldGet;
}

if (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))
if (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet)) {
match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, kind, declaredSig), shadowAccumulator);
}
} else {
AjAttribute.EffectiveSignatureAttribute effectiveSig = declaredSig.getEffectiveSignature();
if (effectiveSig == null)
if (effectiveSig == null) {
return;
}
// System.err.println("call to inter-type member: " +
// effectiveSig);
if (effectiveSig.isWeaveBody())
if (effectiveSig.isWeaveBody()) {
return;
}

ResolvedMember rm = effectiveSig.getEffectiveSignature();
fixParameterNamesForResolvedMember(rm, declaredSig);
fixAnnotationsForResolvedMember(rm, declaredSig); // abracadabra

if (canMatch(effectiveSig.getShadowKind()))
if (canMatch(effectiveSig.getShadowKind())) {
match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, effectiveSig.getShadowKind(), rm),
shadowAccumulator);
}
}
} else {
if (canMatch(Shadow.MethodCall))
if (canMatch(Shadow.MethodCall)) {
match(BcelShadow.makeMethodCall(world, mg, ih, enclosingShadow), shadowAccumulator);
}
}
}

@@ -3032,8 +3089,9 @@ class BcelClassWeaver implements IClassWeaver {
CompilationAndWeavingContext.leavingPhase(mungerMatchToken);
}

if (isMatched)
if (isMatched) {
shadowAccumulator.add(shadow);
}
CompilationAndWeavingContext.leavingPhase(shadowMatchToken);
return isMatched;
} else {

+ 11
- 20
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java Переглянути файл

@@ -266,15 +266,12 @@ public class BcelShadow extends Shadow {
}

private void retargetFrom(InstructionHandle old, InstructionHandle fresh) {
InstructionTargeter[] sources = old.getTargetersArray();
if (sources != null) {
for (InstructionTargeter targeter : sources) {
if (targeter instanceof ExceptionRange) {
ExceptionRange it = (ExceptionRange) targeter;
it.updateTarget(old, fresh, it.getBody());
} else {
targeter.updateTarget(old, fresh);
}
for (InstructionTargeter targeter : old.getTargetersCopy()) {
if (targeter instanceof ExceptionRange) {
ExceptionRange it = (ExceptionRange) targeter;
it.updateTarget(old, fresh, it.getBody());
} else {
targeter.updateTarget(old, fresh);
}
}
}
@@ -328,9 +325,7 @@ public class BcelShadow extends Shadow {
// Now the exception range starts just after our new instruction.
// The next bit of code changes the exception range to point at
// the store instruction
InstructionTargeter[] targeters = start.getTargetersArray();
for (int i = 0; i < targeters.length; i++) {
InstructionTargeter t = targeters[i];
for (InstructionTargeter t: start.getTargetersCopy()) {
if (t instanceof ExceptionRange) {
ExceptionRange er = (ExceptionRange) t;
er.updateTarget(start, insertedInstruction, body);
@@ -412,8 +407,8 @@ public class BcelShadow extends Shadow {
}
}
}
}
}
}

// ---- getters

@@ -817,13 +812,9 @@ public class BcelShadow extends Shadow {
}

public static void retargetAllBranches(InstructionHandle from, InstructionHandle to) {
InstructionTargeter[] sources = from.getTargetersArray();
if (sources != null) {
for (int i = sources.length - 1; i >= 0; i--) {
InstructionTargeter source = sources[i];
if (source instanceof InstructionBranch) {
source.updateTarget(from, to);
}
for (InstructionTargeter source : from.getTargetersCopy()) {
if (source instanceof InstructionBranch) {
source.updateTarget(from, to);
}
}
}

+ 95
- 79
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java Переглянути файл

@@ -428,9 +428,10 @@ public final class LazyMethodGen implements Traceable {
}

public Method getMethod() {
if (savedMethod != null)
if (savedMethod != null) {
return savedMethod; // ??? this relies on gentle treatment of
// constant pool
// constant pool
}

try {
MethodGen gen = pack();
@@ -621,8 +622,9 @@ public final class LazyMethodGen implements Traceable {
// don't print empty ranges, that is, ranges who contain no
// actual instructions
for (InstructionHandle xx = r.getStart(); Range.isRangeHandle(xx); xx = xx.getNext()) {
if (xx == r.getEnd())
if (xx == r.getEnd()) {
continue bodyPrint;
}
}

// doesn't handle nested: if (r.getStart().getNext() ==
@@ -630,8 +632,9 @@ public final class LazyMethodGen implements Traceable {
if (r.getStart() == ih) {
printRangeString(r, depth++);
} else {
if (r.getEnd() != ih)
if (r.getEnd() != ih) {
throw new RuntimeException("bad");
}
printRangeString(r, --depth);
}
} else {
@@ -749,8 +752,9 @@ public final class LazyMethodGen implements Traceable {
InstructionTargeter t = (InstructionTargeter) tIter.next();
if (t instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) t;
if (lvt.getSlot() == index)
if (lvt.getSlot() == index) {
return lvt;
}
}
}
return null;
@@ -794,8 +798,9 @@ public final class LazyMethodGen implements Traceable {
}

public int getAccessFlagsWithoutSynchronized() {
if (isSynchronized())
if (isSynchronized()) {
return modifiers - Modifier.SYNCHRONIZED;
}
return modifiers;
}

@@ -978,10 +983,9 @@ public final class LazyMethodGen implements Traceable {
*/
InstructionHandle oldInstructionHandle = getBody().getStart();
InstructionHandle newInstructionHandle = fresh.getStart();
LinkedList exceptionList = new LinkedList();
LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();

// map from localvariabletag to instruction handle
Map localVariables = new HashMap();
Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();

int currLine = -1;
int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
@@ -1004,9 +1008,7 @@ public final class LazyMethodGen implements Traceable {

// now deal with line numbers
// and store up info for local variables
Iterator tIter = oldInstructionHandle.getTargeters().iterator();
while (tIter.hasNext()) {
InstructionTargeter targeter = (InstructionTargeter) tIter.next();// targeters[k];
for (InstructionTargeter targeter : oldInstructionHandle.getTargeters()) {
if (targeter instanceof LineNumberTag) {
int line = ((LineNumberTag) targeter).getLineNumber();
if (line != currLine) {
@@ -1015,7 +1017,7 @@ public final class LazyMethodGen implements Traceable {
}
} else if (targeter instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) targeter;
LVPosition p = (LVPosition) localVariables.get(lvt);
LVPosition p = localVariables.get(lvt);
// If we don't know about it, create a new position and
// store
// If we do know about it - update its end position
@@ -1100,7 +1102,7 @@ public final class LazyMethodGen implements Traceable {
int currLine = -1;
int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();
LinkedList exceptionList = new LinkedList();
LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();
Set<InstructionHandle> forDeletion = new HashSet<InstructionHandle>();
Set<BranchHandle> branchInstructions = new HashSet<BranchHandle>();
// OPTIMIZE sort out in here: getRange()/insertHandler() and type of
@@ -1127,29 +1129,25 @@ public final class LazyMethodGen implements Traceable {
branchInstructions.add((BranchHandle) iHandle);
}

InstructionTargeter[] targeters = iHandle.getTargetersArray();
if (targeters != null) {
for (int k = targeters.length - 1; k >= 0; k--) {
InstructionTargeter targeter = targeters[k];
if (targeter instanceof LineNumberTag) {
int line = ((LineNumberTag) targeter).getLineNumber();
if (line != currLine) {
gen.addLineNumber(iHandle, line + lineNumberOffset);
currLine = line;
}
} else if (targeter instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) targeter;
LVPosition p = localVariables.get(lvt);
// If we don't know about it, create a new position
// and store
// If we do know about it - update its end position
if (p == null) {
LVPosition newp = new LVPosition();
newp.start = newp.end = iHandle;
localVariables.put(lvt, newp);
} else {
p.end = iHandle;
}
for (InstructionTargeter targeter : iHandle.getTargetersCopy()) {
if (targeter instanceof LineNumberTag) {
int line = ((LineNumberTag) targeter).getLineNumber();
if (line != currLine) {
gen.addLineNumber(iHandle, line + lineNumberOffset);
currLine = line;
}
} else if (targeter instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) targeter;
LVPosition p = localVariables.get(lvt);
// If we don't know about it, create a new position
// and store
// If we do know about it - update its end position
if (p == null) {
LVPosition newp = new LVPosition();
newp.start = newp.end = iHandle;
localVariables.put(lvt, newp);
} else {
p.end = iHandle;
}
}
}
@@ -1160,18 +1158,18 @@ public final class LazyMethodGen implements Traceable {
handleBranchInstruction(branchHandle, forDeletion);
}
// now add exception handlers
for (Iterator iter = exceptionList.iterator(); iter.hasNext();) {
ExceptionRange r = (ExceptionRange) iter.next();
if (r.isEmpty())
for (ExceptionRange r : exceptionList) {
if (r.isEmpty()) {
continue;
}
gen.addExceptionHandler(jumpForward(r.getRealStart(), forDeletion), jumpForward(r.getRealEnd(), forDeletion),
jumpForward(r.getHandler(), forDeletion), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld
.makeBcelType(r.getCatchType()));
}

for (Iterator iterator = forDeletion.iterator(); iterator.hasNext();) {
for (InstructionHandle handle : forDeletion) {
try {
theBody.delete((InstructionHandle) iterator.next());
theBody.delete(handle);
} catch (TargetLostException e) {
e.printStackTrace();
}
@@ -1200,7 +1198,7 @@ public final class LazyMethodGen implements Traceable {
wasPackedOptimally = true;
}

private void addLocalVariables(MethodGen gen, Map localVariables) {
private void addLocalVariables(MethodGen gen, Map<LocalVariableTag, LVPosition> localVariables) {
// now add local variables
gen.removeLocalVariables();

@@ -1209,23 +1207,22 @@ public final class LazyMethodGen implements Traceable {
// bcel we should be able to do without it if we're paranoid enough
// through the rest of the compiler.

Map duplicatedLocalMap = new HashMap();
for (Iterator iter = localVariables.keySet().iterator(); iter.hasNext();) {
LocalVariableTag tag = (LocalVariableTag) iter.next();
Map<InstructionHandle, Set<Integer>> duplicatedLocalMap = new HashMap<InstructionHandle, Set<Integer>>();
for (LocalVariableTag tag : localVariables.keySet()) {
// have we already added one with the same slot number and start
// location?
// if so, just continue.
LVPosition lvpos = (LVPosition) localVariables.get(tag);
LVPosition lvpos = localVariables.get(tag);
InstructionHandle start = lvpos.start;
Set slots = (Set) duplicatedLocalMap.get(start);
Set<Integer> slots = duplicatedLocalMap.get(start);
if (slots == null) {
slots = new HashSet();
slots = new HashSet<Integer>();
duplicatedLocalMap.put(start, slots);
} else if (slots.contains(new Integer(tag.getSlot()))) {
// we already have a var starting at this tag with this slot
continue;
}
slots.add(new Integer(tag.getSlot()));
slots.add(Integer.valueOf(tag.getSlot()));
Type t = tag.getRealType();
if (t == null) {
t = BcelWorld.makeBcelType(UnresolvedType.forSignature(tag.getType()));
@@ -1234,12 +1231,13 @@ public final class LazyMethodGen implements Traceable {
}
}

private void addExceptionHandlers(MethodGen gen, Map<InstructionHandle, InstructionHandle> map, LinkedList exnList) {
private void addExceptionHandlers(MethodGen gen, Map<InstructionHandle, InstructionHandle> map,
LinkedList<ExceptionRange> exnList) {
// now add exception handlers
for (Iterator iter = exnList.iterator(); iter.hasNext();) {
ExceptionRange r = (ExceptionRange) iter.next();
if (r.isEmpty())
for (ExceptionRange r : exnList) {
if (r.isEmpty()) {
continue;
}
InstructionHandle rMappedStart = remap(r.getRealStart(), map);
InstructionHandle rMappedEnd = remap(r.getRealEnd(), map);
InstructionHandle rMappedHandler = remap(r.getHandler(), map);
@@ -1248,7 +1246,8 @@ public final class LazyMethodGen implements Traceable {
}
}

private void handleBranchInstruction(Map map, Instruction oldInstruction, Instruction newInstruction) {
private void handleBranchInstruction(Map<InstructionHandle, InstructionHandle> map, Instruction oldInstruction,
Instruction newInstruction) {
InstructionBranch oldBranchInstruction = (InstructionBranch) oldInstruction;
InstructionBranch newBranchInstruction = (InstructionBranch) newInstruction;
InstructionHandle oldTarget = oldBranchInstruction.getTarget(); // old
@@ -1270,8 +1269,7 @@ public final class LazyMethodGen implements Traceable {
}
}

private InstructionHandle jumpForward(InstructionHandle t, Set handlesForDeletion) {

private InstructionHandle jumpForward(InstructionHandle t, Set<InstructionHandle> handlesForDeletion) {
InstructionHandle target = t;
if (handlesForDeletion.contains(target)) {
do {
@@ -1313,7 +1311,7 @@ public final class LazyMethodGen implements Traceable {
}
}

private void handleRangeInstruction(InstructionHandle ih, LinkedList exnList) {
private void handleRangeInstruction(InstructionHandle ih, LinkedList<ExceptionRange> exnList) {
// we're a range instruction
Range r = Range.getRange(ih);
if (r instanceof ExceptionRange) {
@@ -1422,10 +1420,10 @@ public final class LazyMethodGen implements Traceable {
// but I don't trust the only implementation, TreeSet, to do the right
// thing.

/* private */static void insertHandler(ExceptionRange fresh, LinkedList l) {
/* private */static void insertHandler(ExceptionRange fresh, LinkedList<ExceptionRange> l) {
// Old implementation, simply: l.add(0,fresh);
for (ListIterator iter = l.listIterator(); iter.hasNext();) {
ExceptionRange r = (ExceptionRange) iter.next();
for (ListIterator<ExceptionRange> iter = l.listIterator(); iter.hasNext();) {
ExceptionRange r = iter.next();
// int freal = fresh.getRealStart().getPosition();
// int rreal = r.getRealStart().getPosition();
if (fresh.getPriority() >= r.getPriority()) {
@@ -1478,8 +1476,9 @@ public final class LazyMethodGen implements Traceable {
*/

public void assertGoodBody() {
if (true)
if (true) {
return; // only enable for debugging, consider using cheaper
}
// toString()
assertGoodBody(getBody(), toString()); // definingType.getNameAsIdentifier
// () + "." + getName());
@@ -1490,8 +1489,9 @@ public final class LazyMethodGen implements Traceable {
if (true) {
return; // only to be enabled for debugging
}
if (il == null)
if (il == null) {
return;
}
Set body = new HashSet();
Stack<Range> ranges = new Stack<Range>();
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
@@ -1553,8 +1553,9 @@ public final class LazyMethodGen implements Traceable {
if (r.getStart() == ih) {
ranges.push(r);
} else if (r.getEnd() == ih) {
if (ranges.peek() != r)
if (ranges.peek() != r) {
throw new BCException("bad range inclusion in " + from);
}
ranges.pop();
}
}
@@ -1576,15 +1577,17 @@ public final class LazyMethodGen implements Traceable {
}

private static void assertRangeHandle(InstructionHandle ih, String from) {
if (!Range.isRangeHandle(ih))
if (!Range.isRangeHandle(ih)) {
throw new BCException("bad range handle " + ih + " in " + from);
}
}

private static void assertTargetedBy(InstructionHandle target, InstructionTargeter targeter, String from) {
Iterator tIter = target.getTargeters().iterator();
while (tIter.hasNext()) {
if (((InstructionTargeter) tIter.next()) == targeter)
if (((InstructionTargeter) tIter.next()) == targeter) {
return;
}
}
throw new RuntimeException("bad targeting relationship in " + from);
}
@@ -1592,22 +1595,26 @@ public final class LazyMethodGen implements Traceable {
private static void assertTargets(InstructionTargeter targeter, InstructionHandle target, String from) {
if (targeter instanceof Range) {
Range r = (Range) targeter;
if (r.getStart() == target || r.getEnd() == target)
if (r.getStart() == target || r.getEnd() == target) {
return;
}
if (r instanceof ExceptionRange) {
if (((ExceptionRange) r).getHandler() == target)
if (((ExceptionRange) r).getHandler() == target) {
return;
}
}
} else if (targeter instanceof InstructionBranch) {
InstructionBranch bi = (InstructionBranch) targeter;
if (bi.getTarget() == target)
if (bi.getTarget() == target) {
return;
}
if (targeter instanceof InstructionSelect) {
InstructionSelect sel = (InstructionSelect) targeter;
InstructionHandle[] itargets = sel.getTargets();
for (int k = itargets.length - 1; k >= 0; k--) {
if (itargets[k] == target)
if (itargets[k] == target) {
return;
}
}
}
} else if (targeter instanceof Tag) {
@@ -1625,13 +1632,15 @@ public final class LazyMethodGen implements Traceable {
while (tIter.hasNext()) {
InstructionTargeter ts = (InstructionTargeter) tIter.next();
if (ts instanceof Range) {
if (ret != null)
if (ret != null) {
throw new BCException("range handle with multiple ranges in " + from);
}
ret = (Range) ts;
}
}
if (ret == null)
if (ret == null) {
throw new BCException("range handle with no range in " + from);
}
return ret;
}

@@ -1647,33 +1656,38 @@ public final class LazyMethodGen implements Traceable {
// ----

boolean isAdviceMethod() {
if (memberView == null)
if (memberView == null) {
return false;
}
return memberView.getAssociatedShadowMunger() != null;
}

boolean isAjSynthetic() {
if (memberView == null)
if (memberView == null) {
return true;
}
return memberView.isAjSynthetic();
}

boolean isSynthetic() {
if (memberView == null)
if (memberView == null) {
return false;
}
return memberView.isSynthetic();
}

public ISourceLocation getSourceLocation() {
if (memberView != null)
if (memberView != null) {
return memberView.getSourceLocation();
}
return null;
}

public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() {
// if (memberView == null) return null;
if (effectiveSignature != null)
if (effectiveSignature != null) {
return effectiveSignature;
}
return memberView.getEffectiveSignature();
}

@@ -1682,14 +1696,16 @@ public final class LazyMethodGen implements Traceable {
}

public String getSignature() {
if (memberView != null)
if (memberView != null) {
return memberView.getSignature();
}
return MemberImpl.typesToSignature(BcelWorld.fromBcel(getReturnType()), BcelWorld.fromBcel(getArgumentTypes()), false);
}

public String getParameterSignature() {
if (memberView != null)
if (memberView != null) {
return memberView.getParameterSignature();
}
return MemberImpl.typesToSignature(BcelWorld.fromBcel(getArgumentTypes()));
}


+ 32
- 38
weaver/src/org/aspectj/weaver/bcel/ShadowRange.java Переглянути файл

@@ -62,6 +62,7 @@ final class ShadowRange extends Range {
return shadow.getKind();
}

@Override
public String toString() {
return shadow.toString();
}
@@ -125,37 +126,33 @@ final class ShadowRange extends Range {
// instead of the old instruction. We use updateTarget to do this. One goal is
// to make sure we remove all targeters from the old guy, so we can successfully
// delete it.
InstructionTargeter[] sources = oldIh.getTargetersArray();
if (sources != null) {
for (int j = sources.length - 1; j >= 0; j--) {
InstructionTargeter source = sources[j];
if (source instanceof LocalVariableTag) {
Shadow.Kind kind = getKind();
if (kind == Shadow.AdviceExecution || kind == Shadow.ConstructorExecution || kind == Shadow.MethodExecution
|| kind == Shadow.PreInitialization || kind == Shadow.Initialization
|| kind == Shadow.StaticInitialization) {
LocalVariableTag sourceLocalVariableTag = (LocalVariableTag) source;
if (sourceLocalVariableTag.getSlot() == 0) {
// might be 'this' so should be renamed if being dumped in a static method 277616
if (sourceLocalVariableTag.getName().equals("this")) {
sourceLocalVariableTag.setName("ajc$this");
}
for (InstructionTargeter source : oldIh.getTargetersCopy()) {
if (source instanceof LocalVariableTag) {
Shadow.Kind kind = getKind();
if (kind == Shadow.AdviceExecution || kind == Shadow.ConstructorExecution || kind == Shadow.MethodExecution
|| kind == Shadow.PreInitialization || kind == Shadow.Initialization
|| kind == Shadow.StaticInitialization) {
LocalVariableTag sourceLocalVariableTag = (LocalVariableTag) source;
if (sourceLocalVariableTag.getSlot() == 0) {
// might be 'this' so should be renamed if being dumped in a static method 277616
if (sourceLocalVariableTag.getName().equals("this")) {
sourceLocalVariableTag.setName("ajc$this");
}
// if we're extracting a whole block we can do this...
source.updateTarget(oldIh, freshIh);
} else {
// XXX destroying local variable info
// but only for a call or get join point, so no big deal
source.updateTarget(oldIh, null);
}
} else if (source instanceof Range) {
// exceptions and shadows are just moved
((Range) source).updateTarget(oldIh, freshIh, freshBody);
} else {
// line numbers can be shared,
// branches will be copied along with us.
// if we're extracting a whole block we can do this...
source.updateTarget(oldIh, freshIh);
} else {
// XXX destroying local variable info
// but only for a call or get join point, so no big deal
source.updateTarget(oldIh, null);
}
} else if (source instanceof Range) {
// exceptions and shadows are just moved
((Range) source).updateTarget(oldIh, freshIh, freshBody);
} else {
// line numbers can be shared,
// branches will be copied along with us.
source.updateTarget(oldIh, freshIh);
}
}
// we're now done with the old instruction entirely, and will ignore them through
@@ -225,17 +222,14 @@ final class ShadowRange extends Range {
ret = freshBody.append(InstructionFactory.createReturn(freshMethod.getReturnType()));
}
// and remap all the old targeters of the end handle of the range to the return.
InstructionTargeter[] ts = end.getTargetersArray();
if (ts != null) { // shouldn't be the case, but let's test for paranoia
for (int j = ts.length - 1; j >= 0; j--) {
InstructionTargeter t = ts[j];
if (t == this)
continue;
if (!addReturn) {
throw new BCException("range has target, but we aren't adding a return");
} else {
t.updateTarget(end, ret);
}
for (InstructionTargeter t : end.getTargetersCopy()) {
if (t == this) {
continue;
}
if (!addReturn) {
throw new BCException("range has target, but we aren't adding a return");
} else {
t.updateTarget(end, ret);
}
}


+ 21
- 17
weaver/src/org/aspectj/weaver/bcel/Utility.java Переглянути файл

@@ -28,8 +28,8 @@ import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Unknown;
import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
import org.aspectj.apache.bcel.classfile.annotation.NameValuePair;
import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
import org.aspectj.apache.bcel.classfile.annotation.NameValuePair;
import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
import org.aspectj.apache.bcel.generic.ArrayType;
import org.aspectj.apache.bcel.generic.BasicType;
@@ -119,8 +119,9 @@ public class Utility {
takeFrom = isl.getSourceFile().getPath().lastIndexOf('\\');
}
nice.append(isl.getSourceFile().getPath().substring(takeFrom + 1));
if (isl.getLine() != 0)
if (isl.getLine() != 0) {
nice.append(":").append(isl.getLine());
}
}
return nice.toString();
}
@@ -266,11 +267,13 @@ public class Utility {
// XXX I'm sure this test can be simpler but my brain hurts and this
// works
if (!toType.getWorld().isInJava5Mode()) {
if (toType.needsNoConversionFrom(fromType))
if (toType.needsNoConversionFrom(fromType)) {
return;
}
} else {
if (toType.needsNoConversionFrom(fromType) && !(toType.isPrimitiveType() ^ fromType.isPrimitiveType()))
if (toType.needsNoConversionFrom(fromType) && !(toType.isPrimitiveType() ^ fromType.isPrimitiveType())) {
return;
}
}
if (toType.equals(ResolvedType.VOID)) {
// assert fromType.equals(UnresolvedType.OBJECT)
@@ -345,16 +348,18 @@ public class Utility {
return il;
}

if (fromType.equals(toType))
if (fromType.equals(toType)) {
return il;
}
if (toType.equals(Type.VOID)) {
il.append(InstructionFactory.createPop(fromType.getSize()));
return il;
}

if (fromType.equals(Type.VOID)) {
if (toType instanceof BasicType)
if (toType instanceof BasicType) {
throw new BCException("attempting to cast from void to basic type");
}
il.append(InstructionFactory.createNull(Type.OBJECT));
return il;
}
@@ -493,14 +498,10 @@ public class Utility {
*/
public static void deleteInstruction(InstructionHandle ih, InstructionHandle retargetTo, LazyMethodGen enclosingMethod) {
InstructionList il = enclosingMethod.getBody();
InstructionTargeter[] targeters = ih.getTargetersArray();
if (targeters != null) {
for (int i = targeters.length - 1; i >= 0; i--) {
InstructionTargeter targeter = targeters[i];
targeter.updateTarget(ih, retargetTo);
}
ih.removeAllTargeters();
for (InstructionTargeter targeter : ih.getTargetersCopy()) {
targeter.updateTarget(ih, retargetTo);
}
ih.removeAllTargeters();
try {
il.delete(ih);
} catch (TargetLostException e) {
@@ -563,8 +564,9 @@ public class Utility {
// arbitrary rule that we will never lookahead more than 100
// instructions for a line #
while (lookahead++ < 100) {
if (ih == null)
if (ih == null) {
return -1;
}
Iterator tIter = ih.getTargeters().iterator();
while (tIter.hasNext()) {
InstructionTargeter t = (InstructionTargeter) tIter.next();
@@ -621,8 +623,9 @@ public class Utility {
*/
public static boolean isSuppressing(Member member, String lintkey) {
boolean isSuppressing = Utils.isSuppressing(member.getAnnotations(), lintkey);
if (isSuppressing)
if (isSuppressing) {
return true;
}
UnresolvedType type = member.getDeclaringType();
if (type instanceof ResolvedType) {
return Utils.isSuppressing(((ResolvedType) type).getAnnotations(), lintkey);
@@ -651,14 +654,15 @@ public class Utility {
suppressedWarnings.addAll(lint.allKinds());
} else { // (2)
// We know the value is an array value
ArrayElementValue array = (ArrayElementValue) ((NameValuePair) vals.get(0)).getValue();
ArrayElementValue array = (ArrayElementValue) (vals.get(0)).getValue();
ElementValue[] values = array.getElementValuesArray();
for (int j = 0; j < values.length; j++) {
// We know values in the array are strings
SimpleElementValue value = (SimpleElementValue) values[j];
Lint.Kind lintKind = lint.getLintKind(value.getValueString());
if (lintKind != null)
if (lintKind != null) {
suppressedWarnings.add(lintKind);
}
}
}
}

Завантаження…
Відмінити
Зберегти