Slide 1

Slide 1 text

Nashorn in the future Akihiro Nishikawa Oracle Corporation Japan November, 12, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |

Slide 2

Slide 2 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The 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

Slide 3

Slide 3 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Agenda Overview 8u40 topics In the Future 1 2 3 3

Slide 4

Slide 4 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn Overview 4

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 8u40 Topics New options and improvements 7

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JEP 202: Class Filter import jdk.nashorn.api.scripting.ClassFilter; static class MyFilter implements ClassFilter { @Override public 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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JEP 203: Lexically-scoped variable and constant declarations // let let a = 2; function f(x) { // "a" is 2 here if (x) { let a = 42; } // "a" is still 2 } 14 Sample for “let” // var var a = 2; function f(x) { // "a" is undefined here if (x) { var a = 42; } // Depending on "x", "a" is 42 or undefined }

Slide 15

Slide 15 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JEP 203: Lexically-scoped variable and constant declarations // const 1 function f(x) { const b = 1; b = 99; // Syntax Error } // const 2 function f(x) { const b = 1; var z = b + 1; // z = 2 } var y = b + 1; // b is undefined 15 Sample for “const” // const 3 function f(x) { const b = 1; var z = b + 1; // z = 2 } const b = 10; // Able to define b

Slide 16

Slide 16 text

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 }

Slide 17

Slide 17 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Other Optimization • Methods are only compiled on 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

Slide 18

Slide 18 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashon in the future 18

Slide 19

Slide 19 text

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...

Slide 20

Slide 20 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The 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

Slide 21

Slide 21 text

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 21

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content