0001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
0002:
0003: This file is part of the db4o open source object database.
0004:
0005: db4o is free software; you can redistribute it and/or modify it under
0006: the terms of version 2 of the GNU General Public License as published
0007: by the Free Software Foundation and as clarified by db4objects' GPL
0008: interpretation policy, available at
0009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
0010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
0011: Suite 350, San Mateo, CA 94403, USA.
0012:
0013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
0014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
0015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0016: for more details.
0017:
0018: You should have received a copy of the GNU General Public License along
0019: with this program; if not, write to the Free Software Foundation, Inc.,
0020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
0021: package EDU.purdue.cs.bloat.trans;
0022:
0023: import EDU.purdue.cs.bloat.editor.*;
0024:
0025: public class StackOpt extends InstructionAdapter implements Opcode {
0026:
0027: int stackHeight;
0028:
0029: int minStackHeight;
0030:
0031: UseMap uMap;
0032:
0033: static final boolean DEBUG = false;
0034:
0035: public void transform(final MethodEditor method) {
0036:
0037: uMap = method.uMap();
0038:
0039: for (int i = method.codeLength() - 1; i > 0; i--) {
0040:
0041: Instruction inst;
0042: boolean isWide;
0043: final Object codeEl = method.codeElementAt(i);
0044:
0045: if ((codeEl instanceof Instruction)
0046: && ((Instruction) codeEl).isLoad()) {
0047: inst = (Instruction) codeEl;
0048: } else {
0049: continue;
0050: }
0051:
0052: switch (inst.opcodeClass()) {
0053:
0054: case opcx_iload:
0055: case opcx_fload:
0056: case opcx_aload:
0057: case opcx_iaload:
0058: case opcx_faload:
0059: case opcx_aaload:
0060: case opcx_baload:
0061: case opcx_caload:
0062: case opcx_saload:
0063: isWide = false;
0064: break;
0065: case opcx_lload:
0066: case opcx_dload:
0067: case opcx_laload:
0068: case opcx_daload:
0069: default:
0070: isWide = true;
0071: }
0072:
0073: stackHeight = 0;
0074:
0075: for (int j = i - 1;; j--) {
0076:
0077: // stop at the begining of the code or a basic block.
0078: if ((j <= 0) || // this should be redundant, but to be safe
0079: (method.codeElementAt(j) instanceof Label)) {
0080: break;
0081: }
0082:
0083: if ((stackHeight == -1)
0084: && ((uMap
0085: .hasSameDef(inst, ((Instruction) method
0086: .codeElementAt(j))) && ((Instruction) method
0087: .codeElementAt(j)).isLoad()) || dupRun(
0088: method, j, inst))) {
0089:
0090: if (forwardCountCheck(method, j, i, -1)) {
0091: // found a type 0 relation with a load
0092: if (StackOpt.DEBUG) {
0093: System.err.println("load type 0: "
0094: + ((Instruction) method
0095: .codeElementAt(j))
0096: .toString() + " "
0097: + inst.toString());
0098: }
0099:
0100: if (isWide) {
0101: method.insertCodeAt(new Instruction(
0102: Opcode.opc_dup2), j + 1);
0103: } else {
0104: method.insertCodeAt(new Instruction(
0105: Opcode.opc_dup), j + 1); // add
0106: // dup
0107: }
0108: i++; // code has changed; why don't method editors
0109: // have iterators?
0110: method.removeCodeAt(i); // remove load
0111: }
0112: break; // done, even if final check failed.
0113: }
0114:
0115: else if ((stackHeight == 0)
0116: && uMap.hasSameDef(inst, ((Instruction) method
0117: .codeElementAt(j)))) {
0118: if (((Instruction) method.codeElementAt(j))
0119: .isStore()) {
0120:
0121: if (forwardCountCheck(method, j, i, 0)) {
0122: // found a type 0 with a store
0123: if (StackOpt.DEBUG) {
0124: System.err.println("store type 0: "
0125: + ((Instruction) method
0126: .codeElementAt(j))
0127: .toString() + " "
0128: + inst.toString());
0129: }
0130:
0131: if (isWide) {
0132: method.insertCodeAt(new Instruction(
0133: Opcode.opc_dup2), j);
0134: } else {
0135: method.insertCodeAt(new Instruction(
0136: Opcode.opc_dup), j);
0137: }
0138: i++;
0139: method.removeCodeAt(i);
0140: }
0141: break;
0142: } else if (((Instruction) method.codeElementAt(j))
0143: .isLoad()
0144: && !isWide) { // can't do type 1s with wides.
0145:
0146: if (forwardCountCheck(method, j, i, -1)) {
0147: // found a type 1 with a load
0148: if (StackOpt.DEBUG) {
0149: System.err.println("load type 1: "
0150: + ((Instruction) method
0151: .codeElementAt(j))
0152: .toString() + " "
0153: + inst.toString());
0154: }
0155:
0156: method.insertCodeAt(new Instruction(
0157: Opcode.opc_dup), j + 1);
0158: i++;
0159: method.replaceCodeAt(new Instruction(
0160: Opcode.opc_swap), i);
0161: }
0162: break;
0163: }
0164: }
0165:
0166: else if ((stackHeight == 1)
0167: && uMap.hasSameDef(inst, ((Instruction) method
0168: .codeElementAt(j)))) {
0169: if (((Instruction) method.codeElementAt(j))
0170: .isStore()
0171: && !isWide) { // can't do type 1 with wides
0172:
0173: if (forwardCountCheck(method, j, i, 0)) {
0174: // type 1 for stores
0175: if (StackOpt.DEBUG) {
0176: System.err.println("store type 1: "
0177: + ((Instruction) method
0178: .codeElementAt(j))
0179: .toString() + " "
0180: + inst.toString());
0181: }
0182:
0183: method.insertCodeAt(new Instruction(
0184: Opcode.opc_dup), j);
0185: i++;
0186: method.replaceCodeAt(new Instruction(
0187: Opcode.opc_swap), i);
0188: }
0189: break;
0190: }
0191: }
0192:
0193: heightChange(method.codeElementAt(j));
0194: // System.err.print(stackHeight + ";");
0195: }
0196: }
0197:
0198: }
0199:
0200: boolean forwardCountCheck(final MethodEditor m, final int j,
0201: final int i, final int bound) {
0202:
0203: stackHeight = 0;
0204: minStackHeight = 0;
0205:
0206: for (int k = j + 1; k < i; k++) {
0207: heightChange(m.codeElementAt(k));
0208: if (minStackHeight < bound) {
0209: return false;
0210: }
0211: }
0212:
0213: return true;
0214: }
0215:
0216: boolean dupRun(final MethodEditor m, final int j,
0217: final Instruction inst) {
0218:
0219: if (((Instruction) m.codeElementAt(j)).opcodeClass() == Opcode.opcx_dup) {
0220: for (int k = j - 1;; k--) {
0221: if (m.codeElementAt(k) instanceof Instruction) {
0222: if (((Instruction) m.codeElementAt(k))
0223: .opcodeClass() == Opcode.opcx_dup) {
0224: continue;
0225: } else if (((Instruction) m.codeElementAt(k))
0226: .isLoad()
0227: && uMap.hasSameDef(inst, ((Instruction) m
0228: .codeElementAt(k)))) {
0229: return true;
0230: }
0231: }
0232: break;
0233: }
0234: }
0235:
0236: return false;
0237: }
0238:
0239: void heightChange(final Object inst) {
0240:
0241: if (inst instanceof Instruction) {
0242: ((Instruction) inst).visit(this );
0243: }
0244:
0245: }
0246:
0247: public void visit_nop(final Instruction inst) {
0248: stackHeight += 0;
0249: }
0250:
0251: public void visit_ldc(final Instruction inst) {
0252: final Object operand = inst.operand();
0253:
0254: if ((operand instanceof Long) || (operand instanceof Double)) {
0255: stackHeight += 2;
0256:
0257: } else {
0258: stackHeight += 1;
0259: }
0260: }
0261:
0262: public void visit_iload(final Instruction inst) {
0263: stackHeight += 1;
0264: }
0265:
0266: public void visit_lload(final Instruction inst) {
0267: stackHeight += 2;
0268: }
0269:
0270: public void visit_fload(final Instruction inst) {
0271: stackHeight += 1;
0272: }
0273:
0274: public void visit_dload(final Instruction inst) {
0275: stackHeight += 2;
0276: }
0277:
0278: public void visit_aload(final Instruction inst) {
0279: stackHeight += 1;
0280: }
0281:
0282: public void visit_iaload(final Instruction inst) {
0283: stackHeight -= 2;
0284: if (stackHeight < minStackHeight) {
0285: minStackHeight = stackHeight;
0286: }
0287: stackHeight += 1;
0288: }
0289:
0290: public void visit_laload(final Instruction inst) {
0291: stackHeight -= 2;
0292: if (stackHeight < minStackHeight) {
0293: minStackHeight = stackHeight;
0294: }
0295: stackHeight += 2;
0296: }
0297:
0298: public void visit_faload(final Instruction inst) {
0299: stackHeight -= 2;
0300: if (stackHeight < minStackHeight) {
0301: minStackHeight = stackHeight;
0302: }
0303: stackHeight += 1;
0304: }
0305:
0306: public void visit_daload(final Instruction inst) {
0307: stackHeight -= 2;
0308: if (stackHeight < minStackHeight) {
0309: minStackHeight = stackHeight;
0310: }
0311: stackHeight += 2;
0312: }
0313:
0314: public void visit_aaload(final Instruction inst) {
0315: stackHeight -= 2;
0316: if (stackHeight < minStackHeight) {
0317: minStackHeight = stackHeight;
0318: }
0319: stackHeight += 1;
0320: }
0321:
0322: public void visit_baload(final Instruction inst) {
0323: stackHeight -= 2;
0324: if (stackHeight < minStackHeight) {
0325: minStackHeight = stackHeight;
0326: }
0327: stackHeight += 1;
0328: }
0329:
0330: public void visit_caload(final Instruction inst) {
0331: stackHeight -= 2;
0332: if (stackHeight < minStackHeight) {
0333: minStackHeight = stackHeight;
0334: }
0335: stackHeight += 1;
0336: }
0337:
0338: public void visit_saload(final Instruction inst) {
0339: stackHeight -= 2;
0340: if (stackHeight < minStackHeight) {
0341: minStackHeight = stackHeight;
0342: }
0343: stackHeight += 1;
0344: }
0345:
0346: public void visit_istore(final Instruction inst) {
0347: stackHeight -= 1;
0348: if (stackHeight < minStackHeight) {
0349: minStackHeight = stackHeight;
0350: }
0351:
0352: }
0353:
0354: public void visit_lstore(final Instruction inst) {
0355: stackHeight -= 2;
0356: if (stackHeight < minStackHeight) {
0357: minStackHeight = stackHeight;
0358: }
0359:
0360: }
0361:
0362: public void visit_fstore(final Instruction inst) {
0363: stackHeight -= 1;
0364: if (stackHeight < minStackHeight) {
0365: minStackHeight = stackHeight;
0366: }
0367:
0368: }
0369:
0370: public void visit_dstore(final Instruction inst) {
0371: stackHeight -= 2;
0372: if (stackHeight < minStackHeight) {
0373: minStackHeight = stackHeight;
0374: }
0375:
0376: }
0377:
0378: public void visit_astore(final Instruction inst) {
0379: stackHeight -= 1;
0380: if (stackHeight < minStackHeight) {
0381: minStackHeight = stackHeight;
0382: }
0383:
0384: }
0385:
0386: public void visit_iastore(final Instruction inst) {
0387: stackHeight -= 3;
0388: if (stackHeight < minStackHeight) {
0389: minStackHeight = stackHeight;
0390: }
0391:
0392: }
0393:
0394: public void visit_lastore(final Instruction inst) {
0395: stackHeight -= 4;
0396: if (stackHeight < minStackHeight) {
0397: minStackHeight = stackHeight;
0398: }
0399:
0400: }
0401:
0402: public void visit_fastore(final Instruction inst) {
0403: stackHeight -= 3;
0404: if (stackHeight < minStackHeight) {
0405: minStackHeight = stackHeight;
0406: }
0407:
0408: }
0409:
0410: public void visit_dastore(final Instruction inst) {
0411: stackHeight -= 4;
0412: if (stackHeight < minStackHeight) {
0413: minStackHeight = stackHeight;
0414: }
0415:
0416: }
0417:
0418: public void visit_aastore(final Instruction inst) {
0419: stackHeight -= 3;
0420: if (stackHeight < minStackHeight) {
0421: minStackHeight = stackHeight;
0422: }
0423:
0424: }
0425:
0426: public void visit_bastore(final Instruction inst) {
0427: stackHeight -= 3;
0428: if (stackHeight < minStackHeight) {
0429: minStackHeight = stackHeight;
0430: }
0431:
0432: }
0433:
0434: public void visit_castore(final Instruction inst) {
0435: stackHeight -= 3;
0436: if (stackHeight < minStackHeight) {
0437: minStackHeight = stackHeight;
0438: }
0439:
0440: }
0441:
0442: public void visit_sastore(final Instruction inst) {
0443: stackHeight -= 3;
0444: if (stackHeight < minStackHeight) {
0445: minStackHeight = stackHeight;
0446: }
0447:
0448: }
0449:
0450: public void visit_pop(final Instruction inst) {
0451: stackHeight -= 1;
0452: if (stackHeight < minStackHeight) {
0453: minStackHeight = stackHeight;
0454: }
0455:
0456: }
0457:
0458: public void visit_pop2(final Instruction inst) {
0459: stackHeight -= 2;
0460: if (stackHeight < minStackHeight) {
0461: minStackHeight = stackHeight;
0462: }
0463: }
0464:
0465: public void visit_dup(final Instruction inst) {
0466: stackHeight += 1;
0467: }
0468:
0469: public void visit_dup_x1(final Instruction inst) {
0470: stackHeight -= 2;
0471: if (stackHeight < minStackHeight) {
0472: minStackHeight = stackHeight;
0473: }
0474:
0475: stackHeight += 3;
0476: }
0477:
0478: public void visit_dup_x2(final Instruction inst) {
0479: stackHeight -= 3;
0480: if (stackHeight < minStackHeight) {
0481: minStackHeight = stackHeight;
0482: }
0483:
0484: stackHeight += 4;
0485: }
0486:
0487: public void visit_dup2(final Instruction inst) {
0488: stackHeight += 2;
0489: }
0490:
0491: public void visit_dup2_x1(final Instruction inst) {
0492: stackHeight -= 3;
0493: if (stackHeight < minStackHeight) {
0494: minStackHeight = stackHeight;
0495: }
0496:
0497: stackHeight += 5;
0498: }
0499:
0500: public void visit_dup2_x2(final Instruction inst) {
0501: stackHeight -= 4;
0502: if (stackHeight < minStackHeight) {
0503: minStackHeight = stackHeight;
0504: }
0505:
0506: stackHeight += 6;
0507: }
0508:
0509: public void visit_swap(final Instruction inst) {
0510: stackHeight -= 2;
0511: if (stackHeight < minStackHeight) {
0512: minStackHeight = stackHeight;
0513: }
0514: stackHeight += 2;
0515: }
0516:
0517: public void visit_iadd(final Instruction inst) {
0518: stackHeight -= 2;
0519: if (stackHeight < minStackHeight) {
0520: minStackHeight = stackHeight;
0521: }
0522: stackHeight += 1;
0523:
0524: }
0525:
0526: public void visit_ladd(final Instruction inst) {
0527: stackHeight -= 4;
0528: if (stackHeight < minStackHeight) {
0529: minStackHeight = stackHeight;
0530: }
0531: stackHeight += 2;
0532: }
0533:
0534: public void visit_fadd(final Instruction inst) {
0535: stackHeight -= 2;
0536: if (stackHeight < minStackHeight) {
0537: minStackHeight = stackHeight;
0538: }
0539: stackHeight += 1;
0540: }
0541:
0542: public void visit_dadd(final Instruction inst) {
0543: stackHeight -= 4;
0544: if (stackHeight < minStackHeight) {
0545: minStackHeight = stackHeight;
0546: }
0547: stackHeight += 2;
0548: }
0549:
0550: public void visit_isub(final Instruction inst) {
0551: stackHeight -= 2;
0552: if (stackHeight < minStackHeight) {
0553: minStackHeight = stackHeight;
0554: }
0555: stackHeight += 1;
0556: }
0557:
0558: public void visit_lsub(final Instruction inst) {
0559: stackHeight -= 4;
0560: if (stackHeight < minStackHeight) {
0561: minStackHeight = stackHeight;
0562: }
0563: stackHeight += 2;
0564: }
0565:
0566: public void visit_fsub(final Instruction inst) {
0567: stackHeight -= 2;
0568: if (stackHeight < minStackHeight) {
0569: minStackHeight = stackHeight;
0570: }
0571: stackHeight += 1;
0572: }
0573:
0574: public void visit_dsub(final Instruction inst) {
0575: stackHeight -= 4;
0576: if (stackHeight < minStackHeight) {
0577: minStackHeight = stackHeight;
0578: }
0579: stackHeight += 2;
0580: }
0581:
0582: public void visit_imul(final Instruction inst) {
0583: stackHeight -= 2;
0584: if (stackHeight < minStackHeight) {
0585: minStackHeight = stackHeight;
0586: }
0587: stackHeight += 1;
0588: }
0589:
0590: public void visit_lmul(final Instruction inst) {
0591: stackHeight -= 4;
0592: if (stackHeight < minStackHeight) {
0593: minStackHeight = stackHeight;
0594: }
0595: stackHeight += 2;
0596: }
0597:
0598: public void visit_fmul(final Instruction inst) {
0599: stackHeight -= 2;
0600: if (stackHeight < minStackHeight) {
0601: minStackHeight = stackHeight;
0602: }
0603: stackHeight += 1;
0604: }
0605:
0606: public void visit_dmul(final Instruction inst) {
0607: stackHeight -= 4;
0608: if (stackHeight < minStackHeight) {
0609: minStackHeight = stackHeight;
0610: }
0611: stackHeight += 2;
0612: }
0613:
0614: public void visit_idiv(final Instruction inst) {
0615: stackHeight -= 2;
0616: if (stackHeight < minStackHeight) {
0617: minStackHeight = stackHeight;
0618: }
0619: stackHeight += 1;
0620: }
0621:
0622: public void visit_ldiv(final Instruction inst) {
0623: stackHeight -= 4;
0624: if (stackHeight < minStackHeight) {
0625: minStackHeight = stackHeight;
0626: }
0627: stackHeight += 2;
0628: }
0629:
0630: public void visit_fdiv(final Instruction inst) {
0631: stackHeight -= 2;
0632: if (stackHeight < minStackHeight) {
0633: minStackHeight = stackHeight;
0634: }
0635: stackHeight += 1;
0636: }
0637:
0638: public void visit_ddiv(final Instruction inst) {
0639: stackHeight -= 4;
0640: if (stackHeight < minStackHeight) {
0641: minStackHeight = stackHeight;
0642: }
0643: stackHeight += 2;
0644: }
0645:
0646: public void visit_irem(final Instruction inst) {
0647: stackHeight -= 2;
0648: if (stackHeight < minStackHeight) {
0649: minStackHeight = stackHeight;
0650: }
0651: stackHeight += 1;
0652: }
0653:
0654: public void visit_lrem(final Instruction inst) {
0655: stackHeight -= 4;
0656: if (stackHeight < minStackHeight) {
0657: minStackHeight = stackHeight;
0658: }
0659: stackHeight += 2;
0660: }
0661:
0662: public void visit_frem(final Instruction inst) {
0663: stackHeight -= 2;
0664: if (stackHeight < minStackHeight) {
0665: minStackHeight = stackHeight;
0666: }
0667: stackHeight += 1;
0668: }
0669:
0670: public void visit_drem(final Instruction inst) {
0671: stackHeight -= 4;
0672: if (stackHeight < minStackHeight) {
0673: minStackHeight = stackHeight;
0674: }
0675: stackHeight += 2;
0676: }
0677:
0678: public void visit_ineg(final Instruction inst) {
0679: stackHeight -= 1;
0680: if (stackHeight < minStackHeight) {
0681: minStackHeight = stackHeight;
0682: }
0683: stackHeight += 1;
0684: }
0685:
0686: public void visit_lneg(final Instruction inst) {
0687: stackHeight -= 2;
0688: if (stackHeight < minStackHeight) {
0689: minStackHeight = stackHeight;
0690: }
0691: stackHeight += 2;
0692: }
0693:
0694: public void visit_fneg(final Instruction inst) {
0695: stackHeight -= 1;
0696: if (stackHeight < minStackHeight) {
0697: minStackHeight = stackHeight;
0698: }
0699: stackHeight += 1;
0700: }
0701:
0702: public void visit_dneg(final Instruction inst) {
0703: stackHeight -= 2;
0704: if (stackHeight < minStackHeight) {
0705: minStackHeight = stackHeight;
0706: }
0707: stackHeight += 2;
0708:
0709: }
0710:
0711: public void visit_ishl(final Instruction inst) {
0712: stackHeight -= 2;
0713: if (stackHeight < minStackHeight) {
0714: minStackHeight = stackHeight;
0715: }
0716: stackHeight += 1;
0717: }
0718:
0719: public void visit_lshl(final Instruction inst) {
0720: stackHeight -= 3;
0721: if (stackHeight < minStackHeight) {
0722: minStackHeight = stackHeight;
0723: }
0724: stackHeight += 2;
0725: }
0726:
0727: public void visit_ishr(final Instruction inst) {
0728: stackHeight -= 2;
0729: if (stackHeight < minStackHeight) {
0730: minStackHeight = stackHeight;
0731: }
0732: stackHeight += 1;
0733: }
0734:
0735: public void visit_lshr(final Instruction inst) {
0736: stackHeight -= 3;
0737: if (stackHeight < minStackHeight) {
0738: minStackHeight = stackHeight;
0739: }
0740: stackHeight += 2;
0741: }
0742:
0743: public void visit_iushr(final Instruction inst) {
0744: stackHeight -= 2;
0745: if (stackHeight < minStackHeight) {
0746: minStackHeight = stackHeight;
0747: }
0748: stackHeight += 1;
0749: }
0750:
0751: public void visit_lushr(final Instruction inst) {
0752: stackHeight -= 3;
0753: if (stackHeight < minStackHeight) {
0754: minStackHeight = stackHeight;
0755: }
0756: stackHeight += 2;
0757: }
0758:
0759: public void visit_iand(final Instruction inst) {
0760: stackHeight -= 2;
0761: if (stackHeight < minStackHeight) {
0762: minStackHeight = stackHeight;
0763: }
0764: stackHeight += 1;
0765: }
0766:
0767: public void visit_land(final Instruction inst) {
0768: stackHeight -= 4;
0769: if (stackHeight < minStackHeight) {
0770: minStackHeight = stackHeight;
0771: }
0772: stackHeight += 2;
0773: }
0774:
0775: public void visit_ior(final Instruction inst) {
0776: stackHeight -= 2;
0777: if (stackHeight < minStackHeight) {
0778: minStackHeight = stackHeight;
0779: }
0780: stackHeight += 1;
0781: }
0782:
0783: public void visit_lor(final Instruction inst) {
0784: stackHeight -= 4;
0785: if (stackHeight < minStackHeight) {
0786: minStackHeight = stackHeight;
0787: }
0788: stackHeight += 2;
0789: }
0790:
0791: public void visit_ixor(final Instruction inst) {
0792: stackHeight -= 2;
0793: if (stackHeight < minStackHeight) {
0794: minStackHeight = stackHeight;
0795: }
0796: stackHeight += 1;
0797: }
0798:
0799: public void visit_lxor(final Instruction inst) {
0800: stackHeight -= 4;
0801: if (stackHeight < minStackHeight) {
0802: minStackHeight = stackHeight;
0803: }
0804: stackHeight += 2;
0805: }
0806:
0807: public void visit_iinc(final Instruction inst) {
0808:
0809: }
0810:
0811: public void visit_i2l(final Instruction inst) {
0812: stackHeight -= 1;
0813: if (stackHeight < minStackHeight) {
0814: minStackHeight = stackHeight;
0815: }
0816:
0817: stackHeight += 2;
0818: }
0819:
0820: public void visit_i2f(final Instruction inst) {
0821: stackHeight -= 1;
0822: if (stackHeight < minStackHeight) {
0823: minStackHeight = stackHeight;
0824: }
0825: stackHeight += 1;
0826: }
0827:
0828: public void visit_i2d(final Instruction inst) {
0829: stackHeight -= 1;
0830: if (stackHeight < minStackHeight) {
0831: minStackHeight = stackHeight;
0832: }
0833:
0834: stackHeight += 2;
0835: }
0836:
0837: public void visit_l2i(final Instruction inst) {
0838: stackHeight -= 2;
0839: if (stackHeight < minStackHeight) {
0840: minStackHeight = stackHeight;
0841: }
0842: stackHeight += 1;
0843: }
0844:
0845: public void visit_l2f(final Instruction inst) {
0846: stackHeight -= 2;
0847: if (stackHeight < minStackHeight) {
0848: minStackHeight = stackHeight;
0849: }
0850: stackHeight += 1;
0851: }
0852:
0853: public void visit_l2d(final Instruction inst) {
0854: stackHeight -= 2;
0855: if (stackHeight < minStackHeight) {
0856: minStackHeight = stackHeight;
0857: }
0858: stackHeight += 2;
0859: }
0860:
0861: public void visit_f2i(final Instruction inst) {
0862: stackHeight -= 1;
0863: if (stackHeight < minStackHeight) {
0864: minStackHeight = stackHeight;
0865: }
0866: stackHeight += 1;
0867: }
0868:
0869: public void visit_f2l(final Instruction inst) {
0870: stackHeight -= 1;
0871: if (stackHeight < minStackHeight) {
0872: minStackHeight = stackHeight;
0873: }
0874:
0875: stackHeight += 2;
0876: }
0877:
0878: public void visit_f2d(final Instruction inst) {
0879: stackHeight -= 1;
0880: if (stackHeight < minStackHeight) {
0881: minStackHeight = stackHeight;
0882: }
0883:
0884: stackHeight += 2;
0885: }
0886:
0887: public void visit_d2i(final Instruction inst) {
0888: stackHeight -= 2;
0889: if (stackHeight < minStackHeight) {
0890: minStackHeight = stackHeight;
0891: }
0892: stackHeight += 1;
0893: }
0894:
0895: public void visit_d2l(final Instruction inst) {
0896: stackHeight -= 2;
0897: if (stackHeight < minStackHeight) {
0898: minStackHeight = stackHeight;
0899: }
0900: stackHeight += 2;
0901: }
0902:
0903: public void visit_d2f(final Instruction inst) {
0904: stackHeight -= 2;
0905: if (stackHeight < minStackHeight) {
0906: minStackHeight = stackHeight;
0907: }
0908: stackHeight += 1;
0909: }
0910:
0911: public void visit_i2b(final Instruction inst) {
0912: stackHeight -= 1;
0913: if (stackHeight < minStackHeight) {
0914: minStackHeight = stackHeight;
0915: }
0916: stackHeight += 1;
0917: }
0918:
0919: public void visit_i2c(final Instruction inst) {
0920: stackHeight -= 1;
0921: if (stackHeight < minStackHeight) {
0922: minStackHeight = stackHeight;
0923: }
0924: stackHeight += 1;
0925: }
0926:
0927: public void visit_i2s(final Instruction inst) {
0928: stackHeight -= 1;
0929: if (stackHeight < minStackHeight) {
0930: minStackHeight = stackHeight;
0931: }
0932: stackHeight += 1;
0933: }
0934:
0935: public void visit_lcmp(final Instruction inst) {
0936: stackHeight -= 4;
0937: if (stackHeight < minStackHeight) {
0938: minStackHeight = stackHeight;
0939: }
0940: stackHeight += 1;
0941: }
0942:
0943: public void visit_fcmpl(final Instruction inst) {
0944: stackHeight -= 2;
0945: if (stackHeight < minStackHeight) {
0946: minStackHeight = stackHeight;
0947: }
0948: stackHeight += 1;
0949: }
0950:
0951: public void visit_fcmpg(final Instruction inst) {
0952: stackHeight -= 2;
0953: if (stackHeight < minStackHeight) {
0954: minStackHeight = stackHeight;
0955: }
0956: stackHeight += 1;
0957: }
0958:
0959: public void visit_dcmpl(final Instruction inst) {
0960: stackHeight -= 4;
0961: if (stackHeight < minStackHeight) {
0962: minStackHeight = stackHeight;
0963: }
0964: stackHeight += 1;
0965: }
0966:
0967: public void visit_dcmpg(final Instruction inst) {
0968: stackHeight -= 4;
0969: if (stackHeight < minStackHeight) {
0970: minStackHeight = stackHeight;
0971: }
0972: stackHeight += 1;
0973: }
0974:
0975: public void visit_ifeq(final Instruction inst) {
0976: stackHeight -= 1;
0977: if (stackHeight < minStackHeight) {
0978: minStackHeight = stackHeight;
0979: }
0980: }
0981:
0982: public void visit_ifne(final Instruction inst) {
0983: stackHeight -= 1;
0984: if (stackHeight < minStackHeight) {
0985: minStackHeight = stackHeight;
0986: }
0987: }
0988:
0989: public void visit_iflt(final Instruction inst) {
0990: stackHeight -= 1;
0991: if (stackHeight < minStackHeight) {
0992: minStackHeight = stackHeight;
0993: }
0994: }
0995:
0996: public void visit_ifge(final Instruction inst) {
0997: stackHeight -= 1;
0998: if (stackHeight < minStackHeight) {
0999: minStackHeight = stackHeight;
1000: }
1001: }
1002:
1003: public void visit_ifgt(final Instruction inst) {
1004: stackHeight -= 1;
1005: if (stackHeight < minStackHeight) {
1006: minStackHeight = stackHeight;
1007: }
1008: }
1009:
1010: public void visit_ifle(final Instruction inst) {
1011: stackHeight -= 1;
1012: if (stackHeight < minStackHeight) {
1013: minStackHeight = stackHeight;
1014: }
1015: }
1016:
1017: public void visit_if_icmpeq(final Instruction inst) {
1018: stackHeight -= 2;
1019: if (stackHeight < minStackHeight) {
1020: minStackHeight = stackHeight;
1021: }
1022: }
1023:
1024: public void visit_if_icmpne(final Instruction inst) {
1025: stackHeight -= 2;
1026: if (stackHeight < minStackHeight) {
1027: minStackHeight = stackHeight;
1028: }
1029: }
1030:
1031: public void visit_if_icmplt(final Instruction inst) {
1032: stackHeight -= 2;
1033: if (stackHeight < minStackHeight) {
1034: minStackHeight = stackHeight;
1035: }
1036: }
1037:
1038: public void visit_if_icmpge(final Instruction inst) {
1039: stackHeight -= 2;
1040: if (stackHeight < minStackHeight) {
1041: minStackHeight = stackHeight;
1042: }
1043: }
1044:
1045: public void visit_if_icmpgt(final Instruction inst) {
1046: stackHeight -= 2;
1047: if (stackHeight < minStackHeight) {
1048: minStackHeight = stackHeight;
1049: }
1050: }
1051:
1052: public void visit_if_icmple(final Instruction inst) {
1053: stackHeight -= 2;
1054: if (stackHeight < minStackHeight) {
1055: minStackHeight = stackHeight;
1056: }
1057: }
1058:
1059: public void visit_if_acmpeq(final Instruction inst) {
1060: stackHeight -= 2;
1061: if (stackHeight < minStackHeight) {
1062: minStackHeight = stackHeight;
1063: }
1064:
1065: }
1066:
1067: public void visit_if_acmpne(final Instruction inst) {
1068: stackHeight -= 2;
1069: if (stackHeight < minStackHeight) {
1070: minStackHeight = stackHeight;
1071: }
1072:
1073: }
1074:
1075: public void visit_goto(final Instruction inst) {
1076:
1077: }
1078:
1079: public void visit_jsr(final Instruction inst) {
1080: stackHeight += 1;
1081: }
1082:
1083: public void visit_ret(final Instruction inst) {
1084: }
1085:
1086: public void visit_switch(final Instruction inst) {
1087: stackHeight -= 1;
1088: }
1089:
1090: public void visit_ireturn(final Instruction inst) {
1091: stackHeight -= 1;
1092: if (stackHeight < minStackHeight) {
1093: minStackHeight = stackHeight;
1094: }
1095:
1096: }
1097:
1098: public void visit_lreturn(final Instruction inst) {
1099: stackHeight -= 2;
1100: if (stackHeight < minStackHeight) {
1101: minStackHeight = stackHeight;
1102: }
1103:
1104: }
1105:
1106: public void visit_freturn(final Instruction inst) {
1107: stackHeight -= 1;
1108: if (stackHeight < minStackHeight) {
1109: minStackHeight = stackHeight;
1110: }
1111:
1112: }
1113:
1114: public void visit_dreturn(final Instruction inst) {
1115: stackHeight -= 2;
1116: if (stackHeight < minStackHeight) {
1117: minStackHeight = stackHeight;
1118: }
1119:
1120: }
1121:
1122: public void visit_areturn(final Instruction inst) {
1123: stackHeight -= 1;
1124: if (stackHeight < minStackHeight) {
1125: minStackHeight = stackHeight;
1126: }
1127:
1128: }
1129:
1130: public void visit_return(final Instruction inst) {
1131: }
1132:
1133: public void visit_getstatic(final Instruction inst) {
1134: final Type type = ((MemberRef) inst.operand()).nameAndType()
1135: .type();
1136: stackHeight += type.stackHeight();
1137: }
1138:
1139: public void visit_putstatic(final Instruction inst) {
1140: final Type type = ((MemberRef) inst.operand()).nameAndType()
1141: .type();
1142: stackHeight -= type.stackHeight();
1143: if (stackHeight < minStackHeight) {
1144: minStackHeight = stackHeight;
1145: }
1146:
1147: }
1148:
1149: public void visit_putstatic_nowb(final Instruction inst) {
1150: final Type type = ((MemberRef) inst.operand()).nameAndType()
1151: .type();
1152: stackHeight -= type.stackHeight();
1153: if (stackHeight < minStackHeight) {
1154: minStackHeight = stackHeight;
1155: }
1156:
1157: }
1158:
1159: public void visit_getfield(final Instruction inst) {
1160: final Type type = ((MemberRef) inst.operand()).nameAndType()
1161: .type();
1162:
1163: stackHeight -= 1;
1164: if (stackHeight < minStackHeight) {
1165: minStackHeight = stackHeight;
1166: }
1167:
1168: stackHeight += type.stackHeight();
1169: }
1170:
1171: public void visit_putfield(final Instruction inst) {
1172: final Type type = ((MemberRef) inst.operand()).nameAndType()
1173: .type();
1174: stackHeight -= type.stackHeight() + 1;
1175: if (stackHeight < minStackHeight) {
1176: minStackHeight = stackHeight;
1177: }
1178:
1179: }
1180:
1181: public void visit_putfield_nowb(final Instruction inst) {
1182: final Type type = ((MemberRef) inst.operand()).nameAndType()
1183: .type();
1184: stackHeight -= type.stackHeight() + 1;
1185: if (stackHeight < minStackHeight) {
1186: minStackHeight = stackHeight;
1187: }
1188: }
1189:
1190: public void visit_invokevirtual(final Instruction inst) {
1191: final MemberRef method = (MemberRef) inst.operand();
1192: final Type type = method.nameAndType().type();
1193:
1194: stackHeight -= type.stackHeight() + 1;
1195: if (stackHeight < minStackHeight) {
1196: minStackHeight = stackHeight;
1197: }
1198:
1199: stackHeight += type.returnType().stackHeight();
1200: }
1201:
1202: public void visit_invokespecial(final Instruction inst) {
1203: final MemberRef method = (MemberRef) inst.operand();
1204: final Type type = method.nameAndType().type();
1205:
1206: stackHeight -= type.stackHeight() + 1;
1207: if (stackHeight < minStackHeight) {
1208: minStackHeight = stackHeight;
1209: }
1210:
1211: stackHeight += type.returnType().stackHeight();
1212:
1213: }
1214:
1215: public void visit_invokestatic(final Instruction inst) {
1216: final MemberRef method = (MemberRef) inst.operand();
1217: final Type type = method.nameAndType().type();
1218:
1219: stackHeight -= type.stackHeight();
1220: if (stackHeight < minStackHeight) {
1221: minStackHeight = stackHeight;
1222: }
1223:
1224: stackHeight += type.returnType().stackHeight();
1225: }
1226:
1227: public void visit_invokeinterface(final Instruction inst) {
1228: final MemberRef method = (MemberRef) inst.operand();
1229: final Type type = method.nameAndType().type();
1230:
1231: stackHeight -= type.stackHeight() + 1;
1232:
1233: if (stackHeight < minStackHeight) {
1234: minStackHeight = stackHeight;
1235: }
1236:
1237: stackHeight += type.returnType().stackHeight();
1238: }
1239:
1240: public void visit_new(final Instruction inst) {
1241: stackHeight += 1;
1242: }
1243:
1244: public void visit_newarray(final Instruction inst) {
1245: stackHeight -= 1;
1246: if (stackHeight < minStackHeight) {
1247: minStackHeight = stackHeight;
1248: }
1249: stackHeight += 1;
1250:
1251: }
1252:
1253: public void visit_arraylength(final Instruction inst) {
1254: stackHeight -= 1;
1255: if (stackHeight < minStackHeight) {
1256: minStackHeight = stackHeight;
1257: }
1258: stackHeight += 1;
1259: }
1260:
1261: public void visit_athrow(final Instruction inst) {
1262: stackHeight -= 1;
1263: if (stackHeight < minStackHeight) {
1264: minStackHeight = stackHeight;
1265: }
1266:
1267: }
1268:
1269: public void visit_checkcast(final Instruction inst) {
1270:
1271: }
1272:
1273: public void visit_instanceof (final Instruction inst) {
1274: stackHeight -= 1;
1275: if (stackHeight < minStackHeight) {
1276: minStackHeight = stackHeight;
1277: }
1278: stackHeight += 1;
1279:
1280: }
1281:
1282: public void visit_monitorenter(final Instruction inst) {
1283: stackHeight -= 1;
1284: if (stackHeight < minStackHeight) {
1285: minStackHeight = stackHeight;
1286: }
1287: }
1288:
1289: public void visit_monitorexit(final Instruction inst) {
1290: stackHeight -= 1;
1291: if (stackHeight < minStackHeight) {
1292: minStackHeight = stackHeight;
1293: }
1294:
1295: }
1296:
1297: public void visit_multianewarray(final Instruction inst) {
1298: final MultiArrayOperand operand = (MultiArrayOperand) inst
1299: .operand();
1300: final int dim = operand.dimensions();
1301:
1302: stackHeight -= dim;
1303: if (stackHeight < minStackHeight) {
1304: minStackHeight = stackHeight;
1305: }
1306:
1307: stackHeight += 1;
1308: }
1309:
1310: public void visit_ifnull(final Instruction inst) {
1311: stackHeight -= 1;
1312: if (stackHeight < minStackHeight) {
1313: minStackHeight = stackHeight;
1314: }
1315: }
1316:
1317: public void visit_ifnonnull(final Instruction inst) {
1318: stackHeight -= 1;
1319: if (stackHeight < minStackHeight) {
1320: minStackHeight = stackHeight;
1321: }
1322: }
1323:
1324: public void visit_rc(final Instruction inst) {
1325: }
1326:
1327: public void visit_aupdate(final Instruction inst) {
1328: }
1329:
1330: public void visit_supdate(final Instruction inst) {
1331: }
1332:
1333: public void visit_aswizzle(final Instruction inst) {
1334: stackHeight -= 2;
1335: if (stackHeight < minStackHeight) {
1336: minStackHeight = stackHeight;
1337: }
1338: }
1339:
1340: public void visit_aswrange(final Instruction inst) {
1341: stackHeight -= 3;
1342: if (stackHeight < minStackHeight) {
1343: minStackHeight = stackHeight;
1344: }
1345: }
1346:
1347: }
|