/** * Delete contents of list. Provides besser memory utilization, because the system then may reuse * the instruction handles. This method is typically called right after * <href="MethodGen.html#getMethod()">MethodGen.getMethod()</a>. */ public void dispose() { // Traverse in reverse order, because ih.next is overwritten for (InstructionHandle ih = end; ih != null; ih = ih.prev) { /* Causes BranchInstructions to release target and targeters, because it * calls dispose() on the contained instruction. */ ih.dispose(); } clear(); }
/** * Append another list to this one. Consumes argument list, i.e., it becomes empty. * * @param il list to append to end of this list * @return instruction handle of the <B>first</B> appended instruction */ public InstructionHandle append(InstructionList il) { if (il == null) { throw new ClassGenException("Appending null InstructionList"); } if (il.isEmpty()) { return null; } if (isEmpty()) { start = il.start; end = il.end; length = il.length; il.clear(); return start; } else { return append(end, il); // was end.instruction } }
/** * Insert another list before Instruction handle ih contained in this list. Consumes argument * list, i.e., it becomes empty. * * @param ih where to append the instruction list * @param il Instruction list to insert * @return instruction handle of the first inserted instruction */ public InstructionHandle insert(InstructionHandle ih, InstructionList il) { if (il == null) { throw new ClassGenException("Inserting null InstructionList"); } if (il.isEmpty()) { return ih; } InstructionHandle prev = ih.prev, ret = il.start; ih.prev = il.end; il.end.next = ih; il.start.prev = prev; if (prev != null) { prev.next = il.start; } else { start = il.start; // Update start ... } length += il.length; // Update length il.clear(); return ret; }
/** * Append another list after instruction (handle) ih contained in this list. Consumes argument * list, i.e., it becomes empty. * * @param ih where to append the instruction list * @param il Instruction list to append to this one * @return instruction handle pointing to the <B>first</B> appended instruction */ public InstructionHandle append(InstructionHandle ih, InstructionList il) { if (il == null) { throw new ClassGenException("Appending null InstructionList"); } if (il.isEmpty()) { return ih; } InstructionHandle next = ih.next, ret = il.start; ih.next = il.start; il.start.prev = ih; il.end.next = next; if (next != null) { next.prev = il.end; } else { end = il.end; // Update end ... } length += il.length; // Update length il.clear(); return ret; }