@Nonnull private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) { return new BuilderInstruction21s( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
public static BuilderInstruction buildConstant(int value, int register) { BuilderInstruction result; int bitCount = value == 0 ? 1 : 1 + Integer.numberOfTrailingZeros(Integer.highestOneBit(value)); if (bitCount < 4 && (register & 0xFFFFFFF0) == 0) { result = new BuilderInstruction11n(Opcode.CONST_4, register, value); } else if (bitCount < 16 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction21s(Opcode.CONST_16, register, value); } else { result = new BuilderInstruction31i(Opcode.CONST, register, value); } return result; }
public static BuilderInstruction buildConstant(long value, int register) { BuilderInstruction result; int bitCount = Long.SIZE - Long.numberOfLeadingZeros(value); if (bitCount < 16 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction21s(Opcode.CONST_WIDE_16, register, (int) value); } else if (bitCount < 32 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction31i(Opcode.CONST_WIDE_32, register, (int) value); } else { result = new BuilderInstruction51l(Opcode.CONST_WIDE, register, value); } return result; }
@Override protected BuilderInstruction getRealInsn0(LabelAssigner assigner) { return new BuilderInstruction21s(opc, (short) getRegA().getNumber(), getLitB()); }
@Test public void with15BitLiteral() { int value = (int) (Math.pow(2, 15) - 1); Instruction expected = new BuilderInstruction21s(Opcode.CONST_16, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with7BitLiteral() { byte value = Byte.MAX_VALUE; Instruction expected = new BuilderInstruction21s(Opcode.CONST_16, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with4BitLiteral() { long value = 7L; Instruction expected = new BuilderInstruction21s(Opcode.CONST_WIDE_16, REGISTER, (int) value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with15BitLiteral() { short value = Short.MAX_VALUE; Instruction expected = new BuilderInstruction21s(Opcode.CONST_16, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction21s(opcode, regA, litB));
@Test public void replaceInstructionWithMultipleModifiesStateCorrectly() { //@formatter:off Object[][] expected = new Object[][] { { 0, Opcode.CONST_4, new Object[][][] { { { 1, Opcode.CONST_16 } } } }, { 1, Opcode.CONST_16, new Object[][][] { { { 3, Opcode.CONST_16 } } } }, { 3, Opcode.CONST_16, new Object[][][] { { { 5, Opcode.CONST_4 } } } }, { 5, Opcode.CONST_4, new Object[][][] { { { 6, Opcode.CONST_4 } } } }, { 6, Opcode.CONST_4, new Object[][][] { { { 7, Opcode.CONST_4 } } } }, { 7, Opcode.CONST_4, new Object[][][] { { { 8, Opcode.RETURN_VOID } } } }, { 8, Opcode.RETURN_VOID, new Object[1][0][0] }, }; //@formatter:on manipulator = OptimizerTester.getGraphManipulator(CLASS_NAME, "verySimple()V"); BuilderInstruction replacement1 = new BuilderInstruction21s(Opcode.CONST_16, 1, 1); BuilderInstruction replacement2 = new BuilderInstruction21s(Opcode.CONST_16, 2, 2); List<BuilderInstruction> replacements = new LinkedList<BuilderInstruction>(); replacements.add(replacement1); replacements.add(replacement2); manipulator.replaceInstruction(1, replacements); test(expected, manipulator); testHeritage(manipulator, 0); testHeritage(manipulator, 1); testHeritage(manipulator, 3); HeapItem consensus; consensus = manipulator.getRegisterConsensus(1, 1); assertEquals(1, consensus.getValue()); consensus = manipulator.getRegisterConsensus(3, 2); assertEquals(2, consensus.getValue()); }
@Test public void replacingInstructionWithDifferentOpcodeWidthModifiesStateCorrectly() { //@formatter:off Object[][] expected = new Object[][] { { 0, Opcode.CONST_16, new Object[][][] { { { 2, Opcode.CONST_4 } } } }, { 2, Opcode.CONST_4, new Object[][][] { { { 3, Opcode.CONST_4 } } } }, { 3, Opcode.CONST_4, new Object[][][] { { { 4, Opcode.CONST_4 } } } }, { 4, Opcode.CONST_4, new Object[][][] { { { 5, Opcode.CONST_4 } } } }, { 5, Opcode.CONST_4, new Object[][][] { { { 6, Opcode.RETURN_VOID } } } }, { 6, Opcode.RETURN_VOID, new Object[1][0][0] }, }; //@formatter:on manipulator = OptimizerTester.getGraphManipulator(CLASS_NAME, "verySimple()V"); BuilderInstruction replacement = new BuilderInstruction21s(Opcode.CONST_16, 0, 0); manipulator.replaceInstruction(0, replacement); test(expected, manipulator); HeapItem consensus = manipulator.getRegisterConsensus(0, 0); assertEquals(0, consensus.getValue()); }
@Nonnull private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) { return new BuilderInstruction21s( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) { return new BuilderInstruction21s( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) { return new BuilderInstruction21s( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) { return new BuilderInstruction21s( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction21s(opcode, regA, litB));
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction21s(opcode, regA, litB));