ArtifactSet generatedArtifacts = new ArtifactSet();
DistillerRebindPermutationOracle rpo = new DistillerRebindPermutationOracle(
compilerContext, compilationState, generatedArtifacts, allPermutations);
// Allow GC later.
compilationState = null;
PrecompilationMetricsArtifact precompilationMetrics =
jjsOptions.isCompilerMetricsEnabled()
? new PrecompilationMetricsArtifact(permutationBase) : null;
UnifiedAst unifiedAst =
getCompiler(module).precompile(logger, compilerContext, rpo, declEntryPts, null,
rpo.getPermutationCount() == 1, precompilationMetrics);
if (jjsOptions.isCompilerMetricsEnabled()) {
ModuleMetricsArtifact moduleMetrics = new ModuleMetricsArtifact();
moduleMetrics.setSourceFiles(module.getAllSourceFiles());
// The initial type list has to be gathered before the call to
// precompile().
moduleMetrics.setInitialTypes(initialTypeOracleTypes);
// The elapsed time in ModuleMetricsArtifact represents time
// which could be done once for all permutations.
moduleMetrics.setElapsedMilliseconds(moduleLoadFinished - startTimeMilliseconds);
unifiedAst.setModuleMetrics(moduleMetrics);
}
// Merge all identical permutations together.
List<Permutation> permutations =
new ArrayList<Permutation>(Arrays.asList(rpo.getPermutations()));
// Monolithic compiles have multiple permutations but library compiles do not (since the
// library output contains runtime rebind logic that will find implementations for any
// supported browser).
if (compileMonolithic) {
mergeCollapsedPermutations(permutations);
// Sort the permutations by an ordered key to ensure determinism.
SortedMap<RebindAnswersPermutationKey, Permutation> merged =
new TreeMap<RebindAnswersPermutationKey, Permutation>();
SortedSet<String> liveRebindRequests = unifiedAst.getRebindRequests();
for (Permutation permutation : permutations) {
// Construct a key for the live rebind answers.
RebindAnswersPermutationKey key =
new RebindAnswersPermutationKey(permutation, liveRebindRequests);
if (merged.containsKey(key)) {
Permutation existing = merged.get(key);
existing.mergeFrom(permutation, liveRebindRequests);
} else {
merged.put(key, permutation);
}
}
permutations.clear();
permutations.addAll(merged.values());
}
if (jjsOptions.isCompilerMetricsEnabled()) {
int[] ids = new int[allPermutations.size()];
for (int i = 0; i < allPermutations.size(); i++) {
ids[i] = permutationBase + i;
}
precompilationMetrics.setPermutationIds(ids);
// TODO(zundel): Right now this double counts module load and
// precompile time. It correctly counts the amount of time spent
// in this process. The elapsed time in ModuleMetricsArtifact
// represents time which could be done once for all permutations.
precompilationMetrics.setElapsedMilliseconds(System.currentTimeMillis()
- startTimeMilliseconds);
unifiedAst.setPrecompilationMetrics(precompilationMetrics);
}
return new Precompilation(unifiedAst, permutations, permutationBase, generatedArtifacts);
} catch (UnableToCompleteException e) {