Revision: 9673
Author: [email protected]
Date: Fri Feb  4 12:33:12 2011
Log: Add GeneratorContextExt.isProdMode. Allows generators to specialize output for dev or prod mode. Updates RPC to take advantage of it.

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

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

Modified:
 /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
 /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
 /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
/trunk/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
 /trunk/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
/trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
 /trunk/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java Mon Dec 20 10:49:11 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java Fri Feb 4 12:33:12 2011
@@ -51,6 +51,13 @@
    * Check whether generator result caching is currently enabled.
    */
   boolean isGeneratorResultCachingEnabled();
+
+  /**
+   * Returns true if generators are being run to produce code for a
+ * production compile. Returns false for dev mode. Generators can use this
+   * information to produce code optimized for the target.
+   */
+  boolean isProdMode();

   /**
* Mark a type to be reused from the generator result cache. Calling this
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java Thu Dec 23 06:00:26 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java Fri Feb 4 12:33:12 2011
@@ -46,7 +46,7 @@

   private final GeneratorContext baseContext;

-  public GeneratorContextExtWrapper(GeneratorContext baseContext) {
+  private GeneratorContextExtWrapper(GeneratorContext baseContext) {
     this.baseContext = baseContext;
   }

@@ -87,6 +87,12 @@
   public boolean isGeneratorResultCachingEnabled() {
     return false;
   }
+
+  @Override
+  public boolean isProdMode() {
+    throw new UnsupportedOperationException(
+        "isProdMode is only available from GeneratorContextExt.");
+  }

   public boolean reuseTypeFromCacheIfAvailable(String typeName) {
     return false;
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java Thu Dec 23 06:00:26 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java Fri Feb 4 12:33:12 2011
@@ -45,8 +45,9 @@
       String typeName) throws UnableToCompleteException {

     // wrap the passed in context
-    GeneratorContextExt contextExt =
-      GeneratorContextExtWrapper.newInstance(context);
+    GeneratorContextExt contextExt = context instanceof GeneratorContextExt
+        ? (GeneratorContextExt) context
+        : GeneratorContextExtWrapper.newInstance(context);

RebindResult result = generateIncrementally(logger, contextExt, typeName);
     return result.getReturnedTypeName();
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java Tue Nov 9 09:34:36 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java Fri Feb 4 09:24:25 2011
@@ -57,7 +57,7 @@
     propertyOracles = new StaticPropertyOracle[perms.size()];
     rebindOracles = new RebindOracle[perms.size()];
generatorContext = new StandardGeneratorContext(compilationState, module,
-        genDir, generatorArtifacts);
+        genDir, generatorArtifacts, true);
     BindingProperty[] orderedProps = perms.getOrderedProperties();
SortedSet<ConfigurationProperty> configPropSet = module.getProperties().getConfigurationProperties(); ConfigurationProperty[] configProps = configPropSet.toArray(new ConfigurationProperty[configPropSet.size()]);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java Thu Dec 23 06:00:26 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java Fri Feb 4 09:24:25 2011
@@ -297,16 +297,20 @@

   private List<String> cachedTypeNamesToReuse = null;

+  private boolean isProdMode;
+
   /**
    * Normally, the compiler host would be aware of the same types that are
* available in the supplied type oracle although it isn't strictly required.
    */
   public StandardGeneratorContext(CompilationState compilationState,
-      ModuleDef module, File genDir, ArtifactSet allGeneratedArtifacts) {
+ ModuleDef module, File genDir, ArtifactSet allGeneratedArtifacts, boolean
+      isProdMode) {
     this.compilationState = compilationState;
     this.module = module;
     this.genDir = genDir;
     this.allGeneratedArtifacts = allGeneratedArtifacts;
+    this.isProdMode = isProdMode;
   }

   /**
@@ -562,6 +566,11 @@
   public boolean isGeneratorResultCachingEnabled() {
     return generatorResultCachingEnabled;
   }
+
+  @Override
+  public boolean isProdMode() {
+    return isProdMode;
+  }

   /**
* Adds a type name to the list of types to be reused from cache, if available.
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java Thu Jan 13 13:31:09 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java Fri Feb 4 09:24:25 2011
@@ -109,7 +109,7 @@
       //
       Rules rules = module.getRules();
       StandardGeneratorContext genCtx = new StandardGeneratorContext(
-          compilationState, module, genDir, new ArtifactSet());
+          compilationState, module, genDir, new ArtifactSet(), false);

// Only enable generator result caching if we have a valid rebindCache
       genCtx.setGeneratorResultCachingEnabled((rebindCache != null));
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java Mon Sep 20 15:25:50 2010 +++ /trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java Fri Feb 4 09:24:25 2011
@@ -93,7 +93,7 @@

   public StandardGeneratorContextTest() {
     genCtx = new StandardGeneratorContext(mockCompilationState,
-        new MockModuleDef(), null, artifactSet);
+        new MockModuleDef(), null, artifactSet, false);
     genCtx.setPropertyOracle(mockPropOracle);
     genCtx.setCurrentGenerator(Generator.class);
   }
=======================================
--- /trunk/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java Fri Jan 28 06:04:41 2011 +++ /trunk/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java Fri Feb 4 09:24:25 2011
@@ -185,19 +185,17 @@

     if (srcWriter != null) {
       writeStaticFields();
-
       writeStaticInitializer();

-      writeLoadMethodsJava();
-
-      writeLoadMethodsNative();
-
-      writeLoadSignaturesJava();
-
-      writeLoadSignaturesNative();
+      if (context.isProdMode()) {
+        writeLoadMethodsNative();
+        writeLoadSignaturesNative();
+      } else {
+        writeLoadMethodsJava();
+        writeLoadSignaturesJava();
+      }

       writeConstructor();
-
       srcWriter.commit(logger);
     }

@@ -371,7 +369,11 @@
    */
   private void writeConstructor() {
     srcWriter.println("public " + typeSerializerSimpleName + "() {");
- srcWriter.indentln("super(methodMapJava, methodMapNative, signatureMapJava, signatureMapNative);");
+    if (context.isProdMode()) {
+ srcWriter.indentln("super(null, methodMapNative, null, signatureMapNative);");
+    } else {
+ srcWriter.indentln("super(methodMapJava, null, signatureMapJava, null);");
+    }
     srcWriter.println("}");
     srcWriter.println();
   }
@@ -604,10 +606,13 @@
    * </pre>
    */
   private void writeStaticFields() {
- srcWriter.println("private static final Map<String, String> methodMapJava;");
-    srcWriter.println("private static final MethodMap methodMapNative;");
- srcWriter.println("private static final Map<String, String> signatureMapJava;"); - srcWriter.println("private static final JsArrayString signatureMapNative;");
+    if (context.isProdMode()) {
+      srcWriter.println("private static final MethodMap methodMapNative;");
+ srcWriter.println("private static final JsArrayString signatureMapNative;");
+    } else {
+ srcWriter.println("private static final Map<String, String> methodMapJava;"); + srcWriter.println("private static final Map<String, String> signatureMapJava;");
+    }
     srcWriter.println();
   }

@@ -633,21 +638,13 @@
   private void writeStaticInitializer() {
     srcWriter.println("static {");
     srcWriter.indent();
-    srcWriter.println("if (GWT.isScript()) {");
-    srcWriter.indent();
-    srcWriter.println("methodMapJava = null;");
-    srcWriter.println("methodMapNative = loadMethodsNative();");
-    srcWriter.println("signatureMapJava = null;");
-    srcWriter.println("signatureMapNative = loadSignaturesNative();");
-    srcWriter.outdent();
-    srcWriter.println("} else {");
-    srcWriter.indent();
-    srcWriter.println("methodMapJava = loadMethodsJava();");
-    srcWriter.println("methodMapNative = null;");
-    srcWriter.println("signatureMapJava = loadSignaturesJava();");
-    srcWriter.println("signatureMapNative = null;");
-    srcWriter.outdent();
-    srcWriter.println("}");
+    if (context.isProdMode()) {
+      srcWriter.println("methodMapNative = loadMethodsNative();");
+      srcWriter.println("signatureMapNative = loadSignaturesNative();");
+    } else {
+      srcWriter.println("methodMapJava = loadMethodsJava();");
+      srcWriter.println("signatureMapJava = loadSignaturesJava();");
+    }
     srcWriter.outdent();
     srcWriter.println("}");
     srcWriter.println();

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

Reply via email to