7024568: Very long method resolution causing OOM error

Mon, 07 Mar 2011 14:11:48 +0000

author
mcimadamore
date
Mon, 07 Mar 2011 14:11:48 +0000
changeset 913
74f0c05c51eb
parent 912
5e6c661891da
child 914
ca32f2986301

7024568: Very long method resolution causing OOM error
Summary: Resolve.findMethod scans same receiver type more than once in certain inheritance graphs
Reviewed-by: jjg
Contributed-by: jan.lahoda@oracle.com

src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/7024568/T7024568.java file | annotate | diff | comparison | revisions
test/tools/javac/7024568/T7024568.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Mar 04 19:59:04 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Mar 07 14:11:48 2011 +0000
     1.3 @@ -45,7 +45,9 @@
     1.4  import javax.lang.model.element.ElementVisitor;
     1.5  
     1.6  import java.util.Map;
     1.7 +import java.util.Set;
     1.8  import java.util.HashMap;
     1.9 +import java.util.HashSet;
    1.10  
    1.11  /** Helper class for name resolution, used mostly by the attribution phase.
    1.12   *
    1.13 @@ -896,7 +898,8 @@
    1.14                            bestSoFar,
    1.15                            allowBoxing,
    1.16                            useVarargs,
    1.17 -                          operator);
    1.18 +                          operator,
    1.19 +                          new HashSet<TypeSymbol>());
    1.20      }
    1.21      // where
    1.22      private Symbol findMethod(Env<AttrContext> env,
    1.23 @@ -909,11 +912,13 @@
    1.24                                Symbol bestSoFar,
    1.25                                boolean allowBoxing,
    1.26                                boolean useVarargs,
    1.27 -                              boolean operator) {
    1.28 +                              boolean operator,
    1.29 +                              Set<TypeSymbol> seen) {
    1.30          for (Type ct = intype; ct.tag == CLASS || ct.tag == TYPEVAR; ct = types.supertype(ct)) {
    1.31              while (ct.tag == TYPEVAR)
    1.32                  ct = ct.getUpperBound();
    1.33              ClassSymbol c = (ClassSymbol)ct.tsym;
    1.34 +            if (!seen.add(c)) return bestSoFar;
    1.35              if ((c.flags() & (ABSTRACT | INTERFACE | ENUM)) == 0)
    1.36                  abstractok = false;
    1.37              for (Scope.Entry e = c.members().lookup(name);
    1.38 @@ -942,7 +947,7 @@
    1.39                      bestSoFar = findMethod(env, site, name, argtypes,
    1.40                                             typeargtypes,
    1.41                                             l.head, abstractok, bestSoFar,
    1.42 -                                           allowBoxing, useVarargs, operator);
    1.43 +                                           allowBoxing, useVarargs, operator, seen);
    1.44                  }
    1.45                  if (concrete != bestSoFar &&
    1.46                      concrete.kind < ERR  && bestSoFar.kind < ERR &&
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/7024568/T7024568.java	Mon Mar 07 14:11:48 2011 +0000
     2.3 @@ -0,0 +1,46 @@
     2.4 +/*
     2.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/* @test
    2.28 + * @bug 7024568
    2.29 + * @summary Very long method resolution causing OOM error
    2.30 + * @compile/fail/ref=T7024568.out -XDrawDiagnostics T7024568.java
    2.31 + */
    2.32 +
    2.33 +class Main {
    2.34 +    void test(Obj o) {
    2.35 +        o.test(0, 0, 0, 0, 0, 0, 0, 0, undefined);
    2.36 +    }
    2.37 +}
    2.38 +
    2.39 +interface Test {
    2.40 +    public void test(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, String str);
    2.41 +    public void test(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, long l);
    2.42 +}
    2.43 +
    2.44 +interface Obj extends Test, A, B, C, D, E {}
    2.45 +interface A extends Test {}
    2.46 +interface B extends A, Test {}
    2.47 +interface C extends A, B, Test {}
    2.48 +interface D extends A, B, C, Test {}
    2.49 +interface E extends A, B, C, D, Test {}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/7024568/T7024568.out	Mon Mar 07 14:11:48 2011 +0000
     3.3 @@ -0,0 +1,2 @@
     3.4 +T7024568.java:32:40: compiler.err.cant.resolve.location: kindname.variable, undefined, , , (compiler.misc.location: kindname.class, Main, null)
     3.5 +1 error

mercurial