private OptimizerStats execImpl(OptimizerContext optimizerCtx) { OptimizerStats stats = new OptimizerStats(NAME); while (true) { InliningVisitor inliner = new InliningVisitor(optimizerCtx); Set<JMethod> modifiedMethods = optimizerCtx.getModifiedMethodsSince(optimizerCtx.getLastStepFor(NAME)); Set<JMethod> affectedMethods = affectedMethods(modifiedMethods, optimizerCtx); optimizerCtx.traverse(inliner, affectedMethods); stats.recordModified(inliner.getNumMods()); optimizerCtx.setLastStepFor(NAME, optimizerCtx.getOptimizationStep()); optimizerCtx.incOptimizationStep(); if (!inliner.didChange()) { break; } // Run a cleanup on the methods we just modified OptimizerStats dceStats = DeadCodeElimination.exec(program, optimizerCtx); stats.recordModified(dceStats.getNumMods()); } JavaAstVerifier.assertProgramIsConsistent(program); return stats; }
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; }
private OptimizerStats execImpl(JNode node, OptimizerContext optimizerCtx) { OptimizerStats stats = new OptimizerStats(NAME); AnalysisVisitor analysisVisitor = new AnalysisVisitor(); analysisVisitor.accept(node); for (JParameter parameter : parameterValues.keySet()) { if (nonOptimizableMethods.contains(parameter.getEnclosingMethod())) { continue; } JValueLiteral valueLiteral = parameterValues.get(parameter); if (valueLiteral != null) { SubstituteParameterVisitor substituteParameterVisitor = new SubstituteParameterVisitor( parameter, Simplifier.cast(parameter.getType(), valueLiteral), optimizerCtx); substituteParameterVisitor.accept(parameter.getEnclosingMethod()); stats.recordModified(substituteParameterVisitor.getNumMods()); } } JavaAstVerifier.assertProgramIsConsistent(program); return stats; }