From f51e0736ed52ca6bc3689981f53718b62471251a Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 20 Jan 2006 09:26:04 +0000 Subject: [PATCH] 77166 - newarray joinpoint support. "-Xjoinpoints:arrayconstruction" --- .../org/aspectj/ajdt/ajc/BuildArgParser.java | 2 + .../internal/core/builder/AjBuildConfig.java | 9 ++++ .../internal/core/builder/AjBuildManager.java | 1 + .../core/builder/AjCompilerOptions.java | 2 + .../ajc151/NewarrayJoinpointTests.java | 10 ++-- .../systemtest/ajc151/newarray_joinpoint.xml | 28 ++++++----- .../src/org/aspectj/weaver/ResolvedType.java | 10 ++++ weaver/src/org/aspectj/weaver/World.java | 14 ++++++ .../org/aspectj/weaver/bcel/BcelWorld.java | 46 +++++++++++++++++++ .../org/aspectj/weaver/bcel/LazyClassGen.java | 34 ++++++++++---- 10 files changed, 128 insertions(+), 28 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 2f4eea60e..16c4f67a3 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -532,6 +532,8 @@ public class BuildArgParser extends Main { buildConfig.setNoAtAspectJAnnotationProcessing(true); } else if (arg.equals("-Xdev:Pinpoint")) { buildConfig.setXdevPinpointMode(true); + } else if (arg.equals("-Xjoinpoints:arrayconstruction")) { + buildConfig.setXJoinpoints("arrayconstruction"); } else if (arg.equals("-noweave") || arg.equals( "-XnoWeave")) { buildConfig.setNoWeave(true); } else if (arg.equals("-XserializableAspects")) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index c8dcb428d..70cd246c4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -379,6 +379,7 @@ public class AjBuildConfig { setProceedOnError(true); } setTargetAspectjRuntimeLevel(global.getTargetAspectjRuntimeLevel()); + setXJoinpoints(global.getXJoinpoints()); if (!isXHasMemberEnabled() && global.isXHasMemberEnabled()) { setXHasMemberSupport(true); } @@ -469,6 +470,14 @@ public class AjBuildConfig { public void setXserializableAspects(boolean xserializableAspects) { options.xSerializableAspects = xserializableAspects; } + + public void setXJoinpoints(String jps) { + options.xOptionalJoinpoints = jps; + } + + public String getXJoinpoints() { + return options.xOptionalJoinpoints; + } public boolean isXnoInline() { return options.xNoInline; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 1468bed19..59721acbd 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -616,6 +616,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc BcelWorld bcelWorld = new BcelWorld(cp, handler, null); bcelWorld.setBehaveInJava5Way(buildConfig.getBehaveInJava5Way()); bcelWorld.setTargetAspectjRuntimeLevel(buildConfig.getTargetAspectjRuntimeLevel()); + bcelWorld.setOptionalJoinpoints(buildConfig.getXJoinpoints()); bcelWorld.setXnoInline(buildConfig.isXnoInline()); bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp()); bcelWorld.setXHasMemberSupportEnabled(buildConfig.isXHasMemberEnabled()); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java index d5f04d885..7239541e4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java @@ -71,6 +71,8 @@ public class AjCompilerOptions extends CompilerOptions { public boolean xdevPinpoint = false; public boolean showWeavingInformation = false; + public String xOptionalJoinpoints = null; + // If true - autoboxing behaves differently ... public boolean behaveInJava5Way = false; diff --git a/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java index fb46d3b8f..dbd0be4da 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java @@ -28,15 +28,12 @@ import org.aspectj.testing.XMLBasedAjcTestCase; * The changes to expose the new joinpoint are in: * BcelClassWeaver.match(LazyMethodGen mg,InstructionHandle ih,BcelShadow enclosingShadow,List shadowAccumulator) * - * Determining the type of the array is easy. Determining the size of the array is not easily statically, it is on the stack. + * Determining the type of the array is easy. Determining the size of the array is not easy statically, it is on the stack. * * - * to think about: + * What still needs testing: + * - structure model * - * args - * thisJoinPoint - does anything need to manifest in it? - * wildcards in declaringtype 'Integer*' matches 'Integer[]' ? - * what is the signature of the joinpoint - are its modifiers simply 'public' ? */ @@ -62,6 +59,7 @@ public class NewarrayJoinpointTests extends XMLBasedAjcTestCase { public void testUsingTargetAndAfterReturningAdvice() { runTest("using target and after returning");} public void testUsingItForReal() { runTest("using it for real");} public void testDifferentiatingArrayTypes() { runTest("differentiating array types");} + public void testStructureModel() { runTest("structure model");} // public static Test suite() { diff --git a/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml b/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml index 39fa37225..fedc67322 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml @@ -4,7 +4,7 @@ - + @@ -16,7 +16,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -94,7 +94,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -149,5 +149,9 @@ + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/ResolvedType.java b/weaver/src/org/aspectj/weaver/ResolvedType.java index ce072037f..07eb8a926 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedType.java +++ b/weaver/src/org/aspectj/weaver/ResolvedType.java @@ -1683,6 +1683,16 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl } } + // Handling members for the new array join point + if (world.isJoinpointArrayConstructionEnabled() && this.isArray()) { + if (member.getKind()==Member.CONSTRUCTOR) { + ResolvedMemberImpl ret = + new ResolvedMemberImpl(Member.CONSTRUCTOR,this,Modifier.PUBLIC, + ResolvedType.VOID,"",world.resolve(member.getParameterTypes())); + return ret; + } + } + // if (this.getSuperclass() != ResolvedType.OBJECT && this.getSuperclass() != null) { // return getSuperclass().lookupSyntheticMember(member); // } diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index b73fba107..a8193d2fa 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -86,6 +86,10 @@ public abstract class World implements Dump.INode { /** The level of the aspectjrt.jar the code we generate needs to run on */ private String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT; + /** Flags for the new joinpoints that are 'optional' */ + private boolean optionalJoinpoint_ArrayConstruction = false; // Command line flag: "arrayconstruction" + + /** * A list of RuntimeExceptions containing full stack information for every * type we couldn't find. @@ -660,6 +664,16 @@ public abstract class World implements Dump.INode { targetAspectjRuntimeLevel = s; } + public void setOptionalJoinpoints(String jps) { + if (jps.indexOf("arrayconstruction")!=-1) { + optionalJoinpoint_ArrayConstruction = true; + } + } + + public boolean isJoinpointArrayConstructionEnabled() { + return optionalJoinpoint_ArrayConstruction; + } + public String getTargetAspectjRuntimeLevel() { return targetAspectjRuntimeLevel; } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index 2441176fb..634895fa8 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -28,13 +28,19 @@ import org.aspectj.apache.bcel.classfile.ClassParser; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; import org.aspectj.apache.bcel.classfile.annotation.Annotation; +import org.aspectj.apache.bcel.generic.ANEWARRAY; import org.aspectj.apache.bcel.generic.ConstantPoolGen; import org.aspectj.apache.bcel.generic.FieldInstruction; import org.aspectj.apache.bcel.generic.GETSTATIC; import org.aspectj.apache.bcel.generic.INVOKEINTERFACE; import org.aspectj.apache.bcel.generic.INVOKESPECIAL; import org.aspectj.apache.bcel.generic.INVOKESTATIC; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionHandle; import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; +import org.aspectj.apache.bcel.generic.NEWARRAY; +import org.aspectj.apache.bcel.generic.ObjectType; import org.aspectj.apache.bcel.generic.PUTSTATIC; import org.aspectj.apache.bcel.generic.Type; import org.aspectj.apache.bcel.util.ClassLoaderRepository; @@ -380,6 +386,46 @@ public class BcelWorld extends World implements Repository { } } + + + public Member makeJoinPointSignatureForArrayConstruction(LazyClassGen cg, InstructionHandle handle) { + Instruction i = handle.getInstruction(); + ConstantPoolGen cpg = cg.getConstantPoolGen(); + Member retval = null; + + if (i instanceof ANEWARRAY) { + ANEWARRAY arrayInstruction = (ANEWARRAY)i; + ObjectType ot = arrayInstruction.getLoadClassType(cpg); + UnresolvedType ut = fromBcel(ot); + ut = UnresolvedType.makeArray(ut,1); + retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "", new ResolvedType[]{ResolvedType.INT}); + + } else if (i instanceof MULTIANEWARRAY) { + MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY)i; + UnresolvedType ut = null; + short dimensions = arrayInstruction.getDimensions(); + ObjectType ot = arrayInstruction.getLoadClassType(cpg); + if (ot!=null) { + ut = fromBcel(ot); + ut = UnresolvedType.makeArray(ut,dimensions); + } else { + Type t = arrayInstruction.getType(cpg); + ut = fromBcel(t); + } + ResolvedType[] parms = new ResolvedType[dimensions]; + for (int ii=0;ii", parms); + + } else if (i instanceof NEWARRAY) { + NEWARRAY arrayInstruction = (NEWARRAY)i; + Type ot = arrayInstruction.getType(); + UnresolvedType ut = fromBcel(ot); + retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "", new ResolvedType[]{ResolvedType.INT}); + } else { + throw new BCException("Cannot create array construction signature for this non-array instruction:"+i); + } + return retval; + } public Member makeJoinPointSignatureForMethodInvocation(LazyClassGen cg, InvokeInstruction ii) { ConstantPoolGen cpg = cg.getConstantPoolGen(); diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java index a22920a77..60d91fc4e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java @@ -1035,16 +1035,30 @@ public final class LazyClassGen { Constants.INVOKEVIRTUAL)); } else if(sig.getKind().equals(Member.CONSTRUCTOR)) { BcelWorld w = shadow.getWorld(); - list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w)))); - list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType()))); - list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes()))); - list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w)))); - list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w)))); - list.append(fact.createInvoke(factoryType.getClassName(), - sig.getSignatureMakerName(), - new ObjectType(sig.getSignatureType()), - new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING }, - Constants.INVOKEVIRTUAL)); + if (w.isJoinpointArrayConstructionEnabled() && sig.getDeclaringType().isArray()) { + // its the magical new jp + list.append(new PUSH(getConstantPoolGen(),makeString(Modifier.PUBLIC))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType()))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes()))); + list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getParameterNames(w)))); + list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getExceptions(w)))); + list.append(fact.createInvoke(factoryType.getClassName(), + sig.getSignatureMakerName(), + new ObjectType(sig.getSignatureType()), + new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING }, + Constants.INVOKEVIRTUAL)); + } else { + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w)))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType()))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes()))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w)))); + list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w)))); + list.append(fact.createInvoke(factoryType.getClassName(), + sig.getSignatureMakerName(), + new ObjectType(sig.getSignatureType()), + new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING }, + Constants.INVOKEVIRTUAL)); + } } else if(sig.getKind().equals(Member.FIELD)) { BcelWorld w = shadow.getWorld(); list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w)))); -- 2.39.5