public int allocateSlot(Type type) { final int size = type.getSize(); final int limit = _free; int slot = _firstAvailableSlot, where = 0; if (_free + size > _size) { final int[] array = new int[_size *= 2]; for (int j = 0; j < limit; j++) array[j] = _slotsTaken[j]; _slotsTaken = array; } while (where < limit) { if (slot + size <= _slotsTaken[where]) { // insert for (int j = limit - 1; j >= where; j--) _slotsTaken[j + size] = _slotsTaken[j]; break; } else { slot = _slotsTaken[where++] + 1; } } for (int j = 0; j < size; j++) _slotsTaken[where + j] = slot + j; _free += size; return slot; }
public void initialize(LocalVariableGen[] vars) { final int length = vars.length; int slot = 0, size, index; for (int i = 0; i < length; i++) { size = vars[i].getType().getSize(); index = vars[i].getIndex(); slot = Math.max(slot, index + size); } _firstAvailableSlot = slot; }
@SuppressWarnings("unchecked") @Override public void visitMethod(Method obj) { argNums = null; Type[] argumentTypes = obj.getArgumentTypes(); if(argumentTypes.length == 0) { return; } int lvNum = obj.isStatic() ? 0 : 1; nArgs = argumentTypes.length; int argCount = lvNum; for(Type type : argumentTypes) { argCount+=type.getSize(); } for(int i=0; i<nArgs; i++) { if(argumentTypes[i].getSignature().equals("Ljava/lang/String;")) { if(argNums == null) { argNums = new int[argCount]; Arrays.fill(argNums, -1); } argNums[lvNum] = i; } lvNum+=argumentTypes[i].getSize(); } if(argNums != null) { passedParameters = new List[nArgs]; } super.visitMethod(obj); }
private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) { Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature()); int j = 0; Map<Integer, Value> result = new HashMap<>(); if(!descriptor.isStatic()) { result.put(j++, new Value("this", null, "L"+descriptor.getSlashedClassName()+";")); } for (int i = 0; i < argumentTypes.length; i++) { result.put(j, new Value("arg"+i, null, argumentTypes[i].getSignature())); j += argumentTypes[i].getSize(); } return result; }
public void releaseSlot(LocalVariableGen lvg) { final int size = lvg.getType().getSize(); final int slot = lvg.getIndex(); final int limit = _free; for (int i = 0; i < limit; i++) { if (_slotsTaken[i] == slot) { int j = i + size; while (j < limit) { _slotsTaken[i++] = _slotsTaken[j++]; } _free -= size; return; } } String state = "Variable slot allocation error"+ "(size="+size+", slot="+slot+", limit="+limit+")"; ErrorMsg err = new ErrorMsg(ErrorMsg.INTERNAL_ERR, state); throw new Error(err.toString()); } }
slot += argumentTypes[paramIndex].getSize();
/** @return size of field (1 or 2) */ protected int getFieldSize(ConstantPoolGen cpg) { return getType(cpg).getSize(); }
/** * Also works for instructions whose stack effect depends on the * constant pool entry they reference. * @return Number of words produced onto stack by this instruction */ public int produceStack(ConstantPoolGen cpg) { return getReturnType(cpg).getSize(); }
public void initialize(LocalVariableGen[] vars) { final int length = vars.length; int slot = 0, size, index; for (int i = 0; i < length; i++) { size = vars[i].getType().getSize(); index = vars[i].getIndex(); slot = Math.max(slot, index + size); } _firstAvailableSlot = slot; }
public void initialize(LocalVariableGen[] vars) { final int length = vars.length; int slot = 0, size, index; for (int i = 0; i < length; i++) { size = vars[i].getType().getSize(); index = vars[i].getIndex(); slot = Math.max(slot, index + size); } _firstAvailableSlot = slot; }
/** * Ensures the specific preconditions of the said instruction. */ public void visitSWAP(SWAP o){ if (stack().peek().getSize() != 1){ constraintViolated(o, "The value at the stack top is not of size '1', but of size '"+stack().peek().getSize()+"'."); } if (stack().peek(1).getSize() != 1){ constraintViolated(o, "The value at the stack next-to-top is not of size '1', but of size '"+stack().peek(1).getSize()+"'."); } }
/** * Ensures the specific preconditions of the said instruction. */ public void visitDUP_X1(DUP_X1 o){ if (stack().peek().getSize() != 1){ constraintViolated(o, "Type on stack top '"+stack().peek()+"' should occupy exactly one slot, not '"+stack().peek().getSize()+"'."); } if (stack().peek(1).getSize() != 1){ constraintViolated(o, "Type on stack next-to-top '"+stack().peek(1)+"' should occupy exactly one slot, not '"+stack().peek(1).getSize()+"'."); } }
/** * Ensures the specific preconditions of the said instruction. */ @Override public void visitDUP(final DUP o) { if (stack().peek().getSize() != 1) { constraintViolated(o, "Won't DUP type on stack top '"+stack().peek()+ "' because it must occupy exactly one slot, not '"+stack().peek().getSize()+"'."); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitPOP2(POP2 o){ Type t = stack().pop(); if (t.getSize() == 1){ stack().pop(); } } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
/** * Returns a String representation of this OperandStack instance. */ public String toString(){ String s = "Slots used: "+slotsUsed()+" MaxStack: "+maxStack+".\n"; for (int i=0; i<size(); i++){ s+=peek(i)+" (Size: "+peek(i).getSize()+")\n"; } return s; }
/** * Assures the generic preconditions of a LocalVariableInstruction instance. * That is, the index of the local variable must be valid. */ @Override public void visitLocalVariableInstruction(final LocalVariableInstruction o) { if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ) { constraintViolated(o, "The 'index' is not a valid index into the local variable array."); } }
/** * Ensures the specific preconditions of the said instruction. */ @Override public void visitIINC(final IINC o) { // Mhhh. In BCEL, at this time "IINC" is not a LocalVariableInstruction. if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ) { constraintViolated(o, "The 'index' is not a valid index into the local variable array."); } indexOfInt(o, locals().get(o.getIndex())); }
/** * Ensures the specific preconditions of the said instruction. */ public void visitIINC(IINC o){ // Mhhh. In BCEL, at this time "IINC" is not a LocalVariableInstruction. if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ){ constraintViolated(o, "The 'index' is not a valid index into the local variable array."); } indexOfInt(o, locals().get(o.getIndex())); }