diff options
author | aclement <aclement> | 2010-08-23 20:44:15 +0000 |
---|---|---|
committer | aclement <aclement> | 2010-08-23 20:44:15 +0000 |
commit | 068d72d06654b192bbfd1203699efe5501107bbe (patch) | |
tree | acaf2c05f8a34437647f26780478c3b27f5e123e /weaver | |
parent | cbdbc8b60f8aa741c8d080bff504a28d71304879 (diff) | |
download | aspectj-068d72d06654b192bbfd1203699efe5501107bbe.tar.gz aspectj-068d72d06654b192bbfd1203699efe5501107bbe.zip |
323438
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java | 162 |
1 files changed, 77 insertions, 85 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java index 79ae0c6fc..8a167fb1f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java @@ -1151,11 +1151,10 @@ public final class LazyClassGen { // load the current Class object // XXX check that this works correctly for inners/anonymous - list.append(InstructionFactory.PUSH(getConstantPool(), getClassName())); + list.append(fact.PUSHCLASS(cp, myGen.getClassName())); // XXX do we need to worry about the fact the theorectically this could // throw // a ClassNotFoundException - list.append(fact.createInvoke("java.lang.Class", "forName", classType, new Type[] { Type.STRING }, Constants.INVOKESTATIC)); list.append(fact.createInvoke(factoryType.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, classType }, Constants.INVOKESPECIAL)); @@ -1193,9 +1192,10 @@ public final class LazyClassGen { } private void initializeTjp(InstructionFactory fact, InstructionList list, Field field, BcelShadow shadow) { + boolean fastSJP = false; + boolean isFastSJPAvailable = shadow.getWorld().isTargettingRuntime1_6_10(); + Member sig = shadow.getSignature(); - // ResolvedMember mem = - // shadow.getSignature().resolve(shadow.getWorld()); // load the factory list.append(InstructionFactory.createLoad(factoryType, 0)); @@ -1204,135 +1204,110 @@ public final class LazyClassGen { list.append(InstructionFactory.PUSH(getConstantPool(), shadow.getKind().getName())); // create the signature - list.append(InstructionFactory.createLoad(factoryType, 0)); + if (!isFastSJPAvailable || !sig.getKind().equals(Member.METHOD)) { + list.append(InstructionFactory.createLoad(factoryType, 0)); + } String signatureMakerName = SignatureUtils.getSignatureMakerName(sig); ObjectType signatureType = new ObjectType(SignatureUtils.getSignatureType(sig)); - + UnresolvedType[] exceptionTypes = null; if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We // didn't have optimized // factory methods in 1.2 - list.append(InstructionFactory.PUSH(getConstantPool(), SignatureUtils.getSignatureString(sig, shadow.getWorld()))); + list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.METHOD)) { BcelWorld w = shadow.getWorld(); // For methods, push the parts of the signature on. - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getModifiers(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), sig.getName())); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterTypes()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterNames(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getExceptions(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getReturnType()))); - // And generate a call to the variant of makeMethodSig() that takes - // 7 strings - list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY7, - Constants.INVOKEVIRTUAL)); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getModifiers(w)))); + list.append(InstructionFactory.PUSH(cp, sig.getName())); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterTypes()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterNames(w)))); + exceptionTypes = sig.getExceptions(w); + if (isFastSJPAvailable && exceptionTypes.length == 0) { + fastSJP = true; + } else { + list.append(InstructionFactory.PUSH(cp, makeString(exceptionTypes))); + } + list.append(InstructionFactory.PUSH(cp, makeString(sig.getReturnType()))); + // And generate a call to the variant of makeMethodSig() that takes the strings + if (isFastSJPAvailable) { + fastSJP = true; + } else { + list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY7, + Constants.INVOKEVIRTUAL)); + } + } else if (sig.getKind().equals(Member.MONITORENTER)) { - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.MONITOREXIT)) { - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.HANDLER)) { BcelWorld w = shadow.getWorld(); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterTypes()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterNames(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterTypes()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterNames(w)))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY3, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.CONSTRUCTOR)) { BcelWorld w = shadow.getWorld(); if (w.isJoinpointArrayConstructionEnabled() && sig.getDeclaringType().isArray()) { // its the magical new jp - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(Modifier.PUBLIC))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterTypes()))); - list.append(InstructionFactory.PUSH(getConstantPool(), ""));// makeString - // ( - // "" - // ) - // ) - // ) - // ; - // / - // / - // sig - // . - // getParameterNames - // ( - // w - // ) - // ) - // ) - // ) - // ; - list.append(InstructionFactory.PUSH(getConstantPool(), ""));// makeString - // ( - // "" - // ) - // ) - // ) - // ; - // / - // / - // sig - // . - // getExceptions - // ( - // w - // ) - // ) - // ) - // ) - // ; + list.append(InstructionFactory.PUSH(cp, makeString(Modifier.PUBLIC))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterTypes()))); + list.append(InstructionFactory.PUSH(cp, "")); // sig.getParameterNames? + list.append(InstructionFactory.PUSH(cp, ""));// sig.getExceptions? list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY5, Constants.INVOKEVIRTUAL)); } else { - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getModifiers(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterTypes()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterNames(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getExceptions(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getModifiers(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterTypes()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterNames(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getExceptions(w)))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY5, Constants.INVOKEVIRTUAL)); } } else if (sig.getKind().equals(Member.FIELD)) { BcelWorld w = shadow.getWorld(); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getModifiers(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), sig.getName())); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getModifiers(w)))); + list.append(InstructionFactory.PUSH(cp, sig.getName())); // see pr227401 UnresolvedType dType = sig.getDeclaringType(); if (dType.getTypekind() == TypeKind.PARAMETERIZED || dType.getTypekind() == TypeKind.GENERIC) { dType = sig.getDeclaringType().resolve(world).getGenericType(); } - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(dType))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getReturnType()))); + list.append(InstructionFactory.PUSH(cp, makeString(dType))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getReturnType()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY4, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.ADVICE)) { BcelWorld w = shadow.getWorld(); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getModifiers(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), sig.getName())); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterTypes()))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getParameterNames(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getExceptions(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString((sig.getReturnType())))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getModifiers(w)))); + list.append(InstructionFactory.PUSH(cp, sig.getName())); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterTypes()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getParameterNames(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getExceptions(w)))); + list.append(InstructionFactory.PUSH(cp, makeString((sig.getReturnType())))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING }, Constants.INVOKEVIRTUAL)); } else if (sig.getKind().equals(Member.STATIC_INITIALIZATION)) { BcelWorld w = shadow.getWorld(); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getModifiers(w)))); - list.append(InstructionFactory.PUSH(getConstantPool(), makeString(sig.getDeclaringType()))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getModifiers(w)))); + list.append(InstructionFactory.PUSH(cp, makeString(sig.getDeclaringType()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY2, Constants.INVOKEVIRTUAL)); } else { - list.append(InstructionFactory.PUSH(getConstantPool(), SignatureUtils.getSignatureString(sig, shadow.getWorld()))); + list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld()))); list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, Constants.INVOKEVIRTUAL)); } @@ -1359,13 +1334,30 @@ public final class LazyClassGen { } else { throw new Error("should not happen"); } - list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), new Type[] { Type.STRING, - sigType, Type.INT }, Constants.INVOKEVIRTUAL)); + + if (fastSJP) { + if (exceptionTypes != null && exceptionTypes.length != 0) { + list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), ARRAY_8STRING_INT, + Constants.INVOKEVIRTUAL)); + } else { + list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), ARRAY_7STRING_INT, + Constants.INVOKEVIRTUAL)); + } + } else { + list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), new Type[] { Type.STRING, + sigType, Type.INT }, Constants.INVOKEVIRTUAL)); + } + // put it in the field list.append(fact.createFieldAccess(getClassName(), field.getName(), field.getType(), Constants.PUTSTATIC)); } } + private static final Type[] ARRAY_7STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, + Type.STRING, Type.STRING, Type.INT }; + private static final Type[] ARRAY_8STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, + Type.STRING, Type.STRING, Type.STRING, Type.INT }; + protected String makeString(int i) { return Integer.toString(i, 16); // ??? expensive } |