public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, int local, int position1, int position2) { LocalVariableTable localVariableTable = method.getLocalVariableTable(); String localName = UNKNOWN_NAME; if (localVariableTable != null) { LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1); if (lv1 == null) { lv1 = localVariableTable.getLocalVariable(local, position2); position1 = position2; } if (lv1 != null) { localName = lv1.getName(); } } LineNumberTable lineNumbers = method.getLineNumberTable(); if (lineNumbers == null) { return new LocalVariableAnnotation(localName, local, position1); } int line = lineNumbers.getSourceLine(position1); return new LocalVariableAnnotation(localName, local, position1, line); }
for (Iterator<String> i = p.parameterSignatureIterator(); i.hasNext();) { String s = i.next(); LocalVariable localVariable = t.getLocalVariable(index, 0); if (localVariable != null) { String name = localVariable.getName();
LocalVariable lv = lvTable == null ? null : lvTable.getLocalVariable(index, ih.getPosition()); String name, signature; if(lv == null) {
LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt != null) { LocalVariable localVariable = lvt.getLocalVariable(getRegisterOperand(), getNextPC()); if(localVariable == null || localVariable.getName().endsWith("$")) {
LocalVariableTable lvt = getMethod().getLocalVariableTable(); if(lvt != null) { LocalVariable localVariable = lvt.getLocalVariable(getRegisterOperand(), getNextPC()); if(localVariable != null) { pattern = "CAA_COVARIANT_ARRAY_LOCAL";
if(vi.var == null && vi.origValue == vn.getNumber()) { int index = ((StoreInstruction)inst).getIndex(); LocalVariable lv = lvt == null ? null : lvt.getLocalVariable(index, location.getHandle().getNext().getPosition()); vi.var = lv == null ? "var$"+index : lv.getName(); vi.hasObjectOnlyCall = false;
/** * returns the variable name of the specified register slot * * @param obj * the currently parsed code object * @param reg * the variable register of interest * * @return the variable name of the specified register */ private static String getRegisterName(final Code obj, final int reg) { LocalVariableTable lvt = obj.getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, 0); if (lv != null) { return lv.getName(); } } return String.valueOf(reg); } }
/** * returns the variable name of the specified register slot * * @param obj * the currently parsed code object * @param reg * the variable register of interest * * @return the variable name of the specified register */ private static String getRegisterName(final Code obj, final int reg) { LocalVariableTable lvt = obj.getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, 0); if (lv != null) { return lv.getName(); } } return String.valueOf(reg); } }
/** * in some cases the java compiler synthesizes variable for its own purposes. Hopefully when it does this these, can not be found in the localvariable * table. If we find this to be the case, don't report them * * @param reg * the register to check * * @return if reg variable appears in the local variable table */ private boolean appearsToBeUserRegister(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt == null) { return false; } LocalVariable lv = lvt.getLocalVariable(reg); return lv != null; }
/** * in some cases the java compiler synthesizes variable for its own purposes. Hopefully when it does this these, can not be found in the localvariable * table. If we find this to be the case, don't report them * * @param reg * the register to check * * @return if reg variable appears in the local variable table */ private boolean appearsToBeUserRegister(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt == null) { return false; } LocalVariable lv = lvt.getLocalVariable(reg); return lv != null; }
/** * returns the end pc of the visible range of this register at this pc * * @param lvt * the local variable table for this method * @param reg * the register to examine * @param curPC * the pc of the current instruction * @return the endpc */ public static int getLocalVariableEndRange(LocalVariableTable lvt, int reg, int curPC) { int endRange = Integer.MAX_VALUE; if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, curPC); if (lv != null) { endRange = lv.getStartPC() + lv.getLength(); } } return endRange; }
public boolean isRiskyStoreClass(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, getNextPC()); if ((lv != null) && dangerousStoreClassSigs.contains(lv.getSignature())) { return true; } } return false; }
/** * returns the end pc of the visible range of this register at this pc * * @param lvt * the local variable table for this method * @param reg * the register to examine * @param curPC * the pc of the current instruction * @return the endpc */ public static int getLocalVariableEndRange(LocalVariableTable lvt, int reg, int curPC) { int endRange = Integer.MAX_VALUE; if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, curPC); if (lv != null) { endRange = lv.getStartPC() + lv.getLength(); } } return endRange; }
private void buildVariableEndScopeMap() { endOfScopes = new HashMap<>(); LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt != null) { int len = lvt.getLength(); for (int i = 0; i < len; i++) { @SuppressWarnings("deprecation") LocalVariable lv = lvt.getLocalVariable(i); if (lv != null) { Integer endPC = Integer.valueOf(lv.getStartPC() + lv.getLength()); BitSet vars = endOfScopes.get(endPC); if (vars == null) { vars = new BitSet(); endOfScopes.put(endPC, vars); } vars.set(lv.getIndex()); } } } }
public boolean isRiskyStoreClass(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, getNextPC()); if ((lv != null) && dangerousStoreClassSigs.contains(lv.getSignature())) { return true; } } return false; }
private void buildVariableEndScopeMap() { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if ((lvt == null) || (lvt.getLength() == 0)) { endOfScopes = Collections.emptyMap(); } else { int len = lvt.getLength(); endOfScopes = new HashMap<>((int) (len * 1.6)); for (int i = 0; i < len; i++) { @SuppressWarnings("deprecation") LocalVariable lv = lvt.getLocalVariable(i); if (lv != null) { Integer endPC = Integer.valueOf(lv.getStartPC() + lv.getLength()); BitSet vars = endOfScopes.get(endPC); if (vars == null) { vars = new BitSet(); endOfScopes.put(endPC, vars); } vars.set(lv.getIndex()); } } } }
/** * looks to see if this register has already in scope or whether is a new assignment. return true if it's a new assignment. If you can't tell, return true * anyway. might want to change. * * @param reg * the store register * @return whether this is a new register scope assignment */ private boolean isFirstUse(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt == null) { return true; } LocalVariable lv = lvt.getLocalVariable(reg, getPC()); return lv == null; }
/** * looks to see if this register has already in scope or whether is a new assignment. return true if it's a new assignment. If you can't tell, return true * anyway. might want to change. * * @param reg * the store register * @return whether this is a new register scope assignment */ private boolean isFirstUse(int reg) { LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt == null) { return true; } LocalVariable lv = lvt.getLocalVariable(reg, getPC()); return lv == null; }
/** * reduces the end pc based on the optional LocalVariableTable's exception * register scope * * @param infos the list of active catch blocks * @param pc the current pc * @param seen the currently parsed opcode */ private void updateEndPCsOnCatchRegScope(List<CatchInfo> infos, int pc, int seen) { if (lvt != null) { for (CatchInfo ci : infos) { if ((ci.getStart() == pc) && OpcodeUtils.isAStore(seen)) { int exReg = RegisterUtils.getAStoreReg(this, seen); LocalVariable lv = lvt.getLocalVariable(exReg, pc + 1); if (lv != null) { ci.setFinish(lv.getStartPC() + lv.getLength()); } break; } } } }
/** * BCEL-295: */ public void testB295() throws Exception { final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.PLSETestClass2"); final ClassGen cg = new ClassGen(clazz); final ConstantPoolGen pool = cg.getConstantPool(); final Method m = cg.getMethodAt(1); // 'main' final LocalVariableTable lvt = m.getLocalVariableTable(); final LocalVariable lv = lvt.getLocalVariable(2, 4); // 'i' //System.out.println(lv); final MethodGen mg = new MethodGen(m, cg.getClassName(), pool); final LocalVariableTable new_lvt = mg.getLocalVariableTable(mg.getConstantPool()); final LocalVariable new_lv = new_lvt.getLocalVariable(2, 4); // 'i' //System.out.println(new_lv); assertEquals("live range length", lv.getLength(), new_lv.getLength()); } }