InstructionHandle firstHandle = methodGen.getInstructionList().findHandle(first); InstructionHandle secondHandle = methodGen.getInstructionList().findHandle(second); while(true) { if(firstHandle == null || secondHandle == null) { return false; if(firstHandle.getPosition() >= endOfFirstSegment) { return secondHandle.getPosition() >= endOfSecondSegment; if(secondHandle.getPosition() >= endOfSecondSegment) { return firstHandle.getPosition() >= endOfFirstSegment; Instruction secondInstruction = secondHandle.getInstruction(); if(firstInstruction instanceof BranchInstruction && secondInstruction instanceof BranchInstruction) { int firstOpcode = firstInstruction.getOpcode(); int secondOpcode = secondInstruction.getOpcode(); if(firstOpcode != secondOpcode) { return false; if(!firstInstruction.equals(secondInstruction)) { return false;
return -1; int start1 = ih1.getPosition(); int start2 = ih2.getPosition(); int startNum1 = getInstructionNumber(positions, start1); int startNum2 = getInstructionNumber(positions, start2); return -1; Instruction inst1 = ih1.getInstruction(); Instruction inst2 = ih2.getInstruction(); if(!inst1.equals(inst2)) { if(inst1 instanceof LocalVariableInstruction && inst2 instanceof LocalVariableInstruction) { if(inst1.getClass() != inst2.getClass()) { if(inst1.getOpcode() != inst2.getOpcode()) { return -1; if(ih1.getPosition()-start1+inst1.getLength() >= length) { return ih2.getPosition()+inst2.getLength(); ih1 = ih1.getNext();
/** * Align the instruction to make the output more readable. * @param ins Instruction to print * @return Output the name with 15 pad characters (always 15 chars output) */ private static String formatName(Instruction ins) { return String.format("%-15s",ins.getName()); }
/** * @param methodGen method * @param start instruction to scan * @return instruction which consumes value which was on top of stack before start instruction * or null if cannot be determined */ private InstructionHandle getConsumer(MethodGen methodGen, InstructionHandle start) { int depth = 1; InstructionHandle cur = start; while(cur != null) { Instruction inst = cur.getInstruction(); depth -= inst.consumeStack(methodGen.getConstantPool()); if(depth <= 0) { return cur; } depth += inst.produceStack(methodGen.getConstantPool()); if(inst instanceof BranchInstruction) { if(inst instanceof GotoInstruction) { cur = ((GotoInstruction)inst).getTarget(); continue; } if(!(inst instanceof IfInstruction)) { return null; } } cur = cur.getNext(); } return null; }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, StackDepth fact) throws DataflowAnalysisException { Instruction ins = handle.getInstruction(); int produced = ins.produceStack(cpg); int consumed = ins.consumeStack(cpg); if (produced == Const.UNPREDICTABLE || consumed == Const.UNPREDICTABLE) { throw new IllegalStateException("Unpredictable stack delta for instruction: " + handle); } int depth = fact.getDepth(); depth += (produced - consumed); if (depth < 0) { fact.setDepth(BOTTOM); } else { fact.setDepth(depth); } }
private void checkConsumedAndProducedValues(Instruction ins, ValueNumber[] consumedValueList, ValueNumber[] producedValueList) { int numConsumed = ins.consumeStack(getCPG()); int numProduced = ins.produceStack(getCPG()); if (numConsumed == Const.UNPREDICTABLE) { throw new InvalidBytecodeException("Unpredictable stack consumption for " + ins); } if (numProduced == Const.UNPREDICTABLE) { throw new InvalidBytecodeException("Unpredictable stack production for " + ins); } if (consumedValueList.length != numConsumed) { throw new IllegalStateException("Wrong number of values consumed for " + ins + ": expected " + numConsumed + ", got " + consumedValueList.length); } if (producedValueList.length != numProduced) { throw new IllegalStateException("Wrong number of values produced for " + ins + ": expected " + numProduced + ", got " + producedValueList.length); } }
String outlinedMethodName, ClassGenerator classGen) { if (getExceptionHandlers().length != 0) { String msg = (new ErrorMsg(ErrorMsg.OUTLINE_ERR_TRY_CATCH)) .toString(); int outlineChunkStartOffset = first.getPosition(); int outlineChunkEndOffset = last.getPosition() + last.getInstruction().getLength(); final InstructionList newIL = new InstructionList(); org.apache.bcel.generic.Type.VOID, argTypes, argNames, outlinedMethodName, getClassName(), newIL, cpg); InstructionList oldMethCopyInIL = new InstructionList(); InstructionList oldMethCopyOutIL = new InstructionList(); InstructionList newMethCopyInIL = new InstructionList(); InstructionList newMethCopyOutIL = new InstructionList(); Instruction c = inst.copy(); // Use clone for shallow copy null); int newLocalVarIndex = newLVG.getIndex(); String varSignature = varType.getSignature();
int outlineChunkStartOffset = first.getPosition(); int outlineChunkEndOffset = last.getPosition() + last.getInstruction().getLength(); final InstructionList newIL = new InstructionList(); InstructionList oldMethCopyInIL = new InstructionList(); InstructionList oldMethCopyOutIL = new InstructionList(); InstructionList newMethCopyInIL = new InstructionList(); InstructionList newMethCopyOutIL = new InstructionList(); Instruction c = inst.copy(); // Use clone for shallow copy null); int newLocalVarIndex = newLVG.getIndex(); String varSignature = varType.getSignature();
InstructionHandle[] childihs = new InstructionList(childBytes).getInstructionHandles(); InstructionHandle[] parentihs = new InstructionList(parentBytes).getInstructionHandles(); InstructionHandle childih = childihs[i]; InstructionHandle parentih = parentihs[i]; Instruction childin = childih.getInstruction(); Instruction parentin = parentih.getInstruction(); if (!childin.getName().equals(parentin.getName())) { return false; String childClassName = ((InvokeInstruction) childin).getClassName(childPoolGen); String parentClassName = ((InvokeInstruction) parentin).getClassName(parentPoolGen); if (!childClassName.equals(parentClassName)) { return false; String childMethodName = ((InvokeInstruction) childin).getMethodName(childPoolGen); String parentMethodName = ((InvokeInstruction) parentin).getMethodName(parentPoolGen); if (!childMethodName.equals(parentMethodName)) { Type childType = ((LDC) childin).getType(childPoolGen); Type parentType = ((LDC) parentin).getType(parentPoolGen); if (!childType.equals(parentType)) { return false; if (!childin.equals(parentin)) { return false;
public void start() { if(!_mg.isAbstract() && !_mg.isNative()) { for(InstructionHandle ih = _mg.getInstructionList().getStart(); ih != null; ih = ih.getNext()) { Instruction i = ih.getInstruction(); if(i instanceof BranchInstruction) { branch_map.put(i, ih); // memorize container } if(ih.hasTargeters()) { if(i instanceof BranchInstruction) { _out.println(" InstructionHandle ih_" + ih.getPosition() + ";"); } else { _out.print(" InstructionHandle ih_" + ih.getPosition() + " = "); } } else { _out.print(" "); } if(!visitInstruction(i)) i.accept(this); } updateBranchTargets(); updateExceptionHandlers(); } }
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) { Instruction inst = ih.getInstruction(); switch (inst.getOpcode()) { for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) { Instruction inst = ih.getInstruction(); BranchHandle invertedIfHandle = il.append(oldIfHandle, invertedIfInst);
int pc = handle.getPosition(); IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction(); + location.getHandle().getPosition() + " is " + (storeLive ? "live" : "dead")); System.out.println("Previous is: " + location.getHandle().getPrev()); } else if (prevIns instanceof GETSTATIC) { GETSTATIC getStatic = (GETSTATIC) prevIns; ConstantPoolGen cpg = methodGen.getConstantPool(); foundDeadClassInitialization = getStatic.getFieldName(cpg).startsWith("class$") && "Ljava/lang/Class;".equals(getStatic.getSignature(cpg)); Type t = ldc.getType(methodGen.getConstantPool()); if ("Ljava/lang/Class;".equals(t.getSignature())) { Object value = ldc.getValue(methodGen.getConstantPool()); if (value instanceof ConstantClass) { if (defensiveConstantValueOpcodes.get(prev.getInstruction().getOpcode())) { propertySet.addProperty(DeadLocalStoreProperty.DEFENSIVE_CONSTANT_OPCODE); String signatureOfValue = typeOfValue.getSignature(); if ((signatureOfValue.startsWith("Ljava/sql/") || signatureOfValue.startsWith("Ljavax/sql/")) && !signatureOfValue.endsWith("Exception")) {
RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow, Location location) throws DataflowAnalysisException { Instruction ins = location.getHandle().getInstruction(); short opcode = ins.getOpcode(); if (opcode == Const.IF_ACMPEQ || opcode == Const.IF_ACMPNE) { checkRefComparison(location, jclass, method, methodGen, visitor, typeDataflow, stringComparisonList, InvokeInstruction inv = (InvokeInstruction) ins; boolean isStatic = inv instanceof INVOKESTATIC; @DottedClassName String className = inv.getClassName(cpg); String methodName = inv.getMethodName(cpg); String methodSig = inv.getSignature(cpg); if ( "assertSame".equals(methodName) && "(Ljava/lang/Object;Ljava/lang/Object;)V".equals(methodSig)) { checkRefComparison(location, jclass, method, methodGen, visitor, typeDataflow, stringComparisonList, } else if ( "assertFalse".equals(methodName) && "(Z)V".equals(methodSig)) { SourceLineAnnotation lastLocation = bugAccumulator.getLastBugLocation(); InstructionHandle prevHandle = location.getHandle().getPrev(); if (lastLocation != null && prevHandle != null && lastLocation.getEndBytecode() == prevHandle.getPosition()){ bugAccumulator.forgetLastBug(); if (DEBUG) {
final InstructionList il = new InstructionList(); for (InstructionHandle ih = start; ih != null; ih = ih.getNext()) { final Instruction i = ih.getInstruction(); final Instruction c = i.copy(); // Use clone for shallow copy if (c instanceof BranchInstruction) { map.put(ih, il.append((BranchInstruction) c)); } else { map.put(ih, il.append(c)); InstructionHandle ch = il.start; while (ih != null) { final Instruction i = ih.getInstruction(); final Instruction c = ch.getInstruction(); if (i instanceof BranchInstruction) {
Method[] generatedMethods; InstructionList il = getInstructionList(); InstructionHandle last = il.getEnd(); il.setPositions(); last.getPosition() + last.getInstruction().getLength(); il.setPositions(); last = il.getEnd(); instructionListSize = last.getPosition() + last.getInstruction().getLength();
Instruction inst = location.getHandle().getInstruction(); ValueNumberFrame before = location.frameBefore(); if (!before.isValid()) { int nconsumed = inst.consumeStack(context.cpg); if(nconsumed > 0) { ValueNumber[] vns = new ValueNumber[nconsumed]; Set<ValueInfo> vals = context.getLiveVals(vn); if(vals != null) { switch(inst.getOpcode()) { case ASTORE: case ASTORE_0: 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; .getAnalysisCache() .getClassAnalysis(XClass.class, DescriptorFactory.createClassDescriptorFromSignature(type.getSignature())) .findMatchingMethod(m); } catch (CheckedAnalysisException e) {
Instruction i = Instruction.readInstruction(bytes); InstructionHandle ih; if(i instanceof BranchInstruction) // Use proper append() method ih = append((BranchInstruction)i); else ih = append(i); ih.setPosition(off); ihs[count] = ih; InstructionHandle ih = findHandle(ihs, pos, count, target);
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, LockSet fact) throws DataflowAnalysisException { Instruction ins = handle.getInstruction(); short opcode = ins.getOpcode(); if (opcode == Const.MONITORENTER || opcode == Const.MONITOREXIT) { ValueNumberFrame frame = vnaDataflow.getFactAtLocation(new Location(handle, basicBlock)); modifyLock(frame, fact, opcode == Const.MONITORENTER ? 1 : -1); } else if (opcode == Const.INVOKEVIRTUAL || opcode == Const.INVOKEINTERFACE) { InvokeInstruction inv = (InvokeInstruction) ins; String name = inv.getMethodName(methodGen.getConstantPool()); String sig = inv.getSignature(methodGen.getConstantPool()); ValueNumberFrame frame = vnaDataflow.getFactAtLocation(new Location(handle, basicBlock)); if ("()V".equals(sig) && ("lock".equals(name) || "lockInterruptibly".equals(name))) { modifyLock(frame, fact, 1); } else if ("()V".equals(sig) && ("unlock".equals(name))) { modifyLock(frame, fact, -1); } } else if ((ins instanceof ReturnInstruction) && isSynchronized && !isStatic) { lockOp(fact, vna.getThisValue().getNumber(), -1); } }
Location location = i.next(); Instruction ins = location.getHandle().getInstruction(); switch (ins.getOpcode()) { case INVOKEVIRTUAL: case INVOKEINTERFACE: InvokeInstruction iins = (InvokeInstruction) ins; String invoking = iins.getName(cpg); if ( comparatorMethod(invoking) || booleanComparisonMethod(invoking) ) { if (methodGen.getName().toLowerCase().indexOf("test") >= 0) { break; if (methodGen.getClassName().toLowerCase().indexOf("test") >= 0) { break; break; if (location.getHandle().getNext().getInstruction().getOpcode() == POP) { break; String sig = iins.getSignature(cpg);
lvgStart = getInstructionList().getStart(); lvgEnd = getInstructionList().getEnd(); return ((lvgStart.getPosition() <= offset) && (lvgEnd.getPosition() + lvgEnd.getInstruction().getLength() >= offset));