langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
changeset 29842 826ac2519523
parent 29777 95a89a2efd89
child 30406 530743d1858d
equal deleted inserted replaced
29782:85d4f5471a74 29842:826ac2519523
    73     private final Map<Type,Symbol> stringBufferAppend;
    73     private final Map<Type,Symbol> stringBufferAppend;
    74     private Name accessDollar;
    74     private Name accessDollar;
    75     private final Types types;
    75     private final Types types;
    76     private final Lower lower;
    76     private final Lower lower;
    77     private final Flow flow;
    77     private final Flow flow;
       
    78     private final Annotate annotate;
    78 
    79 
    79     /** Format of stackmap tables to be generated. */
    80     /** Format of stackmap tables to be generated. */
    80     private final Code.StackMapFormat stackMap;
    81     private final Code.StackMapFormat stackMap;
    81 
    82 
    82     /** A type that serves as the expected type for all method expressions.
    83     /** A type that serves as the expected type for all method expressions.
   140                 // ignore ill-formed numbers for jsrlimit
   141                 // ignore ill-formed numbers for jsrlimit
   141             }
   142             }
   142         }
   143         }
   143         this.jsrlimit = setjsrlimit;
   144         this.jsrlimit = setjsrlimit;
   144         this.useJsrLocally = false; // reset in visitTry
   145         this.useJsrLocally = false; // reset in visitTry
       
   146         annotate = Annotate.instance(context);
   145     }
   147     }
   146 
   148 
   147     /** Switches
   149     /** Switches
   148      */
   150      */
   149     private final boolean lineDebugInfo;
   151     private final boolean lineDebugInfo;
  1466         void genCatch(JCCatch tree,
  1468         void genCatch(JCCatch tree,
  1467                       Env<GenContext> env,
  1469                       Env<GenContext> env,
  1468                       int startpc, int endpc,
  1470                       int startpc, int endpc,
  1469                       List<Integer> gaps) {
  1471                       List<Integer> gaps) {
  1470             if (startpc != endpc) {
  1472             if (startpc != endpc) {
  1471                 List<JCExpression> subClauses = TreeInfo.isMultiCatch(tree) ?
  1473                 List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypeExprs
  1472                         ((JCTypeUnion)tree.param.vartype).alternatives :
  1474                         = catchTypesWithAnnotations(tree);
  1473                         List.of(tree.param.vartype);
       
  1474                 while (gaps.nonEmpty()) {
  1475                 while (gaps.nonEmpty()) {
  1475                     for (JCExpression subCatch : subClauses) {
  1476                     for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) {
       
  1477                         JCExpression subCatch = subCatch1.snd;
  1476                         int catchType = makeRef(tree.pos(), subCatch.type);
  1478                         int catchType = makeRef(tree.pos(), subCatch.type);
  1477                         int end = gaps.head.intValue();
  1479                         int end = gaps.head.intValue();
  1478                         registerCatch(tree.pos(),
  1480                         registerCatch(tree.pos(),
  1479                                       startpc,  end, code.curCP(),
  1481                                       startpc,  end, code.curCP(),
  1480                                       catchType);
  1482                                       catchType);
  1481                         if (subCatch.type.isAnnotated()) {
  1483                         for (Attribute.TypeCompound tc :  subCatch1.fst) {
  1482                             for (Attribute.TypeCompound tc :
       
  1483                                      subCatch.type.getAnnotationMirrors()) {
       
  1484                                 tc.position.setCatchInfo(catchType, startpc);
  1484                                 tc.position.setCatchInfo(catchType, startpc);
  1485                             }
       
  1486                         }
  1485                         }
  1487                     }
  1486                     }
  1488                     gaps = gaps.tail;
  1487                     gaps = gaps.tail;
  1489                     startpc = gaps.head.intValue();
  1488                     startpc = gaps.head.intValue();
  1490                     gaps = gaps.tail;
  1489                     gaps = gaps.tail;
  1491                 }
  1490                 }
  1492                 if (startpc < endpc) {
  1491                 if (startpc < endpc) {
  1493                     for (JCExpression subCatch : subClauses) {
  1492                     for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) {
       
  1493                         JCExpression subCatch = subCatch1.snd;
  1494                         int catchType = makeRef(tree.pos(), subCatch.type);
  1494                         int catchType = makeRef(tree.pos(), subCatch.type);
  1495                         registerCatch(tree.pos(),
  1495                         registerCatch(tree.pos(),
  1496                                       startpc, endpc, code.curCP(),
  1496                                       startpc, endpc, code.curCP(),
  1497                                       catchType);
  1497                                       catchType);
  1498                         if (subCatch.type.isAnnotated()) {
  1498                         for (Attribute.TypeCompound tc :  subCatch1.fst) {
  1499                             for (Attribute.TypeCompound tc :
  1499                             tc.position.setCatchInfo(catchType, startpc);
  1500                                      subCatch.type.getAnnotationMirrors()) {
       
  1501                                 tc.position.setCatchInfo(catchType, startpc);
       
  1502                             }
       
  1503                         }
  1500                         }
  1504                     }
  1501                     }
  1505                 }
  1502                 }
  1506                 VarSymbol exparam = tree.param.sym;
  1503                 VarSymbol exparam = tree.param.sym;
  1507                 code.statBegin(tree.pos);
  1504                 code.statBegin(tree.pos);
  1508                 code.markStatBegin();
  1505                 code.markStatBegin();
  1509                 int limit = code.nextreg;
  1506                 int limit = code.nextreg;
  1510                 int exlocal = code.newLocal(exparam);
  1507                 code.newLocal(exparam);
  1511                 items.makeLocalItem(exparam).store();
  1508                 items.makeLocalItem(exparam).store();
  1512                 code.statBegin(TreeInfo.firstStatPos(tree.body));
  1509                 code.statBegin(TreeInfo.firstStatPos(tree.body));
  1513                 genStat(tree.body, env, CRT_BLOCK);
  1510                 genStat(tree.body, env, CRT_BLOCK);
  1514                 code.endScopes(limit);
  1511                 code.endScopes(limit);
  1515                 code.statBegin(TreeInfo.endPos(tree.body));
  1512                 code.statBegin(TreeInfo.endPos(tree.body));
  1516             }
  1513             }
       
  1514         }
       
  1515         // where
       
  1516         List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotations(JCCatch tree) {
       
  1517             return TreeInfo.isMultiCatch(tree) ?
       
  1518                     catchTypesWithAnnotationsFromMulticatch((JCTypeUnion)tree.param.vartype, tree.param.sym.getRawTypeAttributes()) :
       
  1519                     List.of(new Pair<>(tree.param.sym.getRawTypeAttributes(), tree.param.vartype));
       
  1520         }
       
  1521         // where
       
  1522         List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotationsFromMulticatch(JCTypeUnion tree, List<TypeCompound> first) {
       
  1523             List<JCExpression> alts = tree.alternatives;
       
  1524             List<Pair<List<TypeCompound>, JCExpression>> res = List.of(new Pair<>(first, alts.head));
       
  1525             alts = alts.tail;
       
  1526 
       
  1527             while(alts != null && alts.head != null) {
       
  1528                 JCExpression alt = alts.head;
       
  1529                 if (alt instanceof JCAnnotatedType) {
       
  1530                     JCAnnotatedType a = (JCAnnotatedType)alt;
       
  1531                     res = res.prepend(new Pair<>(annotate.fromAnnotations(a.annotations), alt));
       
  1532                 } else {
       
  1533                     res = res.prepend(new Pair<>(List.nil(), alt));
       
  1534                 }
       
  1535                 alts = alts.tail;
       
  1536             }
       
  1537             return res.reverse();
  1517         }
  1538         }
  1518 
  1539 
  1519         /** Register a catch clause in the "Exceptions" code-attribute.
  1540         /** Register a catch clause in the "Exceptions" code-attribute.
  1520          */
  1541          */
  1521         void registerCatch(DiagnosticPosition pos,
  1542         void registerCatch(DiagnosticPosition pos,
  2050          */
  2071          */
  2051         void makeStringBuffer(DiagnosticPosition pos) {
  2072         void makeStringBuffer(DiagnosticPosition pos) {
  2052             code.emitop2(new_, makeRef(pos, stringBufferType));
  2073             code.emitop2(new_, makeRef(pos, stringBufferType));
  2053             code.emitop0(dup);
  2074             code.emitop0(dup);
  2054             callMethod(
  2075             callMethod(
  2055                 pos, stringBufferType, names.init, List.<Type>nil(), false);
  2076                     pos, stringBufferType, names.init, List.<Type>nil(), false);
  2056         }
  2077         }
  2057 
  2078 
  2058         /** Append value (on tos) to string buffer (on tos - 1).
  2079         /** Append value (on tos) to string buffer (on tos - 1).
  2059          */
  2080          */
  2060         void appendString(JCTree tree) {
  2081         void appendString(JCTree tree) {
  2098 
  2119 
  2099         /** Convert string buffer on tos to string.
  2120         /** Convert string buffer on tos to string.
  2100          */
  2121          */
  2101         void bufferToString(DiagnosticPosition pos) {
  2122         void bufferToString(DiagnosticPosition pos) {
  2102             callMethod(
  2123             callMethod(
  2103                 pos,
  2124                     pos,
  2104                 stringBufferType,
  2125                     stringBufferType,
  2105                 names.toString,
  2126                     names.toString,
  2106                 List.<Type>nil(),
  2127                     List.<Type>nil(),
  2107                 false);
  2128                     false);
  2108         }
  2129         }
  2109 
  2130 
  2110         /** Complete generating code for operation, with left operand
  2131         /** Complete generating code for operation, with left operand
  2111          *  already on stack.
  2132          *  already on stack.
  2112          *  @param lhs       The tree representing the left operand.
  2133          *  @param lhs       The tree representing the left operand.