Esempio n. 1
0
 @Override
 public boolean visit(JProgram program, Context ctx) {
   for (Iterator<JDeclaredType> it = program.getDeclaredTypes().iterator(); it.hasNext(); ) {
     JDeclaredType type = it.next();
     if (referencedTypes.contains(type)) {
       accept(type);
     } else {
       prunedMethods.addAll(type.getMethods());
       methodsWereRemoved(type.getMethods());
       fieldsWereRemoved(type.getFields());
       it.remove();
       madeChanges();
     }
   }
   return false;
 }
Esempio n. 2
0
  private OptimizerStats execImpl(OptimizerContext optimizerCtx) {
    OptimizerStats stats = new OptimizerStats(NAME);

    ControlFlowAnalyzer livenessAnalyzer = new ControlFlowAnalyzer(program);
    livenessAnalyzer.setForPruning();

    // SPECIAL: Immortal codegen types are never pruned
    traverseTypes(livenessAnalyzer, program.immortalCodeGenTypes);

    if (saveCodeGenTypes) {
      /*
       * SPECIAL: Some classes contain methods used by code generation later.
       * Unless those transforms have already been performed, we must rescue all
       * contained methods for later user.
       */
      traverseTypes(livenessAnalyzer, program.codeGenTypes);
    }
    livenessAnalyzer.traverseEverything();

    program.typeOracle.setInstantiatedTypes(livenessAnalyzer.getInstantiatedTypes());

    PruneVisitor pruner =
        new PruneVisitor(
            livenessAnalyzer.getReferencedTypes(),
            livenessAnalyzer.getLiveFieldsAndMethods(),
            optimizerCtx);
    pruner.accept(program);
    stats.recordModified(pruner.getNumMods());

    if (!pruner.didChange()) {
      return stats;
    }
    CleanupRefsVisitor cleaner =
        new CleanupRefsVisitor(
            livenessAnalyzer.getLiveFieldsAndMethods(),
            pruner.getPriorParametersByMethod(),
            optimizerCtx);
    cleaner.accept(program.getDeclaredTypes());
    optimizerCtx.incOptimizationStep();
    optimizerCtx.syncDeletedSubCallGraphsSince(
        optimizerCtx.getLastStepFor(NAME) + 1, prunedMethods);
    JavaAstVerifier.assertProgramIsConsistent(program);
    return stats;
  }