Java Code Examples for com.android.dx.util.IntList#add()
The following examples show how to use
com.android.dx.util.IntList#add() .
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: Frame.java From Box with Apache License 2.0 | 6 votes |
/** * Merges this frame's subroutine lists with another. The result * is the deepest common nesting (effectively, the common prefix of the * two lists). * * @param otherSubroutines label list of subroutine start blocks, from * least-nested to most-nested. * @return {@code non-null;} merged subroutine nest list as described above */ private IntList mergeSubroutineLists(IntList otherSubroutines) { if (subroutines.equals(otherSubroutines)) { return subroutines; } IntList resultSubroutines = new IntList(); int szSubroutines = subroutines.size(); int szOthers = otherSubroutines.size(); for (int i = 0; i < szSubroutines && i < szOthers && (subroutines.get(i) == otherSubroutines.get(i)); i++) { resultSubroutines.add(i); } resultSubroutines.setImmutable(); return resultSubroutines; }
Example 2
Source File: Label.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
BasicBlock toBasicBlock() { InsnList result = new InsnList(instructions.size()); for (int i = 0; i < instructions.size(); i++) { result.set(i, instructions.get(i)); } result.setImmutable(); int primarySuccessorIndex = -1; IntList successors = new IntList(); for (Label catchLabel : catchLabels) { successors.add(catchLabel.id); } if (primarySuccessor != null) { primarySuccessorIndex = primarySuccessor.id; successors.add(primarySuccessorIndex); } if (alternateSuccessor != null) { successors.add(alternateSuccessor.id); } successors.setImmutable(); return new BasicBlock(id, result, successors, primarySuccessorIndex); }
Example 3
Source File: Ropper.java From Box with Apache License 2.0 | 6 votes |
/** * Generates a list of subroutine successors. Note: successor blocks * could be listed more than once. This is ok, because this successor * list (and the block it's associated with) will be copied and inlined * before we leave the ropper. Redundent successors will result in * redundent (no-op) merges. * * @return all currently known successors * (return destinations) for that subroutine */ IntList getSuccessors() { IntList successors = new IntList(callerBlocks.size()); /* * For each subroutine caller, get it's target. If the * target is us, add the ret target (subroutine successor) * to our list */ for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); successors.add(subCaller.getSuccessors().get(0)); } successors.setImmutable(); return successors; }
Example 4
Source File: Frame.java From buck with Apache License 2.0 | 6 votes |
/** * Merges this frame's subroutine lists with another. The result * is the deepest common nesting (effectively, the common prefix of the * two lists). * * @param otherSubroutines label list of subroutine start blocks, from * least-nested to most-nested. * @return {@code non-null;} merged subroutine nest list as described above */ private IntList mergeSubroutineLists(IntList otherSubroutines) { if (subroutines.equals(otherSubroutines)) { return subroutines; } IntList resultSubroutines = new IntList(); int szSubroutines = subroutines.size(); int szOthers = otherSubroutines.size(); for (int i = 0; i < szSubroutines && i < szOthers && (subroutines.get(i) == otherSubroutines.get(i)); i++) { resultSubroutines.add(i); } resultSubroutines.setImmutable(); return resultSubroutines; }
Example 5
Source File: Ropper.java From Box with Apache License 2.0 | 6 votes |
/** * Generates a list of subroutine successors. Note: successor blocks * could be listed more than once. This is ok, because this successor * list (and the block it's associated with) will be copied and inlined * before we leave the ropper. Redundent successors will result in * redundent (no-op) merges. * * @return all currently known successors * (return destinations) for that subroutine */ IntList getSuccessors() { IntList successors = new IntList(callerBlocks.size()); /* * For each subroutine caller, get it's target. If the * target is us, add the ret target (subroutine successor) * to our list */ for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); successors.add(subCaller.getSuccessors().get(0)); } successors.setImmutable(); return successors; }
Example 6
Source File: SsaMethod.java From buck with Apache License 2.0 | 5 votes |
/** * Builds an IntList of block indices from a basic block list and a list * of labels taken from Rop form. * * @param ropBlocks Rop blocks * @param labelList list of rop block labels * @return IntList of block indices */ public static IntList indexListFromLabelList(BasicBlockList ropBlocks, IntList labelList) { IntList result = new IntList(labelList.size()); for (int i = 0, sz = labelList.size(); i < sz; i++) { result.add(ropBlocks.indexOfLabel(labelList.get(i))); } return result; }
Example 7
Source File: SsaMethod.java From Box with Apache License 2.0 | 5 votes |
/** * Builds an IntList of block indices from a basic block list and a list * of labels taken from Rop form. * * @param ropBlocks Rop blocks * @param labelList list of rop block labels * @return IntList of block indices */ public static IntList indexListFromLabelList(BasicBlockList ropBlocks, IntList labelList) { IntList result = new IntList(labelList.size()); for (int i = 0, sz = labelList.size(); i < sz; i++) { result.add(ropBlocks.indexOfLabel(labelList.get(i))); } return result; }
Example 8
Source File: ByteCatchList.java From Box with Apache License 2.0 | 5 votes |
/** * Returns a target list corresponding to this instance. The result * is a list of all the exception handler addresses, with the given * {@code noException} address appended if appropriate. The * result is automatically made immutable. * * @param noException {@code >= -1;} the no-exception address to append, or * {@code -1} not to append anything * @return {@code non-null;} list of exception targets, with * {@code noException} appended if necessary */ public IntList toTargetList(int noException) { if (noException < -1) { throw new IllegalArgumentException("noException < -1"); } boolean hasDefault = (noException >= 0); int sz = size(); if (sz == 0) { if (hasDefault) { /* * The list is empty, but there is a no-exception * address; so, the result is just that address. */ return IntList.makeImmutable(noException); } /* * The list is empty and there isn't even a no-exception * address. */ return IntList.EMPTY; } IntList result = new IntList(sz + (hasDefault ? 1 : 0)); for (int i = 0; i < sz; i++) { result.add(get(i).getHandlerPc()); } if (hasDefault) { result.add(noException); } result.setImmutable(); return result; }
Example 9
Source File: SsaBasicBlock.java From Box with Apache License 2.0 | 5 votes |
/** * @return successor list of rop labels */ public IntList getRopLabelSuccessorList() { IntList result = new IntList(successorList.size()); int sz = successorList.size(); for (int i = 0; i < sz; i++) { result.add(parent.blockIndexToRopLabel(successorList.get(i))); } return result; }
Example 10
Source File: SsaBasicBlock.java From buck with Apache License 2.0 | 5 votes |
/** * @return successor list of rop labels */ public IntList getRopLabelSuccessorList() { IntList result = new IntList(successorList.size()); int sz = successorList.size(); for (int i = 0; i < sz; i++) { result.add(parent.blockIndexToRopLabel(successorList.get(i))); } return result; }
Example 11
Source File: ByteCatchList.java From Box with Apache License 2.0 | 5 votes |
/** * Returns a target list corresponding to this instance. The result * is a list of all the exception handler addresses, with the given * {@code noException} address appended if appropriate. The * result is automatically made immutable. * * @param noException {@code >= -1;} the no-exception address to append, or * {@code -1} not to append anything * @return {@code non-null;} list of exception targets, with * {@code noException} appended if necessary */ public IntList toTargetList(int noException) { if (noException < -1) { throw new IllegalArgumentException("noException < -1"); } boolean hasDefault = (noException >= 0); int sz = size(); if (sz == 0) { if (hasDefault) { /* * The list is empty, but there is a no-exception * address; so, the result is just that address. */ return IntList.makeImmutable(noException); } /* * The list is empty and there isn't even a no-exception * address. */ return IntList.EMPTY; } IntList result = new IntList(sz + (hasDefault ? 1 : 0)); for (int i = 0; i < sz; i++) { result.add(get(i).getHandlerPc()); } if (hasDefault) { result.add(noException); } result.setImmutable(); return result; }
Example 12
Source File: ByteCatchList.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Returns a target list corresponding to this instance. The result * is a list of all the exception handler addresses, with the given * {@code noException} address appended if appropriate. The * result is automatically made immutable. * * @param noException {@code >= -1;} the no-exception address to append, or * {@code -1} not to append anything * @return {@code non-null;} list of exception targets, with * {@code noException} appended if necessary */ public IntList toTargetList(int noException) { if (noException < -1) { throw new IllegalArgumentException("noException < -1"); } boolean hasDefault = (noException >= 0); int sz = size(); if (sz == 0) { if (hasDefault) { /* * The list is empty, but there is a no-exception * address; so, the result is just that address. */ return IntList.makeImmutable(noException); } /* * The list is empty and there isn't even a no-exception * address. */ return IntList.EMPTY; } IntList result = new IntList(sz + (hasDefault ? 1 : 0)); for (int i = 0; i < sz; i++) { result.add(get(i).getHandlerPc()); } if (hasDefault) { result.add(noException); } result.setImmutable(); return result; }
Example 13
Source File: SsaRenamer.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Constructs an instance of the renamer * * @param ssaMeth {@code non-null;} un-renamed SSA method that will * be renamed. */ public SsaRenamer(SsaMethod ssaMeth) { ropRegCount = ssaMeth.getRegCount(); this.ssaMeth = ssaMeth; /* * Reserve the first N registers in the SSA register space for * "version 0" registers. */ nextSsaReg = ropRegCount; threshold = 0; startsForBlocks = new RegisterSpec[ssaMeth.getBlocks().size()][]; ssaRegToLocalItems = new ArrayList<LocalItem>(); if (DEBUG) { ssaRegToRopReg = new IntList(ropRegCount); } /* * Appel 19.7 * * Initialization: * for each variable a // register i * Count[a] <- 0 // nextSsaReg, flattened * Stack[a] <- 0 // versionStack * push 0 onto Stack[a] * */ // top entry for the version stack is version 0 RegisterSpec[] initialRegMapping = new RegisterSpec[ropRegCount]; for (int i = 0; i < ropRegCount; i++) { // everyone starts with a version 0 register initialRegMapping[i] = RegisterSpec.make(i, Type.VOID); if (DEBUG) { ssaRegToRopReg.add(i); } } // Initial state for entry block startsForBlocks[ssaMeth.getEntryBlockIndex()] = initialRegMapping; }
Example 14
Source File: Frame.java From Box with Apache License 2.0 | 4 votes |
/** * Merges this frame with the frame of a subroutine caller at * {@code predLabel}. Only called on the frame at the first * block of a subroutine. * * @param other {@code non-null;} another frame * @param subLabel label of subroutine start block * @param predLabel label of calling block * @return {@code non-null;} the result of merging the two frames */ public Frame mergeWithSubroutineCaller(Frame other, int subLabel, int predLabel) { LocalsArray resultLocals; ExecutionStack resultStack; resultLocals = getLocals().mergeWithSubroutineCaller( other.getLocals(), predLabel); resultStack = getStack().merge(other.getStack()); IntList newOtherSubroutines = other.subroutines.mutableCopy(); newOtherSubroutines.add(subLabel); newOtherSubroutines.setImmutable(); if ((resultLocals == getLocals()) && (resultStack == getStack()) && subroutines.equals(newOtherSubroutines)) { return this; } IntList resultSubroutines; if (subroutines.equals(newOtherSubroutines)) { resultSubroutines = subroutines; } else { /* * The new subroutines list should be the deepest of the two * lists being merged, but the postfix of the resultant list * must be equal to the shorter list. */ IntList nonResultSubroutines; if (subroutines.size() > newOtherSubroutines.size()) { resultSubroutines = subroutines; nonResultSubroutines = newOtherSubroutines; } else { resultSubroutines = newOtherSubroutines; nonResultSubroutines = subroutines; } int szResult = resultSubroutines.size(); int szNonResult = nonResultSubroutines.size(); for (int i = szNonResult - 1; i >=0; i-- ) { if (nonResultSubroutines.get(i) != resultSubroutines.get( i + (szResult - szNonResult))) { throw new RuntimeException("Incompatible merged subroutines"); } } } return new Frame(resultLocals, resultStack, resultSubroutines); }
Example 15
Source File: IdenticalBlockCombiner.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Runs algorithm. TODO: This is n^2, and could be made linear-ish with * a hash. In particular, hash the contents of each block and only * compare blocks with the same hash. * * @return {@code non-null;} new method that has been processed */ public RopMethod process() { int szBlocks = blocks.size(); // indexed by label BitSet toDelete = new BitSet(blocks.getMaxLabel()); // For each non-deleted block... for (int bindex = 0; bindex < szBlocks; bindex++) { BasicBlock b = blocks.get(bindex); if (toDelete.get(b.getLabel())) { // doomed block continue; } IntList preds = ropMethod.labelToPredecessors(b.getLabel()); // ...look at all of it's predecessors that have only one succ... int szPreds = preds.size(); for (int i = 0; i < szPreds; i++) { int iLabel = preds.get(i); BasicBlock iBlock = blocks.labelToBlock(iLabel); if (toDelete.get(iLabel) || iBlock.getSuccessors().size() > 1 || iBlock.getFirstInsn().getOpcode().getOpcode() == RegOps.MOVE_RESULT) { continue; } IntList toCombine = new IntList(); // ...and see if they can be combined with any other preds... for (int j = i + 1; j < szPreds; j++) { int jLabel = preds.get(j); BasicBlock jBlock = blocks.labelToBlock(jLabel); if (jBlock.getSuccessors().size() == 1 && compareInsns(iBlock, jBlock)) { toCombine.add(jLabel); toDelete.set(jLabel); } } combineBlocks(iLabel, toCombine); } } for (int i = szBlocks - 1; i >= 0; i--) { if (toDelete.get(newBlocks.get(i).getLabel())) { newBlocks.set(i, null); } } newBlocks.shrinkToFit(); newBlocks.setImmutable(); return new RopMethod(newBlocks, ropMethod.getFirstLabel()); }
Example 16
Source File: IdenticalBlockCombiner.java From Box with Apache License 2.0 | 4 votes |
/** * Runs algorithm. TODO: This is n^2, and could be made linear-ish with * a hash. In particular, hash the contents of each block and only * compare blocks with the same hash. * * @return {@code non-null;} new method that has been processed */ public RopMethod process() { int szBlocks = blocks.size(); // indexed by label BitSet toDelete = new BitSet(blocks.getMaxLabel()); // For each non-deleted block... for (int bindex = 0; bindex < szBlocks; bindex++) { BasicBlock b = blocks.get(bindex); if (toDelete.get(b.getLabel())) { // doomed block continue; } IntList preds = ropMethod.labelToPredecessors(b.getLabel()); // ...look at all of it's predecessors that have only one succ... int szPreds = preds.size(); for (int i = 0; i < szPreds; i++) { int iLabel = preds.get(i); BasicBlock iBlock = blocks.labelToBlock(iLabel); if (toDelete.get(iLabel) || iBlock.getSuccessors().size() > 1 || iBlock.getFirstInsn().getOpcode().getOpcode() == RegOps.MOVE_RESULT) { continue; } IntList toCombine = new IntList(); // ...and see if they can be combined with any other preds... for (int j = i + 1; j < szPreds; j++) { int jLabel = preds.get(j); BasicBlock jBlock = blocks.labelToBlock(jLabel); if (jBlock.getSuccessors().size() == 1 && compareInsns(iBlock, jBlock)) { toCombine.add(jLabel); toDelete.set(jLabel); } } combineBlocks(iLabel, toCombine); } } for (int i = szBlocks - 1; i >= 0; i--) { if (toDelete.get(newBlocks.get(i).getLabel())) { newBlocks.set(i, null); } } newBlocks.shrinkToFit(); newBlocks.setImmutable(); return new RopMethod(newBlocks, ropMethod.getFirstLabel()); }
Example 17
Source File: SsaRenamer.java From Box with Apache License 2.0 | 4 votes |
/** * Constructs an instance of the renamer * * @param ssaMeth {@code non-null;} un-renamed SSA method that will * be renamed. */ public SsaRenamer(SsaMethod ssaMeth) { ropRegCount = ssaMeth.getRegCount(); this.ssaMeth = ssaMeth; /* * Reserve the first N registers in the SSA register space for * "version 0" registers. */ nextSsaReg = ropRegCount; threshold = 0; startsForBlocks = new RegisterSpec[ssaMeth.getBlocks().size()][]; ssaRegToLocalItems = new ArrayList<LocalItem>(); if (DEBUG) { ssaRegToRopReg = new IntList(ropRegCount); } /* * Appel 19.7 * * Initialization: * for each variable a // register i * Count[a] <- 0 // nextSsaReg, flattened * Stack[a] <- 0 // versionStack * push 0 onto Stack[a] * */ // top entry for the version stack is version 0 RegisterSpec[] initialRegMapping = new RegisterSpec[ropRegCount]; for (int i = 0; i < ropRegCount; i++) { // everyone starts with a version 0 register initialRegMapping[i] = RegisterSpec.make(i, Type.VOID); if (DEBUG) { ssaRegToRopReg.add(i); } } // Initial state for entry block startsForBlocks[ssaMeth.getEntryBlockIndex()] = initialRegMapping; }
Example 18
Source File: Frame.java From J2ME-Loader with Apache License 2.0 | 3 votes |
/** * Makes a frame for a subroutine start block, given that this is the * ending frame of one of the subroutine's calling blocks. Subroutine * calls may be nested and thus may have nested locals state, so we * start with an initial state as seen by the subroutine, but keep track * of the individual locals states that will be expected when the individual * subroutine calls return. * * @param subLabel label of subroutine start block * @param callerLabel {@code >=0;} label of the caller block where this frame * came from. * @return a new instance to begin a called subroutine. */ public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) { IntList newSubroutines = subroutines.mutableCopy(); newSubroutines.add(subLabel); Frame newFrame = new Frame(locals.getPrimary(), stack, IntList.makeImmutable(subLabel)); return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel); }
Example 19
Source File: Frame.java From Box with Apache License 2.0 | 3 votes |
/** * Makes a frame for a subroutine start block, given that this is the * ending frame of one of the subroutine's calling blocks. Subroutine * calls may be nested and thus may have nested locals state, so we * start with an initial state as seen by the subroutine, but keep track * of the individual locals states that will be expected when the individual * subroutine calls return. * * @param subLabel label of subroutine start block * @param callerLabel {@code >=0;} label of the caller block where this frame * came from. * @return a new instance to begin a called subroutine. */ public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) { IntList newSubroutines = subroutines.mutableCopy(); newSubroutines.add(subLabel); Frame newFrame = new Frame(locals.getPrimary(), stack, IntList.makeImmutable(subLabel)); return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel); }
Example 20
Source File: Frame.java From Box with Apache License 2.0 | 3 votes |
/** * Makes a frame for a subroutine start block, given that this is the * ending frame of one of the subroutine's calling blocks. Subroutine * calls may be nested and thus may have nested locals state, so we * start with an initial state as seen by the subroutine, but keep track * of the individual locals states that will be expected when the individual * subroutine calls return. * * @param subLabel label of subroutine start block * @param callerLabel {@code >=0;} label of the caller block where this frame * came from. * @return a new instance to begin a called subroutine. */ public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) { IntList newSubroutines = subroutines.mutableCopy(); newSubroutines.add(subLabel); Frame newFrame = new Frame(locals.getPrimary(), stack, IntList.makeImmutable(subLabel)); return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel); }