JDK-8011964 : need indexed access to externally-managed ByteBuffer
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-04-11
  • Updated: 2014-07-29
  • Resolved: 2014-02-14
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
8u20Fixed 9 b04Fixed
Description
An application embedding nashorn for high-performance IO would like to use an external ByteBuffer (perhaps a direct NIO ByteBuffer) as the backing storage for efficiency (think zero-copy) and still be able to use the external ByteBuffer as a JavaScript array. For an example, see the function SetIndexedPropertiesToExternalArrayData in the v8 API.


Comments
Another approach based on JSObject has been prototyped. JSObject allows for faster indexed access (2 to 3 time faster), the drawback is the access to properties that is much slower. Each property access is resolved without any optimisation. Along the performance aspect, here is a list of side effects: - toString is not routed to the JSObject.getMember - toJSON is not routed to the JSObject.getMember - Object.(getPrototypeOf, getOwnPropertyNames, ...) are getting you a TypeError: net.java.avatar.js.buffer.Buffer$IndexedBuffer$$NashornJavaAdapter@34a75079 is not an Object - JSObject passed to a Java method that expects a String doesn't benefit from automatic conversion - b instanceof <Constructor> doesn't make JSObject.isInstanceOf to be called. - can't set the prototype of a JSObject. - JSObject instance set as a prototype as the same issue as JSAdapter, method added to it are not inherited. The JSObject can't be today used as a replacement for JSAdapter.
01-10-2013

Attachment buffer_linker.zip is webrev to add nio Buffer dynalink linker to support integer indexed access of buffer content
15-04-2013

There are two parts to it: ( 1 ) make nio Buffer objects to support array-like indexing. ( 2 ) have JS arrays backup storage to be defined externally. For part ( 1 ), we could define nashorn specific dynalink linker for nio Buffer objects - just like Map, List are treated differently for indexed property access and indexed integer access. We could have a dynalink linker for integer index access of nio Buffer contents. For part ( 2 ), we could use __noSuchProperty__ support for indexed property access. That way, it will be possible to define __noSuchProperty__ on any object and find integer indexed properties (or even string indices) be stored elsewhere outside the object.
15-04-2013