public CompactCodeAttributeComposer invokeinterface(int constantIndex, int constant) { return add(new ConstantInstruction(InstructionConstants.OP_INVOKEINTERFACE, constantIndex, constant)); }
protected void writeInfo(byte[] code, int offset) { int constantIndexSize = constantIndexSize(); int constantSize = constantSize(); if (requiredConstantIndexSize() > constantIndexSize) { throw new IllegalArgumentException("Instruction has invalid constant index size ("+this.toString(offset)+")"); } writeValue(code, offset, constantIndex, constantIndexSize); offset += constantIndexSize; writeValue(code, offset, constant, constantSize); }
public String toString() { return getName()+" #"+constantIndex+(constantSize() == 0 ? "" : ", "+constant); }
protected void readInfo(byte[] code, int offset) { int constantIndexSize = constantIndexSize(); int constantSize = constantSize(); constantIndex = readValue(code, offset, constantIndexSize); offset += constantIndexSize; constant = readValue(code, offset, constantSize); }
public int length(int offset) { return 1 + constantIndexSize() + constantSize(); }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { try { // Try to write out the instruction. constantInstruction.write(codeAttribute, offset); } catch (IllegalArgumentException exception) { // Create a new constant instruction that will fit. Instruction replacementInstruction = new ConstantInstruction(constantInstruction.opcode, constantInstruction.constantIndex, constantInstruction.constant); if (DEBUG) { System.out.println(" "+constantInstruction.toString(offset)+" will be widened to "+replacementInstruction.toString()); } replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Write out the instruction. instructionWriter.visitConstantInstruction(clazz, method, codeAttribute, newOffset, constantInstruction); newOffset += constantInstruction.length(newOffset); }
case InstructionConstants.OP_INVOKEINTERFACE: if (SideEffectInstructionChecker.OPTIMIZE_CONSERVATIVELY && isNullReference(offset, constantInstruction.stackPopCount(clazz) - 1)) case InstructionConstants.OP_GETFIELD: case InstructionConstants.OP_INVOKESTATIC: if (constantInstruction.stackPushCount(clazz) > 0 && !sideEffectInstructionChecker.hasSideEffects(clazz, method,
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { try { // Try to write out the instruction. constantInstruction.write(codeAttribute, offset); } catch (IllegalArgumentException exception) { // Create a new constant instruction that will fit. Instruction replacementInstruction = new ConstantInstruction(constantInstruction.opcode, constantInstruction.constantIndex, constantInstruction.constant).shrink(); replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }
private void debug(Clazz clazz, Method method, int offset, ConstantInstruction constantInstruction, Instruction replacementInstruction) { System.out.println("MethodInvocationFixer:"); System.out.println(" Class = "+clazz.getName()); System.out.println(" Method = "+method.getName(clazz)+method.getDescriptor(clazz)); System.out.println(" Instruction = "+constantInstruction.toString(offset)); System.out.println(" -> Class = "+referencedClass); System.out.println(" Method = "+referencedMethod); if ((referencedClass.getAccessFlags() & ClassConstants.INTERNAL_ACC_INTERFACE) != 0) { System.out.println(" Parameter size = "+(ClassUtil.internalMethodParameterSize(referencedMethod.getDescriptor(referencedMethodClass), false))); } System.out.println(" Replacement instruction = "+replacementInstruction.toString(offset)); } }
public Instruction shrink() { // Do we need a short index or a long index? if (requiredConstantIndexSize() == 1) { // Can we replace the long instruction by a short instruction? if (opcode == InstructionConstants.OP_LDC_W) { opcode = InstructionConstants.OP_LDC; } } else { // Should we replace the short instruction by a long instruction? if (opcode == InstructionConstants.OP_LDC) { opcode = InstructionConstants.OP_LDC_W; } } return this; }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Create a copy of the instruction. Instruction newConstantInstruction = new ConstantInstruction(constantInstruction.opcode, constantAdder.addConstant(clazz, constantInstruction.constantIndex), constantInstruction.constant).shrink(); // Add the instruction. codeAttributeComposer.appendInstruction(offset, newConstantInstruction); } }
public String toString() { return getName()+" #"+constantIndex; }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { switch (constantInstruction.opcode) { case InstructionConstants.OP_GETSTATIC: case InstructionConstants.OP_GETFIELD: replaceAnyPushInstruction(clazz, offset, constantInstruction); break; case InstructionConstants.OP_INVOKEVIRTUAL: case InstructionConstants.OP_INVOKESPECIAL: case InstructionConstants.OP_INVOKESTATIC: case InstructionConstants.OP_INVOKEINTERFACE: if (constantInstruction.stackPushCount(clazz) > 0 && !sideEffectInstructionChecker.hasSideEffects(clazz, method, codeAttribute, offset, constantInstruction)) { replaceAnyPushInstruction(clazz, offset, constantInstruction); } break; case InstructionConstants.OP_CHECKCAST: replaceReferencePushInstruction(clazz, offset, constantInstruction); break; } }
protected void readInfo(byte[] code, int offset) { int constantIndexSize = constantIndexSize(); int constantSize = constantSize(); constantIndex = readValue(code, offset, constantIndexSize); offset += constantIndexSize; constant = readValue(code, offset, constantSize); }
public int length(int offset) { return 1 + constantIndexSize() + constantSize(); }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { try { // Try to write out the instruction. constantInstruction.write(codeAttribute, offset); } catch (IllegalArgumentException exception) { // Create a new constant instruction that will fit. Instruction replacementInstruction = new ConstantInstruction(constantInstruction.opcode, constantInstruction.constantIndex, constantInstruction.constant); if (DEBUG) { System.out.println(" "+constantInstruction.toString(offset)+" will be widened to "+replacementInstruction.toString()); } replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Write out the instruction. instructionWriter.visitConstantInstruction(clazz, method, codeAttribute, newOffset, constantInstruction); newOffset += constantInstruction.length(newOffset); }
case InstructionConstants.OP_INVOKEINTERFACE: if (SideEffectInstructionChecker.OPTIMIZE_CONSERVATIVELY && isNullReference(offset, constantInstruction.stackPopCount(clazz) - 1)) case InstructionConstants.OP_GETFIELD: case InstructionConstants.OP_INVOKESTATIC: if (constantInstruction.stackPushCount(clazz) > 0 && !sideEffectInstructionChecker.hasSideEffects(clazz, method,