Revision: 10089
Author:   scheg...@google.com
Date:     Wed Apr 27 09:34:06 2011
Log:      Adds cache of CollectClassData to make refresh faster.
This gives about 10% performance gain on big projects.

Review at http://gwt-code-reviews.appspot.com/1420809

Review by: sco...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10089

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java
/trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Tue Apr 26 07:38:15 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Wed Apr 27 09:34:06 2011
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.dev.javac;

+import com.google.gwt.dev.javac.TypeOracleMediator.TypeData;
 import com.google.gwt.dev.util.DiskCache;
 import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.Name.InternalName;
@@ -38,6 +39,7 @@
   private final CompiledClass enclosingClass;
   private final String internalName;
   private final boolean isLocal;
+  private transient TypeData typeData;
   private CompilationUnit unit;
   private String signatureHash;

@@ -109,6 +111,15 @@
   public String getSourceName() {
return StringInterner.get().intern(InternalName.toSourceName(internalName));
   }
+
+  public TypeData getTypeData() {
+    if (typeData == null) {
+      typeData =
+ new TypeData(getPackageName(), getSourceName(), getInternalName(), null, getBytes(),
+              getUnit().getLastModified());
+    }
+    return typeData;
+  }

   public CompilationUnit getUnit() {
     return unit;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java Tue Apr 19 07:37:00 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java Wed Apr 27 09:34:06 2011
@@ -84,6 +84,11 @@
      * Bytecode from compiled Java source.
      */
     private final byte[] byteCode;
+
+    /**
+     * Prepared information about this class.
+     */
+    private CollectClassData classData;

     /**
      * See {@link Type#getInternalName()}.
@@ -125,6 +130,24 @@
       this.byteCode = classBytes;
       this.lastModifiedTime = lastModifiedTime;
     }
+
+    /**
+ * Collects data about a class which only needs the bytecode and no TypeOracle + * data structures. This is used to make the initial shallow identity pass for
+     * creating JRealClassType/JGenericType objects.
+     */
+    synchronized CollectClassData getCollectClassData() {
+      if (classData == null) {
+        ClassReader reader = new ClassReader(byteCode);
+        classData = new CollectClassData();
+        ClassVisitor cv = classData;
+        if (TRACE_CLASSES) {
+          cv = new TraceClassVisitor(cv, new PrintWriter(System.out));
+        }
+        reader.accept(cv, 0);
+      }
+      return classData;
+    }
   }

   /**
@@ -364,7 +387,7 @@
TypeOracleBuildContext context = new TypeOracleBuildContext(argsLookup);

     for (TypeData typeData : typeDataList) {
-      CollectClassData cv = processClass(typeData);
+      CollectClassData cv = typeData.getCollectClassData();
       // skip any classes that can't be referenced by name outside of
// their local scope, such as anonymous classes and method-local classes
       if (!cv.hasNoExternalName()) {
@@ -455,7 +478,8 @@

   private Annotation createAnnotation(TreeLogger logger,
Class<? extends Annotation> annotationClass, AnnotationData annotData) {
-    Map<String, Object> values = annotData.getValues();
+    // Make a copy before we mutate the collection.
+ Map<String, Object> values = new HashMap<String, Object>(annotData.getValues());
     for (Map.Entry<String, Object> entry : values.entrySet()) {
       Method method = null;
       Throwable caught = null;
@@ -611,22 +635,6 @@
     }
     return output;
   }
-
-  /**
- * Collects data about a class which only needs the bytecode and no TypeOracle - * data structures. This is used to make the initial shallow identity pass for
-   * creating JRealClassType/JGenericType objects.
-   */
-  private CollectClassData processClass(TypeData typeData) {
-    ClassReader reader = new ClassReader(typeData.byteCode);
-    CollectClassData mcv = new CollectClassData();
-    ClassVisitor cv = mcv;
-    if (TRACE_CLASSES) {
-      cv = new TraceClassVisitor(cv, new PrintWriter(System.out));
-    }
-    reader.accept(cv, 0);
-    return mcv;
-  }

   private boolean resolveAnnotation(TreeLogger logger,
       CollectAnnotationData annotVisitor,
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java Wed Dec 15 07:54:33 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java Wed Apr 27 09:34:06 2011
@@ -44,9 +44,7 @@
     for (CompilationUnit unit : units) {
Collection<CompiledClass> compiledClasses = unit.getCompiledClasses();
       for (CompiledClass compiledClass : compiledClasses) {
-        classDataList.add(new TypeData(compiledClass.getPackageName(),
-            compiledClass.getSourceName(), compiledClass.getInternalName(),
-            null, compiledClass.getBytes(), unit.getLastModified()));
+        classDataList.add(compiledClass.getTypeData());
       }
     }

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

Reply via email to