langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
changeset 45504 ea7475564d07
parent 45316 170696ddb377
equal deleted inserted replaced
45503:d23ae2d67a5d 45504:ea7475564d07
    37 
    37 
    38 import com.sun.tools.javac.code.Symbol.*;
    38 import com.sun.tools.javac.code.Symbol.*;
    39 import com.sun.tools.javac.code.Type.*;
    39 import com.sun.tools.javac.code.Type.*;
    40 import com.sun.tools.javac.jvm.Code.*;
    40 import com.sun.tools.javac.jvm.Code.*;
    41 import com.sun.tools.javac.jvm.Items.*;
    41 import com.sun.tools.javac.jvm.Items.*;
       
    42 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    42 import com.sun.tools.javac.tree.EndPosTable;
    43 import com.sun.tools.javac.tree.EndPosTable;
    43 import com.sun.tools.javac.tree.JCTree.*;
    44 import com.sun.tools.javac.tree.JCTree.*;
    44 
    45 
    45 import static com.sun.tools.javac.code.Flags.*;
    46 import static com.sun.tools.javac.code.Flags.*;
    46 import static com.sun.tools.javac.code.Kinds.Kind.*;
    47 import static com.sun.tools.javac.code.Kinds.Kind.*;
   268             for (List<Type> args = t.getParameterTypes(); args.nonEmpty(); args = args.tail)
   269             for (List<Type> args = t.getParameterTypes(); args.nonEmpty(); args = args.tail)
   269                 checkDimension(pos, args.head);
   270                 checkDimension(pos, args.head);
   270             break;
   271             break;
   271         case ARRAY:
   272         case ARRAY:
   272             if (types.dimensions(t) > ClassFile.MAX_DIMENSIONS) {
   273             if (types.dimensions(t) > ClassFile.MAX_DIMENSIONS) {
   273                 log.error(pos, "limit.dimensions");
   274                 log.error(pos, Errors.LimitDimensions);
   274                 nerrs++;
   275                 nerrs++;
   275             }
   276             }
   276             break;
   277             break;
   277         default:
   278         default:
   278             break;
   279             break;
   515         if (nerrs != 0 || // only complain about a long string once
   516         if (nerrs != 0 || // only complain about a long string once
   516             constValue == null ||
   517             constValue == null ||
   517             !(constValue instanceof String) ||
   518             !(constValue instanceof String) ||
   518             ((String)constValue).length() < Pool.MAX_STRING_LENGTH)
   519             ((String)constValue).length() < Pool.MAX_STRING_LENGTH)
   519             return;
   520             return;
   520         log.error(pos, "limit.string");
   521         log.error(pos, Errors.LimitString);
   521         nerrs++;
   522         nerrs++;
   522     }
   523     }
   523 
   524 
   524     /** Insert instance initializer code into initial constructor.
   525     /** Insert instance initializer code into initial constructor.
   525      *  @param md        The tree potentially representing a
   526      *  @param md        The tree potentially representing a
   886                 extras++;
   887                 extras++;
   887             }
   888             }
   888             //      System.err.println("Generating " + meth + " in " + meth.owner); //DEBUG
   889             //      System.err.println("Generating " + meth + " in " + meth.owner); //DEBUG
   889             if (Code.width(types.erasure(env.enclMethod.sym.type).getParameterTypes()) + extras >
   890             if (Code.width(types.erasure(env.enclMethod.sym.type).getParameterTypes()) + extras >
   890                 ClassFile.MAX_PARAMETERS) {
   891                 ClassFile.MAX_PARAMETERS) {
   891                 log.error(tree.pos(), "limit.parameters");
   892                 log.error(tree.pos(), Errors.LimitParameters);
   892                 nerrs++;
   893                 nerrs++;
   893             }
   894             }
   894 
   895 
   895             else if (tree.body != null) {
   896             else if (tree.body != null) {
   896                 // Create a new code structure and initialize it.
   897                 // Create a new code structure and initialize it.
   903                     startpcCrt = initCode(tree, env, fatcode);
   904                     startpcCrt = initCode(tree, env, fatcode);
   904                     genStat(tree.body, env);
   905                     genStat(tree.body, env);
   905                 }
   906                 }
   906 
   907 
   907                 if (code.state.stacksize != 0) {
   908                 if (code.state.stacksize != 0) {
   908                     log.error(tree.body.pos(), "stack.sim.error", tree);
   909                     log.error(tree.body.pos(), Errors.StackSimError(tree.sym));
   909                     throw new AssertionError();
   910                     throw new AssertionError();
   910                 }
   911                 }
   911 
   912 
   912                 // If last statement could complete normally, insert a
   913                 // If last statement could complete normally, insert a
   913                 // return at the end.
   914                 // return at the end.
  1534                 endpc1 == endpc &&
  1535                 endpc1 == endpc &&
  1535                 handler_pc1 == handler_pc) {
  1536                 handler_pc1 == handler_pc) {
  1536                 code.addCatch(startpc1, endpc1, handler_pc1,
  1537                 code.addCatch(startpc1, endpc1, handler_pc1,
  1537                               (char)catch_type);
  1538                               (char)catch_type);
  1538             } else {
  1539             } else {
  1539                 log.error(pos, "limit.code.too.large.for.try.stmt");
  1540                 log.error(pos, Errors.LimitCodeTooLargeForTryStmt);
  1540                 nerrs++;
  1541                 nerrs++;
  1541             }
  1542             }
  1542         }
  1543         }
  1543 
  1544 
  1544     public void visitIf(JCIf tree) {
  1545     public void visitIf(JCIf tree) {
  1767          *  of dimensions.
  1768          *  of dimensions.
  1768          */
  1769          */
  1769         Item makeNewArray(DiagnosticPosition pos, Type type, int ndims) {
  1770         Item makeNewArray(DiagnosticPosition pos, Type type, int ndims) {
  1770             Type elemtype = types.elemtype(type);
  1771             Type elemtype = types.elemtype(type);
  1771             if (types.dimensions(type) > ClassFile.MAX_DIMENSIONS) {
  1772             if (types.dimensions(type) > ClassFile.MAX_DIMENSIONS) {
  1772                 log.error(pos, "limit.dimensions");
  1773                 log.error(pos, Errors.LimitDimensions);
  1773                 nerrs++;
  1774                 nerrs++;
  1774             }
  1775             }
  1775             int elemcode = Code.arraycode(elemtype);
  1776             int elemcode = Code.arraycode(elemtype);
  1776             if (elemcode == 0 || (elemcode == 1 && ndims == 1)) {
  1777             if (elemcode == 0 || (elemcode == 1 && ndims == 1)) {
  1777                 code.emitAnewarray(makeRef(pos, elemtype), type);
  1778                 code.emitAnewarray(makeRef(pos, elemtype), type);
  2179 
  2180 
  2180             for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
  2181             for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
  2181                 genDef(l.head, localEnv);
  2182                 genDef(l.head, localEnv);
  2182             }
  2183             }
  2183             if (pool.numEntries() > Pool.MAX_ENTRIES) {
  2184             if (pool.numEntries() > Pool.MAX_ENTRIES) {
  2184                 log.error(cdef.pos(), "limit.pool");
  2185                 log.error(cdef.pos(), Errors.LimitPool);
  2185                 nerrs++;
  2186                 nerrs++;
  2186             }
  2187             }
  2187             if (nerrs != 0) {
  2188             if (nerrs != 0) {
  2188                 // if errors, discard code
  2189                 // if errors, discard code
  2189                 for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
  2190                 for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {