More Related Content
Similar to これからのNashorn (20)
これからのNashorn
- 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
Nashornとは
8u40で登場予定の機能
将来のNashorn
1
2
3
3
- 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashornとは
4
- 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn -‐ JavaScript Engine
• Java VM上で動作するJavaScriptエンジン
– Compact1 profileでも動作
• Java 8に同梱(2014年3月から)
• ECMAScript-‐262 Edition 5.1の100%互換実装
• JSR-‐292 (invokedynamic)とDynalinkを用いた、軽量なJavaへのインター
フェースを提供
• 開発者向けWiki(英語)
– https://wiki.openjdk.java.net/display/Nashorn
5
- 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u20
• --const-as-var
– ‘const’を ‘var’で置き換えるオプション
• --no-java
– “Java”オブジェクトや“Packages”オブジェクトなどのJava固有の拡張を使わなくするた
めのオプション
6
主としてセキュリティ対応やJITやJDKの改善
- 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u40で登場予定の機能
7
- 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
8u40
• パフォーマンスの最適化
– 遅延コンパイル
– 楽観的型付け (Optimistic typing)
– invokedynamicのパフォーマンス改善
– プリミティブ型の特殊化 (Primitive type
specializations / Optimistic built-‐in)
• Array
• String
• 数学組み込み関数 (Math intrinsics)
– 全体的なランタイムの改善
• その他
– クラスフィルタ (Class filter)
– 限定的なECMAScript 6仕様のサポート
• 字句スコープの変数と定数の定義 (Lexical-‐
scoped variables and constant definition)
8
パフォーマンス改善を主目的としたリリース
- 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 194: Code Persistence
• 概要
– メモリ使用量の削減ならびに起動時間の短縮のため、同じプロセス内で再利用でき
るようコードをキャッシュできる
– キャッシュの利用は同一プロセスに限定され、プロセス間では共有しない
• 利用方法
– 以下のオプションを利用
• --persistent-code-cache=true|false (-pcc)
– 楽観的型付け情報(Optimistic type information)もキャッシュされる
• --class-cache-size=50 (-ccs)
– グローバル・スコープ毎のクラス・キャッシュサイズ。デフォルトサイズは50
9
コードの永続化
- 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 196: Optimistic Typing
• 概要
– 以下の方針に従い、できるだけ実行時に型付けせずに、Nashornのパフォーマンス
向上をはかる
• 演算および配列のインデックス操作で使用する特定の型(type)を仮定
• 型に対する仮定が正しくない場合に、仮定を取り消し、フォールバック
– コンセプト実現のため、非Javaバイトコードを最適化するためのHotSpot JVMの能力
を向上させる必要があり、同時に実装中
10
楽観的型付け – Javaのようなバイトコードを生成するために
int long double Object
- 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 202: Class Filter
• 概要
– Javaクラスへのアクセスをフィルタリングするためのインターフェース (ClassFilter)
– Nashornを使うJavaアプリケーションが実装可能
• jdk.nashorn.api.scripting.ClassFilter
• 注意
– RhinoのClassShuttersとの互換性はない
• NashornのClassFilter APIは、RhinoのClassShutter APIとコンセプトが類似しているだけ
• ClassFilter APIにはRhinoと同じパッケージ名やクラス名、メソッド名はない(予定)
11
Javaクラスへのアクセスをフィルタリング
- 12. 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
例
- 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JEP 203: Lexically-‐scoped variable and constant declarations
• 概要
– letやconstだけでなく、関数宣言も使って、スコープ内変数や定数を実装
– ECMAScript 6仕様で必要
• 利用方法
– --language=es6を付ける必要がある
– let
• ブロックに含まれるスコープ内変数の宣言に利用
– const
• letと同様、constを使って宣言した定数はブロック内に生存範囲を限定
13
スコープ内変数(let)や定数(const)の宣言
- 14. 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
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
}
- 15. 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
constの例
// const 3
function f(x) {
const b = 1;
var z = b + 1; // z = 2
}
const b = 10; // Able to define b
- 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
その他の最適化
• xをMethodHandle.constantをinvokedynamicのgetterとして利用できる
• xがスコープ内で変更される場合、SwitchPointを使い無効化できる
• このcallsiteが再度定数になることを禁止する、n回の再試行を認める、ま
たはreceiver guardを使って試行する、のいずれかを手段としてとることが
できる
16
部分評価 (Partial Evaluation)
for (var i = 0; i < x.length; i++) {
//xが不変の場合...
}
- 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
その他の最適化
• オンデマンドでメソッドのコンパイルのみ実行
– リンク時にマッチするシグネチャがない場合
• できる限り曖昧でないメソッドをコンパイル
– リンク時にマッチするシグネチャが存在する場合
• もっと具体的にメソッドのコンパイルを試行
17
遅延コンパイル
- 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The Future
• プロファイリング
• Java Flight Recorderの活用
• ECMAScript6のサポート(仕様が確定した暁には)
...などなど
19
Java 9からその先
- 20. 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