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