Nasgen: static initializer prefix: member count is sometimes 1 more than what is needed

Ahmed Ashour asashour at
Wed Jun 17 13:46:11 UTC 2015

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:

   {      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);   }

More information about the nashorn-dev mailing list