/** Optimize instructions and mark those that can be reached */ void optimize(Environment env, Label lbl) { lbl.pc = REACHED; for (Instruction inst = lbl.next; inst != null; inst = inst.next) { switch (inst.pc) { case NOTREACHED: inst.optimize(env); inst.pc = REACHED; break; case REACHED: return; case NEEDED: break; } switch (inst.opc) { case opc_label: case opc_dead: if (inst.pc == REACHED) { inst.pc = NOTREACHED; } break; case opc_ifeq: case opc_ifne: case opc_ifgt: case opc_ifge: case opc_iflt: case opc_ifle: case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpgt: case opc_if_icmpge: case opc_if_icmplt: case opc_if_icmple: case opc_if_acmpeq: case opc_if_acmpne: case opc_ifnull: case opc_ifnonnull: optimize(env, (Label) inst.value); break; case opc_goto: optimize(env, (Label) inst.value); return; case opc_jsr: optimize(env, (Label) inst.value); break; case opc_ret: case opc_return: case opc_ireturn: case opc_lreturn: case opc_freturn: case opc_dreturn: case opc_areturn: case opc_athrow: return; case opc_tableswitch: case opc_lookupswitch: { SwitchData sw = (SwitchData) inst.value; optimize(env, sw.defaultLabel); for (Enumeration e = sw.tab.elements(); e.hasMoreElements(); ) { optimize(env, (Label) e.nextElement()); } return; } case opc_try: { TryData td = (TryData) inst.value; td.getEndLabel().pc = NEEDED; for (Enumeration e = td.catches.elements(); e.hasMoreElements(); ) { CatchData cd = (CatchData) e.nextElement(); optimize(env, cd.getLabel()); } break; } } } }