Revision: 7431
Author: sp...@google.com
Date: Tue Jan 19 12:32:37 2010
Log: Make com.google.gwt.lang.Array's instance methods always be in the
initial download.  Fixes issue 4282.

Review by: cromwellian

http://code.google.com/p/google-web-toolkit/source/detail?r=7431

Added:
 /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/CodeSplitterTest.java
Modified:
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
 /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java

=======================================
--- /dev/null
+++ /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/CodeSplitterTest.java Tue Jan 19 12:32:37 2010
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2008 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.jjs.impl;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.javac.impl.MockJavaResource;
+import com.google.gwt.dev.jjs.ast.JProgram;
+
+/**
+ * Tests class {...@link CodeSplitter}.
+ */
+public class CodeSplitterTest extends OptimizerTestBase {
+  /**
+   * Tests that everything in the magic Array class is considered initially
+   * live.
+   */
+  public void testArrayIsInitial() throws UnableToCompleteException {
+ sourceOracle.addOrReplace(new MockJavaResource("com.google.gwt.lang.Array") {
+      @Override
+      protected CharSequence getContent() {
+        StringBuffer code = new StringBuffer();
+        code.append("package com.google.gwt.lang;\n");
+        code.append("public class Array {\n");
+        code.append("  private Class type;\n");
+        code.append("  public Class getClass() { return type; }\n");
+        code.append("}\n");
+        return code;
+      }
+    });
+
+    JProgram program = compileSnippet("void", "");
+    ControlFlowAnalyzer cfa = CodeSplitter.computeInitiallyLive(program);
+
+    assertTrue(cfa.getInstantiatedTypes().contains(
+        findType(program, "com.google.gwt.lang.Array")));
+    assertTrue(cfa.getLiveFieldsAndMethods().contains(
+ findMethod(findType(program, "com.google.gwt.lang.Array"), "getClass")));
+  }
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java Fri Jan 15 08:24:03 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CodeSplitter.java Tue Jan 19 12:32:37 2010
@@ -453,6 +453,7 @@
     ControlFlowAnalyzer cfa = new ControlFlowAnalyzer(jprogram);
     cfa.setDependencyRecorder(dependencyRecorder);
     traverseEntry(jprogram, cfa, 0);
+    traverseClassArray(jprogram, cfa);

     dependencyRecorder.endDependencyGraph();
     return cfa;
@@ -577,6 +578,28 @@
     }
     return revmap;
   }
+
+  /**
+   * Any instance method in the magic Array class must be in the initial
+ * download. The methods of that class are copied to a separate object the + * first time class Array is touched, and any methods added later won't be
+   * part of the copy.
+   */
+  private static void traverseClassArray(JProgram jprogram,
+      ControlFlowAnalyzer cfa) {
+ JDeclaredType typeArray = jprogram.getFromTypeMap("com.google.gwt.lang.Array");
+    if (typeArray == null) {
+      // It was pruned; nothing to do
+      return;
+    }
+
+    cfa.traverseFromInstantiationOf(typeArray);
+    for (JMethod method : typeArray.getMethods()) {
+      if (!method.isStatic()) {
+        cfa.traverseFrom(method);
+      }
+    }
+  }

   /**
    * Traverse all code in the program that is reachable via split point
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Fri Jan 15 08:24:03 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Tue Jan 19 12:32:37 2010
@@ -789,6 +789,14 @@
   public void traverseFrom(JMethod method) {
     rescuer.rescue(method);
   }
+
+  /**
+   * Assume <code>type</code> is instantiated, and find out what else will
+   * execute as a result.
+   */
+  public void traverseFromInstantiationOf(JDeclaredType type) {
+    rescuer.rescue(type, true, true);
+  }

   public void traverseFromLeftoversFragmentHasLoaded() {
     if (program.entryMethods.size() > 1) {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java Fri Jan 15 08:24:03 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java Tue Jan 19 12:32:37 2010
@@ -68,21 +68,25 @@
     return findMethod(program, "onModuleLoad");
   }

-  public static JMethod findMethod(JProgram program, String methodName) {
-    JDeclaredType mainType = program.getFromTypeMap("test.EntryPoint");
-    for (JMethod method : mainType.getMethods()) {
+  public static JMethod findMethod(JDeclaredType type, String methodName) {
+    for (JMethod method : type.getMethods()) {
       if (method.getName().equals(methodName)) {
         return method;
       }
     }
-
+
     return null;
   }
+
+  public static JMethod findMethod(JProgram program, String methodName) {
+    JDeclaredType mainType = program.getFromTypeMap("test.EntryPoint");
+    return findMethod(mainType, methodName);
+  }

   /**
* Finds a type by name. The type name may be short, e.g. <code>"Foo"</code>,
-   * or fully-qualified, e.g. <code>"com.google.example.Foo"</code>. If a
-   * short name is used, it must be unambiguous.
+ * or fully-qualified, e.g. <code>"com.google.example.Foo"</code>. If a short
+   * name is used, it must be unambiguous.
    */
   public static JDeclaredType findType(JProgram program, String typeName) {
     JDeclaredType type = program.getFromTypeMap(typeName);
-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to