Revision: 8845
Author: con...@google.com
Date: Wed Sep 22 11:03:58 2010
Log: Reduce DevMode memory footprint by using a WeakInterner for potentially duplicated strings

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

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

Added:
 /trunk/dev/core/src/com/google/gwt/dev/util/StringInterner.java
Modified:
 /trunk/dev/build.xml
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
 /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JTypeParameter.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/Dependencies.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectAnnotationData.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectClassData.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java
 /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsName.java
 /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsNameRef.java
 /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsScope.java
 /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsStringLiteral.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/impl/PathPrefixSet.java
 /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java
 /trunk/dev/core/src/com/google/gwt/dev/shell/DispatchClassInfo.java
 /trunk/eclipse/dev/.classpath

=======================================
--- /dev/null
+++ /trunk/dev/core/src/com/google/gwt/dev/util/StringInterner.java Wed Sep 22 11:03:58 2010
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.gwt.dev.util;
+
+import com.google.gwt.thirdparty.guava.common.collect.Interner;
+import com.google.gwt.thirdparty.guava.common.collect.Interners;
+
+/**
+ * A utility class for reducing String memory waste. Note that this does not use + * the String.intern() method which would prevent GC and fill the PermGen space.
+ * Instead, we use a Google Collections WeakInterner.
+ */
+public class StringInterner {
+  private static final StringInterner instance = new StringInterner();
+
+  public static StringInterner get() {
+    return instance;
+  }
+
+  private final Interner<String> stringPool = Interners.newWeakInterner();
+
+  protected StringInterner() {
+  }
+
+  public String intern(String s) {
+    return stringPool.intern(s);
+  }
+
+}
=======================================
--- /trunk/dev/build.xml        Mon Sep 20 07:10:58 2010
+++ /trunk/dev/build.xml        Wed Sep 22 11:03:58 2010
@@ -108,6 +108,7 @@
           <include name="w3c/sac/sac-1.3.jar" />
           <!-- htmlunit dependencies not already included: END -->
           <include name="sun/swingworker/swing-worker-1.1.jar" />
+          <include name="guava/guava-r06/guava-r06-rebased.jar" />
         </fileset>
         <fileset file="build.xml"/>
       </sourcefiles>
@@ -170,6 +171,7 @@
           <zipfileset src="${gwt.tools.lib}/w3c/sac/sac-1.3.jar" />
           <!-- htmlunit dependencies not already included: END -->
<zipfileset src="${gwt.tools.lib}/sun/swingworker/swing-worker-1.1.jar" /> + <zipfileset src="${gwt.tools.lib}/guava/guava-r06/guava-r06-rebased.jar" />
         </gwt.jar>
       </sequential>
     </outofdate>
@@ -207,6 +209,7 @@
           <pathelement location="${gwt.tools.lib}/eclipse/jdt-3.4.2.jar" />
<pathelement location="${gwt.tools.lib}/tomcat/commons-collections-3.1.jar" />
           <pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" />
+ <pathelement location="${gwt.tools.lib}/guava/guava-r06/guava-r06-rebased.jar" />
       </classpath>
     </gwt.javac>

=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java Thu Aug 12 11:58:29 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.Lists;

 import java.lang.annotation.Annotation;
@@ -55,7 +56,7 @@
   JAbstractMethod(String name,
       Map<Class<? extends Annotation>, Annotation> declaredAnnotations,
       JTypeParameter[] jtypeParameters) {
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
     annotations = new Annotations(declaredAnnotations);

     if (jtypeParameters != null) {
@@ -239,7 +240,13 @@
     for (int i = 0; i < n; ++i) {
       // Identity tests are ok since identity is durable within an oracle.
       if (params.get(i) == parameter) {
- return realParameterNames == null ? "arg" + i : realParameterNames[i];
+        String realParameterName;
+        if (realParameterNames == null) {
+          realParameterName = StringInterner.get().intern("arg" + i);
+        } else {
+ realParameterName = StringInterner.get().intern(realParameterNames[i]);
+        }
+        return realParameterName;
       }
     }
     // TODO: report error if we are asked for an unknown JParameter?
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java Mon Sep 13 14:23:29 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
+
 import java.lang.annotation.Annotation;
 import java.util.Map;

@@ -205,7 +207,8 @@
   @Override
   public String getSimpleSourceName() {
     if (lazySimpleName == null) {
-      lazySimpleName = getComponentType().getSimpleSourceName() + "[]";
+      lazySimpleName = StringInterner.get().intern(
+          getComponentType().getSimpleSourceName() + "[]");
     }
     return lazySimpleName;
   }
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java Thu Aug 12 11:58:29 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
+
 import java.lang.annotation.Annotation;
 import java.util.Map;

@@ -50,7 +52,7 @@
       Map<Class<? extends Annotation>, Annotation> declaredAnnotations) {
     assert (enclosingType != null);
     this.enclosingType = enclosingType;
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
     this.enclosingType.addField(this);
     annotations = new Annotations(declaredAnnotations);
   }
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java Thu Aug 12 11:58:29 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
+
 import java.lang.annotation.Annotation;
 import java.util.Map;

@@ -37,7 +39,7 @@
   JParameter(JAbstractMethod enclosingMethod, JParameter srcParam) {
     this.enclosingMethod = enclosingMethod;
     this.type = srcParam.type;
-    this.name = srcParam.name;
+    this.name = StringInterner.get().intern(srcParam.name);
     this.annotations = new Annotations(srcParam.annotations);
   }

@@ -56,7 +58,7 @@
       boolean argNameIsReal) {
     this.enclosingMethod = enclosingMethod;
     this.type = type;
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
     this.argNameIsReal = argNameIsReal;

     enclosingMethod.addParameter(this);
@@ -123,7 +125,7 @@

   // Only called by JAbstractMethod after real parameter names are fetched.
   void setName(String name) {
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
   }

   // Called when parameter types are found to be parameterized
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java Mon Sep 13 14:23:29 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.IdentitySets;
 import com.google.gwt.dev.util.collect.Lists;

@@ -75,7 +76,7 @@
       String enclosingTypeName, String name, boolean isInterface) {
     this.oracle = oracle;
     this.declaringPackage = declaringPackage;
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
     this.isInterface = isInterface;
     if (enclosingTypeName == null) {
       // Add myself to my package.
@@ -244,6 +245,7 @@
       } else {
         lazyQualifiedName = nestedName;
       }
+      lazyQualifiedName = StringInterner.get().intern(lazyQualifiedName);
     }
     return lazyQualifiedName;
   }
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JTypeParameter.java Mon Nov 9 20:50:50 2009 +++ /trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JTypeParameter.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.core.ext.typeinfo;

+import com.google.gwt.dev.util.StringInterner;
+
 import java.util.ArrayList;
 import java.util.List;

@@ -28,7 +30,7 @@
   private final String typeName;

   public JTypeParameter(String typeName, int ordinal) {
-    this.typeName = typeName;
+    this.typeName = StringInterner.get().intern(typeName);
     this.ordinal = ordinal;
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java Thu Sep 9 08:24:17 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java Wed Sep 22 11:03:58 2010
@@ -22,6 +22,7 @@
 import com.google.gwt.dev.javac.JdtCompiler.UnitProcessor;
 import com.google.gwt.dev.js.ast.JsProgram;
 import com.google.gwt.dev.resource.Resource;
+import com.google.gwt.dev.util.StringInterner;
 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;
@@ -81,21 +82,25 @@

MethodArgNamesLookup methodArgs = MethodParamCollector.collect(cud);

-        String packageName = Shared.getPackageName(builder.getTypeName());
+        StringInterner interner = StringInterner.get();
+        String packageName = interner.intern(
+            Shared.getPackageName(builder.getTypeName()));
         List<String> unresolvedQualified = new ArrayList<String>();
         List<String> unresolvedSimple = new ArrayList<String>();
for (char[] simpleRef : cud.compilationResult().simpleNameReferences) {
-          unresolvedSimple.add(canonical(String.valueOf(simpleRef)));
-        }
- for (char[][] qualifiedRef : cud.compilationResult().qualifiedReferences) { - unresolvedQualified.add(canonical(CharOperation.toString(qualifiedRef)));
+          unresolvedSimple.add(interner.intern(String.valueOf(simpleRef)));
+        }
+        for (char[][] qualifiedRef :
+            cud.compilationResult().qualifiedReferences) {
+          unresolvedQualified.add(
+              interner.intern(CharOperation.toString(qualifiedRef)));
         }
         for (String jsniDep : jsniDeps) {
-          unresolvedQualified.add(canonical(jsniDep));
+          unresolvedQualified.add(interner.intern(jsniDep));
         }
         ArrayList<String> apiRefs = compiler.collectApiRefs(cud);
         for (int i = 0; i < apiRefs.size(); ++i) {
-          apiRefs.set(i, canonical(apiRefs.get(i)));
+          apiRefs.set(i, interner.intern(apiRefs.get(i)));
         }
         Dependencies dependencies = new Dependencies(packageName,
             unresolvedQualified, unresolvedSimple, apiRefs);
@@ -118,15 +123,6 @@
         }
         newlyBuiltUnits.add(unit);
       }
-
-      private String canonical(String str) {
-        String result = internedTypeNames.get(str);
-        if (result != null) {
-          return result;
-        }
-        internedTypeNames.put(str, str);
-        return str;
-      }
     }

     /**
@@ -142,14 +138,6 @@
     private final JdtCompiler compiler = new JdtCompiler(
         new UnitProcessorImpl());

-    /**
-     * Memory efficiency only. Stores canonical versions of dependency type
- * names so that String instances can be shared among many units. Otherwise, - * we'd get many duplicate String objects since we have to build them from
-     * JDT's char arrays.
-     */
- private final Map<String, String> internedTypeNames = new HashMap<String, String>();
-
     /**
      * Continuation state for JSNI checking.
      */
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Mon Aug 30 09:54:26 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Wed Sep 22 11:03:58 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.dev.util.DiskCache;
 import com.google.gwt.dev.util.Name.InternalName;
+import com.google.gwt.dev.util.StringInterner;

 import org.eclipse.jdt.core.compiler.CharOperation;
 import org.eclipse.jdt.internal.compiler.ClassFile;
@@ -64,7 +65,8 @@
   CompiledClass(ClassFile classFile, CompiledClass enclosingClass) {
     this.enclosingClass = enclosingClass;
     SourceTypeBinding binding = classFile.referenceBinding;
- this.internalName = CharOperation.charToString(binding.constantPoolName());
+    this.internalName = StringInterner.get().intern(
+        CharOperation.charToString(binding.constantPoolName()));
     byte[] bytes = classFile.getBytes();
     this.cacheToken = diskCache.writeByteArray(bytes);
     this.isLocal = isLocalType(binding);
@@ -99,7 +101,7 @@
    * Returns the qualified source name, e.g. {...@code java.util.Map.Entry}.
    */
   public String getSourceName() {
-    return InternalName.toSourceName(internalName);
+ return StringInterner.get().intern(InternalName.toSourceName(internalName));
   }

   public CompilationUnit getUnit() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/Dependencies.java Thu Aug 19 06:52:40 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/Dependencies.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.dev.javac;

+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.HashMap;
 import com.google.gwt.dev.util.collect.Lists;

@@ -49,7 +50,8 @@
    */
   Dependencies(String myPackage, List<String> unresolvedQualified,
       List<String> unresolvedSimple, List<String> apiRefs) {
-    this.myPackage = (myPackage.length() == 0) ? "" : (myPackage + '.');
+    this.myPackage = StringInterner.get().intern(
+        (myPackage.length() == 0) ? "" : (myPackage + '.'));
     this.unresolvedQualified = unresolvedQualified;
     this.unresolvedSimple = unresolvedSimple;
     this.apiRefs = apiRefs;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java Mon Jan 11 17:58:07 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java Wed Sep 22 11:03:58 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.core.ext.typeinfo.JAbstractMethod;
 import com.google.gwt.dev.javac.asm.CollectMethodData;
+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.Maps;

 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -84,12 +85,13 @@
     int n = method.arguments.length;
     String[] argNames = new String[n];
     for (int i = 0; i < n; ++i) {
-      argNames[i] = String.valueOf(method.arguments[i].name);
+      argNames[i] = StringInterner.get().intern(
+          String.valueOf(method.arguments[i].name));
     }
     StringBuilder buf = new StringBuilder();
     buf.append(enclosingType).append('.').append(method.selector);
     buf.append(method.binding.signature());
-    String key = buf.toString();
+    String key = StringInterner.get().intern(buf.toString());
     methodArgs.put(key, argNames);
   }
 }
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectAnnotationData.java Thu Nov 12 06:32:35 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectAnnotationData.java Wed Sep 22 11:03:58 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.dev.asm.AnnotationVisitor;
 import com.google.gwt.dev.javac.asm.CollectClassData.AnnotationEnum;
+import com.google.gwt.dev.util.StringInterner;

 import java.util.ArrayList;
 import java.util.HashMap;
@@ -37,12 +38,12 @@
     private final boolean visible;

     protected AnnotationData(String desc, boolean visible) {
-      this.desc = desc;
+      this.desc = StringInterner.get().intern(desc);
       this.visible = visible;
     }

     public void addValue(String name, Object value) {
-      values.put(name, value);
+      values.put(StringInterner.get().intern(name), value);
     }

     /**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectClassData.java Thu Nov 12 08:22:02 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/asm/CollectClassData.java Wed Sep 22 11:03:58 2010
@@ -21,6 +21,7 @@
 import com.google.gwt.dev.asm.Opcodes;
 import com.google.gwt.dev.asm.commons.EmptyVisitor;
 import com.google.gwt.dev.util.Name;
+import com.google.gwt.dev.util.StringInterner;

 import java.util.ArrayList;
 import java.util.List;
@@ -114,8 +115,8 @@
      * @param value actual value in this enum
      */
     public AnnotationEnum(String desc, String value) {
-      this.desc = desc;
-      this.value = value;
+      this.desc = StringInterner.get().intern(desc);
+      this.value = StringInterner.get().intern(value);
     }

     /**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Mon Jun 14 14:39:55 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Wed Sep 22 11:03:58 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.dev.jjs.InternalCompilerException;
 import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.Lists;

 import java.io.IOException;
@@ -78,7 +79,7 @@
JType returnType, boolean isAbstract, boolean isStatic, boolean isFinal,
       boolean isPrivate) {
     super(info);
-    this.name = name;
+    this.name = StringInterner.get().intern(name);
     this.enclosingType = enclosingType;
     this.returnType = returnType;
     this.isAbstract = isAbstract;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java Mon Feb 8 08:29:30 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JParameter.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.jjs.ast;

 import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.util.StringInterner;

 /**
  * Java method parameter definition.
@@ -28,8 +29,8 @@
     assert (type != null);
     assert (enclosingMethod != null);

-    JParameter x = new JParameter(info, name, type, isFinal, isThis,
-        enclosingMethod);
+ JParameter x = new JParameter(info, StringInterner.get().intern(name), type,
+        isFinal, isThis, enclosingMethod);

     enclosingMethod.addParam(x);
     return x;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsName.java Tue Jun 22 06:26:45 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsName.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.js.ast;

 import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.util.StringInterner;

 import java.io.Serializable;

@@ -40,8 +41,8 @@
    */
   JsName(JsScope enclosing, String ident, String shortIdent) {
     this.enclosing = enclosing;
-    this.ident = ident;
-    this.shortIdent = shortIdent;
+    this.ident = StringInterner.get().intern(ident);
+    this.shortIdent = StringInterner.get().intern(shortIdent);
     this.isObfuscatable = true;
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsNameRef.java Mon Dec 1 16:51:17 2008 +++ /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsNameRef.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.js.ast;

 import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.util.StringInterner;

 /**
  * Represents a JavaScript expression that references a name.
@@ -36,7 +37,7 @@

   public JsNameRef(SourceInfo sourceInfo, String ident) {
     super(sourceInfo);
-    this.ident = ident;
+    this.ident = StringInterner.get().intern(ident);
   }

   public String getIdent() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsScope.java Fri Jul 31 23:49:15 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsScope.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.js.ast;

 import com.google.gwt.dev.js.JsKeywords;
+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.Lists;
 import com.google.gwt.dev.util.collect.Maps;

@@ -59,7 +60,7 @@
     if (JsKeywords.isKeyword(ident)) {
       ident = ident + "_$";
     }
-    return ident;
+    return StringInterner.get().intern(ident);
   }

   private List<JsScope> children = Collections.emptyList();
@@ -72,7 +73,7 @@
    */
   public JsScope(JsScope parent, String description) {
     assert (parent != null);
-    this.description = description;
+    this.description = StringInterner.get().intern(description);
     this.parent = parent;
     parent.children = Lists.add(parent.children, this);
   }
@@ -81,7 +82,7 @@
    * Subclasses can be parentless.
    */
   protected JsScope(String description) {
-    this.description = description;
+    this.description = StringInterner.get().intern(description);
     this.parent = null;
   }

@@ -200,6 +201,8 @@
    * Creates a new name in this scope.
    */
   protected JsName doCreateName(String ident, String shortIdent) {
+    ident = StringInterner.get().intern(ident);
+    shortIdent = StringInterner.get().intern(shortIdent);
     JsName name = new JsName(this, ident, shortIdent);
     names = Maps.putOrdered(names, ident, name);
     return name;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsStringLiteral.java Wed Aug 11 09:22:23 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/js/ast/JsStringLiteral.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.js.ast;

 import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.util.StringInterner;

 /**
  * A JavaScript string literal expression.
@@ -27,7 +28,7 @@
   // These only get created by JsProgram so that they can be interned.
   JsStringLiteral(SourceInfo sourceInfo, String value) {
     super(sourceInfo);
-    this.value = value;
+    this.value = StringInterner.get().intern(value);
   }

   public String getValue() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/PathPrefixSet.java Tue Aug 17 08:14:13 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/PathPrefixSet.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.dev.resource.impl;

+import com.google.gwt.dev.util.StringInterner;
 import com.google.gwt.dev.util.collect.Maps;

 import java.util.ArrayList;
@@ -42,10 +43,11 @@
     private PathPrefix prefix;

     public TrieNode(String part) {
-      this.part = part;
+      this.part = StringInterner.get().intern(part);
     }

     public TrieNode addChild(String part) {
+      part = StringInterner.get().intern(part);
       TrieNode newChild = new TrieNode(part);
       assert !children.containsKey(part);
       children = Maps.put(children, part, newChild);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java Wed Aug 4 09:54:49 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileResource.java Wed Sep 22 11:03:58 2010
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.dev.resource.impl;

+import com.google.gwt.dev.util.StringInterner;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.zip.ZipEntry;
@@ -31,7 +33,7 @@
   public ZipFileResource(ZipFileClassPathEntry classPathEntry, String path,
       long lastModified) {
     this.classPathEntry = classPathEntry;
-    this.path = path;
+    this.path = StringInterner.get().intern(path);
     this.lastModified = lastModified;
   }

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/shell/DispatchClassInfo.java Tue Jun 22 10:07:56 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/shell/DispatchClassInfo.java Wed Sep 22 11:03:58 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.shell;

 import com.google.gwt.dev.util.JsniRef;
+import com.google.gwt.dev.util.StringInterner;

 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -82,7 +83,8 @@
private void addMemberIfUnique(String name, List<Member> membersForName) {
     if (membersForName.size() == 1) {
       memberById.add(membersForName.get(0));
-      memberIdByName.put(name, memberById.size() - 1);
+      memberIdByName.put(
+          StringInterner.get().intern(name), memberById.size() - 1);
     }
   }

@@ -182,7 +184,8 @@
     }
     sb.append(")");

-    String mangledName = sb.toString();
+    String mangledName = StringInterner.get().intern(sb.toString());
+
     return mangledName;
   }

=======================================
--- /trunk/eclipse/dev/.classpath       Thu Aug 12 17:25:52 2010
+++ /trunk/eclipse/dev/.classpath       Wed Sep 22 11:03:58 2010
@@ -40,5 +40,6 @@
<classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940-sources.jar"/> <classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940-sources.jar"/> <classpathentry kind="var" path="GWT_TOOLS/lib/protobuf/protobuf-2.2.0/protobuf-java-rebased-2.2.0.jar"/> + <classpathentry kind="var" path="GWT_TOOLS/lib/guava/guava-r06/guava-r06-rebased.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>

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

Reply via email to