langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java
changeset 8032 e1aa25ccdabb
parent 8031 d5fe2c1cecfc
child 8036 17b976649c61
equal deleted inserted replaced
8031:d5fe2c1cecfc 8032:e1aa25ccdabb
   498                         checkStringConstant(vdef.init.pos(), sym.getConstValue());
   498                         checkStringConstant(vdef.init.pos(), sym.getConstValue());
   499                     }
   499                     }
   500                 }
   500                 }
   501                 break;
   501                 break;
   502             default:
   502             default:
   503                 assert false;
   503                 Assert.error();
   504             }
   504             }
   505         }
   505         }
   506         // Insert any instance initializers into all constructors.
   506         // Insert any instance initializers into all constructors.
   507         if (initCode.length() != 0) {
   507         if (initCode.length() != 0) {
   508             List<JCStatement> inits = initCode.toList();
   508             List<JCStatement> inits = initCode.toList();
   855         for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) {
   855         for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) {
   856             genExpr(l.head, pts.head).load();
   856             genExpr(l.head, pts.head).load();
   857             pts = pts.tail;
   857             pts = pts.tail;
   858         }
   858         }
   859         // require lists be of same length
   859         // require lists be of same length
   860         assert pts.isEmpty();
   860         Assert.check(pts.isEmpty());
   861     }
   861     }
   862 
   862 
   863 /* ************************************************************************
   863 /* ************************************************************************
   864  * Visitor methods for statements and definitions
   864  * Visitor methods for statements and definitions
   865  *************************************************************************/
   865  *************************************************************************/
  1109         code.resolve(localEnv.info.exit);
  1109         code.resolve(localEnv.info.exit);
  1110     }
  1110     }
  1111 
  1111 
  1112     public void visitSwitch(JCSwitch tree) {
  1112     public void visitSwitch(JCSwitch tree) {
  1113         int limit = code.nextreg;
  1113         int limit = code.nextreg;
  1114         assert tree.selector.type.tag != CLASS;
  1114         Assert.check(tree.selector.type.tag != CLASS);
  1115         int startpcCrt = genCrt ? code.curPc() : 0;
  1115         int startpcCrt = genCrt ? code.curPc() : 0;
  1116         Item sel = genExpr(tree.selector, syms.intType);
  1116         Item sel = genExpr(tree.selector, syms.intType);
  1117         List<JCCase> cases = tree.cases;
  1117         List<JCCase> cases = tree.cases;
  1118         if (cases.isEmpty()) {
  1118         if (cases.isEmpty()) {
  1119             // We are seeing:  switch <sel> {}
  1119             // We are seeing:  switch <sel> {}
  1146                     labels[i] = val;
  1146                     labels[i] = val;
  1147                     if (val < lo) lo = val;
  1147                     if (val < lo) lo = val;
  1148                     if (hi < val) hi = val;
  1148                     if (hi < val) hi = val;
  1149                     nlabels++;
  1149                     nlabels++;
  1150                 } else {
  1150                 } else {
  1151                     assert defaultIndex == -1;
  1151                     Assert.check(defaultIndex == -1);
  1152                     defaultIndex = i;
  1152                     defaultIndex = i;
  1153                 }
  1153                 }
  1154                 l = l.tail;
  1154                 l = l.tail;
  1155             }
  1155             }
  1156 
  1156 
  1288         // in a new environment with the "exit-monitor" operation as finalizer.
  1288         // in a new environment with the "exit-monitor" operation as finalizer.
  1289         final Env<GenContext> syncEnv = env.dup(tree, new GenContext());
  1289         final Env<GenContext> syncEnv = env.dup(tree, new GenContext());
  1290         syncEnv.info.finalize = new GenFinalizer() {
  1290         syncEnv.info.finalize = new GenFinalizer() {
  1291             void gen() {
  1291             void gen() {
  1292                 genLast();
  1292                 genLast();
  1293                 assert syncEnv.info.gaps.length() % 2 == 0;
  1293                 Assert.check(syncEnv.info.gaps.length() % 2 == 0);
  1294                 syncEnv.info.gaps.append(code.curPc());
  1294                 syncEnv.info.gaps.append(code.curPc());
  1295             }
  1295             }
  1296             void genLast() {
  1296             void genLast() {
  1297                 if (code.isAlive()) {
  1297                 if (code.isAlive()) {
  1298                     lockVar.load();
  1298                     lockVar.load();
  1327                         tryEnv.info.cont =
  1327                         tryEnv.info.cont =
  1328                             new Chain(code.emitJump(jsr),
  1328                             new Chain(code.emitJump(jsr),
  1329                                       tryEnv.info.cont,
  1329                                       tryEnv.info.cont,
  1330                                       jsrState);
  1330                                       jsrState);
  1331                     }
  1331                     }
  1332                     assert tryEnv.info.gaps.length() % 2 == 0;
  1332                     Assert.check(tryEnv.info.gaps.length() % 2 == 0);
  1333                     tryEnv.info.gaps.append(code.curPc());
  1333                     tryEnv.info.gaps.append(code.curPc());
  1334                 } else {
  1334                 } else {
  1335                     assert tryEnv.info.gaps.length() % 2 == 0;
  1335                     Assert.check(tryEnv.info.gaps.length() % 2 == 0);
  1336                     tryEnv.info.gaps.append(code.curPc());
  1336                     tryEnv.info.gaps.append(code.curPc());
  1337                     genLast();
  1337                     genLast();
  1338                 }
  1338                 }
  1339             }
  1339             }
  1340             void genLast() {
  1340             void genLast() {
  1638         genExpr(tree.expr, tree.expr.type).drop();
  1638         genExpr(tree.expr, tree.expr.type).drop();
  1639     }
  1639     }
  1640 
  1640 
  1641     public void visitBreak(JCBreak tree) {
  1641     public void visitBreak(JCBreak tree) {
  1642         Env<GenContext> targetEnv = unwind(tree.target, env);
  1642         Env<GenContext> targetEnv = unwind(tree.target, env);
  1643         assert code.state.stacksize == 0;
  1643         Assert.check(code.state.stacksize == 0);
  1644         targetEnv.info.addExit(code.branch(goto_));
  1644         targetEnv.info.addExit(code.branch(goto_));
  1645         endFinalizerGaps(env, targetEnv);
  1645         endFinalizerGaps(env, targetEnv);
  1646     }
  1646     }
  1647 
  1647 
  1648     public void visitContinue(JCContinue tree) {
  1648     public void visitContinue(JCContinue tree) {
  1649         Env<GenContext> targetEnv = unwind(tree.target, env);
  1649         Env<GenContext> targetEnv = unwind(tree.target, env);
  1650         assert code.state.stacksize == 0;
  1650         Assert.check(code.state.stacksize == 0);
  1651         targetEnv.info.addCont(code.branch(goto_));
  1651         targetEnv.info.addCont(code.branch(goto_));
  1652         endFinalizerGaps(env, targetEnv);
  1652         endFinalizerGaps(env, targetEnv);
  1653     }
  1653     }
  1654 
  1654 
  1655     public void visitReturn(JCReturn tree) {
  1655     public void visitReturn(JCReturn tree) {
  1718     }
  1718     }
  1719 
  1719 
  1720     public void visitNewClass(JCNewClass tree) {
  1720     public void visitNewClass(JCNewClass tree) {
  1721         // Enclosing instances or anonymous classes should have been eliminated
  1721         // Enclosing instances or anonymous classes should have been eliminated
  1722         // by now.
  1722         // by now.
  1723         assert tree.encl == null && tree.def == null;
  1723         Assert.check(tree.encl == null && tree.def == null);
  1724 
  1724 
  1725         code.emitop2(new_, makeRef(tree.pos(), tree.type));
  1725         code.emitop2(new_, makeRef(tree.pos(), tree.type));
  1726         code.emitop0(dup);
  1726         code.emitop0(dup);
  1727 
  1727 
  1728         // Generate code for all arguments, where the expected types are
  1728         // Generate code for all arguments, where the expected types are
  1900                 result = od.load();
  1900                 result = od.load();
  1901                 code.emitop0(dup);
  1901                 code.emitop0(dup);
  1902                 genNullCheck(tree.pos());
  1902                 genNullCheck(tree.pos());
  1903                 break;
  1903                 break;
  1904             default:
  1904             default:
  1905                 assert false;
  1905                 Assert.error();
  1906             }
  1906             }
  1907         }
  1907         }
  1908     }
  1908     }
  1909 
  1909 
  1910     /** Generate a null check from the object value at stack top. */
  1910     /** Generate a null check from the object value at stack top. */
  1975                 t = syms.objectType;
  1975                 t = syms.objectType;
  1976             }
  1976             }
  1977             items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
  1977             items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
  1978         }
  1978         }
  1979         Symbol getStringBufferAppend(JCTree tree, Type t) {
  1979         Symbol getStringBufferAppend(JCTree tree, Type t) {
  1980             assert t.constValue() == null;
  1980             Assert.checkNull(t.constValue());
  1981             Symbol method = stringBufferAppend.get(t);
  1981             Symbol method = stringBufferAppend.get(t);
  1982             if (method == null) {
  1982             if (method == null) {
  1983                 method = rs.resolveInternalMethod(tree.pos(),
  1983                 method = rs.resolveInternalMethod(tree.pos(),
  1984                                                   attrEnv,
  1984                                                   attrEnv,
  1985                                                   stringBufferType,
  1985                                                   stringBufferType,
  2118 
  2118 
  2119     public void visitSelect(JCFieldAccess tree) {
  2119     public void visitSelect(JCFieldAccess tree) {
  2120         Symbol sym = tree.sym;
  2120         Symbol sym = tree.sym;
  2121 
  2121 
  2122         if (tree.name == names._class) {
  2122         if (tree.name == names._class) {
  2123             assert target.hasClassLiterals();
  2123             Assert.check(target.hasClassLiterals());
  2124             code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
  2124             code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
  2125             result = items.makeStackItem(pt);
  2125             result = items.makeStackItem(pt);
  2126             return;
  2126             return;
  2127         }
  2127         }
  2128 
  2128