JDK-8117883 : nasgen prototype, instance member count calculation is wrong
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-06-17
  • Updated: 2015-09-29
  • Resolved: 2015-06-18
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
8u60Fixed 9 b70Fixed
Description
This issue was reported via a nashorn-dev email: http://mail.openjdk.java.net/pipermail/nashorn-dev/2015-June/004784.html

--- email content duplicated here ----
Hi all,
During digging a little into the bytecode generated by Nasgen, there is a pattern of "new ArrayList(memberCount)", but that member count is 1 more that what is needed, this is not always the case, as it depends on the members.
This doesn't have functional impact, but every single byte counts 
The root cause for Prototype, is that Constructor are included in the total count, but it is not added.

To give example:
NativeArrayBuffer$Prototype:

   {      ArrayList list = new ArrayList(2);
      list.add(AccessorProperty.create("slice", 2, "G$slice", "S$slice"));      $nasgenmap$ = PropertyMap.newMap(list);   }
although the list will contain a single entry, ArrayList was initialized by 2.
This also happens in the ScriptClass, e.g.:
NativeArray:   {      ArrayList list = new ArrayList(2);
      list.add(AccessorProperty.create("length", 6, "length", "length"));      $nasgenmap$ = PropertyMap.newMap(list);   }
But it is fine in, e.g.:
ArrayBufferView:   {      ArrayList list = new ArrayList(4);      list.add(AccessorProperty.create("buffer", 7, "buffer", (MethodHandle)null));      list.add(AccessorProperty.create("byteOffset", 7, "byteOffset", (MethodHandle)null));      list.add(AccessorProperty.create("byteLength", 7, "byteLength", (MethodHandle)null));      list.add(AccessorProperty.create("length", 7, "length", (MethodHandle)null));      $nasgenmap$ = PropertyMap.newMap(list);   }
Thanks,Ahmed