これからのnashorn

23
これからのNashorn Akihiro Nishikawa Oracle Corporation Japan November, 12, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |

Upload: akihiro-nishikawa

Post on 02-Jul-2015

1.239 views

Category:

Technology


2 download

DESCRIPTION

Nashorn in the Futureの日本語版です。

TRANSCRIPT

Page 1: これからのNashorn

これからのNashorn

Akihiro  NishikawaOracle  Corporation  JapanNovember,  12,  2014

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

Page 2: これからのNashorn

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

Page 3: これからのNashorn

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

Agenda

Nashornとは

8u40で登場予定の機能

将来のNashorn

1

2

3

3

Page 4: これからのNashorn

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

Nashornとは

4

Page 5: これからのNashorn

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

Page 6: これからのNashorn

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

8u20

• --const-as-var– ‘const’を ‘var’で置き換えるオプション

• --no-java– “Java”オブジェクトや“Packages”オブジェクトなどのJava固有の拡張を使わなくするためのオプション

6

主としてセキュリティ対応やJITやJDKの改善

Page 7: これからのNashorn

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

8u40で登場予定の機能

7

Page 8: これからのNashorn

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

パフォーマンス改善を主目的としたリリース

Page 9: これからのNashorn

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

コードの永続化

Page 10: これからのNashorn

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

Page 11: これからのNashorn

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クラスへのアクセスをフィルタリング

Page 12: これからのNashorn

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 {@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

Page 13: これからのNashorn

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)の宣言

Page 14: これからのNashorn

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

letの例

// varvar a = 2;

function f(x) {// "a" is undefined hereif (x) {

var a = 42;}// Depending on "x", "a" is 42 or undefined

}

Page 15: これからのNashorn

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

constの例

// const 3function f(x) {

const b = 1;var z = b + 1; // z = 2

}const b = 10; // Able to define b

Page 16: これからのNashorn

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が不変の場合...

}

Page 17: これからのNashorn

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

その他の最適化

•オンデマンドでメソッドのコンパイルのみ実行– リンク時にマッチするシグネチャがない場合• できる限り曖昧でないメソッドをコンパイル

– リンク時にマッチするシグネチャが存在する場合• もっと具体的にメソッドのコンパイルを試行

17

遅延コンパイル

Page 18: これからのNashorn

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

もっと先の話

18

Page 19: これからのNashorn

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

The  Future

• プロファイリング• Java  Flight  Recorderの活用• ECMAScript6のサポート(仕様が確定した暁には)

...などなど

19

Java  9からその先

Page 20: これからのNashorn

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

Page 21: これからのNashorn

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

Page 22: これからのNashorn
Page 23: これからのNashorn