JDK-8065985 : Inlining failure of Number.doubleValue() in JSType.toNumeric() causes 15% peak perf regresion on Box2D
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40,9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-11-26
  • Updated: 2017-08-09
  • Resolved: 2014-11-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b42Fixed
Description
Inlining failure of Number.doubleValue() for Double in JSType.toNumeric() costs ~15% peak performance on some of the Octane benchmarks (e.g. Box2D). 
 
Comments
noreg-perf: fixes intermittent slowdowns on Octane (e.g. Box2D)
27-11-2014

Current inlining heuristics in HotSpot aren't stable enough for this particular case. Depending on the execution sequence and gathered profile data, Number.doubleValue() can be devirtualized to Double.doubleValue() or emitted as a pure virtual call. The problem is that Number.doubleValue() is a polymorphic call site. Most of the time it has Double receiver, but sometimes it's Integer and (very rarely) something else. Most of the time, Double case matches major receiver heuristics ( TypeProfileMajorReceiverPercent [=90%]), but if compilation is triggered earlier, profile data could be "incomplete" (Double cases <90% of all cases). Bimorphic inlining doesn't work here, because the call site has >2 receivers.
26-11-2014

Suggested fix: diff --git a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java --- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java @@ -702,6 +702,9 @@ * @return a number */ public static double toNumber(final Object obj) { + if (obj instanceof Double) { + return (Double)obj; + } if (obj instanceof Number) { return ((Number)obj).doubleValue(); }
26-11-2014