Cleanup in bootstrap sequence.
- Renamed JCHSU to Runtime
- Call Runtime.bootstrap instead of JCHSU.modernizeBrowser inline,
this allows to add JS bootstrap code like modernizeBrowser easily.
- Simplified immortal types generation.
Change-Id: Ib864cdf9dd98700717f54e113d06cb9220a410e7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
index ec62cd0..8f1652f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
@@ -146,7 +146,7 @@
*/
public static final Set<String> IMMORTAL_CODEGEN_TYPES_SET = Sets.newLinkedHashSet(Arrays.asList(
"com.google.gwt.lang.CollapsedPropertyHolder",
- "com.google.gwt.lang.JavaClassHierarchySetupUtil",
+ "com.google.gwt.lang.Runtime",
"com.google.gwt.lang.ModuleUtils"));
public static final String JAVASCRIPTOBJECT = "com.google.gwt.core.client.JavaScriptObject";
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java b/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java
new file mode 100644
index 0000000..8fe30e7
--- /dev/null
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2015 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.ast;
+
+/**
+ * Provides access to known types, methods and fields.
+ */
+public class RuntimeConstants {
+ public static final String ASYNC_FRAGMENT_LOADER_BROWSER_LOADER =
+ "AsyncFragmentLoader.BROWSER_LOADER";
+ public static final String ASYNC_FRAGMENT_LOADER_ON_LOAD = "AsyncFragmentLoader.onLoad";
+ public static final String ASYNC_FRAGMENT_LOADER_RUN_ASYNC = "AsyncFragmentLoader.runAsync";
+
+ public static final String ARRAY_GET_CLASS_LITERAL_FOR_ARRAY = "Array.getClassLiteralForArray";
+ public static final String ARRAY_INIT_DIM = "Array.initDim";
+ public static final String ARRAY_INIT_DIMS = "Array.initDims";
+ public static final String ARRAY_INIT_VALUES = "Array.initValues";
+ public static final String ARRAY_SET_CHECK = "Array.setCheck";
+
+ public static final String CAST_CHAR_TO_STRING = "Cast.charToString";
+ public static final String CAST_HAS_JAVA_OBJECT_VIRTUAL_DISPATCH =
+ "Cast.hasJavaObjectVirtualDispatch";
+ public static final String CAST_IS_JAVA_ARRAY = "Cast.isJavaArray";
+ public static final String CAST_THROW_CLASS_CAST_EXCEPTION_UNLESS_NULL
+ = "Cast.throwClassCastExceptionUnlessNull";
+
+ public static final String CLASS_CREATE_FOR_CLASS = "Class.createForClass";
+ public static final String CLASS_CREATE_FOR_PRIMITIVE = "Class.createForPrimitive";
+ public static final String CLASS_CREATE_FOR_INTERFACE = "Class.createForInterface";
+
+ public static final String COLLAPSED_PROPERTY_HOLDER_GET_PERMUTATION_ID
+ = "CollapsedPropertyHolder.getPermutationId";
+
+ public static final String COVERAGE_UTIL_COVERAGE = "CoverageUtil.coverage";
+
+ public static final String ENUM_CREATE_VALUE_OF_MAP = "Enum.createValueOfMap";
+ public static final String ENUM_ENUM = "Enum.Enum";
+ public static final String ENUM_NAME = "Enum.name";
+ public static final String ENUM_ORDINAL = "Enum.ordinal";
+ public static final String ENUM_TO_STRING = "Enum.toString";
+
+ public static final String EXCEPTIONS_CHECK_NOT_NULL = "Exceptions.checkNotNull";
+ public static final String EXCEPTIONS_MAKE_ASSERTION_ERROR_ = "Exceptions.makeAssertionError";
+ public static final String EXCEPTIONS_UNWRAP = "Exceptions.unwrap";
+ public static final String EXCEPTIONS_WRAP = "Exceptions.wrap";
+
+ public static final String GWT_IS_SCRIPT = "GWT.isScript";
+
+ public static final String LONG_LIB_FROM_DOUBLE = "LongLib.fromDouble";
+ public static final String LONG_LIB_FROM_INT = "LongLib.fromInt";
+ public static final String LONG_LIB_TO_DOUBLE = "LongLib.toDouble";
+ public static final String LONG_LIB_TO_INT = "LongLib.toInt";
+ public static final String LONG_LIB_TO_STRING = "LongLib.toString";
+
+ public static final String OBJECT_CASTABLE_TYPE_MAP = "Object.castableTypeMap";
+ public static final String OBJECT_CLAZZ = "Object.___clazz";
+ public static final String OBJECT_GET_CLASS = "Object.getClass";
+ public static final String OBJECT_TO_STRING = "Object.toString";
+ public static final String OBJECT_TYPEMARKER = "Object.typeMarker";
+
+ public static final String RUN_ASYNC_CALLBACK_ON_SUCCESS = "RunAsyncCallback.onSuccess";
+ public static final String RUN_ASYNC_CODE_FOR_SPLIT_POINT_NUMBER
+ = "RunAsyncCode.forSplitPointNumber";
+
+ public static final String RUNTIME = "Runtime";
+ public static final String RUNTIME_BOOTSTRAP = "Runtime.bootstrap";
+ public static final String RUNTIME_COPY_OBJECT_PROPERTIES = "Runtime.copyObjectProperties";
+ public static final String RUNTIME_DEFINE_CLASS = "Runtime.defineClass";
+ public static final String RUNTIME_DEFINE_PROPERTIES = "Runtime.defineProperties";
+ public static final String RUNTIME_EMPTY_METHOD = "Runtime.emptyMethod";
+ public static final String RUNTIME_GET_CLASS_PROTOTYPE = "Runtime.getClassPrototype";
+ public static final String RUNTIME_MAKE_LAMBDA_FUNCTION = "Runtime.makeLambdaFunction";
+ public static final String RUNTIME_PROVIDE = "Runtime.provide";
+ public static final String RUNTIME_TYPE_MARKER_FN = "Runtime.typeMarkerFn";
+ public static final String RUNTIME_UNIQUE_ID = "Runtime.uniqueId";
+
+ public static final String UTIL_MAKE_ENUM_NAME = "Util.makeEnumName";
+}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
index 75d07c9..b667cd9 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ArrayNormalizer.java
@@ -34,6 +34,7 @@
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JRuntimeTypeReference;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JsonArray;
import java.util.Collections;
@@ -213,10 +214,10 @@
private ArrayNormalizer(JProgram program) {
this.program = program;
- setCheckMethod = program.getIndexedMethod("Array.setCheck");
- initDim = program.getIndexedMethod("Array.initDim");
- initDims = program.getIndexedMethod("Array.initDims");
- initValues = program.getIndexedMethod("Array.initValues");
+ setCheckMethod = program.getIndexedMethod(RuntimeConstants.ARRAY_SET_CHECK);
+ initDim = program.getIndexedMethod(RuntimeConstants.ARRAY_INIT_DIM);
+ initDims = program.getIndexedMethod(RuntimeConstants.ARRAY_INIT_DIMS);
+ initValues = program.getIndexedMethod(RuntimeConstants.ARRAY_INIT_VALUES);
}
private void execImpl() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
index 12d289c..c594100 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/AssertionNormalizer.java
@@ -31,6 +31,7 @@
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JUnaryOperation;
import com.google.gwt.dev.jjs.ast.JUnaryOperator;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JDebuggerStatement;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
@@ -63,7 +64,8 @@
then.addStmt(new JDebuggerStatement(x.getSourceInfo()));
- String methodName = "Exceptions.makeAssertionError" + getAssertMethodSuffix(x.getArg());
+ String methodName =
+ RuntimeConstants.EXCEPTIONS_MAKE_ASSERTION_ERROR_ + getAssertMethodSuffix(x.getArg());
JMethod method = program.getIndexedMethod(methodName);
JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method);
if (x.getArg() != null) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
index 6f22564..f490f7c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
@@ -39,6 +39,7 @@
import com.google.gwt.dev.jjs.ast.JThrowStatement;
import com.google.gwt.dev.jjs.ast.JTryStatement;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import java.util.ArrayList;
import java.util.List;
@@ -53,7 +54,7 @@
* Collapses all multi-catch blocks into a single catch block.
*/
private class CollapseCatchBlocks extends JModVisitor {
- JMethod wrapMethod = program.getIndexedMethod("Exceptions.wrap");
+ JMethod wrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_WRAP);
@Override
public void endVisit(JMethodBody x, Context ctx) {
@@ -144,7 +145,7 @@
private class UnwrapJavaScriptExceptionVisitor extends JModVisitor {
JDeclaredType jseType =
program.getFromTypeMap("com.google.gwt.core.client.JavaScriptException");
- JMethod unwrapMethod = program.getIndexedMethod("Exceptions.unwrap");
+ JMethod unwrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_UNWRAP);
@Override
public void endVisit(JThrowStatement x, Context ctx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
index 4e1e5e9..7a4368a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
@@ -50,6 +50,7 @@
import com.google.gwt.dev.jjs.ast.JVariable;
import com.google.gwt.dev.jjs.ast.JVariableRef;
import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
@@ -795,7 +796,7 @@
* TODO: can we narrow the focus by walking up the type hierarchy or
* doing explicit toString calls?
*/
- JMethod toStringMethod = program.getIndexedMethod("Object.toString");
+ JMethod toStringMethod = program.getIndexedMethod(RuntimeConstants.OBJECT_TO_STRING);
rescue(toStringMethod);
} else if (type == charType) {
/*
@@ -916,6 +917,8 @@
program = cfa.program;
asyncFragmentOnLoad = cfa.asyncFragmentOnLoad;
runAsyncOnSuccess = cfa.runAsyncOnSuccess;
+ getClassField = cfa.getClassField;
+ getClassMethod = cfa.getClassMethod;
fieldsWritten = Sets.newHashSet(cfa.fieldsWritten);
instantiatedTypes = Sets.newHashSet(cfa.instantiatedTypes);
liveFieldsAndMethods = Sets.newHashSet(cfa.liveFieldsAndMethods);
@@ -928,17 +931,15 @@
argsToRescueIfParameterRead =
ArrayListMultimap.create(cfa.argsToRescueIfParameterRead);
}
- getClassField = program.getIndexedField("Object.___clazz");
- getClassMethod = program.getIndexedMethod("Object.getClass");
rescuer = new RescueVisitor();
}
public ControlFlowAnalyzer(JProgram program) {
this.program = program;
- asyncFragmentOnLoad = program.getIndexedMethod("AsyncFragmentLoader.onLoad");
- runAsyncOnSuccess = program.getIndexedMethod("RunAsyncCallback.onSuccess");
- getClassField = program.getIndexedField("Object.___clazz");
- getClassMethod = program.getIndexedMethod("Object.getClass");
+ asyncFragmentOnLoad = program.getIndexedMethod(RuntimeConstants.ASYNC_FRAGMENT_LOADER_ON_LOAD);
+ runAsyncOnSuccess = program.getIndexedMethod(RuntimeConstants.RUN_ASYNC_CALLBACK_ON_SUCCESS);
+ getClassField = program.getIndexedField(RuntimeConstants.OBJECT_CLAZZ);
+ getClassMethod = program.getIndexedMethod(RuntimeConstants.OBJECT_GET_CLASS);
rescuer = new RescueVisitor();
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index b602019..5a326b9 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -65,6 +65,7 @@
import com.google.gwt.dev.jjs.ast.JVariableRef;
import com.google.gwt.dev.jjs.ast.JVisitor;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
import com.google.gwt.dev.util.Ieee754_64_Arithmetic;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
@@ -93,6 +94,7 @@
* other passes will feed into this, however.
*/
public class DeadCodeElimination {
+
/**
* Eliminates dead or unreachable code when possible, and makes local
* simplifications like changing "<code>x || true</code>" to "<code>x</code>".
@@ -139,9 +141,11 @@
private final Set<JBlock> switchBlocks = Sets.newHashSet();
- private final JMethod isScriptMethod = program.getIndexedMethod("GWT.isScript");
- private final JMethod enumOrdinalMethod = program.getIndexedMethod("Enum.ordinal");
- private final JField enumOrdinalField = program.getIndexedField("Enum.ordinal");
+ private final JMethod isScriptMethod = program.getIndexedMethod(RuntimeConstants.GWT_IS_SCRIPT);
+ private final JMethod enumOrdinalMethod =
+ program.getIndexedMethod(RuntimeConstants.ENUM_ORDINAL);
+ private final JField enumOrdinalField =
+ program.getIndexedField(RuntimeConstants.ENUM_ORDINAL);
/**
* Short circuit binary operations.
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DefaultJsInteropExportsGenerator.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DefaultJsInteropExportsGenerator.java
index a131f2b..b9ba337 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DefaultJsInteropExportsGenerator.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DefaultJsInteropExportsGenerator.java
@@ -19,6 +19,7 @@
import com.google.gwt.dev.jjs.ast.JConstructor;
import com.google.gwt.dev.jjs.ast.JDeclaredType;
import com.google.gwt.dev.jjs.ast.JMember;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.js.ast.JsExpression;
import com.google.gwt.dev.js.ast.JsFunction;
import com.google.gwt.dev.js.ast.JsInvocation;
@@ -51,7 +52,7 @@
Map<String, JsFunction> indexedFunctions) {
this.exportStmts = exportStmts;
this.globalTemp = globalTemp;
- this.provideFunc = indexedFunctions.get("JavaClassHierarchySetupUtil.provide").getName();
+ this.provideFunc = indexedFunctions.get(RuntimeConstants.RUNTIME_PROVIDE).getName();
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Devirtualizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Devirtualizer.java
index 258503b..6cb8b5b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Devirtualizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Devirtualizer.java
@@ -36,6 +36,7 @@
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JTypeOracle;
import com.google.gwt.dev.jjs.ast.JVariableRef;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.impl.MakeCallsStatic.CreateStaticImplsVisitor;
import com.google.gwt.dev.jjs.impl.MakeCallsStatic.StaticCallConverter;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
@@ -289,8 +290,8 @@
this.program = program;
this.hasJavaObjectVirtualDispatch =
- program.getIndexedMethod("Cast.hasJavaObjectVirtualDispatch");
- this.isJavaArray = program.getIndexedMethod("Cast.isJavaArray");
+ program.getIndexedMethod(RuntimeConstants.CAST_HAS_JAVA_OBJECT_VIRTUAL_DISPATCH);
+ this.isJavaArray = program.getIndexedMethod(RuntimeConstants.CAST_IS_JAVA_ARRAY);
// TODO: consider turning on null checks for "this"?
// However, for JSO's there is existing code that relies on nulls being okay.
this.converter = new StaticCallConverter(program, false);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/EnumNameObfuscator.java b/dev/core/src/com/google/gwt/dev/jjs/impl/EnumNameObfuscator.java
index 7056e00..deeadb2 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/EnumNameObfuscator.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/EnumNameObfuscator.java
@@ -31,6 +31,7 @@
import com.google.gwt.dev.jjs.ast.JParameter;
import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
import java.util.Collection;
@@ -61,11 +62,11 @@
List<String> blacklistedEnums) {
this.logger = logger;
this.blacklistedEnums = blacklistedEnums;
- this.enumNameMethod = jprogram.getIndexedMethod("Enum.name");
- this.enumToStringMethod = jprogram.getIndexedMethod("Enum.toString");
- this.classType = jprogram.getIndexedType("Class");
- this.enumType = jprogram.getIndexedType("Enum");
- this.stringType = jprogram.getIndexedType("String");
+ this.enumNameMethod = jprogram.getIndexedMethod(RuntimeConstants.ENUM_NAME);
+ this.enumToStringMethod = jprogram.getIndexedMethod(RuntimeConstants.ENUM_TO_STRING);
+ this.classType = jprogram.getFromTypeMap("java.lang.Class");
+ this.enumType = jprogram.getFromTypeMap("java.lang.Enum");
+ this.stringType = jprogram.getFromTypeMap("java.lang.String");
/*
* Find the correct version of enumValueOfMethod.
@@ -159,7 +160,7 @@
this.jprogram = jprogram;
this.blacklistedEnums = blacklistedEnums;
this.closureMode = closureMode;
- this.makeEnumName = jprogram.getIndexedMethod("Util.makeEnumName");
+ this.makeEnumName = jprogram.getIndexedMethod(RuntimeConstants.UTIL_MAKE_ENUM_NAME);
}
private void exec() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/EnumOrdinalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/EnumOrdinalizer.java
index 7ab9e54..71127dd 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/EnumOrdinalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/EnumOrdinalizer.java
@@ -37,6 +37,7 @@
import com.google.gwt.dev.jjs.ast.JPrimitiveType;
import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
@@ -96,6 +97,7 @@
* {@code ordinal} with the appropriate ordinal value.
*/
public class EnumOrdinalizer {
+
/**
* A simple Tracker class for compiling lists of enum classes processed by
* this optimizer. If enabled, the results can be logged as debug output, and
@@ -749,10 +751,11 @@
this.program = program;
this.classLiteralHolderType = program.getTypeClassLiteralHolder();
this.javaScriptObjectType = program.getJavaScriptObject();
- this.enumOrdinalField = program.getIndexedField("Enum.ordinal");
- this.enumCreateValueOfMapMethod = program.getIndexedMethod("Enum.createValueOfMap");
- this.enumOrdinalMethod = program.getIndexedMethod("Enum.ordinal");
- this.enumSuperConstructor = program.getIndexedMethod("Enum.Enum");
+ this.enumOrdinalField = program.getIndexedField(RuntimeConstants.ENUM_ORDINAL);
+ this.enumCreateValueOfMapMethod =
+ program.getIndexedMethod(RuntimeConstants.ENUM_CREATE_VALUE_OF_MAP);
+ this.enumOrdinalMethod = program.getIndexedMethod(RuntimeConstants.ENUM_ORDINAL);
+ this.enumSuperConstructor = program.getIndexedMethod(RuntimeConstants.ENUM_ENUM);
}
private OptimizerStats execImpl(OptimizerContext optimizerCtx) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index 480c4c3..de8ede7 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -93,6 +93,7 @@
import com.google.gwt.dev.jjs.ast.JVariable;
import com.google.gwt.dev.jjs.ast.JVisitor;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JDebuggerStatement;
import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
@@ -190,6 +191,7 @@
* Creates a JavaScript AST from a <code>JProgram</code> node.
*/
public class GenerateJavaScriptAST {
+
/**
* Finds the nodes that are targets of JNameOf so that a name is assigned to them.
*/
@@ -522,16 +524,6 @@
public static final String GOOG_ABSTRACT_METHOD = "goog.abstractMethod";
public static final String GOOG_INHERITS = "goog.inherits";
public static final String GOOG_OBJECT_CREATE_SET = "goog.object.createSet";
- public static final String JCHSU = "JavaClassHierarchySetupUtil";
- public static final String JCHSU_COPY_OBJECT_PROPERTIES = JCHSU + ".copyObjectProperties";
- public static final String JCHSU_DEFINE_CLASS = JCHSU + ".defineClass";
- public static final String JCHSU_DEFINE_PROPERTIES = JCHSU + ".defineProperties";
- public static final String JCHSU_EMPTY_METHOD = JCHSU + ".emptyMethod";
- public static final String JCHSU_GET_CLASS_PROTOTYPE = JCHSU + ".getClassPrototype";
- public static final String JCHSU_MAKE_LAMBDA_FUNCTION = JCHSU + ".makeLambdaFunction";
- public static final String JCHSU_MODERNIZE_BROWSER = JCHSU + ".modernizeBrowser";
- public static final String JCHSU_TYPE_MARKER_FN = JCHSU + ".typeMarkerFn";
- public static final String OBJECT_TYPEMARKER = "Object.typeMarker";
private final Set<JDeclaredType> alreadyRan = Sets.newLinkedHashSet();
@@ -956,7 +948,7 @@
// TODO(rluble): Ideally we would want to construct the inheritance chain the JS way and
// then we could do Type.prototype.polyname.call(this, ...). Currently prototypes do not
// have global names instead they are stuck into the prototypesByTypeId array.
- return constructInvocation(sourceInfo, JCHSU_GET_CLASS_PROTOTYPE,
+ return constructInvocation(sourceInfo, RuntimeConstants.RUNTIME_GET_CLASS_PROTOTYPE,
(JsExpression) transform(getRuntimeTypeReference(type)));
}
}
@@ -1025,7 +1017,7 @@
ctorName, prototype, polymorphicNames.get(jsFunctionMethod));
// makeLambdaFunction(Foo.prototype.functionMethodName, new Foo(...))
- return constructInvocation(sourceInfo, JCHSU_MAKE_LAMBDA_FUNCTION, funcNameRef, newExpr);
+ return constructInvocation(sourceInfo, RuntimeConstants.RUNTIME_MAKE_LAMBDA_FUNCTION, funcNameRef, newExpr);
}
private JMethod getJsFunctionMethod(JClassType type) {
@@ -1243,8 +1235,8 @@
// Perform necessary polyfills.
addTypeDefinitionStatement(
- program.getIndexedType(JCHSU),
- constructInvocation(program.getSourceInfo(), JCHSU_MODERNIZE_BROWSER).makeStmt());
+ program.getIndexedType(RuntimeConstants.RUNTIME),
+ constructInvocation(program.getSourceInfo(), RuntimeConstants.RUNTIME_BOOTSTRAP).makeStmt());
Set<JDeclaredType> alreadyProcessed =
Sets.<JDeclaredType>newLinkedHashSet(program.immortalCodeGenTypes);
@@ -1601,7 +1593,7 @@
if (jsName == null) {
// this can occur when JSNI references an instance method on a
// type that was never actually instantiated.
- jsName = indexedFunctions.get(JCHSU_EMPTY_METHOD).getName();
+ jsName = indexedFunctions.get(RuntimeConstants.RUNTIME_EMPTY_METHOD).getName();
}
x.resolve(jsName);
}
@@ -1759,7 +1751,8 @@
private JsExpression generateCastableTypeMap(JDeclaredType type) {
JCastMap castMap = program.getCastMap(type);
- JField castableTypeMapField = program.getIndexedField("Object.castableTypeMap");
+ JField castableTypeMapField = program.getIndexedField(
+ RuntimeConstants.OBJECT_CASTABLE_TYPE_MAP);
JsName castableTypeMapName = names.get(castableTypeMapField);
if (castMap != null && castableTypeMapName != null) {
@@ -1928,9 +1921,6 @@
private void generateImmortalTypes(JsVars globals) {
List<JClassType> immortalTypesReversed = Lists.reverse(program.immortalCodeGenTypes);
// visit in reverse order since insertions start at head
- JMethod createEmptyObjectMethod = program.getIndexedMethod("JavaScriptObject.createObject");
- JMethod createEmptyArrayMethod = program.getIndexedMethod("JavaScriptObject.createArray");
-
for (JClassType x : immortalTypesReversed) {
// Don't generate JS for referenceOnly types.
if (program.isReferenceOnly(x)) {
@@ -1943,7 +1933,7 @@
/*
* Skip virtual methods and constructors. Even in cases where there is no constructor
* defined, the compiler will synthesize a default constructor which invokes
- * a synthensized $init() method. We must skip both of these inserted methods.
+ * a synthesized $init() method. We must skip both of these inserted methods.
*/
if (method.needsDynamicDispatch() || method instanceof JConstructor
|| doesNotHaveConcreteImplementation(method)) {
@@ -1955,33 +1945,16 @@
addMethodDefinitionStatement(1, method, function.makeStmt());
}
- // TODO(rluble): simplify this so that emitFields can be reused here.
// insert fields into global var declaration
for (JField field : x.getFields()) {
- assert field.isStatic() : "All fields on immortal types must be static.";
- JExpression fieldInitializer = field.getInitializer();
- JsExpression initializer = null;
-
- // Patch up fields that are initialized to empty object/array literal by a call to
- // JavaScriptObject.createObject() and JavaScriptObject.createArray()
- if (fieldInitializer != null
- && field.getLiteralInitializer() == null
- && fieldInitializer.getType() == program.getJavaScriptObject()) {
- assert fieldInitializer instanceof JMethodCall;
- JMethod method = ((JMethodCall) fieldInitializer).getTarget();
- if (method == createEmptyObjectMethod) {
- initializer = new JsObjectLiteral(fieldInitializer.getSourceInfo());
- } else if (method == createEmptyArrayMethod) {
- initializer = new JsArrayLiteral(fieldInitializer.getSourceInfo());
- } else {
- assert false : "Illegal initializer expression for immortal field " + field;
- }
- } else if (fieldInitializer != null) {
- initializer = transform(fieldInitializer);
- }
+ assert field.isStatic() : "'" + field.getName()
+ + "' is not static. Only static fields are allowed on immortal types";
+ assert field.getInitializer() == field.getLiteralInitializer() : "'" + field.getName()
+ + "' is not initilialized to a literal."
+ + " Only literal initializers are allowed on immortal types";
JsVar var = new JsVar(x.getSourceInfo(), names.get(field));
- var.setInitExpr(initializer);
+ var.setInitExpr(transform(field.getLiteralInitializer()));
globals.add(var);
}
}
@@ -2001,15 +1974,15 @@
defineClassArguments.add(generateCastableTypeMap(type));
defineClassArguments.addAll(constructorArgs);
- // JavaClassHierarchySetupUtil.defineClass(typeId, superTypeId, castableMap, constructors)
+ // Runtime.defineClass(typeId, superTypeId, castableMap, constructors)
JsStatement defineClassStatement = constructInvocation(type.getSourceInfo(),
- JCHSU_DEFINE_CLASS, defineClassArguments).makeStmt();
+ RuntimeConstants.RUNTIME_DEFINE_CLASS, defineClassArguments).makeStmt();
addTypeDefinitionStatement(type, defineClassStatement);
if (jsPrototype != null) {
JsStatement statement =
constructInvocation(type.getSourceInfo(),
- JCHSU_COPY_OBJECT_PROPERTIES,
+ RuntimeConstants.RUNTIME_COPY_OBJECT_PROPERTIES,
getPrototypeQualifierViaLookup(program.getTypeJavaLangObject(), type.getSourceInfo()),
globalTemp.makeRef(type.getSourceInfo()))
.makeStmt();
@@ -2142,7 +2115,7 @@
if (jsPrototype != null) {
JsStatement statement =
constructInvocation(info,
- JCHSU_COPY_OBJECT_PROPERTIES,
+ RuntimeConstants.RUNTIME_COPY_OBJECT_PROPERTIES,
getPrototypeQualifierOf(program.getTypeJavaLangObject(), info),
getPrototypeQualifierOf(type, info)).makeStmt();
addTypeDefinitionStatement(type, statement);
@@ -2155,8 +2128,8 @@
}
private void setupTypeMarkerOnJavaLangObjectPrototype(JDeclaredType type) {
- JsFunction typeMarkerMethod = indexedFunctions.get(JCHSU_TYPE_MARKER_FN);
- generatePrototypeAssignmentForJavaField(type, OBJECT_TYPEMARKER,
+ JsFunction typeMarkerMethod = indexedFunctions.get(RuntimeConstants.RUNTIME_TYPE_MARKER_FN);
+ generatePrototypeAssignmentForJavaField(type, RuntimeConstants.OBJECT_TYPEMARKER,
typeMarkerMethod.getName().makeRef(type.getSourceInfo()));
}
@@ -2220,7 +2193,7 @@
private void maybeGenerateToStringAlias(JDeclaredType type) {
if (type == program.getTypeJavaLangObject()) {
// special: setup a "toString" alias for java.lang.Object.toString()
- JMethod toStringMethod = program.getIndexedMethod("Object.toString");
+ JMethod toStringMethod = program.getIndexedMethod(RuntimeConstants.OBJECT_TO_STRING);
if (type.getMethods().contains(toStringMethod)) {
JsName toStringName = objectScope.declareUnobfuscatableName("toString");
generatePrototypeDefinitionAlias(toStringMethod, toStringName);
@@ -2261,7 +2234,7 @@
// Some JS optimizers, e.g. the closure compiler, relies on this subtle difference for
// obfuscating property names.
JsNameRef definePropertyMethod =
- indexedFunctions.get(JCHSU_DEFINE_PROPERTIES).getName().makeRef(sourceInfo);
+ indexedFunctions.get(RuntimeConstants.RUNTIME_DEFINE_PROPERTIES).getName().makeRef(sourceInfo);
JsObjectLiteral definePropertyLiteral =
JsObjectLiteral.builder(sourceInfo)
@@ -2443,7 +2416,7 @@
// provides a better debug experience that does not step into already used clinits.
JsFunction emptyFunctionFn = incremental ? objectConstructorFunction
- : indexedFunctions.get(JCHSU_EMPTY_METHOD);
+ : indexedFunctions.get(RuntimeConstants.RUNTIME_EMPTY_METHOD);
JsExpression assignment = createAssignment(clinitFunction.getName().makeRef(sourceInfo),
emptyFunctionFn.getName().makeRef(sourceInfo));
statements.add(0, assignment.makeStmt());
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementCastsAndTypeChecks.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementCastsAndTypeChecks.java
index 0da29e2..aafc9a3 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementCastsAndTypeChecks.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementCastsAndTypeChecks.java
@@ -32,6 +32,7 @@
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JRuntimeTypeReference;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import java.util.EnumSet;
@@ -45,6 +46,7 @@
* May or may not prune trivial casts depending on configuration.
*/
public class ImplementCastsAndTypeChecks {
+
/**
* Replaces all casts and instanceof operations with calls to implementation
* methods.
@@ -69,7 +71,8 @@
* We handle this cast by throwing a ClassCastException, unless the
* argument is null.
*/
- JMethod method = program.getIndexedMethod("Cast.throwClassCastExceptionUnlessNull");
+ JMethod method = program.getIndexedMethod(
+ RuntimeConstants.CAST_THROW_CLASS_CAST_EXCEPTION_UNLESS_NULL);
// Note, we must update the method call to return the null type.
JMethodCall call = new JMethodCall(info, null, method, toType);
call.addArg(expr);
@@ -129,24 +132,24 @@
* one to narrow. Construct the inner call here and fall through to
* do the narrowing conversion.
*/
- JMethod castMethod = program.getIndexedMethod("LongLib.toInt");
+ JMethod castMethod = program.getIndexedMethod(RuntimeConstants.LONG_LIB_TO_INT);
JMethodCall call = new JMethodCall(info, null, castMethod);
call.addArg(expr);
expr = call;
fromType = tInt;
} else if (tInt == toType) {
- methodName = "LongLib.toInt";
+ methodName = RuntimeConstants.LONG_LIB_TO_INT;
} else if (tFloat == toType || tDouble == toType) {
- methodName = "LongLib.toDouble";
+ methodName = RuntimeConstants.LONG_LIB_TO_DOUBLE;
}
}
if (toType == tLong && fromType != tLong) {
// Longs get special treatment.
if (tByte == fromType || tShort == fromType || tChar == fromType || tInt == fromType) {
- methodName = "LongLib.fromInt";
+ methodName = RuntimeConstants.LONG_LIB_FROM_INT;
} else if (tFloat == fromType || tDouble == fromType) {
- methodName = "LongLib.fromDouble";
+ methodName = RuntimeConstants.LONG_LIB_FROM_DOUBLE;
}
} else if (tByte == fromType) {
if (tChar == toType) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
index 1f07892..ac05b0f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
@@ -39,6 +39,7 @@
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JRuntimeTypeReference;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
@@ -140,7 +141,8 @@
JLiteral superclassLiteral) {
// Class.createForClass(packageName, typeName, runtimeTypeReference, superclassliteral)
- JMethodCall call = createBaseCall(info, program, type, "Class.createForClass");
+ JMethodCall call =
+ createBaseCall(info, program, type, RuntimeConstants.CLASS_CREATE_FOR_CLASS);
call.addArg(new JRuntimeTypeReference(info, program.getTypeJavaLangObject(),
(JReferenceType) type));
@@ -154,8 +156,8 @@
JLiteral superclassLiteral) {
// Class.createForPrimitive(typeName, typeSignature)
- JMethodCall call =
- new JMethodCall(info, null, program.getIndexedMethod("Class.createForPrimitive"));
+ JMethodCall call = new JMethodCall(info, null, program.getIndexedMethod(
+ RuntimeConstants.CLASS_CREATE_FOR_PRIMITIVE));
call.addArg(program.getStringLiteral(info, type.getShortName()));
call.addArg(program.getStringLiteral(info, type.getJavahSignatureName()));
return call;
@@ -167,7 +169,7 @@
JLiteral superclassLiteral) {
// Class.createForInterface(packageName, typeName)
- return createBaseCall(info, program, type, "Class.createForInterface");
+ return createBaseCall(info, program, type, RuntimeConstants.CLASS_CREATE_FOR_INTERFACE);
}
};
@@ -239,7 +241,7 @@
final Multimap<String, JsniClassLiteral> jsniClassLiteralsByJsniReference =
ArrayListMultimap.create();
final JMethod getClassLiteralForArrayMethod =
- program.getIndexedMethod("Array.getClassLiteralForArray");
+ program.getIndexedMethod(RuntimeConstants.ARRAY_GET_CLASS_LITERAL_FOR_ARRAY);
final String getClassLiteralForArrayMethodIdent =
"@" + getClassLiteralForArrayMethod.getJsniSignature(true, false);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
index 3377fb9..650175c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MakeCallsStatic.java
@@ -32,6 +32,7 @@
import com.google.gwt.dev.jjs.ast.JThisRef;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
import com.google.gwt.dev.jjs.impl.codesplitter.CodeSplitter;
@@ -381,7 +382,7 @@
StaticCallConverter(JProgram program, boolean addNullChecksForThis) {
if (addNullChecksForThis) {
- checkNotNull = program.getIndexedMethod("Exceptions.checkNotNull");
+ checkNotNull = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_CHECK_NOT_NULL);
} else {
checkNotNull = null;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceGetClassOverrides.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceGetClassOverrides.java
index c552108..1d04fdc 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceGetClassOverrides.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ReplaceGetClassOverrides.java
@@ -22,6 +22,7 @@
import com.google.gwt.dev.jjs.ast.JMethodCall;
import com.google.gwt.dev.jjs.ast.JModVisitor;
import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
/**
* Prune all overrides of Object.getClass() except when the enclosing class is JavaScriptObject
@@ -41,8 +42,8 @@
public GetClassInlinerRemover(JProgram program) {
this.program = program;
- getClassMethod = program.getIndexedMethod("Object.getClass");
- clazzField = program.getIndexedField("Object.___clazz");
+ getClassMethod = program.getIndexedMethod(RuntimeConstants.OBJECT_GET_CLASS);
+ clazzField = program.getIndexedField(RuntimeConstants.OBJECT_CLAZZ);
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java
index 94eb7d9..515e9d5 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java
@@ -36,6 +36,7 @@
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JReturnStatement;
import com.google.gwt.dev.jjs.ast.JSwitchStatement;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.thirdparty.guava.common.base.Function;
import com.google.gwt.thirdparty.guava.common.base.Joiner;
import com.google.gwt.thirdparty.guava.common.collect.FluentIterable;
@@ -135,7 +136,8 @@
}).toSet();
this.commonPropertyAndBindingInfo = PropertyAndBindingInfo.getCommonAnswers(gwtCreateAnswers);
this.holderType = (JClassType) program.getIndexedType("CollapsedPropertyHolder");
- this.permutationIdMethod = program.getIndexedMethod("CollapsedPropertyHolder.getPermutationId");
+ this.permutationIdMethod = program.getIndexedMethod(
+ RuntimeConstants.COLLAPSED_PROPERTY_HOLDER_GET_PERMUTATION_ID);
}
public JExpression computeInstantiationExpression(JPermutationDependentValue x) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRuntimeTypeReferences.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRuntimeTypeReferences.java
index 8fa4da3..779bffc 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRuntimeTypeReferences.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ResolveRuntimeTypeReferences.java
@@ -29,6 +29,7 @@
import com.google.gwt.dev.jjs.ast.JStringLiteral;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.thirdparty.guava.common.annotations.VisibleForTesting;
import com.google.gwt.thirdparty.guava.common.base.Objects;
import com.google.gwt.thirdparty.guava.common.collect.LinkedHashMultiset;
@@ -166,7 +167,7 @@
@Override
public JMethodCall get(JType type) {
- JMethod getUniqueId = program.getIndexedMethod("JavaClassHierarchySetupUtil.uniqueId");
+ JMethod getUniqueId = program.getIndexedMethod(RuntimeConstants.RUNTIME_UNIQUE_ID);
return new JMethodCall(type.getSourceInfo(), null,
getUniqueId, program.getStringLiteral(type.getSourceInfo(), type.getName()));
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeCoercionNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeCoercionNormalizer.java
index 6da9df6..fa0db96 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeCoercionNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeCoercionNormalizer.java
@@ -30,6 +30,7 @@
import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JStringLiteral;
import com.google.gwt.dev.jjs.ast.JType;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
/**
* Type coercion (and operator overloading) semantics differ widely in Java and JavaScript.
@@ -103,7 +104,7 @@
return program.getStringLiteral(expr.getSourceInfo(), String.valueOf(longValue));
} else if (expr.getType() == typePrimitiveLong) {
JMethodCall call = new JMethodCall(expr.getSourceInfo(), null,
- program.getIndexedMethod("LongLib.toString"), expr);
+ program.getIndexedMethod(RuntimeConstants.LONG_LIB_TO_STRING), expr);
return call;
} else if (expr instanceof JCharLiteral) {
// Replace the literal by a string containing the literal.
@@ -113,7 +114,7 @@
// A non literal expression of type Char.
// Replace with Cast.charToString(c)
JMethodCall call = new JMethodCall(expr.getSourceInfo(), null,
- program.getIndexedMethod("Cast.charToString"), expr);
+ program.getIndexedMethod(RuntimeConstants.CAST_CHAR_TO_STRING), expr);
return call;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java b/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
index 2bad71d..10dc791 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/UnifyAst.java
@@ -67,6 +67,7 @@
import com.google.gwt.dev.jjs.ast.JTryStatement;
import com.google.gwt.dev.jjs.ast.JType;
import com.google.gwt.dev.jjs.ast.JVariable;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.ast.js.JDebuggerStatement;
import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
@@ -845,7 +846,7 @@
// String literals.
instantiate(program.getTypeJavaLangString());
// ControlFlowAnalyzer.rescueByConcat().
- flowInto(program.getIndexedMethod("Object.toString"));
+ flowInto(program.getIndexedMethod(RuntimeConstants.OBJECT_TO_STRING));
mapApi(program.getTypeJavaLangString());
flowInto(methodMap.get("java.lang.String.valueOf(C)Ljava/lang/String;"));
@@ -860,8 +861,8 @@
// ReplaceRunAsyncs
if (compilerContext.getOptions().isRunAsyncEnabled()) {
- flowInto(program.getIndexedMethod("AsyncFragmentLoader.onLoad"));
- flowInto(program.getIndexedMethod("AsyncFragmentLoader.runAsync"));
+ flowInto(program.getIndexedMethod(RuntimeConstants.ASYNC_FRAGMENT_LOADER_ON_LOAD));
+ flowInto(program.getIndexedMethod(RuntimeConstants.ASYNC_FRAGMENT_LOADER_RUN_ASYNC));
}
// ImplementClassLiteralsAsFields
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractor.java
index f8c575f..fa7eaa1 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractor.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractor.java
@@ -22,6 +22,7 @@
import com.google.gwt.dev.jjs.ast.JField;
import com.google.gwt.dev.jjs.ast.JMethod;
import com.google.gwt.dev.jjs.ast.JProgram;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.impl.JavaToJavaScriptMap;
import com.google.gwt.dev.js.JsHoister.Cloner;
import com.google.gwt.dev.js.ast.JsBinaryOperation;
@@ -68,7 +69,7 @@
*/
public class FragmentExtractor {
- /**
+ /**
* A logger for statements that the fragment extractor encounters. Install one using
* {@link FragmentExtractor#setStatementLogger(StatementLogger)} .
*/
@@ -169,7 +170,7 @@
* Create a call to {@link AsyncFragmentLoader#onLoad}.
*/
public List<JsStatement> createOnLoadedCall(int fragmentId) {
- JMethod loadMethod = jprogram.getIndexedMethod("AsyncFragmentLoader.onLoad");
+ JMethod loadMethod = jprogram.getIndexedMethod(RuntimeConstants.ASYNC_FRAGMENT_LOADER_ON_LOAD);
JsName loadMethodName = map.nameForMethod(loadMethod);
SourceInfo sourceInfo = jsprogram.getSourceInfo();
JsInvocation call = new JsInvocation(sourceInfo);
@@ -409,7 +410,7 @@
}
JsNameRef func = (JsNameRef) call.getQualifier();
JsFunction defineClassJsFunc =
- jsprogram.getIndexedFunction("JavaClassHierarchySetupUtil.defineClass");
+ jsprogram.getIndexedFunction(RuntimeConstants.RUNTIME_DEFINE_CLASS);
if (func.getName() != defineClassJsFunc.getName()) {
return null;
}
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/ReplaceRunAsyncs.java b/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/ReplaceRunAsyncs.java
index bab526a..7cae93d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/ReplaceRunAsyncs.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/ReplaceRunAsyncs.java
@@ -32,6 +32,7 @@
import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JReferenceType;
import com.google.gwt.dev.jjs.ast.JRunAsync;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
@@ -52,10 +53,11 @@
* by an equivalent call using an integer rather than a class literal.
*/
public class ReplaceRunAsyncs {
+
private class AsyncCreateVisitor extends JModVisitor {
private JMethod currentMethod;
private final JMethod runAsyncOnsuccess = program
- .getIndexedMethod("RunAsyncCallback.onSuccess");
+ .getIndexedMethod(RuntimeConstants.RUN_ASYNC_CALLBACK_ON_SUCCESS);
@Override
public void endVisit(JMethodCall x, Context ctx) {
@@ -99,7 +101,8 @@
int splitPoint = runAsyncs.size() + 1;
SourceInfo info = x.getSourceInfo();
- JMethod runAsyncMethod = program.getIndexedMethod("AsyncFragmentLoader.runAsync");
+ JMethod runAsyncMethod =
+ program.getIndexedMethod(RuntimeConstants.ASYNC_FRAGMENT_LOADER_RUN_ASYNC);
assert runAsyncMethod != null;
JMethodCall runAsyncCall = new JMethodCall(info, null, runAsyncMethod);
runAsyncCall.addArg(new JNumericEntry(info, "RunAsyncFragmentIndex", splitPoint));
@@ -111,7 +114,7 @@
callbackMethod = program.typeOracle.getInstanceMethodBySignature(
(JClassType) callbackType, "onSuccess()V");
} else {
- callbackMethod = program.getIndexedMethod("RunAsyncCallback.onSuccess");
+ callbackMethod = program.getIndexedMethod(RuntimeConstants.RUN_ASYNC_CALLBACK_ON_SUCCESS);
}
if (callbackMethod == null ||
// The callback method is a synthetic stub inserted for more accurate override
@@ -196,7 +199,7 @@
int splitPoint = matches.get(0).getRunAsyncId();
JMethodCall newCall =
new JMethodCall(info, null, program
- .getIndexedMethod("RunAsyncCode.forSplitPointNumber"));
+ .getIndexedMethod(RuntimeConstants.RUN_ASYNC_CODE_FOR_SPLIT_POINT_NUMBER));
newCall.addArg(new JNumericEntry(info, "RunAsyncFragmentIndex", splitPoint));
ctx.replaceMe(newCall);
}
@@ -218,7 +221,7 @@
* parts of the compiler modify this initializer call.
*/
static JMethodCall getBrowserLoaderConstructor(JProgram program) {
- JField field = program.getIndexedField("AsyncFragmentLoader.BROWSER_LOADER");
+ JField field = program.getIndexedField(RuntimeConstants.ASYNC_FRAGMENT_LOADER_BROWSER_LOADER);
JMethodCall initializerCall = (JMethodCall) field.getDeclarationStatement().getInitializer();
assert initializerCall.getArgs().size() == 2;
return initializerCall;
diff --git a/dev/core/src/com/google/gwt/dev/js/CoverageInstrumentor.java b/dev/core/src/com/google/gwt/dev/js/CoverageInstrumentor.java
index f5e8aaa..c4c797c 100644
--- a/dev/core/src/com/google/gwt/dev/js/CoverageInstrumentor.java
+++ b/dev/core/src/com/google/gwt/dev/js/CoverageInstrumentor.java
@@ -16,6 +16,7 @@
package com.google.gwt.dev.js;
import com.google.gwt.dev.jjs.SourceInfo;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.js.ast.JsBinaryOperation;
import com.google.gwt.dev.js.ast.JsBinaryOperator;
import com.google.gwt.dev.js.ast.JsContext;
@@ -40,6 +41,7 @@
* executed).
*/
public class CoverageInstrumentor {
+
/**
* This class does the actual instrumentation. It replaces
* {@code expr} with {@code (CoverageUtil.cover(file, line), expr)}.
@@ -116,7 +118,8 @@
}
private void initializeBaselineCoverage(SourceInfo info) {
- JsNameRef coverageObject = jsProgram.getIndexedField("CoverageUtil.coverage").makeRef(info);
+ JsNameRef coverageObject =
+ jsProgram.getIndexedField(RuntimeConstants.COVERAGE_UTIL_COVERAGE).makeRef(info);
JsBinaryOperation init = new JsBinaryOperation(info, JsBinaryOperator.ASG, coverageObject,
baselineCoverage(info, instrumentableLines));
jsProgram.getGlobalBlock().getStatements().add(init.makeStmt());
diff --git a/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
index 8e038e8..47e5763 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
@@ -118,7 +118,7 @@
if (out.getPosition() <= beforePosition || beforeLine < 0 || out.getLine() < 0) {
// Skip bogus entries.
- // JavaClassHierarchySetupUtil:prototypesByTypeId is pruned here. Maybe others too?
+ // Runtime:prototypesByTypeId is pruned here. Maybe others too?
return toReturn;
}
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
index f922736..84f3022 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
@@ -61,7 +61,7 @@
static native boolean canCastClass(Class<?> srcClazz, Class<?> dstClass) /*-{
var srcTypeId = srcClazz.@java.lang.Class::typeId;
var dstTypeId = dstClass.@java.lang.Class::typeId;
- var prototype = @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId[srcTypeId];
+ var prototype = @com.google.gwt.lang.Runtime::prototypesByTypeId[srcTypeId];
return @com.google.gwt.lang.Cast::canCast(*)(prototype, dstTypeId);
}-*/;
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/CollapsedPropertyHolder.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/CollapsedPropertyHolder.java
index bd889ad..05b85f2 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/CollapsedPropertyHolder.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/CollapsedPropertyHolder.java
@@ -21,13 +21,15 @@
*/
final class CollapsedPropertyHolder {
+ private static final int PERMUTATION_NOT_SET = 0xFFFFFFFF;
+
/**
* This variable is initialized by the compiler in gwtOnLoad.
*/
- public static volatile int permutationId = -1;
+ public static volatile int permutationId = PERMUTATION_NOT_SET;
public static int getPermutationId() {
- assert permutationId != -1 : "The bootstrap linker did not provide a "
+ assert permutationId != PERMUTATION_NOT_SET : "The bootstrap linker did not provide a "
+ "soft permutation id to the gwtOnLoad function";
return permutationId;
}
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/JavaClassHierarchySetupUtil.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
similarity index 87%
rename from dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/JavaClassHierarchySetupUtil.java
rename to dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
index 121c98c..0cdfd56 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/JavaClassHierarchySetupUtil.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
@@ -20,14 +20,14 @@
import javaemul.internal.annotations.ForceInline;
/**
- * Utility class for defining class prototyes to setup an equivalent to the Java class hierarchy in
- * JavaScript.
+ * Utility class that provides methods for dealing with the runtime representation of Java classes
+ * and bootstraping code.
*/
-public class JavaClassHierarchySetupUtil {
+public class Runtime {
/**
* Holds a map from typeIds to prototype objects.
*/
- private static JavaScriptObject prototypesByTypeId = JavaScriptObject.createObject();
+ private static JavaScriptObject prototypesByTypeId;
/**
* If not already created it creates the prototype for the class and stores it in
@@ -50,22 +50,22 @@
public static native void defineClass(JavaScriptObject typeId,
JavaScriptObject superTypeIdOrPrototype, JavaScriptObject castableTypeMap) /*-{
// Setup aliases for (horribly long) JSNI references.
- var prototypesByTypeId = @JavaClassHierarchySetupUtil::prototypesByTypeId;
+ var prototypesByTypeId = @Runtime::prototypesByTypeId;
// end of alias definitions.
var prototype = prototypesByTypeId[typeId];
- var clazz = @JavaClassHierarchySetupUtil::maybeGetClassLiteralFromPlaceHolder(*)(prototype);
+ var clazz = @Runtime::maybeGetClassLiteralFromPlaceHolder(*)(prototype);
if (prototype && !clazz) {
// not a placeholder entry setup by Class.setClassLiteral
_ = prototype;
} else {
- _ = @JavaClassHierarchySetupUtil::createSubclassPrototype(*)(superTypeIdOrPrototype);
+ _ = @Runtime::createSubclassPrototype(*)(superTypeIdOrPrototype);
_.@Object::castableTypeMap = castableTypeMap;
_.constructor = _;
if (!superTypeIdOrPrototype) {
// Set the typeMarker on java.lang.Object's prototype, implicitly setting it for all
// Java subclasses (String and Arrays have special handling in Cast and Array respectively).
- _.@Object::typeMarker = @JavaClassHierarchySetupUtil::typeMarkerFn(*);
+ _.@Object::typeMarker = @Runtime::typeMarkerFn(*);
}
prototypesByTypeId[typeId] = _;
}
@@ -92,9 +92,9 @@
var superPrototype = superTypeIdOrPrototype && superTypeIdOrPrototype.prototype;
if (!superPrototype) {
// If it is not a prototype, then it should be a type id.
- superPrototype = @JavaClassHierarchySetupUtil::prototypesByTypeId[superTypeIdOrPrototype];
+ superPrototype = @Runtime::prototypesByTypeId[superTypeIdOrPrototype];
}
- return @JavaClassHierarchySetupUtil::portableObjCreate(*)(superPrototype);
+ return @Runtime::portableObjCreate(*)(superPrototype);
}-*/;
public static native void copyObjectProperties(JavaScriptObject from,
@@ -172,9 +172,13 @@
}-*/;
/**
- * Do polyfills for all methods expected in a modern browser.
+ * Called at the beginning to setup required structures before any of the classes is defined.
+ * The code written in and invoked by this method should be plain JavaScript.
*/
- public static native void modernizeBrowser() /*-{
+ public static native void bootstrap() /*-{
+ @Runtime::prototypesByTypeId = {};
+
+ // Do polyfills for all methods expected in a modern browser.
// Patch up Array.isArray for browsers that don't support the fast native check.
if (!Array.isArray) {
Array.isArray = function (vArg) {
@@ -187,7 +191,7 @@
* Retrieves the prototype for a type if it exists, null otherwise.
*/
public static native JavaScriptObject getClassPrototype(JavaScriptObject typeId) /*-{
- return @JavaClassHierarchySetupUtil::prototypesByTypeId[typeId];
+ return @Runtime::prototypesByTypeId[typeId];
}-*/;
/**
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Util.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Util.java
index 1e9640b..496707a 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Util.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Util.java
@@ -31,12 +31,12 @@
static native void setTypeMarker(Object o) /*-{
o.@java.lang.Object::typeMarker =
- @com.google.gwt.lang.JavaClassHierarchySetupUtil::typeMarkerFn(*);
+ @com.google.gwt.lang.Runtime::typeMarkerFn(*);
}-*/;
static native boolean hasTypeMarker(Object o) /*-{
return o.@java.lang.Object::typeMarker ===
- @com.google.gwt.lang.JavaClassHierarchySetupUtil::typeMarkerFn(*);
+ @com.google.gwt.lang.Runtime::typeMarkerFn(*);
}-*/;
static native void setCastableTypeMap(Object o, JavaScriptObject castableTypeMap) /*-{
diff --git a/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java b/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
index 31c0f06..02b5068 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
@@ -161,7 +161,8 @@
public CharSequence getContent() {
return Joiner.on("\n").join(
"package com.google.gwt.lang; public class CollapsedPropertyHolder {",
- " public static int permutationId = -1;",
+ " private static final int PERMUTATION_NOT_SET = 0xFFFFFFFF;",
+ " public static int permutationId = PERMUTATION_NOT_SET;",
"}"
);
}
@@ -260,17 +261,17 @@
}
};
- public static final MockJavaResource JAVA_CLASS_HIERARCHY_SETUP_UTIL =
- new MockJavaResource("com.google.gwt.lang.JavaClassHierarchySetupUtil") {
+ public static final MockJavaResource RUNTIME =
+ new MockJavaResource("com.google.gwt.lang.Runtime") {
@Override
public CharSequence getContent() {
return Joiner.on("\n").join(
"package com.google.gwt.lang;",
- "public class JavaClassHierarchySetupUtil {",
+ "public class Runtime {",
" public static Object defineClass(int typeId, int superTypeId, Object map) {",
" return null;",
" }",
- " public static void modernizeBrowser() {}",
+ " public static void bootstrap() {}",
" public static void emptyMethod() {}",
" public static void getClassPrototype() {}",
" static native void typeMarkerFn() /*-{}-*/;",
@@ -389,7 +390,7 @@
result.remove(JavaResourceBase.ENUM);
Collections.addAll(result, ASYNCFRAGMENTLOADER, ARRAY, CAST, CLASS, CLASS_LITERAL_HOLDER,
COLLAPSED_PROPERTY_HOLDER, ENUM, EXCEPTIONS, GWT, GWT_SHARED, IMPL,
- JAVA_CLASS_HIERARCHY_SETUP_UTIL, LONGLIB, MODULE_UTILS, RUNASYNCCALLBACK, RUNASYNCCODE,
+ RUNTIME, LONGLIB, MODULE_UTILS, RUNASYNCCALLBACK, RUNASYNCCODE,
UTIL);
return result.toArray(new MockJavaResource[result.size()]);
}
diff --git a/dev/core/test/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractorTest.java b/dev/core/test/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractorTest.java
index d29b439..1e3a8ad 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractorTest.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractorTest.java
@@ -24,6 +24,7 @@
import com.google.gwt.dev.jjs.ast.JDeclaredType;
import com.google.gwt.dev.jjs.ast.JField;
import com.google.gwt.dev.jjs.ast.JMethod;
+import com.google.gwt.dev.jjs.ast.RuntimeConstants;
import com.google.gwt.dev.jjs.impl.JJSTestBase;
import com.google.gwt.dev.jjs.impl.JavaToJavaScriptMap;
import com.google.gwt.dev.js.ast.JsExprStmt;
@@ -185,7 +186,7 @@
final JConstructor barConstructor =
new JConstructor(nullSourceInfo, barType, AccessModifier.PUBLIC);
Map<String, JsFunction> functionsByName = new HashMap<String, JsFunction>();
- functionsByName.put("JavaClassHierarchySetupUtil.defineClass",
+ functionsByName.put(RuntimeConstants.RUNTIME_DEFINE_CLASS,
new JsFunction(nullSourceInfo, new JsRootScope(), DEFINE_CLASS_FUNCTION_NAME));
final JsExprStmt defineClassStatement = createDefineClassStatement(barConstructorName);
diff --git a/user/super/com/google/gwt/emul/java/lang/Class.java b/user/super/com/google/gwt/emul/java/lang/Class.java
index 701af68..fca599a 100644
--- a/user/super/com/google/gwt/emul/java/lang/Class.java
+++ b/user/super/com/google/gwt/emul/java/lang/Class.java
@@ -130,7 +130,7 @@
return null;
}
var typeId = clazz.@Class::typeId;
- var prototype = @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId[typeId];
+ var prototype = @com.google.gwt.lang.Runtime::prototypesByTypeId[typeId];
return prototype;
}-*/;
@@ -141,7 +141,7 @@
/**
* null implies non-instantiable type, with no entries in
- * {@link JavaClassHierarchySetupUtil::prototypesByTypeId}.
+ * {@link Runtime::prototypesByTypeId}.
*/
private static native boolean isInstantiable(JavaScriptObject typeId) /*-{
return !!typeId;
@@ -187,7 +187,7 @@
if (!prototype) {
// Leave a place holder for now to be filled in by __defineClass__ later.
// TODO(rluble): Do not rely on the fact that if the entry is an array it is a placeholder.
- @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId[typeId] = [clazz];
+ @com.google.gwt.lang.Runtime::prototypesByTypeId[typeId] = [clazz];
return;
}
// Type already registered in the metadata table, install the class literal in the appropriate