nashorn/samples/dynalink/README
author dholmes
Wed, 24 Aug 2016 19:54:03 -0400
changeset 40669 252f9d8272af
parent 34549 412a690d4414
permissions -rw-r--r--
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure Reviewed-by: simonis, aph, kbarrett

This directory contains samples for Dynalink API (http://openjdk.java.net/jeps/276).
These samples require a jar file to be built and such jars be placed in the
classpath of the jjs tool. Linker samples are named with the naming pattern
"xyz_linker.js". These scripts build dynalink linker jar from java code and exec
another jjs process with appropriate classpath set.

Note: you need to build jdk9 forest and put "images/jdk/bin" in your PATH to use
these scripts. This is because these scripts use javac to build dynalink jar and
exec another jjs with classpath set! Alternatively, you can also manually build
dynalink linker jars and invoke sample scripts by putting linker jar in jjs tool's
classpath as well.

Dynalink samples:

* array_stream_linker.js

This sample builds ArrayStreamLinkerExporter.java and uses it in a sample script
called "array_stream.js". This linker adds "stream" property to Java array
objects. The "stream" property returns appropriate Stream type for the given
Java array (IntStream, DoubleStream ...).

* buffer_indexing_linker.js

This sample builds BufferIndexingLinkerExporter.java and uses it in a sample script
called "buffer_index.js". This linker adds array-like indexed access, indexed assignment
and "length" property to Java NIO Buffer objects. Script can treat NIO Buffer objects
as if those are just array objects.

* dom_linker.js

This sample builds DOMLinkerExporter.java and uses it in a sample script
called "dom_linker_gutenberg.js". This linker handles DOM Element objects to add
properties to access child elements of a given element by child element tag name.
This simplifies script access of parsed XML DOM Documents.

* missing_method_linker.js

This sample builds MissingMethodLinkerExporter.java and uses it in a sample script
called "missing_method.js". This linker supports Smalltalk-style "doesNotUnderstand"
calls on Java objects. i.e., A Java class can implement MissingMethodHandler interface
with one method named "doesNotUnderstand". When script accesses a method on such
object and if that method does not exist in the Java class (or any of it's supertypes),
then "doesNotUnderstand" method is invoked.

* underscore_linker.js

This sample builds UnderscoreNameLinkerExporter.java and uses it in a sample script
called "underscore.js". This linker converts underscore separated names to Camel Case
names (as used in Java APIs). You can call Java APIs using Ruby-like naming convention
and this linker converts method names to CamelCase!