Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nashorn in the Future

Nashorn in the Future

Summarized updated information about Nashorn.

Akihiro Nishikawa

November 12, 2014
Tweet

More Decks by Akihiro Nishikawa

Other Decks in Technology

Transcript

  1. Nashorn in the future Akihiro Nishikawa Oracle Corporation Japan November,

    12, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  2. 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
  3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

    | Agenda Overview 8u40 topics In the Future 1 2 3 3
  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
  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
  6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

    | 8u40 Topics New options and improvements 7
  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
  8. 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
  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
  10. 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
  11. 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
  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
  13. 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 }
  14. 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
  15. 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 }
  16. 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
  17. 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...
  18. 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