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
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9673 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java b/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
index 5dfbea7..86f818d 100644
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
+++ b/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
@@ -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
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java b/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
index 9eed7ac..ccfcaef 100644
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
+++ b/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
@@ -46,7 +46,7 @@
private final GeneratorContext baseContext;
- public GeneratorContextExtWrapper(GeneratorContext baseContext) {
+ private GeneratorContextExtWrapper(GeneratorContext baseContext) {
this.baseContext = baseContext;
}
@@ -88,6 +88,12 @@
return false;
}
+ @Override
+ public boolean isProdMode() {
+ throw new UnsupportedOperationException(
+ "isProdMode is only available from GeneratorContextExt.");
+ }
+
public boolean reuseTypeFromCacheIfAvailable(String typeName) {
return false;
}
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java b/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
index ed8c976..4e24aaf 100644
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
+++ b/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
@@ -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();
diff --git a/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java b/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java
index babb988..617d2fc 100644
--- a/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java
+++ b/dev/core/src/com/google/gwt/dev/DistillerRebindPermutationOracle.java
@@ -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()]);
diff --git a/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java b/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
index 1b3e4b7..315aba2 100644
--- a/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
+++ b/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
@@ -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.
diff --git a/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java b/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
index 8a23629..e5ac9b4 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
+++ b/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
@@ -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));
diff --git a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
index cdc8a18..1ce8d39 100644
--- a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
+++ b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
@@ -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);
}
diff --git a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
index 423591e..99e2ad8 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
@@ -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();