8203838: javac performance regression in 11+11
Summary: Share method check exception
Reviewed-by: vromero
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Jun 14 17:32:31 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jun 15 19:24:15 2018 +0100
@@ -69,8 +69,6 @@
import javax.lang.model.element.ElementVisitor;
-import com.sun.tools.javac.comp.Infer.InferenceException;
-
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Flags.STATIC;
@@ -818,8 +816,28 @@
String key = inferDiag ? diag.inferKey : diag.basicKey;
throw inferDiag ?
infer.error(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)) :
- new InapplicableMethodException(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args));
- }
+ methodCheckFailure.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args));
+ }
+
+ /**
+ * To eliminate the overhead associated with allocating an exception object in such an
+ * hot execution path, we use flyweight pattern - and share the same exception instance
+ * across multiple method check failures.
+ */
+ class SharedInapplicableMethodException extends InapplicableMethodException {
+ private static final long serialVersionUID = 0;
+
+ SharedInapplicableMethodException() {
+ super(null);
+ }
+
+ SharedInapplicableMethodException setMessage(JCDiagnostic details) {
+ this.diagnostic = details;
+ return this;
+ }
+ }
+
+ SharedInapplicableMethodException methodCheckFailure = new SharedInapplicableMethodException();
public MethodCheck mostSpecificCheck(List<Type> actuals) {
return nilMethodCheck;