try {
Event javaEvent = SpeedTracerLogger.start(CompilerEventType.PERMUTATION_JAVA);
// (1) Initialize local state.
long startTimeMs = System.currentTimeMillis();
PermProps props = permutation.getProps();
int permutationId = permutation.getId();
AST ast = unifiedAst.getFreshAst();
jprogram = ast.getJProgram();
jsProgram = ast.getJsProgram();
Map<StandardSymbolData, JsName> symbolTable =
new TreeMap<StandardSymbolData, JsName>(new SymbolData.ClassIdentComparator());
// TODO(stalcup): hide metrics gathering in a callback or subclass
if (compilerContext.shouldCompileMonolithic() && logger.isLoggable(TreeLogger.INFO)) {
logger.log(TreeLogger.INFO, "Compiling permutation " + permutationId + "...");
}
printPermutationTrace(permutation);
// (2) Transform unresolved Java AST to resolved Java AST
ResolveRebinds.exec(jprogram, permutation.getGwtCreateAnswers());
// TODO(stalcup): hide metrics gathering in a callback or subclass
// This has to happen before optimizations because functions might
// be optimized out; we want those marked as "not executed", not "not
// instrumentable".
Multimap<String, Integer> instrumentableLines = null;
if (System.getProperty("gwt.coverage") != null) {
instrumentableLines = BaselineCoverageGatherer.exec(jprogram);
}
// TypeOracle needs this to make decisions in several optimization passes
jprogram.typeOracle.setJsInteropMode(compilerContext.getOptions().getJsInteropMode());
// Record initial set of type->type references.
// type->type references need to be collected in two phases, 1) before any process to the
// AST has happened (to record for example reference to types declaring compile-time
// constants) and 2) after all normalizations to collect synthetic references (e.g. to
// record references to runtime classes like LongLib).
maybeRecordTypeReferences(false);
// Replace compile time constants by their values.
// TODO(rluble): eventually move to normizeSemantics.
CompileTimeConstantsReplacer.exec(jprogram);
// TODO(stalcup): move to after normalize.
// (3) Optimize the resolved Java AST
optimizeJava();
// TODO(stalcup): move to before optimize.
// (4) Normalize the resolved Java AST
TypeMapper<?> typeMapper = normalizeSemantics();
// TODO(stalcup): this stage shouldn't exist, move into optimize.
postNormalizationOptimizeJava();
// Now that the AST has stopped mutating update with the final references.
maybeRecordTypeReferences(true);
jprogram.typeOracle.recomputeAfterOptimizations(jprogram.getDeclaredTypes());
javaEvent.end();
Event javaScriptEvent = SpeedTracerLogger.start(CompilerEventType.PERMUTATION_JAVASCRIPT);
// (5) Construct the Js AST
Pair<? extends JavaToJavaScriptMap, Set<JsNode>> jjsMapAndInlineableFunctions =
GenerateJavaScriptAST.exec(logger, jprogram, jsProgram,
compilerContext, typeMapper, symbolTable, props);
JavaToJavaScriptMap jjsmap = jjsMapAndInlineableFunctions.getLeft();
// TODO(stalcup): hide metrics gathering in a callback or subclass
if (System.getProperty("gwt.coverage") != null) {
CoverageInstrumentor.exec(jsProgram, instrumentableLines);
}
// (6) Normalize the Js AST
JsNormalizer.exec(jsProgram);
// TODO(stalcup): move to AST construction
JsSymbolResolver.exec(jsProgram);
if (options.getNamespace() == JsNamespaceOption.PACKAGE) {
JsNamespaceChooser.exec(jsProgram, jjsmap);
}
// TODO(stalcup): move to normalization
EvalFunctionsAtTopScope.exec(jsProgram, jjsmap);
// (7) Optimize the JS AST.
final Set<JsNode> inlinableJsFunctions = jjsMapAndInlineableFunctions.getRight();
optimizeJs(inlinableJsFunctions);
// TODO(stalcup): move to normalization
// Must run before code splitter and namer.
JsStackEmulator.exec(jprogram, jsProgram, props, jjsmap);
// TODO(stalcup): move to normalization
Pair<SyntheticArtifact, MultipleDependencyGraphRecorder> dependenciesAndRecorder =
splitJsIntoFragments(props, permutationId, jjsmap);
// TODO(stalcup): move to optimize.
Map<JsName, JsLiteral> internedLiteralByVariableName = renameJsSymbols(props);
// TODO(stalcup): move to normalization
JsBreakUpLargeVarStatements.exec(jsProgram, props.getConfigProps());
// (8) Generate Js source
List<JsSourceMap> sourceInfoMaps = new ArrayList<JsSourceMap>();
boolean isSourceMapsEnabled = props.isTrueInAnyPermutation("compiler.useSourceMaps");
String[] jsFragments = new String[jsProgram.getFragmentCount()];
StatementRanges[] ranges = new StatementRanges[jsFragments.length];
SizeBreakdown[] sizeBreakdowns = options.isJsonSoycEnabled() || options.isSoycEnabled()
|| options.isCompilerMetricsEnabled() ? new SizeBreakdown[jsFragments.length] : null;
generateJavaScriptCode(jjsmap, jsFragments, ranges, sizeBreakdowns, sourceInfoMaps,