summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoraclement <aclement>2006-03-09 17:24:19 +0000
committeraclement <aclement>2006-03-09 17:24:19 +0000
commit6e6658a5e9e1665d18f3b4eb8d94609592b56228 (patch)
tree1722d0a9c478d5df7c536c2b4157b0d0d91dd667 /weaver
parent856694bcf982aa6ec4a6be5df1022b6483608f2d (diff)
downloadaspectj-6e6658a5e9e1665d18f3b4eb8d94609592b56228.tar.gz
aspectj-6e6658a5e9e1665d18f3b4eb8d94609592b56228.zip
101411: -XaddSerialVersionUIDPOST_MEMORY_CHANGES
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/Lint.java3
-rw-r--r--weaver/src/org/aspectj/weaver/World.java6
-rw-r--r--weaver/src/org/aspectj/weaver/XlintDefault.properties1
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java37
4 files changed, 44 insertions, 3 deletions
diff --git a/weaver/src/org/aspectj/weaver/Lint.java b/weaver/src/org/aspectj/weaver/Lint.java
index 2ca50ad85..f2542367c 100644
--- a/weaver/src/org/aspectj/weaver/Lint.java
+++ b/weaver/src/org/aspectj/weaver/Lint.java
@@ -114,6 +114,9 @@ public class Lint {
public final Kind swallowedExceptionInCatchBlock =
new Kind("swallowedExceptionInCatchBlock","exception swallowed in catch block");
+ public final Kind calculatingSerialVersionUID =
+ new Kind("calculatingSerialVersionUID","calculated SerialVersionUID for type {0} to be {1}");
+
// there are a lot of messages in the cant find type family - I'm defining an umbrella lint warning that
// allows a user to control their severity (for e.g. ltw or binary weaving)
public final Kind cantFindType =
diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java
index 5f9cf6d01..870ba7f43 100644
--- a/weaver/src/org/aspectj/weaver/World.java
+++ b/weaver/src/org/aspectj/weaver/World.java
@@ -90,6 +90,9 @@ public abstract class World implements Dump.INode {
/** Flags for the new joinpoints that are 'optional' */
private boolean optionalJoinpoint_ArrayConstruction = false; // Command line flag: "arrayconstruction"
+ private boolean addSerialVerUID = false;
+
+
private Properties extraConfiguration = null;
// Records whether ASM is around ... so we might use it for delegates
@@ -1061,6 +1064,9 @@ public abstract class World implements Dump.INode {
workInProgress1.remove(baseClass);
}
+ public void setAddSerialVerUID(boolean b) { addSerialVerUID=b;}
+ public boolean isAddSerialVerUID() { return addSerialVerUID;}
+
public void flush() {
// System.err.println("BEFORE FLUSHING");
// System.err.println(typeMap.toString());
diff --git a/weaver/src/org/aspectj/weaver/XlintDefault.properties b/weaver/src/org/aspectj/weaver/XlintDefault.properties
index bef407969..70063a74e 100644
--- a/weaver/src/org/aspectj/weaver/XlintDefault.properties
+++ b/weaver/src/org/aspectj/weaver/XlintDefault.properties
@@ -40,3 +40,4 @@ cantFindTypeAffectingJPMatch = warning
unorderedAdviceAtShadow=ignore
swallowedExceptionInCatchBlock=warning
+calculatingSerialVersionUID=ignore \ No newline at end of file
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
index 3d485ab02..6533ea131 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
@@ -39,6 +39,7 @@ import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.Unknown;
import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.generic.BasicType;
import org.aspectj.apache.bcel.generic.ClassGen;
import org.aspectj.apache.bcel.generic.ConstantPoolGen;
import org.aspectj.apache.bcel.generic.FieldGen;
@@ -69,6 +70,7 @@ import org.aspectj.weaver.WeaverStateInfo;
import org.aspectj.weaver.World;
import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
+
/**
* Lazy lazy lazy.
* We don't unpack the underlying class unless necessary. Things
@@ -99,6 +101,8 @@ public final class LazyClassGen {
private boolean isSerializable = false;
private boolean hasSerialVersionUIDField = false;
+ private boolean serialVersionUIDRequiresInitialization = false;
+ private long calculatedSerialVersionUID;
private boolean hasClinit = false;
// ---
@@ -279,12 +283,28 @@ public final class LazyClassGen {
hasClinit = true;
}
}
+
+ // Do we need to calculate an SUID and add it?
+ if (!hasSerialVersionUIDField && world.isAddSerialVerUID()) {
+ calculatedSerialVersionUID = myGen.getSUID();
+ Field fg = new FieldGen(
+ Constants.ACC_PRIVATE|Constants.ACC_FINAL|Constants.ACC_STATIC,
+ BasicType.LONG,"serialVersionUID",getConstantPoolGen()).getField();
+ addField(fg);
+ hasSerialVersionUIDField=true;
+ serialVersionUIDRequiresInitialization=true;
+ // warn about what we've done?
+ if (world.getLint().calculatingSerialVersionUID.isEnabled())
+ world.getLint().calculatingSerialVersionUID.signal(
+ new String[]{getClassName(),Long.toString(calculatedSerialVersionUID)+"L"},null,null);
+ }
}
Method[] methods = myGen.getMethods();
for (int i = 0; i < methods.length; i++) {
addMethodGen(new LazyMethodGen(methods[i], this));
}
+
}
public static boolean hasSerialVersionUIDField (ResolvedType type) {
@@ -935,10 +955,21 @@ public final class LazyClassGen {
// }
private void addAjcInitializers() {
- if (tjpFields.size() == 0) return;
+ if (tjpFields.size() == 0 && !serialVersionUIDRequiresInitialization) return;
+ InstructionList il = null;
+
+ if (tjpFields.size()>0) {
+ il = initializeAllTjps();
+ }
+
+ if (serialVersionUIDRequiresInitialization) {
+ if (il==null) {
+ il= new InstructionList();
+ }
+ il.append(new PUSH(getConstantPoolGen(),calculatedSerialVersionUID));
+ il.append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG, Constants.PUTSTATIC));
+ }
- InstructionList il = initializeAllTjps();
-
getStaticInitializer().getBody().insert(il);
}