]> source.dussan.org Git - aspectj.git/commitdiff
312839: smaller class files
authoraclement <aclement>
Wed, 19 May 2010 15:12:50 +0000 (15:12 +0000)
committeraclement <aclement>
Wed, 19 May 2010 15:12:50 +0000 (15:12 +0000)
org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java
org.aspectj.matcher/src/org/aspectj/weaver/CompressingDataOutputStream.java
org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java
org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java
org.aspectj.matcher/src/org/aspectj/weaver/patterns/ExactTypePattern.java
org.aspectj.matcher/src/org/aspectj/weaver/patterns/TypePatternList.java

index 982a5ab8c2aa27db0addb81c63876417a4c413ac..ab1aca1349074065254ca01736a566e3ef4fff06 100644 (file)
@@ -366,12 +366,33 @@ public abstract class AjAttribute {
 
                @Override
                public void write(CompressingDataOutputStream s) throws IOException {
-                       s.writeUTF(sourceFileName);
-                       FileUtil.writeIntArray(lineBreaks, s);
+                       if (s.canCompress()) {
+                               s.writeCompressedPath(sourceFileName);
+                       } else {
+                               s.writeUTF(sourceFileName);
+                       }
+                       s.writeInt(lineBreaks.length);
+                       int previous = 0;
+                       for (int i = 0, max = lineBreaks.length; i < max; i++) {
+                               s.writeShort(lineBreaks[i] - previous);
+                               previous = lineBreaks[i];
+                       }
                }
 
                public static SourceContextAttribute read(VersionedDataInputStream s) throws IOException {
-                       return new SourceContextAttribute(s.readUTF(), FileUtil.readIntArray(s));
+                       String sourceFileName = s.isAtLeast169() ? s.readPath() : s.readUTF();
+                       int lineBreaks = s.readInt();
+                       int[] lines = new int[lineBreaks];
+                       int previous = 0;
+                       for (int i = 0; i < lineBreaks; i++) {
+                               if (s.isAtLeast169()) {
+                                       lines[i] = s.readShort() + previous;
+                                       previous = lines[i];
+                               } else {
+                                       lines[i] = s.readInt();
+                               }
+                       }
+                       return new SourceContextAttribute(sourceFileName, lines);
                }
 
                public int[] getLineBreaks() {
index 1e2f31c35d6cfe12e929e57c043ee70ebd4fcac6..59b4fbcab7c6614ccd94db7bf85e914d721cfe2e 100644 (file)
@@ -32,10 +32,6 @@ public class CompressingDataOutputStream extends DataOutputStream {
                this.constantPoolWriter = constantPoolWriter;
        }
 
-       public CompressingDataOutputStream(ByteArrayOutputStream baos) {
-               super(baos);
-       }
-
        public CompressingDataOutputStream(FileOutputStream fos) {
                super(fos);
        }
index 7f9330c87ea40d619dff57e0b4820c5612704161..963490118fc8af0c0a916f47fb0aa7ee94cc626a 100644 (file)
@@ -380,10 +380,28 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
 
        public void write(CompressingDataOutputStream s) throws IOException {
                getKind().write(s);
-               getDeclaringType().write(s);
+               s.writeBoolean(s.canCompress()); // boolean indicates if parts of this are compressed references
+
+               // write out the signature of the declaring type of this member
+               if (s.canCompress()) {
+                       s.writeCompressedSignature(getDeclaringType().getSignature());
+               } else {
+                       getDeclaringType().write(s);
+               }
+
+               // write out the modifiers
                s.writeInt(modifiers);
-               s.writeUTF(getName());
-               s.writeUTF(getSignature());
+
+               // write out the name and the signature of this member
+               if (s.canCompress()) {
+                       s.writeCompressedName(getName());
+                       s.writeCompressedSignature(getSignature());
+               } else {
+                       s.writeUTF(getName());
+                       s.writeUTF(getSignature());
+               }
+
+               // write out the array clauses
                UnresolvedType.writeArray(getExceptions(), s);
 
                s.writeInt(getStart());
@@ -392,24 +410,33 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
 
                // Write out any type variables...
                if (typeVariables == null) {
-                       s.writeInt(0);
+                       s.writeByte(0);
                } else {
-                       s.writeInt(typeVariables.length);
+                       s.writeByte(typeVariables.length);
                        for (int i = 0; i < typeVariables.length; i++) {
                                typeVariables[i].write(s);
                        }
                }
                String gsig = getGenericSignature();
+
+               // change this to a byte: 255=false 0>254 means true and encodes the number of parameters
                if (getSignature().equals(gsig)) {
-                       s.writeBoolean(false);
+                       s.writeByte(0xff);
                } else {
-                       s.writeBoolean(true);
-                       s.writeInt(parameterTypes.length);
+                       s.writeByte(parameterTypes.length);
                        for (int i = 0; i < parameterTypes.length; i++) {
-                               UnresolvedType array_element = parameterTypes[i];
-                               array_element.write(s);
+                               if (s.canCompress()) {
+                                       s.writeCompressedSignature(parameterTypes[i].getSignature());
+                               } else {
+                                       UnresolvedType array_element = parameterTypes[i];
+                                       array_element.write(s);
+                               }
+                       }
+                       if (s.canCompress()) {
+                               s.writeCompressedSignature(returnType.getSignature());
+                       } else {
+                               returnType.write(s);
                        }
-                       returnType.write(s);
                }
        }
 
@@ -469,8 +496,13 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
        public static ResolvedMemberImpl readResolvedMember(VersionedDataInputStream s, ISourceContext sourceContext)
                        throws IOException {
 
-               ResolvedMemberImpl m = new ResolvedMemberImpl(MemberKind.read(s), UnresolvedType.read(s), s.readInt(), s.readUTF(), s
-                               .readUTF());
+               MemberKind mk = MemberKind.read(s);
+               boolean compressed = (s.isAtLeast169() ? s.readBoolean() : false);
+               UnresolvedType declaringType = compressed ? UnresolvedType.forSignature(s.readUtf8(s.readShort())) : UnresolvedType.read(s);
+               int modifiers = s.readInt();
+               String name = compressed ? s.readUtf8(s.readShort()) : s.readUTF();
+               String signature = compressed ? s.readUtf8(s.readShort()) : s.readUTF();
+               ResolvedMemberImpl m = new ResolvedMemberImpl(mk, declaringType, modifiers, name, signature);
                m.checkedExceptions = UnresolvedType.readArray(s);
 
                m.start = s.readInt();
@@ -486,7 +518,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                                }
                        }
 
-                       int tvcount = s.readInt();
+                       int tvcount = s.isAtLeast169() ? s.readByte() : s.readInt();
                        if (tvcount != 0) {
                                m.typeVariables = new TypeVariable[tvcount];
                                for (int i = 0; i < tvcount; i++) {
@@ -495,14 +527,26 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                                }
                        }
                        if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) {
-                               boolean hasAGenericSignature = s.readBoolean();
+                               int pcount = -1;
+                               boolean hasAGenericSignature = false;
+                               if (s.isAtLeast169()) {
+                                       pcount = s.readByte();
+                                       hasAGenericSignature = (pcount >= 0 && pcount < 255);
+                               } else {
+                                       hasAGenericSignature = s.readBoolean();
+                               }
                                if (hasAGenericSignature) {
-                                       int ps = s.readInt();
+                                       int ps = (s.isAtLeast169() ? pcount : s.readInt());
                                        UnresolvedType[] params = new UnresolvedType[ps];
                                        for (int i = 0; i < params.length; i++) {
-                                               params[i] = TypeFactory.createTypeFromSignature(s.readUTF());
+                                               if (compressed) {
+                                                       params[i] = TypeFactory.createTypeFromSignature(s.readSignature());
+                                               } else {
+                                                       params[i] = TypeFactory.createTypeFromSignature(s.readUTF());
+                                               }
                                        }
-                                       UnresolvedType rt = TypeFactory.createTypeFromSignature(s.readUTF());
+                                       UnresolvedType rt = compressed ? TypeFactory.createTypeFromSignature(s.readSignature()) : TypeFactory
+                                                       .createTypeFromSignature(s.readUTF());
                                        m.parameterTypes = params;
                                        m.returnType = rt;
                                }
index 404d8790f30a4589e684105e8752fc00b12a4de4..10915ea580c4a281d0e73a20af623658fe06a28f 100644 (file)
@@ -167,7 +167,12 @@ public abstract class ResolvedTypeMunger {
 
        protected static Set<ResolvedMember> readSuperMethodsCalled(VersionedDataInputStream s) throws IOException {
                Set<ResolvedMember> ret = new HashSet<ResolvedMember>();
-               int n = s.readInt();
+               int n = -1;
+               if (s.isAtLeast169()) {
+                       n = s.readByte();
+               } else {
+                       n = s.readInt();
+               }
                if (n < 0) {
                        throw new BCException("Problem deserializing type munger");
                }
@@ -177,21 +182,18 @@ public abstract class ResolvedTypeMunger {
                return ret;
        }
 
-       protected void writeSuperMethodsCalled(CompressingDataOutputStream s) throws IOException {
-
+       protected final void writeSuperMethodsCalled(CompressingDataOutputStream s) throws IOException {
                if (superMethodsCalled == null || superMethodsCalled.size() == 0) {
-                       s.writeInt(0);
+                       s.writeByte(0);
                        return;
                }
-
                List<ResolvedMember> ret = new ArrayList<ResolvedMember>(superMethodsCalled);
                Collections.sort(ret);
                int n = ret.size();
-               s.writeInt(n);
+               s.writeByte(n);
                for (ResolvedMember m : ret) {
                        m.write(s);
                }
-
        }
 
        protected static ISourceLocation readSourceLocation(VersionedDataInputStream s) throws IOException {
@@ -204,15 +206,29 @@ public abstract class ResolvedTypeMunger {
                try {
                        // This logic copes with the location missing from the attribute - an EOFException will
                        // occur on the next line and we ignore it.
-                       ois = new ObjectInputStream(s);
-                       Boolean validLocation = (Boolean) ois.readObject();
-                       if (validLocation.booleanValue()) {
-                               File f = (File) ois.readObject();
-                               Integer ii = (Integer) ois.readObject();
-                               Integer offset = (Integer) ois.readObject();
-                               ret = new SourceLocation(f, ii.intValue());
-                               ret.setOffset(offset.intValue());
+                       byte b = 0;
+                       // if we aren't on 1.6.9 or we are on 1.6.9 but not compressed, then read as object stream
+                       if (!s.isAtLeast169() || (b = s.readByte()) == 0) {
+                               ois = new ObjectInputStream(s);
+                               boolean validLocation = (Boolean) ois.readObject();
+                               if (validLocation) {
+                                       File f = (File) ois.readObject();
+                                       Integer ii = (Integer) ois.readObject();
+                                       Integer offset = (Integer) ois.readObject();
+                                       ret = new SourceLocation(f, ii.intValue());
+                                       ret.setOffset(offset.intValue());
+                               }
+                       } else {
+                               boolean validLocation = b == 2;
+                               if (validLocation) {
+                                       String path = s.readUtf8(s.readShort());
+                                       File f = new File(path);
+                                       ret = new SourceLocation(f, s.readInt());
+                                       int offset = s.readInt();
+                                       ret.setOffset(offset);
+                               }
                        }
+
                } catch (EOFException eof) {
                        return null; // This exception occurs if processing an 'old style' file where the
                        // type munger attributes don't include the source location.
@@ -230,17 +246,26 @@ public abstract class ResolvedTypeMunger {
                return ret;
        }
 
-       protected void writeSourceLocation(DataOutputStream s) throws IOException {
-               ObjectOutputStream oos = new ObjectOutputStream(s);
-               // oos.writeObject(location);
-               oos.writeObject(new Boolean(location != null));
-               if (location != null) {
-                       oos.writeObject(location.getSourceFile());
-                       oos.writeObject(new Integer(location.getLine()));
-                       oos.writeObject(new Integer(location.getOffset()));
+       protected final void writeSourceLocation(CompressingDataOutputStream s) throws IOException {
+               if (s.canCompress()) {
+                       s.writeByte(1 + (location == null ? 0 : 1)); // 1==compressed no location 2==compressed with location
+                       if (location != null) {
+                               s.writeCompressedPath(location.getSourceFile().getPath());
+                               s.writeInt(location.getLine());
+                               s.writeInt(location.getOffset());
+                       }
+               } else {
+                       s.writeByte(0);
+                       ObjectOutputStream oos = new ObjectOutputStream(s);
+                       oos.writeObject(new Boolean(location != null));
+                       if (location != null) {
+                               oos.writeObject(location.getSourceFile());
+                               oos.writeObject(new Integer(location.getLine()));
+                               oos.writeObject(new Integer(location.getOffset()));
+                       }
+                       oos.flush();
+                       oos.close();
                }
-               oos.flush();
-               oos.close();
        }
 
        public abstract void write(CompressingDataOutputStream s) throws IOException;
@@ -346,7 +371,12 @@ public abstract class ResolvedTypeMunger {
 
        protected static List<String> readInTypeAliases(VersionedDataInputStream s) throws IOException {
                if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
-                       int count = s.readInt();
+                       int count = -1;
+                       if (s.isAtLeast169()) {
+                               count = s.readByte();
+                       } else {
+                               count = s.readInt();
+                       }
                        if (count != 0) {
                                List<String> aliases = new ArrayList<String>();
                                for (int i = 0; i < count; i++) {
@@ -358,12 +388,12 @@ public abstract class ResolvedTypeMunger {
                return null;
        }
 
-       protected void writeOutTypeAliases(DataOutputStream s) throws IOException {
+       protected final void writeOutTypeAliases(DataOutputStream s) throws IOException {
                // Write any type variable aliases
                if (typeVariableAliases == null || typeVariableAliases.size() == 0) {
-                       s.writeInt(0);
+                       s.writeByte(0);
                } else {
-                       s.writeInt(typeVariableAliases.size());
+                       s.writeByte(typeVariableAliases.size());
                        for (String element : typeVariableAliases) {
                                s.writeUTF(element);
                        }
index 8414c06a1973ed831651077e7a1e50eef7643cff..62a643919bdf0298e7e95003c524fe28bdd67a7e 100644 (file)
@@ -30,10 +30,6 @@ public class VersionedDataInputStream extends DataInputStream {
 
        private ConstantPoolReader constantPoolReader;
 
-       public VersionedDataInputStream(InputStream is) {
-               super(is);
-       }
-
        public VersionedDataInputStream(InputStream is, ConstantPoolReader constantPoolReader) {
                super(is);
                this.constantPoolReader = constantPoolReader;
@@ -80,4 +76,8 @@ public class VersionedDataInputStream extends DataInputStream {
        public String readSignature() throws IOException {
                return readUtf8(readShort());
        }
+
+       public UnresolvedType readSignatureAsUnresolvedType() throws IOException {
+               return UnresolvedType.forSignature(readUtf8(readShort()));
+       }
 }
\ No newline at end of file
index 7bc560305d122b1c3a112f700b7fe5c840f7b7a9..0e0997962a357d8c285e2471f5ae505434e4702f 100644 (file)
@@ -246,7 +246,7 @@ public class ExactTypePattern extends TypePattern {
        public void write(CompressingDataOutputStream out) throws IOException {
                out.writeByte(TypePattern.EXACT);
                out.writeByte(EXACT_VERSION);
-               type.write(out);
+               out.writeCompressedSignature(type.getSignature());
                out.writeBoolean(includeSubtypes);
                out.writeBoolean(isVarArgs);
                annotationPattern.write(out);
@@ -267,7 +267,8 @@ public class ExactTypePattern extends TypePattern {
                if (version > EXACT_VERSION) {
                        throw new BCException("ExactTypePattern was written by a more recent version of AspectJ");
                }
-               TypePattern ret = new ExactTypePattern(UnresolvedType.read(s), s.readBoolean(), s.readBoolean());
+               TypePattern ret = new ExactTypePattern(s.isAtLeast169() ? s.readSignatureAsUnresolvedType() : UnresolvedType.read(s), s
+                               .readBoolean(), s.readBoolean());
                ret.setAnnotationTypePattern(AnnotationTypePattern.read(s, context));
                ret.setTypeParameters(TypePatternList.read(s, context));
                ret.readLocation(context, s);
index 1db65b6888038e59c960a0543187a01b5799a371..e388ba3b0319bb7445325b96402f73673219d096 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.CompressingDataOutputStream;
 import org.aspectj.weaver.ISourceContext;
@@ -492,17 +493,39 @@ public class TypePatternList extends PatternNode {
                        arguments[i] = TypePattern.read(s, context);
                }
                TypePatternList ret = new TypePatternList(arguments);
-               ret.readLocation(context, s);
+               if (!s.isAtLeast169()) {
+                       ret.readLocation(context, s);
+               }
                return ret;
        }
 
+       @Override
+       public int getEnd() {
+               throw new IllegalStateException();
+       }
+
+       @Override
+       public ISourceContext getSourceContext() {
+               throw new IllegalStateException();
+       }
+
+       @Override
+       public ISourceLocation getSourceLocation() {
+               throw new IllegalStateException();
+       }
+
+       @Override
+       public int getStart() {
+               throw new IllegalStateException();
+       }
+
        @Override
        public void write(CompressingDataOutputStream s) throws IOException {
                s.writeShort(typePatterns.length);
                for (int i = 0; i < typePatterns.length; i++) {
                        typePatterns[i].write(s);
                }
-               writeLocation(s);
+               // writeLocation(s);
        }
 
        public TypePattern[] getTypePatterns() {