Nashorn in the Future
Oracle Corporation JapanFusion Middleware Business UnitNISHIKAWA, Akihiro
201548
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Safe Harbor Statement The following is intended to outline our general product direcIon. It is intended for informaIon purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or funcIonality, and should not be relied upon in making purchasing decisions. The development, release, and Iming of any features or funcIonality described for Oracles products remains at the sole discreIon of Oracle.
2
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Agenda
What's Nashorn?
8u20
8u40
In the future...
1
2
3
4
3
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Whats Nashorn?
4
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Nashorn
Rhino
InvokeDynamic (JSR-292) Proof of Concept
5
Java 8JavaScript Engine (JEP 174)
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Nashorn
ECMAScript-262 EdiIon 5.1
javax.script (JSR 223) API
JavaJavaScript
jjs
Java 8JavaScript Engine (JEP 174)
6
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
jjs Hello World Lambda Expression, Stream
jjs scripting Web API
jjs fx WebView
7
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Lambda ExpressionFuncIon // Java array.stream().sorted(Comparator.naturalOrder()) .forEach( t -> sortedArray.add(t) ); // Nashorn array.stream().sorted(Comparator.naturalOrder()) .forEach(function(t) sortedArray.add(t));
8
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Java(1)ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); // engine.eval("print('hello world')"); // hello world engine.eval(new FileReader(hello.js)); // hello.js
9
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Java(2)
engine.eval("function hello(name){ print('Hello, ' + name); }"); Invocable inv=(Invocable)engine; // Hello, Taro Object obj= inv.invokeFunction("hello","Taro");
10
JavaScriptfunc:on
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Java(3)
engine.eval("function run(){ print('run() called'); }"); Invocable inv =(Invocable)engine; Runnable r=inv.getInterface(Runnable.class); Thread th=new Threads(r); th.start(); th.join();
11
Script func:onInterface
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u20
12
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u20
JIT/JDK
13
20148
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
const var
false
8u40const
14
--const-as-var=true|false
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
ScriptJava PackageClass
false
15
--no-java=true|false (-nj)
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
ECMAScript
Java.typeExtension -scripting
16
--no-syntax-extensions (-nse)
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
#sourceURL@sourceURL
Eval//# sourceURL=myScript.js @sourceURL=myScript.js
17
JDK-8032068 : implement @sourceURL and #sourceURL direc:ves
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u20
Java engine.eval(new URLReader(myScriptURL));
JavaScript load(url);
18
JDK-8021350 : Share script classes between threads/globals within context
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u40
19
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u40
OpImisIc typing (JEP 196) Code Persistence (JEP 194)
Class Filter (JEP 202)
ECMAScript 6 Lexical-scoped variables and constant deniIon (JEP 203)
20
JEP
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 196: OpImisIc Typing
type
--optimistic-types=true|false (-ot) false
21
Java
int long
double
Object
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 196: OpImisIc Typing
nashorn.typeInfo.maxFiles 0
nashorn.typeInfo.cacheDir Windows: ${java.io.tmpdir}\com.oracle.java.NashornTypeInfo LinuxSolaris: ~/.cache/com.oracle.java.NashornTypeInfo Mac OS X: ~/Library/Caches/com.oracle.java.NashornTypeInfo
22
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 194: Code Persistence
23
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 194: Code Persistence
--class-cache-size=50 (-ccs) 50
--persistent-code-cache=true|false (-pcc) OpImisIc type informaIon false
24
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 194: Code Persistence
-pcc nashorn_code_cache nashorn.persistent.code.cache
25
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
On Demand true 8u31false
26
--lazy-compilation=true|false
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 202: Class Filter
JEP 202: Nashorn Class Filter hjps://bugs.openjdk.java.net/browse/JDK-8043717
JavaScriptJava jdk.nashorn.api.scripting.ClassFilter
27
JavaScriptJava
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
ClassFilter
import jdk.nashorn.api.scripting.ClassFilter; class MyFilter implements ClassFilter { @Override public boolean exposeToScripts(String s) { if (s.compareTo("java.io.File") == 0) return false; return true; } }
28
java.io.File
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
ECMAScript 6
29
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 203: Lexically-scoped variable and constant declaraIons
--language=es5|es6 es5 constlet--language=es6
let
constletconst
30
letconst
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
// let let a=2; function f(x) { // a2 if(x) { let a=42; } // a2}
// var var a=2; function f(x) { // a if(x) { var a=42; } // xa42}
31
letvar
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
// 1) function f(x) { const b=1; // b = 99; }
// 2) 1function f(x) { const b=1; var z=b+1; //z=2 } //bvar y=b+1;
32
// 3) 2function f(x) { const b=1; var z =b+1; //z=2 } //bconst b = 10;
const
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Server Side JavaScript
33
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Server Side JavaScript JVMNode.js Nodyn Vert.x + Dyn.JS + Nejy
Trieme apigeeNode.js
ReacIve Programming RxJS React.JS
34
Copyright 2015, Oracle and/or its aliates. All rights reserved. | 35
hVps://blogs.oracle.com/theaquarium/entry/project_avatar_update ...
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
In the future...
36
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
In the Future
OpImisIc TypingCode Persistence
Java 9 ECMAScript 6 Parser API for Nashorn (JEP 236) Java Flight Recorder JavaScript Proler Nashorn
... 37
Java 8u609
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JSON JSON PropertyHashMap#findElement
jdk.nashorn.internal.parser.JSONParser
38
8u60
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Java Flight Recorder
39
JavaScript Proler
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 236: Parser API for Nashorn
ECMAScriptASTParser API Visitor (jdk.nashorn.internal.ir)
Java APIAPI ECMAScriptAST
40
ECMAScript ASTAPI
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
JEP 236: Parser API for Nashorn
JDK9 b55 JavaDochjps://bugs.openjdk.java.net/browse/JDK-8048176
41
jdk.nashorn.api.tree
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
42
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
8u208u40
Nashorn
43
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Nashorn Project
Nashorn Mailing List [email protected]
Nashorn Wiki hjps://wiki.openjdk.java.net/display/Nashorn/Main
DEVELOPER_README hjp://hg.openjdk.java.net/jdk8u/jdk8u-dev/nashorn/le/Ip/docs/DEVELOPER_README
Nashorn - JavaScript for the JVM hjp://blogs.oracle.com/nashorn/
44
hjp://openjdk.java.net/projects/nashorn/
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
Safe Harbor Statement The preceding is intended to outline our general product direcIon. It is intended for informaIon purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or funcIonality, and should not be relied upon in making purchasing decisions. The development, release, and Iming of any features or funcIonality described for Oracles products remains at the sole discreIon of Oracle.
45
Copyright 2015, Oracle and/or its aliates. All rights reserved. |
46
Copyright 2015, Oracle and/or its aliates. All rights reserved. |