RFR: 8061472 String.format in DeferredAttr.DeferredTypeMap constructor leads to excessive object creation
Joel Borggrén-Franck
joel.franck at oracle.com
Wed Dec 17 17:18:28 UTC 2014
Hi,
Claes in the performance team noticed that we spend a lot of time in String.format() in the constructor in DeferredTypeMap. For an sjavac compile of the jdk a profile could show as high as 2% time spent in that method, excluding the cost of garbage collection.
This simple fix results in up to a 5% performance enhancement compiling the Jdk in a micro benchmark setup.
Bug: https://bugs.openjdk.java.net/browse/JDK-8061472
Patch is really small:
cheers
/Joel
diff -r 46105e2a56c7 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Dec 17 16:47:56 2014 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Dec 17 17:58:33 2014 +0100
@@ -352,11 +352,26 @@
* type are reversed after the speculative round finishes. This means the
* expression tree will be left in a blank state.
*/
- SPECULATIVE,
+ SPECULATIVE {
+ @Override
+ public String getDescriptiveName() {
+ return "deferredTypeMap[SPECULATIVE]";
+ }
+ },
/**
* This is the plain type-checking mode. Produces side-effects on the underlying AST node
*/
- CHECK
+ CHECK {
+ @Override
+ public String getDescriptiveName() {
+ return "deferredTypeMap[CHECK]";
+ }
+ };
+
+ /**
+ * @return a descriptive name of this mode
+ */
+ public abstract String getDescriptiveName();
}
/**
@@ -849,7 +864,7 @@
DeferredAttrContext deferredAttrContext;
protected DeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
- super(String.format("deferredTypeMap[%s]", mode));
+ super(mode.getDescriptiveName());
this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase,
infer.emptyContext, emptyDeferredAttrContext, types.noWarnings);
}
More information about the compiler-dev
mailing list