Add a compiler flag -XdisableRunAsync to disable code-splitting on a per-compile basis.
Mainly intended for tech-demonstration and diagnostic purposes.

Patch by: bobv
Review by: spoon


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@4346 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/GWTShell.java b/dev/core/src/com/google/gwt/dev/GWTShell.java
index ae8649a..785ab20 100644
--- a/dev/core/src/com/google/gwt/dev/GWTShell.java
+++ b/dev/core/src/com/google/gwt/dev/GWTShell.java
@@ -37,6 +37,7 @@
 import com.google.gwt.dev.shell.tomcat.EmbeddedTomcatServer;
 import com.google.gwt.dev.util.Util;
 import com.google.gwt.dev.util.arg.ArgHandlerDisableAggressiveOptimization;
+import com.google.gwt.dev.util.arg.ArgHandlerDisableRunAsync;
 import com.google.gwt.dev.util.arg.ArgHandlerEnableAssertions;
 import com.google.gwt.dev.util.arg.ArgHandlerExtraDir;
 import com.google.gwt.dev.util.arg.ArgHandlerGenDir;
@@ -451,6 +452,7 @@
     registerHandler(new ArgHandlerScriptStyle(options));
     registerHandler(new ArgHandlerEnableAssertions(options));
     registerHandler(new ArgHandlerDisableAggressiveOptimization(options));
+    registerHandler(new ArgHandlerDisableRunAsync(options));
   }
 
   public void addStartupURL(String url) {
diff --git a/dev/core/src/com/google/gwt/dev/Precompile.java b/dev/core/src/com/google/gwt/dev/Precompile.java
index c6a1c97..0e55c39 100644
--- a/dev/core/src/com/google/gwt/dev/Precompile.java
+++ b/dev/core/src/com/google/gwt/dev/Precompile.java
@@ -41,6 +41,7 @@
 import com.google.gwt.dev.util.PerfLogger;
 import com.google.gwt.dev.util.Util;
 import com.google.gwt.dev.util.arg.ArgHandlerDisableAggressiveOptimization;
+import com.google.gwt.dev.util.arg.ArgHandlerDisableRunAsync;
 import com.google.gwt.dev.util.arg.ArgHandlerEnableAssertions;
 import com.google.gwt.dev.util.arg.ArgHandlerGenDir;
 import com.google.gwt.dev.util.arg.ArgHandlerScriptStyle;
@@ -76,6 +77,7 @@
       registerHandler(new ArgHandlerEnableAssertions(options));
       registerHandler(new ArgHandlerDisableAggressiveOptimization(options));
       registerHandler(new ArgHandlerValidateOnlyFlag(options));
+      registerHandler(new ArgHandlerDisableRunAsync(options));
     }
 
     @Override
@@ -122,6 +124,10 @@
       return jjsOptions.isEnableAssertions();
     }
 
+    public boolean isRunAsyncEnabled() {
+      return jjsOptions.isRunAsyncEnabled();
+    }
+
     public boolean isSoycEnabled() {
       return jjsOptions.isSoycEnabled();
     }
@@ -146,6 +152,10 @@
       jjsOptions.setOutput(output);
     }
 
+    public void setRunAsyncEnabled(boolean enabled) {
+      jjsOptions.setRunAsyncEnabled(enabled);
+    }
+
     public void setSoycEnabled(boolean enabled) {
       jjsOptions.setSoycEnabled(enabled);
     }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JJSOptions.java b/dev/core/src/com/google/gwt/dev/jjs/JJSOptions.java
index 770e932..a762504 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JJSOptions.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JJSOptions.java
@@ -17,6 +17,7 @@
 
 import com.google.gwt.dev.util.arg.OptionAggressivelyOptimize;
 import com.google.gwt.dev.util.arg.OptionEnableAssertions;
+import com.google.gwt.dev.util.arg.OptionRunAsyncEnabled;
 import com.google.gwt.dev.util.arg.OptionScriptStyle;
 import com.google.gwt.dev.util.arg.OptionSoycEnabled;
 
@@ -24,5 +25,6 @@
  * Controls options for the {@link JavaToJavaScriptCompiler}.
  */
 public interface JJSOptions extends OptionAggressivelyOptimize,
-    OptionEnableAssertions, OptionScriptStyle, OptionSoycEnabled {
+    OptionEnableAssertions, OptionRunAsyncEnabled, OptionScriptStyle,
+    OptionSoycEnabled {
 }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java b/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
index 5001319..d0742d4 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
@@ -25,6 +25,7 @@
   private boolean aggressivelyOptimize = true;
   private boolean enableAssertions;
   private JsOutputOption output = JsOutputOption.OBFUSCATED;
+  private boolean runAsyncEnabled = true;
   private boolean soycEnabled = false;
 
   public JJSOptionsImpl() {
@@ -38,6 +39,7 @@
     setAggressivelyOptimize(other.isAggressivelyOptimize());
     setEnableAssertions(other.isEnableAssertions());
     setOutput(other.getOutput());
+    setRunAsyncEnabled(other.isRunAsyncEnabled());
     setSoycEnabled(other.isSoycEnabled());
   }
 
@@ -53,6 +55,10 @@
     return enableAssertions;
   }
 
+  public boolean isRunAsyncEnabled() {
+    return runAsyncEnabled;
+  }
+
   public boolean isSoycEnabled() {
     return soycEnabled;
   }
@@ -69,6 +75,10 @@
     this.output = output;
   }
 
+  public void setRunAsyncEnabled(boolean enabled) {
+    runAsyncEnabled = enabled;
+  }
+
   public void setSoycEnabled(boolean enabled) {
     soycEnabled = enabled;
   }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
index 1daa7b7..d117d02 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
@@ -225,7 +225,7 @@
           stringLiteralMap);
 
       // (10.5) Split up the program into fragments
-      if (options.isAggressivelyOptimize()) {
+      if (options.isAggressivelyOptimize() && options.isRunAsyncEnabled()) {
         CodeSplitter.exec(logger, jprogram, jsProgram, postStringInterningMap);
       }
 
@@ -367,7 +367,7 @@
       ReplaceRebinds.exec(logger, jprogram, rpo);
 
       // Fix up GWT.runAsync()
-      if (options.isAggressivelyOptimize()) {
+      if (options.isAggressivelyOptimize() && options.isRunAsyncEnabled()) {
         ReplaceRunAsyncs.exec(logger, jprogram);
       }
 
diff --git a/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableRunAsync.java b/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableRunAsync.java
new file mode 100644
index 0000000..581ba32
--- /dev/null
+++ b/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableRunAsync.java
@@ -0,0 +1,51 @@
+/*
+ * 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.util.arg;
+
+import com.google.gwt.util.tools.ArgHandlerFlag;
+
+/**
+ * An ArgHandler than can be used to disable runAsync code-splitting.
+ */
+public class ArgHandlerDisableRunAsync extends ArgHandlerFlag {
+
+  private final OptionRunAsyncEnabled option;
+
+  public ArgHandlerDisableRunAsync(OptionRunAsyncEnabled option) {
+    this.option = option;
+  }
+
+  @Override
+  public String getPurpose() {
+    return "Disable runAsync code-splitting";
+  }
+
+  @Override
+  public String getTag() {
+    return "-XdisableRunAsync";
+  }
+
+  @Override
+  public boolean isUndocumented() {
+    return true;
+  }
+
+  @Override
+  public boolean setFlag() {
+    option.setRunAsyncEnabled(false);
+    return true;
+  }
+}
diff --git a/dev/core/src/com/google/gwt/dev/util/arg/OptionRunAsyncEnabled.java b/dev/core/src/com/google/gwt/dev/util/arg/OptionRunAsyncEnabled.java
new file mode 100644
index 0000000..78dfc7b
--- /dev/null
+++ b/dev/core/src/com/google/gwt/dev/util/arg/OptionRunAsyncEnabled.java
@@ -0,0 +1,26 @@
+/*
+ * 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.util.arg;
+
+/**
+ * An option to control whether or not runAsync code-splitting will be employed
+ * by the compilation.
+ */
+public interface OptionRunAsyncEnabled {
+  boolean isRunAsyncEnabled();
+
+  void setRunAsyncEnabled(boolean enabled);
+}