< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java

Print this page

 382             if (pendingStatPos != Position.NOPOS)
 383                 markStatBegin();
 384             if (pendingStackMap) {
 385                 pendingStackMap = false;
 386                 emitStackMap();
 387             }
 388             if (debugCode)
 389                 System.err.println("emit@" + cp + " stack=" +
 390                                    state.stacksize + ": " +
 391                                    mnem(op));
 392             emit1(op);
 393         }
 394     }
 395 
 396     void postop() {
 397         Assert.check(alive || isStatementStart());
 398     }
 399 
 400     /** Emit a ldc (or ldc_w) instruction, taking into account operand size
 401     */











 402     public void emitLdc(LoadableConstant constant) {
 403         int od = poolWriter.putConstant(constant);
 404         if (od <= 255) {
 405             emitop1(ldc1, od, constant);
 406         }
 407         else {
 408             emitop2(ldc2, od, constant);
 409         }
 410     }
 411 
 412     /** Emit a multinewarray instruction.
 413      */
 414     public void emitMultianewarray(int ndims, int type, Type arrayType) {
 415         emitop(multianewarray);
 416         if (!alive) return;
 417         emit2(type);
 418         emit1(ndims);
 419         state.pop(ndims);
 420         state.push(arrayType);
 421     }

1003         emitop2(op, od, constant);
1004     }
1005 
1006     public void emitop2(int op, int od) {
1007         emitop2(op, od, null);
1008     }
1009 
1010     public void emitop2(int op, int od, PoolConstant data) {
1011         emitop(op);
1012         if (!alive) return;
1013         emit2(od);
1014         switch (op) {
1015         case getstatic:
1016             state.push(((Symbol)data).erasure(types));
1017             break;
1018         case putstatic:
1019             state.pop(((Symbol)data).erasure(types));
1020             break;
1021         case new_: {
1022             Type t = (Type)data;
1023             state.push(uninitializedObject(t.tsym.erasure(types), cp-3));





1024             break;
1025         }
1026         case sipush:
1027             state.push(syms.intType);
1028             break;
1029         case if_acmp_null:
1030         case if_acmp_nonnull:
1031         case ifeq:
1032         case ifne:
1033         case iflt:
1034         case ifge:
1035         case ifgt:
1036         case ifle:
1037             state.pop(1);
1038             break;
1039         case if_icmpeq:
1040         case if_icmpne:
1041         case if_icmplt:
1042         case if_icmpge:
1043         case if_icmpgt:
1044         case if_icmple:
1045         case if_acmpeq:
1046         case if_acmpne:
1047             state.pop(2);
1048             break;
1049         case goto_:
1050             markDead();
1051             break;



1052         case putfield:
1053             state.pop(((Symbol)data).erasure(types));
1054             state.pop(1); // object ref
1055             break;
1056         case getfield:
1057             state.pop(1); // object ref
1058             state.push(((Symbol)data).erasure(types));
1059             break;
1060         case checkcast: {
1061             state.pop(1); // object ref
1062             Type t = types.erasure((Type)data);
1063             state.push(t);
1064             break; }
1065         case ldc2w:
1066             state.push(types.constantType((LoadableConstant)data));
1067             break;
1068         case instanceof_:
1069             state.pop(1);
1070             state.push(syms.intType);
1071             break;
1072         case ldc2:
1073             state.push(types.constantType((LoadableConstant)data));
1074             break;
1075         case jsr:
1076             break;
1077         default:
1078             throw new AssertionError(mnem(op));
1079         }
1080         // postop();
1081     }
1082 

1756             if (debugCode) System.err.println("   popping " + n);
1757             while (n > 0) {
1758                 stack[--stacksize] = null;
1759                 n--;
1760             }
1761         }
1762 
1763         void pop(Type t) {
1764             pop(width(t));
1765         }
1766 
1767         /** Force the top of the stack to be treated as this supertype
1768          *  of its current type. */
1769         void forceStackTop(Type t) {
1770             if (!alive) return;
1771             switch (t.getTag()) {
1772             case CLASS:
1773             case ARRAY:
1774                 int width = width(t);
1775                 Type old = stack[stacksize-width];
1776                 Assert.check(types.isSubtype(types.erasure(old),
1777                                        types.erasure(t)));
1778                 stack[stacksize-width] = t;
1779                 break;
1780             default:
1781             }
1782         }
1783 
1784         void markInitialized(UninitializedType old) {
1785             Type newtype = old.initializedType();
1786             for (int i=0; i<stacksize; i++) {
1787                 if (stack[i] == old) stack[i] = newtype;
1788             }
1789             for (int i=0; i<lvar.length; i++) {
1790                 LocalVar lv = lvar[i];
1791                 if (lv != null && lv.sym.type == old) {
1792                     VarSymbol sym = lv.sym;
1793                     sym = sym.clone(sym.owner);
1794                     sym.type = newtype;
1795                     LocalVar newlv = lvar[i] = new LocalVar(sym);
1796                     newlv.aliveRanges = lv.aliveRanges;
1797                 }

2431             mnem[invokespecial] = "invokespecial";
2432             mnem[invokestatic] = "invokestatic";
2433             mnem[invokeinterface] = "invokeinterface";
2434             mnem[invokedynamic] = "invokedynamic";
2435             mnem[new_] = "new_";
2436             mnem[newarray] = "newarray";
2437             mnem[anewarray] = "anewarray";
2438             mnem[arraylength] = "arraylength";
2439             mnem[athrow] = "athrow";
2440             mnem[checkcast] = "checkcast";
2441             mnem[instanceof_] = "instanceof_";
2442             mnem[monitorenter] = "monitorenter";
2443             mnem[monitorexit] = "monitorexit";
2444             mnem[wide] = "wide";
2445             mnem[multianewarray] = "multianewarray";
2446             mnem[if_acmp_null] = "if_acmp_null";
2447             mnem[if_acmp_nonnull] = "if_acmp_nonnull";
2448             mnem[goto_w] = "goto_w";
2449             mnem[jsr_w] = "jsr_w";
2450             mnem[breakpoint] = "breakpoint";


2451         }
2452     }
2453 }

 382             if (pendingStatPos != Position.NOPOS)
 383                 markStatBegin();
 384             if (pendingStackMap) {
 385                 pendingStackMap = false;
 386                 emitStackMap();
 387             }
 388             if (debugCode)
 389                 System.err.println("emit@" + cp + " stack=" +
 390                                    state.stacksize + ": " +
 391                                    mnem(op));
 392             emit1(op);
 393         }
 394     }
 395 
 396     void postop() {
 397         Assert.check(alive || isStatementStart());
 398     }
 399 
 400     /** Emit a ldc (or ldc_w) instruction, taking into account operand size
 401     */
 402     public void emitLdc(LoadableConstant constant, int od) {
 403         if (od <= 255) {
 404             emitop1(ldc1, od, constant);
 405         }
 406         else {
 407             emitop2(ldc2, od, constant);
 408         }
 409     }
 410 
 411     /** Emit a ldc (or ldc_w) instruction, taking into account operand size
 412      */
 413     public void emitLdc(LoadableConstant constant) {
 414         int od = poolWriter.putConstant(constant);
 415         if (od <= 255) {
 416             emitop1(ldc1, od, constant);
 417         }
 418         else {
 419             emitop2(ldc2, od, constant);
 420         }
 421     }
 422 
 423     /** Emit a multinewarray instruction.
 424      */
 425     public void emitMultianewarray(int ndims, int type, Type arrayType) {
 426         emitop(multianewarray);
 427         if (!alive) return;
 428         emit2(type);
 429         emit1(ndims);
 430         state.pop(ndims);
 431         state.push(arrayType);
 432     }

1014         emitop2(op, od, constant);
1015     }
1016 
1017     public void emitop2(int op, int od) {
1018         emitop2(op, od, null);
1019     }
1020 
1021     public void emitop2(int op, int od, PoolConstant data) {
1022         emitop(op);
1023         if (!alive) return;
1024         emit2(od);
1025         switch (op) {
1026         case getstatic:
1027             state.push(((Symbol)data).erasure(types));
1028             break;
1029         case putstatic:
1030             state.pop(((Symbol)data).erasure(types));
1031             break;
1032         case new_: {
1033             Type t = (Type)data;
1034             state.push(uninitializedObject(t.tsym.erasure(types), cp - 3));
1035             break;
1036         }
1037         case defaultvalue: {
1038             Type t = (Type)data;
1039             state.push(t.tsym.erasure(types));
1040             break;
1041         }
1042         case sipush:
1043             state.push(syms.intType);
1044             break;
1045         case if_acmp_null:
1046         case if_acmp_nonnull:
1047         case ifeq:
1048         case ifne:
1049         case iflt:
1050         case ifge:
1051         case ifgt:
1052         case ifle:
1053             state.pop(1);
1054             break;
1055         case if_icmpeq:
1056         case if_icmpne:
1057         case if_icmplt:
1058         case if_icmpge:
1059         case if_icmpgt:
1060         case if_icmple:
1061         case if_acmpeq:
1062         case if_acmpne:
1063             state.pop(2);
1064             break;
1065         case goto_:
1066             markDead();
1067             break;
1068         case withfield:
1069             state.pop(((Symbol)data).erasure(types));
1070             break;
1071         case putfield:
1072             state.pop(((Symbol)data).erasure(types));
1073             state.pop(1); // object ref
1074             break;
1075         case getfield:
1076             state.pop(1); // object ref
1077             state.push(((Symbol)data).erasure(types));
1078             break;
1079         case checkcast: {
1080             state.pop(1); // object ref
1081             Type t = types.erasure(data instanceof  ConstantPoolQType ? ((ConstantPoolQType)data).type: (Type)data);
1082             state.push(t);
1083             break; }
1084         case ldc2w:
1085             state.push(types.constantType((LoadableConstant)data));
1086             break;
1087         case instanceof_:
1088             state.pop(1);
1089             state.push(syms.intType);
1090             break;
1091         case ldc2:
1092             state.push(types.constantType((LoadableConstant)data));
1093             break;
1094         case jsr:
1095             break;
1096         default:
1097             throw new AssertionError(mnem(op));
1098         }
1099         // postop();
1100     }
1101 

1775             if (debugCode) System.err.println("   popping " + n);
1776             while (n > 0) {
1777                 stack[--stacksize] = null;
1778                 n--;
1779             }
1780         }
1781 
1782         void pop(Type t) {
1783             pop(width(t));
1784         }
1785 
1786         /** Force the top of the stack to be treated as this supertype
1787          *  of its current type. */
1788         void forceStackTop(Type t) {
1789             if (!alive) return;
1790             switch (t.getTag()) {
1791             case CLASS:
1792             case ARRAY:
1793                 int width = width(t);
1794                 Type old = stack[stacksize-width];
1795                 Assert.check(types.isSubtype(types.erasure(old), types.erasure(t)) ||
1796                         (old.isPrimitiveClass() != t.isPrimitiveClass() && types.isConvertible(types.erasure(old), types.erasure(t))));
1797                 stack[stacksize-width] = t;
1798                 break;
1799             default:
1800             }
1801         }
1802 
1803         void markInitialized(UninitializedType old) {
1804             Type newtype = old.initializedType();
1805             for (int i=0; i<stacksize; i++) {
1806                 if (stack[i] == old) stack[i] = newtype;
1807             }
1808             for (int i=0; i<lvar.length; i++) {
1809                 LocalVar lv = lvar[i];
1810                 if (lv != null && lv.sym.type == old) {
1811                     VarSymbol sym = lv.sym;
1812                     sym = sym.clone(sym.owner);
1813                     sym.type = newtype;
1814                     LocalVar newlv = lvar[i] = new LocalVar(sym);
1815                     newlv.aliveRanges = lv.aliveRanges;
1816                 }

2450             mnem[invokespecial] = "invokespecial";
2451             mnem[invokestatic] = "invokestatic";
2452             mnem[invokeinterface] = "invokeinterface";
2453             mnem[invokedynamic] = "invokedynamic";
2454             mnem[new_] = "new_";
2455             mnem[newarray] = "newarray";
2456             mnem[anewarray] = "anewarray";
2457             mnem[arraylength] = "arraylength";
2458             mnem[athrow] = "athrow";
2459             mnem[checkcast] = "checkcast";
2460             mnem[instanceof_] = "instanceof_";
2461             mnem[monitorenter] = "monitorenter";
2462             mnem[monitorexit] = "monitorexit";
2463             mnem[wide] = "wide";
2464             mnem[multianewarray] = "multianewarray";
2465             mnem[if_acmp_null] = "if_acmp_null";
2466             mnem[if_acmp_nonnull] = "if_acmp_nonnull";
2467             mnem[goto_w] = "goto_w";
2468             mnem[jsr_w] = "jsr_w";
2469             mnem[breakpoint] = "breakpoint";
2470             mnem[defaultvalue] = "defaultvalue";
2471             mnem[withfield] = "withfield";
2472         }
2473     }
2474 }
< prev index next >