public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
private static BuilderTryBlock buildTryBlock(int startAddress, int codeUnits, List<? extends BuilderExceptionHandler> handlers) { BuilderTryBlock tryBlock = mock(BuilderTryBlock.class); when(tryBlock.getStartCodeAddress()).thenReturn(startAddress); when(tryBlock.getCodeUnitCount()).thenReturn(codeUnits); doReturn(handlers).when(tryBlock).getExceptionHandlers(); return tryBlock; }
private static Set<Integer> getExceptionHandlerAddresses(ExecutionGraphManipulator manipulator) { int[] allAddresses = manipulator.getAddresses(); Arrays.sort(allAddresses); int highestAddress = allAddresses[allAddresses.length - 1]; Set<Integer> handlerAddresses = new HashSet<>(); List<BuilderTryBlock> tryBlocks = manipulator.getTryBlocks(); for (BuilderTryBlock tryBlock : tryBlocks) { List<? extends BuilderExceptionHandler> handlers = tryBlock.getExceptionHandlers(); for (BuilderExceptionHandler handler : handlers) { int address = handler.getHandlerCodeAddress(); BuilderInstruction instruction = manipulator.getInstruction(address); while (address < highestAddress) { // Add all instructions until return, goto, etc. handlerAddresses.add(address); address += instruction.getCodeUnits(); instruction = manipulator.getInstruction(address); if (!instruction.getOpcode().canContinue()) { break; } } } } return handlerAddresses; }
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, handler)); }
@Test public void testNewLabelByAddress() { MethodImplementationBuilder builder = new MethodImplementationBuilder(10); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0)); MutableMethodImplementation mutableMethodImplementation = new MutableMethodImplementation(builder.getMethodImplementation()); mutableMethodImplementation.addCatch( mutableMethodImplementation.newLabelForAddress(0), mutableMethodImplementation.newLabelForAddress(8), mutableMethodImplementation.newLabelForAddress(1)); Assert.assertEquals(0, mutableMethodImplementation.getTryBlocks().get(0).getStartCodeAddress()); Assert.assertEquals(8, mutableMethodImplementation.getTryBlocks().get(0).getCodeUnitCount()); Assert.assertEquals(1, mutableMethodImplementation.getTryBlocks().get(0).getExceptionHandlers().get(0) .getHandlerCodeAddress()); }
public void addCatch(@Nullable TypeReference type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
@Test public void testNewLabelByIndex() { MethodImplementationBuilder builder = new MethodImplementationBuilder(10); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0)); MutableMethodImplementation mutableMethodImplementation = new MutableMethodImplementation(builder.getMethodImplementation()); mutableMethodImplementation.addCatch( mutableMethodImplementation.newLabelForIndex(0), mutableMethodImplementation.newLabelForIndex(6), mutableMethodImplementation.newLabelForIndex(1)); Assert.assertEquals(0, mutableMethodImplementation.getTryBlocks().get(0).getStartCodeAddress()); Assert.assertEquals(8, mutableMethodImplementation.getTryBlocks().get(0).getCodeUnitCount()); Assert.assertEquals(1, mutableMethodImplementation.getTryBlocks().get(0).getExceptionHandlers().get(0) .getHandlerCodeAddress()); } }
tryBlocks.add(new BuilderTryBlock(startLabel, endLabel, (TypeReference) convertReference(exceptionHandler.getExceptionTypeReference()), newLabel(codeAddressToIndex, exceptionHandler.getHandlerCodeAddress())));
public void addCatch(@Nullable TypeReference type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, handler)); }
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nullable TypeReference type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, handler)); }
public void addCatch(@Nullable TypeReference type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, handler)); }
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, handler)); }
public void addCatch(@Nullable TypeReference type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { tryBlocks.add(new BuilderTryBlock(from, to, type, handler)); }