
Self-Specialising Interpreters and Start P:object Partial Evaluation IsNull Graal and Truffle If true false P:profiledHubs-0 Begin Begin guard Chris Seaton Deoptimize LoadHub Research Manager Oracle Labs == 9 August 2016 P:hubIsPositive-0 If true false IR Node Begin Begin Control-flow Edge Data-flow Edge Return Deoptimize Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to provide some insight into a line of research in Oracle Labs. 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. Oracle reserves the right to alter its development plans and practices at any time, and the development, release, and timing of any features or functionality described in connection with any Oracle product or service remains at the sole discretion of Oracle. Any views expressed in this presentation are my own and do not necessarily reflect the views of Oracle. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Compilers are, of course, metaprogramming systems Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Writing languages that target the JVM Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Hotspot Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Hotspot Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | JIT Hotspot (Graal) JIT Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Truffle JIT Hotspot (Graal) JIT Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Two levels of program representation • Truffle – ASTs • Graal – compiler IR Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Truffle Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Node Rewriting Compilation using U for Profiling Feedback G Partial Evaluation G U U Node Transitions I G I G Uninitialized Integer I I U U U I I I S D AST Interpreter AST Interpreter Compiled Code Uninitialized Nodes String Double Rewritten Nodes G Generic T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Node Rewriting Compilation using U for Profiling Feedback G Partial Evaluation G U U Node Transitions I G I G Uninitialized Integer I I U U U I I I S D AST Interpreter AST Interpreter Compiled Code Uninitialized Nodes String Double Rewritten Nodes G Generic T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Node Rewriting Compilation using U for Profiling Feedback G Partial Evaluation G U U Node Transitions I G I G Uninitialized Integer I I U U U I I I S D AST Interpreter AST Interpreter Compiled Code Uninitialized Nodes String Double Rewritten Nodes G Generic T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Node Rewriting Compilation using U for Profiling Feedback G Partial Evaluation G U U Node Transitions I G I G Uninitialized Integer I I U U U I I I S D AST Interpreter AST Interpreter Compiled Code Uninitialized Nodes String Double Rewritten Nodes G Generic T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | codon.com/compilers-for-free Presentation, by Tom Stuart, licensed under a Creative Commons Attribution ShareAlike 3.0 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19 Deoptimization Node Rewriting to Update Recompilation using to AST Interpreter G Profiling Feedback G Partial Evaluation G G I G I G D G D G I I I D I I I D T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. 12/08/2016 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Deoptimization Node Rewriting to Update Recompilation using to AST Interpreter G Profiling Feedback G Partial Evaluation G G I G I G D G D G I I I D I I I D T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. WolcZko. One VM to rule them all. In Proceedings of Onward!, 2013. 12/08/2016 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 22 Frequently executed call Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 23 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 24 double BigInteger int Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 25 double BigInteger int Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 26 double BigInteger int Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27 Partial Evaluation and Transfer to Interpreter Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28 Example: Partial Evaluation class ExampleNode { // parameter this in rsi @CompilationFinal boolean flag; normal compilation cmpb [rsi + 16], 0 of method foo() jz L1 int foo() { mov eax, 42 if (this.flag) { ret return 42; L1: mov eax, -1 } else { ret return -1; } } mov rax, 42 Object value of this ret ExampleNode flag: true partial evaluation of method foo() with known parameter this Memory access is eliminated and condition is constant folded during partial evaluation @CompilationFinal field is treated like a final field during partial evaluation Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29 Example: Transfer to Interpreter class ExampleNode { int foo(boolean flag) { compilation of method // parameter flag in edi if (flag) { foo() cmp edi, 0 return 42; jz L1 } else { mov eax, 42 throw new IllegalArgumentException( ret "flag: " + flag); L1: ... } // lots of code here } class ExampleNode { // parameter flag in edi int foo(boolean flag) { compilation of method foo() cmp edi, 0 if (flag) { jz L1 return 42; mov eax, 42 } else { ret transferToInterpreter(); L1: mov [rsp + 24], edi throw new IllegalArgumentException( call transferToInterpreter "flag: " + flag); // no more code, this point is unreachable } } transferToInterpreter() is a call into the VM runtime that does not return to its caller, because execution continues in the interpreter Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30 Example: Partial Evaluation and Transfer to Interpreter class ExampleNode { Expected behavior: method negate() only partial evaluation called with allowed values @CompilationFinal boolean minValueSeen; of method negate() int negate(int value) { with known parameter this if (value == Integer.MIN_VALUE) { // parameter value in eax if (!minValueSeen) { cmp eax, 0x80000000 transferToInterpreterAndInvalidate(); ExampleNode jz L1 minValueSeen = true; minValueSeen: false neg eax } ret throw new ArithmeticException() L1: mov [rsp + 24], eax } call transferToInterpreterAndInvalidate // no more code, this point is unreachable return -value; } } if compiled code is invoked with minimum int value: 1) transfer back to the interpreter 2) invalidate the compiled code // parameter value in eax cmp eax, 0x80000000 jz L1 ExampleNode neg eax minValueSeen: true ret second L1: ... partial evaluation // lots of code here to throw exception Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31 Branch Profiles class ExampleNode { Truffle profile API provides high-level API that final BranchProfile minValueSeen = BranchProfile.create(); hides complexity and is easier to use int negate(int value) { if (value == Integer.MIN_VALUE) { minValueSeen.enter(); throw new ArithmeticException(); } return -value; } } Best Practice: Use classes in com.oracle.truffle.api.profiles when possible, instead of @CompilationFinal Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 32 Condition Profiles for Branch Probability class ExampleNode { final ConditionProfile positive = ConditionProfile.createCountingProfile(); final BranchProfile minValueSeen = BranchProfile.create(); int abs(int value) { if (positive.profile(value >= 0)) { Counting ConditionProfile: add branch probability return value; for code paths with different execution frequencies } else if (value == Integer.MIN_VALUE) { minValueSeen.enter(); throw new ArithmeticException(); BranchProfile: remove unlikely code paths } else { return -value; } } } Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 33 Profiles: Summary • BranchProfile to speculate on unlikely branches – Benefit: remove code of unlikely code paths Profiles
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages197 Page
-
File Size-