]> source.dussan.org Git - aspectj.git/commitdiff
390269: fix for gc'd raw type refs
authorAndy Clement <andrew.clement@gmail.com>
Sat, 26 Jan 2013 00:54:33 +0000 (16:54 -0800)
committerAndy Clement <andrew.clement@gmail.com>
Sat, 26 Jan 2013 00:54:33 +0000 (16:54 -0800)
org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java
org.aspectj.matcher/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java

index c8b1c777f2db497fcc87f052e3759bf13f23e398..6eeaf139634f7a68e9b298eeb8dc0be6bd687c9d 100644 (file)
@@ -43,6 +43,8 @@ public class ReferenceType extends ResolvedType {
         * For parameterized types (or the raw type) - this field points to the actual reference type from which they are derived.
         */
        ReferenceType genericType = null;
+       
+       ReferenceType rawType = null; // generic types have a pointer back to their raw variant (prevents GC of the raw from the typemap!)
 
        ReferenceTypeDelegate delegate = null;
        int startPos = 0;
@@ -147,6 +149,7 @@ public class ReferenceType extends ResolvedType {
        public ReferenceType(UnresolvedType genericType, World world) {
                super(genericType.getSignature(), world);
                typeKind = TypeKind.GENERIC;
+               this.typeVariables=genericType.typeVariables;
        }
 
        @Override
@@ -428,7 +431,6 @@ public class ReferenceType extends ResolvedType {
                                return true;
                        }
                }
-
                if (this == other) {
                        return true;
                }
@@ -985,6 +987,9 @@ public class ReferenceType extends ResolvedType {
                if (typeKind == TypeKind.RAW) {
                        genericType.addDependentType(this);
                }
+               if (isRawType()) {
+                       genericType.rawType = this;
+               }
                if (this.isRawType() && rt.isRawType()) {
                        new RuntimeException("PR341926 diagnostics: Incorrect setup for a generic type, raw type should not point to raw: "
                                        + this.getName()).printStackTrace();
index 960b05975df5752dfc2e0c9331481f126a091246..043d94e82666875be084366223582c848ad8c286 100644 (file)
@@ -475,13 +475,9 @@ public abstract class World implements Dump.INode {
                                simpleOrRawType.setNeedsModifiableDelegate(true);
                        }
                        ReferenceTypeDelegate delegate = resolveDelegate(simpleOrRawType);
-                       // 117854
-                       // if (delegate == null) return ResolvedType.MISSING;
+
                        if (delegate == null) {
-                               return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), erasedSignature, this);// ResolvedType
-                               // .
-                               // MISSING
-                               // ;
+                               return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), erasedSignature, this);
                        }
 
                        if (delegate.isGeneric() && behaveInJava5Way) {
@@ -493,14 +489,10 @@ public abstract class World implements Dump.INode {
                                                                        + simpleOrRawType.getName());
                                }
                                ReferenceType genericType = makeGenericTypeFrom(delegate, simpleOrRawType);
-                               // name =
-                               // ReferenceType.fromTypeX(UnresolvedType.forRawTypeNames(
-                               // ty.getName()),this);
                                simpleOrRawType.setDelegate(delegate);
                                genericType.setDelegate(delegate);
                                simpleOrRawType.setGenericType(genericType);
                                return simpleOrRawType;
-
                        } else {
                                // ======== simple type =========
                                simpleOrRawType.setDelegate(delegate);
@@ -1020,6 +1012,7 @@ public abstract class World implements Dump.INode {
        /*
         * Map of types in the world, can have 'references' to expendable ones which can be garbage collected to recover memory. An
         * expendable type is a reference type that is not exposed to the weaver (ie just pulled in for type resolution purposes).
+        * Generic types have their raw form added to the map, which has a pointer to the underlying generic.
         */
        public static class TypeMap {
 
@@ -1269,7 +1262,6 @@ public abstract class World implements Dump.INode {
                                }
                                return type;
                        } else {
-
                                if (demotionSystemActive) {
                                        // System.out.println("Added since last demote " + key);
                                        addedSinceLastDemote.add(key);
@@ -1295,7 +1287,8 @@ public abstract class World implements Dump.INode {
                        if (!memoryProfiling) {
                                return;
                        }
-                       while (rq.poll() != null) {
+                       Reference r = null;
+                       while ((r=rq.poll()) != null) {
                                collectedTypes++;
                        }
                }
@@ -1311,11 +1304,17 @@ public abstract class World implements Dump.INode {
                                        WeakReference<ResolvedType> ref = (WeakReference<ResolvedType>) expendableMap.get(key);
                                        if (ref != null) {
                                                ret = ref.get();
+//                                             if (ret==null) {
+//                                                     expendableMap.remove(key);
+//                                             }
                                        }
                                } else if (policy == USE_SOFT_REFS) {
                                        SoftReference<ResolvedType> ref = (SoftReference<ResolvedType>) expendableMap.get(key);
                                        if (ref != null) {
                                                ret = ref.get();
+//                                             if (ret==null) {
+//                                                     expendableMap.remove(key);
+//                                             }
                                        }
                                        // } else {
                                        // return (ResolvedType) expendableMap.get(key);
index 7bf873bb1d32c506615328d2a61ce1bd860f20ed..9fce00cd476e7c8958a32813d243e3c2c2055e31 100644 (file)
@@ -461,14 +461,14 @@ public class BcelWorld extends World implements Repository {
 
                if (nameTypeX == null) {
                        if (jc.isGeneric() && isInJava5Mode()) {
-                               nameTypeX = ReferenceType.fromTypeX(UnresolvedType.forRawTypeName(jc.getClassName()), this);
-                               ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
+                               ReferenceType rawType = ReferenceType.fromTypeX(UnresolvedType.forRawTypeName(jc.getClassName()), this);
+                               ret = buildBcelDelegate(rawType, jc, artificial, true);
                                ReferenceType genericRefType = new ReferenceType(UnresolvedType.forGenericTypeSignature(signature,
                                                ret.getDeclaredGenericSignature()), this);
-                               nameTypeX.setDelegate(ret);
+                               rawType.setDelegate(ret);
                                genericRefType.setDelegate(ret);
-                               nameTypeX.setGenericType(genericRefType);
-                               typeMap.put(signature, nameTypeX);
+                               rawType.setGenericType(genericRefType);
+                               typeMap.put(signature, rawType);
                        } else {
                                nameTypeX = new ReferenceType(signature, this);
                                ret = buildBcelDelegate(nameTypeX, jc, artificial, true);