Mon, 11 May 2015 13:28:14 +0530
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
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Jun 01 11:07:29 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon May 11 13:28:14 2015 +0530 1.3 @@ -1256,6 +1256,9 @@ 1.4 return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); 1.5 case APPLY: 1.6 return true; 1.7 + case NEWCLASS: 1.8 + JCNewClass nc = (JCNewClass) rec; 1.9 + return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc); 1.10 default: 1.11 return false; 1.12 } 1.13 @@ -1310,17 +1313,24 @@ 1.14 Type site; 1.15 1.16 if (rec != null) { 1.17 - if (rec.hasTag(APPLY)) { 1.18 - Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 1.19 - if (recSym == null) 1.20 - return null; 1.21 - Symbol resolvedReturnType = 1.22 - analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 1.23 - if (resolvedReturnType == null) 1.24 - return null; 1.25 - site = resolvedReturnType.type; 1.26 - } else { 1.27 - site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 1.28 + switch (rec.getTag()) { 1.29 + case APPLY: 1.30 + Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 1.31 + if (recSym == null) 1.32 + return null; 1.33 + Symbol resolvedReturnType = 1.34 + analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 1.35 + if (resolvedReturnType == null) 1.36 + return null; 1.37 + site = resolvedReturnType.type; 1.38 + break; 1.39 + case NEWCLASS: 1.40 + JCNewClass nc = (JCNewClass) rec; 1.41 + site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type; 1.42 + break; 1.43 + default: 1.44 + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 1.45 + break; 1.46 } 1.47 } else { 1.48 site = env.enclClass.sym.type;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java Mon May 11 13:28:14 2015 +0530 2.3 @@ -0,0 +1,178 @@ 2.4 +/* 2.5 + * Copyright (c) 2015, 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 +/* 2.28 + * @test 2.29 + * @bug 8079613 2.30 + * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such 2.31 + * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest 2.32 + */ 2.33 + 2.34 +public class DeeplyChainedNonPolyExpressionTest { 2.35 + static class JSO { 2.36 + 2.37 + JSO put(String s, Object y) { 2.38 + return null; 2.39 + } 2.40 + 2.41 + JSO put(java.lang.String x, java.util.Collection<String> y) { 2.42 + return null; 2.43 + } 2.44 + 2.45 + JSO put(java.lang.String x, int y) { 2.46 + return null; 2.47 + } 2.48 + 2.49 + JSO put(java.lang.String x, long y) { 2.50 + return null; 2.51 + } 2.52 + 2.53 + JSO put(java.lang.String x, double y) { 2.54 + return null; 2.55 + } 2.56 + 2.57 + JSO put(java.lang.String x, java.util.Map<String, String> y) { 2.58 + return null; 2.59 + } 2.60 + 2.61 + JSO put(java.lang.String x, boolean y) { 2.62 + return null; 2.63 + } 2.64 + } 2.65 + 2.66 + static class JSA { 2.67 + 2.68 + JSA put(Object o) { 2.69 + return null; 2.70 + } 2.71 + 2.72 + JSA put(int i, Object x) { 2.73 + return null; 2.74 + } 2.75 + 2.76 + JSA put(boolean x) { 2.77 + return null; 2.78 + } 2.79 + 2.80 + JSA put(int x) { 2.81 + return null; 2.82 + } 2.83 + 2.84 + JSA put(int i, int x) { 2.85 + return null; 2.86 + } 2.87 + 2.88 + JSA put(int x, boolean y) { 2.89 + return null; 2.90 + } 2.91 + 2.92 + JSA put(int i, long x) { 2.93 + return null; 2.94 + } 2.95 + 2.96 + JSA put(long x) { 2.97 + return null; 2.98 + } 2.99 + 2.100 + JSA put(java.util.Collection<String> x) { 2.101 + return null; 2.102 + } 2.103 + 2.104 + JSA put(int i, java.util.Collection<String> x) { 2.105 + return null; 2.106 + } 2.107 + 2.108 + JSA put(int i, java.util.Map<String, String> x) { 2.109 + return null; 2.110 + } 2.111 + 2.112 + JSA put(java.util.Map<String, String> x) { 2.113 + return null; 2.114 + } 2.115 + 2.116 + JSA put(int i, double x) { 2.117 + return null; 2.118 + } 2.119 + 2.120 + JSA put(double x) { 2.121 + return null; 2.122 + } 2.123 + } 2.124 + 2.125 + public static void main(String [] args) { 2.126 + } 2.127 + public static void foo() { 2.128 + new JSO() 2.129 + .put("s", new JSA()) 2.130 + .put("s", new JSA()) 2.131 + .put("s", new JSO() 2.132 + .put("s", new JSO() 2.133 + .put("s", new JSA().put("s")) 2.134 + .put("s", new JSA()) 2.135 + .put("s", new JSO() 2.136 + .put("s", new JSO() 2.137 + .put("s", new JSA().put("s").put("s")) 2.138 + .put("s", new JSA()) 2.139 + .put("s", new JSO() 2.140 + .put("s", new JSO() 2.141 + .put("s", new JSA().put("s").put("s").put("s") 2.142 + .put("s").put("s").put("s") 2.143 + .put("s").put("s")) 2.144 + .put("s", new JSA()) 2.145 + .put("s", new JSO() 2.146 + .put("s", new JSO() 2.147 + .put("s", new JSA().put("s")) 2.148 + .put("s", new JSA()) 2.149 + ) 2.150 + ) 2.151 + ) 2.152 + ) 2.153 + ) 2.154 + .put("s", new JSO() 2.155 + .put("s", new JSA().put("s")) 2.156 + .put("s", new JSA()) 2.157 + .put("s", new JSO() 2.158 + .put("s", new JSO() 2.159 + .put("s", new JSA().put("s").put("s")) 2.160 + .put("s", new JSA()) 2.161 + .put("s", new JSO() 2.162 + .put("s", new JSO() 2.163 + .put("s", new JSA().put("s").put("s").put("s") 2.164 + .put("s").put("s").put("s") 2.165 + .put("s").put("s")) 2.166 + .put("s", new JSA()) 2.167 + .put("s", new JSO() 2.168 + .put("s", new JSO() 2.169 + .put("s", new JSA().put("s")) 2.170 + .put("s", new JSA())) 2.171 + ) 2.172 + ) 2.173 + ) 2.174 + ) 2.175 + ) 2.176 + ) 2.177 + ) 2.178 + ) 2.179 + ); 2.180 + } 2.181 +}