changeset 2852:610ec7dcf431

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
author sadayapalam
date Mon, 11 May 2015 13:28:14 +0530
parents 1b59f823d630
children 9ec429ab0e7e
files src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java
diffstat 2 files changed, 199 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon Jun 01 11:07:29 2015 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon May 11 13:28:14 2015 +0530
@@ -1256,6 +1256,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;
                 }
@@ -1310,17 +1313,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/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()))
+                          )
+                        )
+                      )
+                    )
+                  )
+                )
+              )
+            )
+          );
+  }
+}