Reviewers: zundel,

http://gwt-code-reviews.appspot.com/1450816/diff/1/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
File dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
(right):

http://gwt-code-reviews.appspot.com/1450816/diff/1/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java#newcode493
dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java:493:
CompilationUnit unit = (CompilationUnit) inputStream.readObject();
I wasn't sure if this was kosher, but I considered casting this to
CachedCompilationUnit, which would reduce the size of this patch
considerably since I could only deal with astVersion there.  Thoughts?

Description:
A crude way to not load cached units that won't work properly.  "Crude"
because it requires manual updating when the GWT AST or behavior of
GwtAstBuilder changes.  Some kind of automatic hashing over the set of
files might be better.

Please review this at http://gwt-code-reviews.appspot.com/1450816/

Affected files:
  M dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
  M dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
  M dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java
  M dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
  M dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
  M dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java


Index: dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java index 6cb542be9b4e9dfa9022514b0f92510301b3a4d9..265fd3d2d309266059788aafc0c1df22f86cf63f 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
@@ -27,6 +27,7 @@ import java.util.List;
  */
 public class CachedCompilationUnit extends CompilationUnit {
   private final DiskCacheToken astToken;
+  private final long astVersion;
   private final Collection<CompiledClass> compiledClasses;
   private final ContentId contentId;
   private final Dependencies dependencies;
@@ -64,6 +65,7 @@ public class CachedCompilationUnit extends CompilationUnit {
     this.isSuperSource = unit.isSuperSource();
     this.problems = unit.problems;
     this.astToken = unit.astToken;
+    this.astVersion = unit.astVersion;
     this.sourceToken = unit.sourceToken;

     // Override these fields
@@ -106,6 +108,7 @@ public class CachedCompilationUnit extends CompilationUnit {
       }
     }
     this.astToken = new DiskCacheToken(astToken);
+    this.astVersion = unit.getTypesSerializedVersion();
     this.sourceToken = new DiskCacheToken(sourceToken);
   }

@@ -161,6 +164,11 @@ public class CachedCompilationUnit extends CompilationUnit {
   }

   @Override
+  public long getTypesSerializedVersion() {
+    return astVersion;
+  }
+
+  @Override
   public boolean isError() {
     return isError;
   }
Index: dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java index fd30f4f987f35092affaa94b45bc3abc961b2ac7..3bbdb9a5a3574a82a5b2b7b1b99c36167bdc06cb 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
@@ -339,6 +339,11 @@ public abstract class CompilationUnit implements Serializable {
    */
   public abstract byte[] getTypesSerialized();

+  /**
+   * Returns the GWT AST version of the serialized types in this unit.
+   */
+  public abstract long getTypesSerializedVersion();
+
   @Deprecated
   public final boolean hasAnonymousClasses() {
     for (CompiledClass cc : getCompiledClasses()) {
Index: dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java index 0722decb69bcbdfbc775f279cfda0a65eeb7bbec..61c8759ca248a4c6dfe1db910b72a0d44bb9aa45 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnitImpl.java
@@ -17,6 +17,7 @@ package com.google.gwt.dev.javac;

 import com.google.gwt.dev.jjs.ast.JDeclaredType;
 import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.impl.GwtAstBuilder;
 import com.google.gwt.dev.util.collect.Lists;

 import org.eclipse.jdt.core.compiler.CategorizedProblem;
@@ -34,6 +35,7 @@ abstract class CompilationUnitImpl extends CompilationUnit {
    */
   protected transient long astToken;

+  private final long astVersion;
   private final Dependencies dependencies;
   private final List<CompiledClass> exposedCompiledClasses;
   private final boolean hasErrors;
@@ -68,6 +70,7 @@ abstract class CompilationUnitImpl extends CompilationUnit {
       JProgram.serializeTypes(types, out);
       out.close();
       astToken = diskCache.writeByteArray(baos.toByteArray());
+      astVersion = GwtAstBuilder.getSerializationVersion();
     } catch (IOException e) {
throw new RuntimeException("Unexpected IOException on in-memory stream",
           e);
@@ -95,6 +98,11 @@ abstract class CompilationUnitImpl extends CompilationUnit {
   }

   @Override
+  public long getTypesSerializedVersion() {
+    return astVersion;
+  }
+
+  @Override
   public boolean isError() {
     return hasErrors;
   }
Index: dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java index 39bfe9cfc2d5d0ff90fff03a3b1ec19e8198b93b..2283c03c046b4f7945ee0b4489ef5ddc83473b6b 100644
--- a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
+++ b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
@@ -17,6 +17,7 @@ package com.google.gwt.dev.javac;

 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.jjs.impl.GwtAstBuilder;
 import com.google.gwt.dev.util.log.speedtracer.DevModeEventType;
 import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
 import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
@@ -493,6 +494,11 @@ class PersistentUnitCache extends MemoryUnitCache {
               if (unit == null) {
                 break;
               }
+              if (GwtAstBuilder.ENABLED) {
+ if (unit.getTypesSerializedVersion() != GwtAstBuilder.getSerializationVersion()) {
+                  continue;
+                }
+              }
UnitCacheEntry entry = new UnitCacheEntry(unit, UnitOrigin.PERSISTENT); UnitCacheEntry oldEntry = unitMap.get(unit.getResourcePath()); if (oldEntry != null && unit.getLastModified() > oldEntry.getUnit().getLastModified()) {
Index: dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java index 120e4ed62cfe77f007e8c2dc09d95d08ebf4fa48..32971878c729bdc9077ba55538a147e295816c37 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -2752,6 +2752,13 @@ public class GwtAstBuilder {

public static boolean ENABLED = System.getProperties().containsKey("x.gwt.astBuilder");

+  /**
+   * Manually tracked version count.
+   *
+   * TODO(zundel): something much more awesome?
+   */
+  private static final long AST_VERSION = 1;
+
   private static final char[] _STRING = "_String".toCharArray();
   private static final String ARRAY_LENGTH_FIELD = "length";

@@ -2782,6 +2789,16 @@ public class GwtAstBuilder {
     }
   }

+  /**
+   * Returns a serialization version number. Used to determine if the AST
+ * contained within cached compilation units is compatible with the current
+   * version of GWT.
+   */
+  public static long getSerializationVersion() {
+    // TODO(zundel): something much awesomer.
+    return ENABLED ? AST_VERSION : 0L;
+  }
+
   static String dotify(char[][] name) {
     StringBuffer result = new StringBuffer();
     for (int i = 0; i < name.length; ++i) {
Index: dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
diff --git a/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java b/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java index 77f9e0a3aa9b863c38c4e0294e13224c761ce26f..a45978408b29b327ce5d3a08ad8fd71bc68db20e 100644
--- a/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
+++ b/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.dev.javac;

+import com.google.gwt.dev.jjs.impl.GwtAstBuilder;
 import com.google.gwt.dev.util.DiskCache;
 import com.google.gwt.dev.util.Util;

@@ -102,6 +103,11 @@ public class MockCompilationUnit extends CompilationUnit {
   }

   @Override
+  public long getTypesSerializedVersion() {
+    return GwtAstBuilder.getSerializationVersion();
+  }
+
+  @Override
   public boolean isError() {
     return false;
   }


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to