static private void deleteIns(InstructionList il, InstructionHandle ih, InstructionHandle new_target) { // System.out.println("deleteIns: instructionList = " + il); // System.out.println(" handle = " + ih); try { il.delete(ih); } catch (TargetLostException e) { InstructionHandle[] targets = e.getTargets(); for (int i = 0; i < targets.length; i++) { InstructionTargeter[] targeters = targets[i].getTargeters(); for (int j = 0; j < targeters.length; j++) { targeters[j].updateTarget(targets[i], new_target); } } } }
static private void deleteIns(InstructionList il, InstructionHandle a, InstructionHandle b, InstructionHandle new_target) { try { il.delete(a, b); } catch (TargetLostException e) { InstructionHandle[] targets = e.getTargets(); for (int i = 0; i < targets.length; i++) { InstructionTargeter[] targeters = targets[i].getTargeters(); for (int j = 0; j < targeters.length; j++) { targeters[j].updateTarget(targets[i], new_target); } } } }
private boolean change1(MethodGen mg) { InstructionList il = mg.getInstructionList(); InstructionFinder f = new InstructionFinder(il); String pat = "[LDC_W|LDC] INVOKEVIRTUAL IFNE ICONST_1 GOTO ICONST_0"; boolean changed = false; for(Iterator j = f.search(pat, new IsLdcClass()); j.hasNext(); ) { InstructionHandle[] match = (InstructionHandle[]) j.next(); // replace // LDC_W <class> // INVOKEVIRTUAL Class.desiredAssertionStatus // IFNE // ICONST_1 // goto // ICONST_0 // with // ICONST_1 changed = true; match[0].setInstruction(InstructionConstants.ICONST_1); try { il.delete(match[1], match[5]); // System.out.println(il); } catch (TargetLostException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } return changed; }
private boolean change2(MethodGen mg) { InstructionList il = mg.getInstructionList(); InstructionFinder f = new InstructionFinder(il); String pat = "ALOAD_0 ALOAD_1 PUTFIELD ALOAD_0 INVOKESPECIAL"; boolean changed = false; for(Iterator j = f.search(pat, new IsInnerConstructor()); j.hasNext(); ) { InstructionHandle[] match = (InstructionHandle[]) j.next(); // replace // ALOAD_0 [0] // ALOAD_1 [1] // PUTFIELD [2] // ALOAD_0 [3] // INVOKESPECIAL [4] // with // ALOAD_0 [0] // INVOKESPECIAL [4] // ALOAD_0 [3] // ALOAD_1 [1] // PUTFIELD [2] changed = true; try { InstructionList il2 = new InstructionList(); il2.append(match[3].getInstruction()); il2.append(match[4].getInstruction()); il.delete(match[3], match[4]); il.insert(match[0], il2); } catch (TargetLostException e) { System.err.println("ERROR IN "+mg); e.printStackTrace(); } } return changed; }