View
200
Download
1
Category
Preview:
DESCRIPTION
This presentation is intended to use at some conference. As safe harbor statement says, this is intended to outline functions and features.
Citation preview
Nashorn in the future
Akihiro NishikawaOracle Corporation JapanNovember, 12, 2014
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Agenda
Overview
8u40 topics
In the Future
1
2
3
3
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn Overview
4
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn -‐ JavaScript Engine• JavaScript engine running on Java VM– Able to run even on Compact1 profile
• Released with Java 8 (March, 2014)• Implementation of ECMAScript-‐262 Edition 5.1• Lightweight interface to Java using JSR-‐292 and Dynalink• Wiki for Developers– https://wiki.openjdk.java.net/display/Nashorn
5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u20
• --const-as-var– Replace 'const' with 'var’.
• --no-java– switch-‐off Java specific extensions like "Java", "Packages" object etc.
6
Security fixes and several JIT / JDK improvements
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u40 TopicsNew options and improvements
7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u40
• Performance Optimizations– Lazy compilation– Optimistic typing– Improved invoke dynamic performance– Primitive type specializations (Optimistic built-‐in)• Array• String• Math intrinsics
– General runtime improvements
• Other features– Class filter– Limited ECMAScript 6 Support• Lexical-‐scoped variables and constant definition
8
Major performance release
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 194: Code Persistence• Overview– Cache code so that it can be reused in the same process for reducing in memory usage and start up time.
– No attempt will be made to share the cache across processes.
• How to use– The following options are required.• --persistent-code-cache=true|false (-pcc)– Optimistic type information is also cached to disk
• --class-cache-size=50 (-ccs)– Class cache size per global scope– Default size: 50
9
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 196: Optimistic Typing
• Overview– Improve Nashorn performance by making assumptions about specific types used in arithmetic and array indexing operations, by being prepared to recover when those assumptions prove incorrect, and by improving the HotSpot JVM's ability to optimize non-‐Java bytecode.
10
“Generate Java-‐like bytecode”
int long double Object
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 202: Class Filter• Overview– Provide a Java class-‐access filtering interface (ClassFilter) that can be implemented by Java applications that use Nashorn.• jdk.nashorn.api.scripting.ClassFilter
– Incompatible with Mozilla Rhino's ClassShutters• Nashorn's ClassFilter API is only conceptually similar to the Rhino's ClassShutter API.• The ClassFilter API will not have same package, class, or method names as that of the Mozilla Rhino engine.
11
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 202: Class Filterimport jdk.nashorn.api.scripting.ClassFilter;
static class MyFilter implements ClassFilter {@Overridepublic boolean exposeToScripts(String classname) {
return false;}
}…NashornScriptEngine engine = factory.getScriptEngine(new MyFilter());
try {engine.eval("Java.type('java.util.Vector')");
} catch (ex) {print("No access to Java Classes");
}
12
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 203: Lexically-‐scoped variable and constant declarations• Overview– Implement lexical scope for variables and constants declared via let and const as well as function declarations as required by ECMAScript 6.
–When using these keywords, "--language=es6" option is required.
• let– Limit the declaration of lexically-‐scoped variable to its containing block:
• const– Like let, constants declared by const are limited to their containing lexical scope.
13
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 203: Lexically-‐scoped variable and constant declarations
// letlet a = 2;
function f(x) {// "a" is 2 hereif (x) {
let a = 42;}// "a" is still 2
}
14
Sample for “let”
// varvar a = 2;
function f(x) {// "a" is undefined hereif (x) {
var a = 42;}// Depending on "x", "a" is 42 or undefined
}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 203: Lexically-‐scoped variable and constant declarations
// const 1function f(x) {
const b = 1;b = 99; // Syntax Error
}
// const 2function f(x) {
const b = 1;var z = b + 1; // z = 2
}var y = b + 1; // b is undefined
15
Sample for “const”
// const 3function f(x) {
const b = 1;var z = b + 1; // z = 2
}const b = 10; // Able to define b
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Other Optimization
• x can use MethodHandle.constant as an indy getter.• We can use a SwitchPoint to invalidate it, given that x is modified in the scope.• Either forbid this callsite from being constant again, allow n retries, or try with a receiver guard
16
Partial Evaluation
for (var i = 0; i < x.length; i++) {//x is loop invariant
}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Other Optimization
• Methods are only compiledon demand• At link time...– If no matching signature exists, compile one, as specific as possible– If matching signature does exist, try to compile an even more specific one
17
Lazy Compilation
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashon in the future
18
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The Future
• Java 9 and beyond– Profiling– Java Flight Recorder– Support for ECMAScript 6 (In case specification is finalized)
...etc.
19
To be the intelligent dynamic language execution framework for the JVM...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor StatementThe preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
20
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 21
Recommended