Java Code Examples for com.android.dx.rop.code.RegOps#AGET
The following examples show how to use
com.android.dx.rop.code.RegOps#AGET .
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: EscapeAnalysis.java From Box with Apache License 2.0 | 4 votes |
/** * Determine the origin of a move result pseudo instruction that generates * an object. Creates a new EscapeSet for the new object accordingly. * * @param insn {@code non-null;} move result pseudo instruction to process * @return {@code non-null;} an EscapeSet for the object referred to by the * move result pseudo instruction */ private EscapeSet processMoveResultPseudoInsn(SsaInsn insn) { RegisterSpec result = insn.getResult(); SsaInsn prevSsaInsn = getInsnForMove(insn); int prevOpcode = prevSsaInsn.getOpcode().getOpcode(); EscapeSet escSet; RegisterSpec prevSource; switch(prevOpcode) { // New instance / Constant case RegOps.NEW_INSTANCE: case RegOps.CONST: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); break; // New array case RegOps.NEW_ARRAY: case RegOps.FILLED_NEW_ARRAY: prevSource = prevSsaInsn.getSources().get(0); if (prevSource.getTypeBearer().isConstant()) { // New fixed array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); escSet.replaceableArray = true; } else { // New variable array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; // Loading a static object case RegOps.GET_STATIC: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); break; // Type cast / load an object from a field or array case RegOps.CHECK_CAST: case RegOps.GET_FIELD: case RegOps.AGET: prevSource = prevSsaInsn.getSources().get(0); int setIndex = findSetIndex(prevSource); // Set should already exist, try to find it if (setIndex != latticeValues.size()) { escSet = latticeValues.get(setIndex); escSet.regSet.set(result.getReg()); return escSet; } // Set not found, must be either null or unknown if (prevSource.getType() == Type.KNOWN_NULL) { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); } else { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; default: return null; } // Add the newly created escSet to the lattice and return it latticeValues.add(escSet); return escSet; }
Example 2
Source File: EscapeAnalysis.java From Box with Apache License 2.0 | 4 votes |
/** * Replaces the use for a scalar replaceable array. Gets and puts become * move instructions, and array lengths and fills are handled. Can also * identify ArrayIndexOutOfBounds exceptions and throw them if detected. * * @param use {@code non-null;} move result instruction for array * @param prev {@code non-null;} instruction for instantiating new array * @param newRegs {@code non-null;} mapping of array indices to new * registers * @param deletedInsns {@code non-null;} set of instructions marked for * deletion */ private void replaceUse(SsaInsn use, SsaInsn prev, ArrayList<RegisterSpec> newRegs, HashSet<SsaInsn> deletedInsns) { int index; int length = newRegs.size(); SsaInsn next; RegisterSpecList sources; RegisterSpec source, result; CstLiteralBits indexReg; switch (use.getOpcode().getOpcode()) { case RegOps.AGET: // Replace array gets with moves next = getMoveForInsn(use); sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(1).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = newRegs.get(index); result = source.withReg(next.getResult().getReg()); insertPlainInsnBefore(next, RegisterSpecList.make(source), result, RegOps.MOVE, null); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(next, sources.get(1), deletedInsns); deletedInsns.add(next.getBlock().getInsns().get(2)); } deletedInsns.add(next); break; case RegOps.APUT: // Replace array puts with moves sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(2).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = sources.get(0); result = source.withReg(newRegs.get(index).getReg()); insertPlainInsnBefore(use, RegisterSpecList.make(source), result, RegOps.MOVE, null); // Update the newReg entry to mark value as unknown now newRegs.set(index, result.withSimpleType()); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(use, sources.get(2), deletedInsns); } break; case RegOps.ARRAY_LENGTH: // Replace array lengths with const instructions TypeBearer lengthReg = prev.getSources().get(0).getTypeBearer(); //CstInteger lengthReg = CstInteger.make(length); next = getMoveForInsn(use); insertPlainInsnBefore(next, RegisterSpecList.EMPTY, next.getResult(), RegOps.CONST, (Constant) lengthReg); deletedInsns.add(next); break; case RegOps.MARK_LOCAL: // Remove mark local instructions break; case RegOps.FILL_ARRAY_DATA: // Create const instructions for each fill value Insn ropUse = use.getOriginalRopInsn(); FillArrayDataInsn fill = (FillArrayDataInsn) ropUse; ArrayList<Constant> constList = fill.getInitValues(); for (int i = 0; i < length; i++) { RegisterSpec newFill = RegisterSpec.make(newRegs.get(i).getReg(), (TypeBearer) constList.get(i)); insertPlainInsnBefore(use, RegisterSpecList.EMPTY, newFill, RegOps.CONST, constList.get(i)); // Update the newRegs to hold the new const value newRegs.set(i, newFill); } break; default: } }
Example 3
Source File: EscapeAnalysis.java From Box with Apache License 2.0 | 4 votes |
/** * Determine the origin of a move result pseudo instruction that generates * an object. Creates a new EscapeSet for the new object accordingly. * * @param insn {@code non-null;} move result pseudo instruction to process * @return {@code non-null;} an EscapeSet for the object referred to by the * move result pseudo instruction */ private EscapeSet processMoveResultPseudoInsn(SsaInsn insn) { RegisterSpec result = insn.getResult(); SsaInsn prevSsaInsn = getInsnForMove(insn); int prevOpcode = prevSsaInsn.getOpcode().getOpcode(); EscapeSet escSet; RegisterSpec prevSource; switch(prevOpcode) { // New instance / Constant case RegOps.NEW_INSTANCE: case RegOps.CONST: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); break; // New array case RegOps.NEW_ARRAY: case RegOps.FILLED_NEW_ARRAY: prevSource = prevSsaInsn.getSources().get(0); if (prevSource.getTypeBearer().isConstant()) { // New fixed array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); escSet.replaceableArray = true; } else { // New variable array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; // Loading a static object case RegOps.GET_STATIC: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); break; // Type cast / load an object from a field or array case RegOps.CHECK_CAST: case RegOps.GET_FIELD: case RegOps.AGET: prevSource = prevSsaInsn.getSources().get(0); int setIndex = findSetIndex(prevSource); // Set should already exist, try to find it if (setIndex != latticeValues.size()) { escSet = latticeValues.get(setIndex); escSet.regSet.set(result.getReg()); return escSet; } // Set not found, must be either null or unknown if (prevSource.getType() == Type.KNOWN_NULL) { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); } else { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; default: return null; } // Add the newly created escSet to the lattice and return it latticeValues.add(escSet); return escSet; }
Example 4
Source File: EscapeAnalysis.java From Box with Apache License 2.0 | 4 votes |
/** * Replaces the use for a scalar replaceable array. Gets and puts become * move instructions, and array lengths and fills are handled. Can also * identify ArrayIndexOutOfBounds exceptions and throw them if detected. * * @param use {@code non-null;} move result instruction for array * @param prev {@code non-null;} instruction for instantiating new array * @param newRegs {@code non-null;} mapping of array indices to new * registers * @param deletedInsns {@code non-null;} set of instructions marked for * deletion */ private void replaceUse(SsaInsn use, SsaInsn prev, ArrayList<RegisterSpec> newRegs, HashSet<SsaInsn> deletedInsns) { int index; int length = newRegs.size(); SsaInsn next; RegisterSpecList sources; RegisterSpec source, result; CstLiteralBits indexReg; switch (use.getOpcode().getOpcode()) { case RegOps.AGET: // Replace array gets with moves next = getMoveForInsn(use); sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(1).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = newRegs.get(index); result = source.withReg(next.getResult().getReg()); insertPlainInsnBefore(next, RegisterSpecList.make(source), result, RegOps.MOVE, null); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(next, sources.get(1), deletedInsns); deletedInsns.add(next.getBlock().getInsns().get(2)); } deletedInsns.add(next); break; case RegOps.APUT: // Replace array puts with moves sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(2).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = sources.get(0); result = source.withReg(newRegs.get(index).getReg()); insertPlainInsnBefore(use, RegisterSpecList.make(source), result, RegOps.MOVE, null); // Update the newReg entry to mark value as unknown now newRegs.set(index, result.withSimpleType()); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(use, sources.get(2), deletedInsns); } break; case RegOps.ARRAY_LENGTH: // Replace array lengths with const instructions TypeBearer lengthReg = prev.getSources().get(0).getTypeBearer(); //CstInteger lengthReg = CstInteger.make(length); next = getMoveForInsn(use); insertPlainInsnBefore(next, RegisterSpecList.EMPTY, next.getResult(), RegOps.CONST, (Constant) lengthReg); deletedInsns.add(next); break; case RegOps.MARK_LOCAL: // Remove mark local instructions break; case RegOps.FILL_ARRAY_DATA: // Create const instructions for each fill value Insn ropUse = use.getOriginalRopInsn(); FillArrayDataInsn fill = (FillArrayDataInsn) ropUse; ArrayList<Constant> constList = fill.getInitValues(); for (int i = 0; i < length; i++) { RegisterSpec newFill = RegisterSpec.make(newRegs.get(i).getReg(), (TypeBearer) constList.get(i)); insertPlainInsnBefore(use, RegisterSpecList.EMPTY, newFill, RegOps.CONST, constList.get(i)); // Update the newRegs to hold the new const value newRegs.set(i, newFill); } break; default: } }
Example 5
Source File: EscapeAnalysis.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Determine the origin of a move result pseudo instruction that generates * an object. Creates a new EscapeSet for the new object accordingly. * * @param insn {@code non-null;} move result pseudo instruction to process * @return {@code non-null;} an EscapeSet for the object referred to by the * move result pseudo instruction */ private EscapeSet processMoveResultPseudoInsn(SsaInsn insn) { RegisterSpec result = insn.getResult(); SsaInsn prevSsaInsn = getInsnForMove(insn); int prevOpcode = prevSsaInsn.getOpcode().getOpcode(); EscapeSet escSet; RegisterSpec prevSource; switch(prevOpcode) { // New instance / Constant case RegOps.NEW_INSTANCE: case RegOps.CONST: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); break; // New array case RegOps.NEW_ARRAY: case RegOps.FILLED_NEW_ARRAY: prevSource = prevSsaInsn.getSources().get(0); if (prevSource.getTypeBearer().isConstant()) { // New fixed array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); escSet.replaceableArray = true; } else { // New variable array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; // Loading a static object case RegOps.GET_STATIC: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); break; // Type cast / load an object from a field or array case RegOps.CHECK_CAST: case RegOps.GET_FIELD: case RegOps.AGET: prevSource = prevSsaInsn.getSources().get(0); int setIndex = findSetIndex(prevSource); // Set should already exist, try to find it if (setIndex != latticeValues.size()) { escSet = latticeValues.get(setIndex); escSet.regSet.set(result.getReg()); return escSet; } // Set not found, must be either null or unknown if (prevSource.getType() == Type.KNOWN_NULL) { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); } else { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; default: return null; } // Add the newly created escSet to the lattice and return it latticeValues.add(escSet); return escSet; }
Example 6
Source File: EscapeAnalysis.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Replaces the use for a scalar replaceable array. Gets and puts become * move instructions, and array lengths and fills are handled. Can also * identify ArrayIndexOutOfBounds exceptions and throw them if detected. * * @param use {@code non-null;} move result instruction for array * @param prev {@code non-null;} instruction for instantiating new array * @param newRegs {@code non-null;} mapping of array indices to new * registers * @param deletedInsns {@code non-null;} set of instructions marked for * deletion */ private void replaceUse(SsaInsn use, SsaInsn prev, ArrayList<RegisterSpec> newRegs, HashSet<SsaInsn> deletedInsns) { int index; int length = newRegs.size(); SsaInsn next; RegisterSpecList sources; RegisterSpec source, result; CstLiteralBits indexReg; switch (use.getOpcode().getOpcode()) { case RegOps.AGET: // Replace array gets with moves next = getMoveForInsn(use); sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(1).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = newRegs.get(index); result = source.withReg(next.getResult().getReg()); insertPlainInsnBefore(next, RegisterSpecList.make(source), result, RegOps.MOVE, null); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(next, sources.get(1), deletedInsns); deletedInsns.add(next.getBlock().getInsns().get(2)); } deletedInsns.add(next); break; case RegOps.APUT: // Replace array puts with moves sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(2).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = sources.get(0); result = source.withReg(newRegs.get(index).getReg()); insertPlainInsnBefore(use, RegisterSpecList.make(source), result, RegOps.MOVE, null); // Update the newReg entry to mark value as unknown now newRegs.set(index, result.withSimpleType()); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(use, sources.get(2), deletedInsns); } break; case RegOps.ARRAY_LENGTH: // Replace array lengths with const instructions TypeBearer lengthReg = prev.getSources().get(0).getTypeBearer(); //CstInteger lengthReg = CstInteger.make(length); next = getMoveForInsn(use); insertPlainInsnBefore(next, RegisterSpecList.EMPTY, next.getResult(), RegOps.CONST, (Constant) lengthReg); deletedInsns.add(next); break; case RegOps.MARK_LOCAL: // Remove mark local instructions break; case RegOps.FILL_ARRAY_DATA: // Create const instructions for each fill value Insn ropUse = use.getOriginalRopInsn(); FillArrayDataInsn fill = (FillArrayDataInsn) ropUse; ArrayList<Constant> constList = fill.getInitValues(); for (int i = 0; i < length; i++) { RegisterSpec newFill = RegisterSpec.make(newRegs.get(i).getReg(), (TypeBearer) constList.get(i)); insertPlainInsnBefore(use, RegisterSpecList.EMPTY, newFill, RegOps.CONST, constList.get(i)); // Update the newRegs to hold the new const value newRegs.set(i, newFill); } break; default: } }
Example 7
Source File: EscapeAnalysis.java From buck with Apache License 2.0 | 4 votes |
/** * Determine the origin of a move result pseudo instruction that generates * an object. Creates a new EscapeSet for the new object accordingly. * * @param insn {@code non-null;} move result pseudo instruction to process * @return {@code non-null;} an EscapeSet for the object referred to by the * move result pseudo instruction */ private EscapeSet processMoveResultPseudoInsn(SsaInsn insn) { RegisterSpec result = insn.getResult(); SsaInsn prevSsaInsn = getInsnForMove(insn); int prevOpcode = prevSsaInsn.getOpcode().getOpcode(); EscapeSet escSet; RegisterSpec prevSource; switch(prevOpcode) { // New instance / Constant case RegOps.NEW_INSTANCE: case RegOps.CONST: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); break; // New array case RegOps.NEW_ARRAY: case RegOps.FILLED_NEW_ARRAY: prevSource = prevSsaInsn.getSources().get(0); if (prevSource.getTypeBearer().isConstant()) { // New fixed array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); escSet.replaceableArray = true; } else { // New variable array escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; // Loading a static object case RegOps.GET_STATIC: escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); break; // Type cast / load an object from a field or array case RegOps.CHECK_CAST: case RegOps.GET_FIELD: case RegOps.AGET: prevSource = prevSsaInsn.getSources().get(0); int setIndex = findSetIndex(prevSource); // Set should already exist, try to find it if (setIndex != latticeValues.size()) { escSet = latticeValues.get(setIndex); escSet.regSet.set(result.getReg()); return escSet; } // Set not found, must be either null or unknown if (prevSource.getType() == Type.KNOWN_NULL) { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE); } else { escSet = new EscapeSet(result.getReg(), regCount, EscapeState.GLOBAL); } break; default: return null; } // Add the newly created escSet to the lattice and return it latticeValues.add(escSet); return escSet; }
Example 8
Source File: EscapeAnalysis.java From buck with Apache License 2.0 | 4 votes |
/** * Replaces the use for a scalar replaceable array. Gets and puts become * move instructions, and array lengths and fills are handled. Can also * identify ArrayIndexOutOfBounds exceptions and throw them if detected. * * @param use {@code non-null;} move result instruction for array * @param prev {@code non-null;} instruction for instantiating new array * @param newRegs {@code non-null;} mapping of array indices to new * registers * @param deletedInsns {@code non-null;} set of instructions marked for * deletion */ private void replaceUse(SsaInsn use, SsaInsn prev, ArrayList<RegisterSpec> newRegs, HashSet<SsaInsn> deletedInsns) { int index; int length = newRegs.size(); SsaInsn next; RegisterSpecList sources; RegisterSpec source, result; CstLiteralBits indexReg; switch (use.getOpcode().getOpcode()) { case RegOps.AGET: // Replace array gets with moves next = getMoveForInsn(use); sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(1).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = newRegs.get(index); result = source.withReg(next.getResult().getReg()); insertPlainInsnBefore(next, RegisterSpecList.make(source), result, RegOps.MOVE, null); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(next, sources.get(1), deletedInsns); deletedInsns.add(next.getBlock().getInsns().get(2)); } deletedInsns.add(next); break; case RegOps.APUT: // Replace array puts with moves sources = use.getSources(); indexReg = ((CstLiteralBits) sources.get(2).getTypeBearer()); index = indexReg.getIntBits(); if (index < length) { source = sources.get(0); result = source.withReg(newRegs.get(index).getReg()); insertPlainInsnBefore(use, RegisterSpecList.make(source), result, RegOps.MOVE, null); // Update the newReg entry to mark value as unknown now newRegs.set(index, result.withSimpleType()); } else { // Throw an exception if the index is out of bounds insertExceptionThrow(use, sources.get(2), deletedInsns); } break; case RegOps.ARRAY_LENGTH: // Replace array lengths with const instructions TypeBearer lengthReg = prev.getSources().get(0).getTypeBearer(); //CstInteger lengthReg = CstInteger.make(length); next = getMoveForInsn(use); insertPlainInsnBefore(next, RegisterSpecList.EMPTY, next.getResult(), RegOps.CONST, (Constant) lengthReg); deletedInsns.add(next); break; case RegOps.MARK_LOCAL: // Remove mark local instructions break; case RegOps.FILL_ARRAY_DATA: // Create const instructions for each fill value Insn ropUse = use.getOriginalRopInsn(); FillArrayDataInsn fill = (FillArrayDataInsn) ropUse; ArrayList<Constant> constList = fill.getInitValues(); for (int i = 0; i < length; i++) { RegisterSpec newFill = RegisterSpec.make(newRegs.get(i).getReg(), (TypeBearer) constList.get(i)); insertPlainInsnBefore(use, RegisterSpecList.EMPTY, newFill, RegOps.CONST, constList.get(i)); // Update the newRegs to hold the new const value newRegs.set(i, newFill); } break; default: } }