com.android.dx.ssa.Optimizer Java Examples
The following examples show how to use
com.android.dx.ssa.Optimizer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptimizerOptions.java From Box with Apache License 2.0 | 5 votes |
/** * Compares the output of the optimizer run normally with a run skipping * some optional steps. Results are printed to stderr. * * @param nonOptRmeth {@code non-null;} origional rop method * @param paramSize {@code >= 0;} parameter size of method * @param isStatic true if this method has no 'this' pointer argument. * @param args {@code non-null;} translator arguments * @param advice {@code non-null;} translation advice * @param rmeth {@code non-null;} method with all optimization steps run. */ public void compareOptimizerStep(RopMethod nonOptRmeth, int paramSize, boolean isStatic, CfOptions args, TranslationAdvice advice, RopMethod rmeth) { EnumSet<Optimizer.OptionalStep> steps; steps = EnumSet.allOf(Optimizer.OptionalStep.class); // This is the step to skip. steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR); RopMethod skipRopMethod = Optimizer.optimize(nonOptRmeth, paramSize, isStatic, args.localInfo, advice, steps); int normalInsns = rmeth.getBlocks().getEffectiveInstructionCount(); int skipInsns = skipRopMethod.getBlocks().getEffectiveInstructionCount(); System.err.printf( "optimize step regs:(%d/%d/%.2f%%)" + " insns:(%d/%d/%.2f%%)\n", rmeth.getBlocks().getRegCount(), skipRopMethod.getBlocks().getRegCount(), 100.0 * ((skipRopMethod.getBlocks().getRegCount() - rmeth.getBlocks().getRegCount()) / (float) skipRopMethod.getBlocks().getRegCount()), normalInsns, skipInsns, 100.0 * ((skipInsns - normalInsns) / (float) skipInsns)); }
Example #2
Source File: OptimizerOptions.java From Box with Apache License 2.0 | 5 votes |
/** * Compares the output of the optimizer run normally with a run skipping * some optional steps. Results are printed to stderr. * * @param nonOptRmeth {@code non-null;} origional rop method * @param paramSize {@code >= 0;} parameter size of method * @param isStatic true if this method has no 'this' pointer argument. * @param args {@code non-null;} translator arguments * @param advice {@code non-null;} translation advice * @param rmeth {@code non-null;} method with all optimization steps run. */ public void compareOptimizerStep(RopMethod nonOptRmeth, int paramSize, boolean isStatic, CfOptions args, TranslationAdvice advice, RopMethod rmeth) { EnumSet<Optimizer.OptionalStep> steps; steps = EnumSet.allOf(Optimizer.OptionalStep.class); // This is the step to skip. steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR); RopMethod skipRopMethod = Optimizer.optimize(nonOptRmeth, paramSize, isStatic, args.localInfo, advice, steps); int normalInsns = rmeth.getBlocks().getEffectiveInstructionCount(); int skipInsns = skipRopMethod.getBlocks().getEffectiveInstructionCount(); System.err.printf( "optimize step regs:(%d/%d/%.2f%%)" + " insns:(%d/%d/%.2f%%)\n", rmeth.getBlocks().getRegCount(), skipRopMethod.getBlocks().getRegCount(), 100.0 * ((skipRopMethod.getBlocks().getRegCount() - rmeth.getBlocks().getRegCount()) / (float) skipRopMethod.getBlocks().getRegCount()), normalInsns, skipInsns, 100.0 * ((skipInsns - normalInsns) / (float) skipInsns)); }
Example #3
Source File: OptimizerOptions.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Compares the output of the optimizer run normally with a run skipping * some optional steps. Results are printed to stderr. * * @param nonOptRmeth {@code non-null;} origional rop method * @param paramSize {@code >= 0;} parameter size of method * @param isStatic true if this method has no 'this' pointer argument. * @param args {@code non-null;} translator arguments * @param advice {@code non-null;} translation advice * @param rmeth {@code non-null;} method with all optimization steps run. */ public void compareOptimizerStep(RopMethod nonOptRmeth, int paramSize, boolean isStatic, CfOptions args, TranslationAdvice advice, RopMethod rmeth) { EnumSet<Optimizer.OptionalStep> steps; steps = EnumSet.allOf(Optimizer.OptionalStep.class); // This is the step to skip. steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR); RopMethod skipRopMethod = Optimizer.optimize(nonOptRmeth, paramSize, isStatic, args.localInfo, advice, steps); int normalInsns = rmeth.getBlocks().getEffectiveInstructionCount(); int skipInsns = skipRopMethod.getBlocks().getEffectiveInstructionCount(); System.err.printf( "optimize step regs:(%d/%d/%.2f%%)" + " insns:(%d/%d/%.2f%%)\n", rmeth.getBlocks().getRegCount(), skipRopMethod.getBlocks().getRegCount(), 100.0 * ((skipRopMethod.getBlocks().getRegCount() - rmeth.getBlocks().getRegCount()) / (float) skipRopMethod.getBlocks().getRegCount()), normalInsns, skipInsns, 100.0 * ((skipInsns - normalInsns) / (float) skipInsns)); }
Example #4
Source File: OptimizerOptions.java From buck with Apache License 2.0 | 5 votes |
/** * Compares the output of the optimizer run normally with a run skipping * some optional steps. Results are printed to stderr. * * @param nonOptRmeth {@code non-null;} origional rop method * @param paramSize {@code >= 0;} parameter size of method * @param isStatic true if this method has no 'this' pointer argument. * @param args {@code non-null;} translator arguments * @param advice {@code non-null;} translation advice * @param rmeth {@code non-null;} method with all optimization steps run. */ public void compareOptimizerStep(RopMethod nonOptRmeth, int paramSize, boolean isStatic, CfOptions args, TranslationAdvice advice, RopMethod rmeth) { EnumSet<Optimizer.OptionalStep> steps; steps = EnumSet.allOf(Optimizer.OptionalStep.class); // This is the step to skip. steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR); RopMethod skipRopMethod = Optimizer.optimize(nonOptRmeth, paramSize, isStatic, args.localInfo, advice, steps); int normalInsns = rmeth.getBlocks().getEffectiveInstructionCount(); int skipInsns = skipRopMethod.getBlocks().getEffectiveInstructionCount(); System.err.printf( "optimize step regs:(%d/%d/%.2f%%)" + " insns:(%d/%d/%.2f%%)\n", rmeth.getBlocks().getRegCount(), skipRopMethod.getBlocks().getRegCount(), 100.0 * ((skipRopMethod.getBlocks().getRegCount() - rmeth.getBlocks().getRegCount()) / (float) skipRopMethod.getBlocks().getRegCount()), normalInsns, skipInsns, 100.0 * ((skipInsns - normalInsns) / (float) skipInsns)); }
Example #5
Source File: BlockDumper.java From Box with Apache License 2.0 | 4 votes |
/** * Does a registerizing dump. * * @param meth {@code non-null;} method data to dump */ private void ropDump(ConcreteMethod meth) { TranslationAdvice advice = DexTranslationAdvice.THE_ONE; BytecodeArray code = meth.getCode(); ByteArray bytes = code.getBytes(); RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods(), dexOptions); StringBuilder sb = new StringBuilder(2000); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); } BasicBlockList blocks = rmeth.getBlocks(); int[] order = blocks.getLabelsInOrder(); sb.append("first " + Hex.u2(rmeth.getFirstLabel()) + "\n"); for (int label : order) { BasicBlock bb = blocks.get(blocks.indexOfLabel(label)); sb.append("block "); sb.append(Hex.u2(label)); sb.append("\n"); IntList preds = rmeth.labelToPredecessors(label); int psz = preds.size(); for (int i = 0; i < psz; i++) { sb.append(" pred "); sb.append(Hex.u2(preds.get(i))); sb.append("\n"); } InsnList il = bb.getInsns(); int ilsz = il.size(); for (int i = 0; i < ilsz; i++) { Insn one = il.get(i); sb.append(" "); sb.append(il.get(i).toHuman()); sb.append("\n"); } IntList successors = bb.getSuccessors(); int ssz = successors.size(); if (ssz == 0) { sb.append(" returns\n"); } else { int primary = bb.getPrimarySuccessor(); for (int i = 0; i < ssz; i++) { int succ = successors.get(i); sb.append(" next "); sb.append(Hex.u2(succ)); if ((ssz != 1) && (succ == primary)) { sb.append(" *"); } sb.append("\n"); } } } suppressDump = false; parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true; }
Example #6
Source File: DotDumper.java From Box with Apache License 2.0 | 4 votes |
@Override public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) { if (!(member instanceof Method)) { return; } if (!shouldDumpMethod(name)) { return; } ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true); TranslationAdvice advice = DexTranslationAdvice.THE_ONE; RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods(), dexOptions); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); rmeth = Optimizer.optimize(rmeth, BaseDumper.computeParamWidth(meth, isStatic), isStatic, true, advice); } System.out.println("digraph " + name + "{"); System.out.println("\tfirst -> n" + Hex.u2(rmeth.getFirstLabel()) + ";"); BasicBlockList blocks = rmeth.getBlocks(); int sz = blocks.size(); for (int i = 0; i < sz; i++) { BasicBlock bb = blocks.get(i); int label = bb.getLabel(); IntList successors = bb.getSuccessors(); if (successors.size() == 0) { System.out.println("\tn" + Hex.u2(label) + " -> returns;"); } else if (successors.size() == 1) { System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(successors.get(0)) + ";"); } else { System.out.print("\tn" + Hex.u2(label) + " -> {"); for (int j = 0; j < successors.size(); j++ ) { int successor = successors.get(j); if (successor != bb.getPrimarySuccessor()) { System.out.print(" n" + Hex.u2(successor) + " "); } } System.out.println("};"); System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(bb.getPrimarySuccessor()) + " [label=\"primary\"];"); } } System.out.println("}"); }
Example #7
Source File: BlockDumper.java From Box with Apache License 2.0 | 4 votes |
/** * Does a registerizing dump. * * @param meth {@code non-null;} method data to dump */ private void ropDump(ConcreteMethod meth) { TranslationAdvice advice = DexTranslationAdvice.THE_ONE; BytecodeArray code = meth.getCode(); ByteArray bytes = code.getBytes(); RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods(), dexOptions); StringBuilder sb = new StringBuilder(2000); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); } BasicBlockList blocks = rmeth.getBlocks(); int[] order = blocks.getLabelsInOrder(); sb.append("first " + Hex.u2(rmeth.getFirstLabel()) + "\n"); for (int label : order) { BasicBlock bb = blocks.get(blocks.indexOfLabel(label)); sb.append("block "); sb.append(Hex.u2(label)); sb.append("\n"); IntList preds = rmeth.labelToPredecessors(label); int psz = preds.size(); for (int i = 0; i < psz; i++) { sb.append(" pred "); sb.append(Hex.u2(preds.get(i))); sb.append("\n"); } InsnList il = bb.getInsns(); int ilsz = il.size(); for (int i = 0; i < ilsz; i++) { Insn one = il.get(i); sb.append(" "); sb.append(il.get(i).toHuman()); sb.append("\n"); } IntList successors = bb.getSuccessors(); int ssz = successors.size(); if (ssz == 0) { sb.append(" returns\n"); } else { int primary = bb.getPrimarySuccessor(); for (int i = 0; i < ssz; i++) { int succ = successors.get(i); sb.append(" next "); sb.append(Hex.u2(succ)); if ((ssz != 1) && (succ == primary)) { sb.append(" *"); } sb.append("\n"); } } } suppressDump = false; parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true; }
Example #8
Source File: DotDumper.java From Box with Apache License 2.0 | 4 votes |
@Override public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) { if (!(member instanceof Method)) { return; } if (!shouldDumpMethod(name)) { return; } ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true); TranslationAdvice advice = DexTranslationAdvice.THE_ONE; RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods(), dexOptions); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); rmeth = Optimizer.optimize(rmeth, BaseDumper.computeParamWidth(meth, isStatic), isStatic, true, advice); } System.out.println("digraph " + name + "{"); System.out.println("\tfirst -> n" + Hex.u2(rmeth.getFirstLabel()) + ";"); BasicBlockList blocks = rmeth.getBlocks(); int sz = blocks.size(); for (int i = 0; i < sz; i++) { BasicBlock bb = blocks.get(i); int label = bb.getLabel(); IntList successors = bb.getSuccessors(); if (successors.size() == 0) { System.out.println("\tn" + Hex.u2(label) + " -> returns;"); } else if (successors.size() == 1) { System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(successors.get(0)) + ";"); } else { System.out.print("\tn" + Hex.u2(label) + " -> {"); for (int j = 0; j < successors.size(); j++ ) { int successor = successors.get(j); if (successor != bb.getPrimarySuccessor()) { System.out.print(" n" + Hex.u2(successor) + " "); } } System.out.println("};"); System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(bb.getPrimarySuccessor()) + " [label=\"primary\"];"); } } System.out.println("}"); }
Example #9
Source File: BlockDumper.java From buck with Apache License 2.0 | 4 votes |
/** * Does a registerizing dump. * * @param meth {@code non-null;} method data to dump */ private void ropDump(ConcreteMethod meth) { TranslationAdvice advice = DexTranslationAdvice.THE_ONE; BytecodeArray code = meth.getCode(); ByteArray bytes = code.getBytes(); RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods()); StringBuffer sb = new StringBuffer(2000); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); } BasicBlockList blocks = rmeth.getBlocks(); int[] order = blocks.getLabelsInOrder(); sb.append("first " + Hex.u2(rmeth.getFirstLabel()) + "\n"); for (int label : order) { BasicBlock bb = blocks.get(blocks.indexOfLabel(label)); sb.append("block "); sb.append(Hex.u2(label)); sb.append("\n"); IntList preds = rmeth.labelToPredecessors(label); int psz = preds.size(); for (int i = 0; i < psz; i++) { sb.append(" pred "); sb.append(Hex.u2(preds.get(i))); sb.append("\n"); } InsnList il = bb.getInsns(); int ilsz = il.size(); for (int i = 0; i < ilsz; i++) { Insn one = il.get(i); sb.append(" "); sb.append(il.get(i).toHuman()); sb.append("\n"); } IntList successors = bb.getSuccessors(); int ssz = successors.size(); if (ssz == 0) { sb.append(" returns\n"); } else { int primary = bb.getPrimarySuccessor(); for (int i = 0; i < ssz; i++) { int succ = successors.get(i); sb.append(" next "); sb.append(Hex.u2(succ)); if ((ssz != 1) && (succ == primary)) { sb.append(" *"); } sb.append("\n"); } } } suppressDump = false; setAt(bytes, 0); parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true; }
Example #10
Source File: DotDumper.java From buck with Apache License 2.0 | 4 votes |
public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) { if (!(member instanceof Method)) { return; } if (!shouldDumpMethod(name)) { return; } ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true); TranslationAdvice advice = DexTranslationAdvice.THE_ONE; RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods()); if (optimize) { boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags()); rmeth = Optimizer.optimize(rmeth, BaseDumper.computeParamWidth(meth, isStatic), isStatic, true, advice); } System.out.println("digraph " + name + "{"); System.out.println("\tfirst -> n" + Hex.u2(rmeth.getFirstLabel()) + ";"); BasicBlockList blocks = rmeth.getBlocks(); int sz = blocks.size(); for (int i = 0; i < sz; i++) { BasicBlock bb = blocks.get(i); int label = bb.getLabel(); IntList successors = bb.getSuccessors(); if (successors.size() == 0) { System.out.println("\tn" + Hex.u2(label) + " -> returns;"); } else if (successors.size() == 1) { System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(successors.get(0)) + ";"); } else { System.out.print("\tn" + Hex.u2(label) + " -> {"); for (int j = 0; j < successors.size(); j++ ) { int successor = successors.get(j); if (successor != bb.getPrimarySuccessor()) { System.out.print(" n" + Hex.u2(successor) + " "); } } System.out.println("};"); System.out.println("\tn" + Hex.u2(label) + " -> n" + Hex.u2(bb.getPrimarySuccessor()) + " [label=\"primary\"];"); } } System.out.println("}"); }