8079613: Deeply chained expressions + several overloads + unnecessary inference result in excessive compile times.
authorsadayapalam
Mon, 11 May 2015 13:28:14 +0530
changeset 30728 f0c022c5290c
parent 30727 a4dac07f827c
child 30729 398f0f51917a
8079613: Deeply chained expressions + several overloads + unnecessary inference result in excessive compile times. Summary: Eliminate compile time performance bottlneck due to mischaracterization of standalone expressions as being poly expressions. Reviewed-by: mcimadamore, jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
langtools/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon May 18 09:27:09 2015 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon May 11 13:28:14 2015 +0530
@@ -1317,6 +1317,9 @@
                         return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType);
                     case APPLY:
                         return true;
+                    case NEWCLASS:
+                        JCNewClass nc = (JCNewClass) rec;
+                        return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc);
                     default:
                         return false;
                 }
@@ -1371,17 +1374,24 @@
             Type site;
 
             if (rec != null) {
-                if (rec.hasTag(APPLY)) {
-                    Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec);
-                    if (recSym == null)
-                        return null;
-                    Symbol resolvedReturnType =
-                            analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer);
-                    if (resolvedReturnType == null)
-                        return null;
-                    site = resolvedReturnType.type;
-                } else {
-                    site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type;
+                switch (rec.getTag()) {
+                    case APPLY:
+                        Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec);
+                        if (recSym == null)
+                            return null;
+                        Symbol resolvedReturnType =
+                                analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer);
+                        if (resolvedReturnType == null)
+                            return null;
+                        site = resolvedReturnType.type;
+                        break;
+                    case NEWCLASS:
+                        JCNewClass nc = (JCNewClass) rec;
+                        site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type;
+                        break;
+                    default:
+                        site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type;
+                        break;
                 }
             } else {
                 site = env.enclClass.sym.type;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java	Mon May 11 13:28:14 2015 +0530
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8079613
+ * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such
+ * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest
+ */
+
+public class DeeplyChainedNonPolyExpressionTest {
+    static class JSO {
+
+        JSO put(String s, Object y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, java.util.Collection<String> y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, int y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, long y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, double y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, java.util.Map<String, String> y) {
+            return null;
+        }
+
+        JSO put(java.lang.String x, boolean y) {
+            return null;
+        }
+    }
+
+    static class JSA {
+
+        JSA put(Object o) {
+            return null;
+        }
+
+        JSA put(int i, Object x) {
+            return null;
+        }
+
+        JSA put(boolean x) {
+            return null;
+        }
+
+        JSA put(int x) {
+            return null;
+        }
+
+        JSA put(int i, int x) {
+            return null;
+        }
+
+        JSA put(int x, boolean y) {
+            return null;
+        }
+
+        JSA put(int i, long x) {
+            return null;
+        }
+
+        JSA put(long x) {
+            return null;
+        }
+
+        JSA put(java.util.Collection<String> x) {
+            return null;
+        }
+
+        JSA put(int i, java.util.Collection<String> x) {
+            return null;
+        }
+
+        JSA put(int i, java.util.Map<String, String> x) {
+            return null;
+        }
+
+        JSA put(java.util.Map<String, String> x) {
+            return null;
+        }
+
+        JSA put(int i, double x) {
+            return null;
+        }
+
+        JSA put(double x) {
+            return null;
+        }
+    }
+
+    public static void main(String [] args) {
+    }
+    public static void foo() {
+         new JSO()
+          .put("s", new JSA())
+          .put("s", new JSA())
+          .put("s", new JSO()
+            .put("s", new JSO()
+              .put("s", new JSA().put("s"))
+              .put("s", new JSA())
+              .put("s", new JSO()
+                .put("s", new JSO()
+                  .put("s", new JSA().put("s").put("s"))
+                  .put("s", new JSA())
+                  .put("s", new JSO()
+                    .put("s", new JSO()
+                      .put("s", new JSA().put("s").put("s").put("s")
+                            .put("s").put("s").put("s")
+                            .put("s").put("s"))
+                      .put("s", new JSA())
+                      .put("s", new JSO()
+                        .put("s", new JSO()
+                          .put("s", new JSA().put("s"))
+                          .put("s", new JSA())
+                        )
+                      )
+                    )
+                  )
+                )
+                .put("s", new JSO()
+                  .put("s", new JSA().put("s"))
+                  .put("s", new JSA())
+                  .put("s", new JSO()
+                  .put("s", new JSO()
+                    .put("s", new JSA().put("s").put("s"))
+                    .put("s", new JSA())
+                    .put("s", new JSO()
+                      .put("s", new JSO()
+                        .put("s", new JSA().put("s").put("s").put("s")
+                                .put("s").put("s").put("s")
+                                .put("s").put("s"))
+                        .put("s", new JSA())
+                        .put("s", new JSO()
+                          .put("s", new JSO()
+                            .put("s", new JSA().put("s"))
+                            .put("s", new JSA()))
+                          )
+                        )
+                      )
+                    )
+                  )
+                )
+              )
+            )
+          );
+  }
+}