JDK-8055911 : Questionable String.intern() in jdk.nashorn.internal.ir.IdentNode()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-08-25
  • Updated: 2015-06-04
  • Resolved: 2014-08-26
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 b29Fixed
Description
Profiling a simple scenario: 

$ ~/Install/jdk9u20/bin/java -jar dist/nashorn.jar -Dnashorn.typeInfo.disabled=false --class-cache-size=0 --persistent-code-cache=false -scripting --log=time test/script/basic/compile-octane.js -- --iterations 5 

...yields a few simple low-hanging fruits, here is one of them. Out of 320 seconds of run, 8 seconds are spent here: 

8.410	jdk.nashorn.internal.ir.IdentNode.<init>(long, int, java.lang.String)
8.410	java.lang.String.intern()

I don't see off-hand why interning is needed for IdentNode.name. We compare through String.equals all the time. We escape the name via getName(), but Javadocs do not tell us to expect the interned String. If this is deduplication strategy, then doing the throw-away HashMap-based deduplication will save cycles going to VM, and save SystemDictionary from contamination.

Following up on this might require benchmarking to choose the proper interning/de-duplication strategy.
Comments
We indeed did it to cut down on memory use. It could be replaced with a throwaway HashMap in the parser though. If, in a largish script (such as Mandreel) you have ~11k IdentNodes for the same name (I think in Mandreel that actually happens), that adds up quickly.
25-08-2014

I think we introduced this for footprint, Attila, but it looks like the cost is larger than the taste. As we only do equals comparisons anyway, it might be good to revisit. Assigning to you as I think you wrote the original code and I Can't remember why. Vague memories of packing the mandreel ast or something
25-08-2014

See e.g.: http://hg.openjdk.java.net/code-tools/jmh/file/f3a68bbd0f15/jmh-core/src/main/java/org/openjdk/jmh/util/Deduplicator.java
25-08-2014