SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
1   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot
VM
Krystal Mo
Member of Technical Staff
HotSpot JVM Compiler Team



2   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
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.




3   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


         Background
         Intrinsic Methods in HotSpot VM
         Intrinsic Methods added in TaobaoJDK
         Experiment: Implement Your Own Intrinsic
         Further Experiment



4   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


         Background
         Intrinsic Methods in HotSpot VM
         Intrinsic Methods added in TaobaoJDK
         Experiment: Implement Your Own Intrinsic
         Further Experiment



5   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
What is a Intrinsic Method?


           In compiler theory, an intrinsic function is a function available for use in
            a given programming language whose implementation is handled
            specially by the compiler. Typically, it substitutes a sequence of
            automatically generated instructions for the original function call,
            similar to an inline function. Unlike an inline function though, the
            compiler has an intimate knowledge of the intrinsic function and can
            therefore better integrate it and optimize it for the situation. This is also
            called builtin function in many languages.
           (via Wikipedia)


6   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Functions in Native Compilers
        Examples


           Microsoft Visual C/C++ Compiler
                    – __debugbreak()
                                  inserts an “int 3” instruction for breaking into debugger
           GCC
                    – __builtin_ia32_pause()
                                  inserts a “pause” instruction and necessary compiler barriers to prevent
                                      the instruction from floating around




7   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in JVMs


           Specific to JVM implementations
                    – can’t assume a method is intrinsic across JVMs in general
                    – mostly implemented in JVM compilers




8   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in JVMs


           Compatible
                    – appear to be no different from normal Java methods on Java source level;
                            all special handling is done within JVM
                    – can fallback to normal (non-intrinsic) version on JVMs that don’t intrinsify
                            them




9   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in JVMs


            Reliable
                     – are good “anchor” points for JVM optimizations for common code patterns
                     – e.g. java.lang.System.arraycopy()
                                   easier to recognize than matching an explicit array-copying loop




10   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in JVMs


            Extend Java semantics
                     – the same way native methods do, but usually more performant
                                   reliably inlined
                                   no JNI overhead
                     – e.g. sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64
                                   no Java bytecode can express its semantics
                                   without intrinsics: implemented in native via JNI
                                       (Unsafe_CompareAndSwapInt())
                                   with intrinsics: a direct cmpxchg instruction, inlined to caller

11   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


          Background
          Intrinsic Methods in HotSpot VM
          Intrinsic Methods added in TaobaoJDK
          Experiment: Implement Your Own Intrinsic
          Further Experiment



12   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         What to intrinsify?


            Commonly used public APIs in JDK core library
                     – to speed up common code patterns
                     – so use JDK core library methods whenever you can
                                   they may be better optimized!
            Special internal methods
                     – to implement special semantics
                     – the “secret sauce” to allow more parts of the Java core library be
                             implemented in Java
                     – may be exposed indirectly via ease-of-use APIs, e.g. j.u.c.atomic.*

13   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         How to intrinsify?


            Declare intrinsic methods in vmSymbols
            Implement intrinsic methods in
                     – Interpreter
                                   currently only implements intrinsics for
                                               – some math functions
                                               – a few MethodHandle internals for bootstrapping
                     – Client Compiler (C1)
                     – Server Compiler (C2)


14   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: java.lang.System.currentTimeMillis() on Linux


            Interpreter
                     – not intrinsified
                     – java.lang.System.currentTimeMillis() (Java / core library)
                                   (-> through normal JNI call path)
                                   JVM_CurrentTimeMillis() (C++ / HotSpot VM)
                                   os::javaTimeMillis() (C++ / HotSpot VM)
                                   gettimeofday() (C / Linux)




15   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: java.lang.System.currentTimeMillis() on Linux


            C1
                     – intrinsified
                     – inlined to caller as a direct call to os::javaTimeMillis()
            C2
                     – same as in C1


            (Intrinsification eliminates JNI overhead in compiled code)



16   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64


            Interpreter
                     – not intrinsified
                     – sun.misc.Unsafe.compareAndSwapInt() (Java / core library)
                                   (-> through normal JNI call path)
                                   Unsafe_CompareAndSwapInt() (C++ / HotSpot VM)
                                   Atomic::cmpxchg() (C++ inline asm / HotSpot VM)
                                   lock cmpxchgl




17   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64


            C1
                     – intrinsified
                     – inlined into caller as a plain “lock cmpxchgl” instruction
            C2
                     – same as in C1


            (Intrinsification easily leverages special hardware instructions)



18   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: java.lang.Math.log() on x86/AMD64


            Interpreter
                     – intrinsified
                     – java.lang.Math.log() (Java / core library)
                                   (-> through special interpreter method entry)
                                   “flog” x87 instruction




19   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Example: java.lang.Math.log() on x86/AMD64


            C1 and C2
                     – intrinsified
                     – inlined into caller as “flog” x87 instruction


            (Intrinsification ignores Java-level implementation)
                     – java.lang.Math.log() is implemented in pure Java in JDK core library
                     – HotSpot VM ignores that implementation on platforms where hardware
                             floating point instructions are available


20   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Other intrinsic methods of interest (on AMD64)


            java.lang.Thread.currentThread()
                     – mov reg, [r15 + java_thread_offset]
            java.lang.String.indexOf()/compareTo()/equals()
                     – use STTNI instructions in SSE4.2
            com.sun.crypto.provider.AESCrypt.encryptBlock()/decryptBlock()
                     – use AES instructions




21   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Find out if you’re using intrinsics in compiled code


            -XX:+PrintCompilation -XX:+PrintInlining
                     – (prepend -XX:+UnlockDiagnosticVMOptions when running on product VM)




22   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Find out if you’re using intrinsics in compiled code: example

                                                     public class Foo {
                                                       private static Object bar() {
                                                         return Thread.currentThread();
                                                       }

                                                            public static void main(String[] args) {
                                                              while (true) { bar(); }
                                                            }
                                                     }




23   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Find out if you’re using intrinsics in compiled code: example



$ java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand='exclude,Foo,main' 
  -XX:+PrintCompilation -XX:+PrintInlining Foo
CompilerOracle: exclude Foo.main
     50    1     n       java.lang.Thread::currentThread (0 bytes)   (static)
### Excluding compile: static Foo::main
     50    2             Foo::bar (4 bytes)
                            @ 0   java.lang.Thread::currentThread (0 bytes)   (intrinsic)




24   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Find out what intrinsic compiled into


            -XX:+PrintAssembly
                     – (prepend -XX:+UnlockDiagnosticVMOptions when running on product VM)
                     – requires hsdis disassembler plugin




25   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Intrinsic Methods in HotSpot VM
         Find out what intrinsic compiled into: example
               $ java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand='exclude,Foo,main' 
                 -XX:+PrintAssembly Foo
               ...
                 # {method} 'bar' '()Ljava/lang/Object;' in 'Foo'
                 #           [sp+0x20] (sp of caller)
                 0x00007f91cd061bc0: sub    $0x18,%rsp
                 0x00007f91cd061bc7: mov    %rbp,0x10(%rsp)    ;*synchronization entry
                                                               ; - Foo::bar@-1 (line 3)
                 0x00007f91cd061bcc: mov    0x1b0(%r15),%rax   ;*invokestatic currentThread
                                                               ; - Foo::bar@0 (line 3)
                 0x00007f91cd061bd3: add    $0x10,%rsp
                 0x00007f91cd061bd7: pop    %rbp
                 0x00007f91cd061bd8: test   %eax,0xb7ed422(%rip)        # 0x00007f91d884f000
                                                               ;   {poll_return}
                 0x00007f91cd061bde: retq
                 0x00007f91cd061bdf: hlt




26   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


          Background
          Intrinsic Methods in HotSpot VM
          Intrinsic Methods added in TaobaoJDK
          Experiment: Implement Your Own Intrinsic
          Further Experiment



27   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Instrinsic Methods Added in TaobaoJDK
         Why make your own custom intrinsic method?


            Make better use of new instructions available on new hardware
                     – In Taobao’s case, new instructions on Westmere/Sandy Bridge
            Eliminate JNI overhead when having to invoke hot native methods
                     – Instead of calling a native method through normal JNI, implement it as an
                             intrinsic method




                                                                                         (this section is material from Taobao;
                                                                                         TaobaoJDK is a custom version of OpenJDK from Taobao)

28   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Instrinsic Methods Added in TaobaoJDK
         A few examples


            TCrc32.xxx
                     – crc32c instruction in SSE4.2
            Unsafe.byteArrayCompare()
                     – byte array comparison via packed compare instructions
            Unsafe.pause()
                     – insert “pause” instruction before backedge of spinlock-like loop
           …



29   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Instrinsic Methods Added in TaobaoJDK
         crc32c


            Used in Hadoop
                     – throughput in TestDFSIO benchmark increased by 40%-180%




30   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
JVM Instrinsics Added in TaobaoJDK
         crc32c




31   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


          Background
          Intrinsic Methods in HotSpot VM
          Intrinsic Methods added in TaobaoJDK
          Experiment: Implement Your Own Intrinsic
          Further Experiment



32   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Implementing an Intrinsic in C1
         Example


            Implement java.lang.Class.isInstance() intrinsic in C1
                     – https://gist.github.com/rednaxelafx/2830194


            Note: starting point at GraphBuilder::try_inline_intrinsics()




33   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Implementing an Intrinsic in C2
         Example


            Implement a simple intrinsic demo in C2
                     – https://gist.github.com/rednaxelafx/1986224
            Implement a prototype for java.lang.Math.addExact() intrinsic in C2
                     – https://gist.github.com/rednaxelafx/db03ab15ef8b76246b84


            Note: starting point at LibraryCallKit::try_to_inline()




34   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Agenda


          Background
          Intrinsic Methods in HotSpot VM
          Intrinsic Methods added in TaobaoJDK
          Experiment: Implement Your Own Intrinsic
          Further Experiment



35   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Further Experiment
         Introducing Graal


            Experiment with implementing your own language-/library-specific
                intrinsic in HotSpot VM, but don’t want to write C++ or build HotSpot
                VM?
                     – Graal (from Oracle Labs) is the answer to your call!
                                   bytecode-to-native compiler implemented in Java, can be plugged into
                                       HotSpot VM
                                   OpenJDK project page
                                   Graal introduction (from JVM Language Summit 2011)



36   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
Q&A


37   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013
38   Copyright © 2013, Oracle and/or its affiliates. All rights reserved.   02/22/2013

Más contenido relacionado

La actualidad más candente

JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
謎の言語Forthが謎なので実装した
謎の言語Forthが謎なので実装した謎の言語Forthが謎なので実装した
謎の言語Forthが謎なので実装したt-sin
 
java.lang.OutOfMemoryError #渋谷java
java.lang.OutOfMemoryError #渋谷javajava.lang.OutOfMemoryError #渋谷java
java.lang.OutOfMemoryError #渋谷javaYuji Kubota
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチンyohhoy
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesKris Mok
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術Kiyokuni Kawachiya
 
20160906 pplss ishizaki public
20160906 pplss ishizaki public20160906 pplss ishizaki public
20160906 pplss ishizaki publicKazuaki Ishizaki
 
純粋関数型アルゴリズム入門
純粋関数型アルゴリズム入門純粋関数型アルゴリズム入門
純粋関数型アルゴリズム入門Kimikazu Kato
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safeKumazaki Hiroki
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案yohhoy
 
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」直久 住川
 
中3女子でもわかる constexpr
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexprGenya Murakami
 
Visual Studio を使わず .NET する
Visual Studio を使わず .NET するVisual Studio を使わず .NET する
Visual Studio を使わず .NET するm ishizaki
 
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法Yoshifumi Kawai
 
C++でテスト駆動開発
C++でテスト駆動開発C++でテスト駆動開発
C++でテスト駆動開発Akineko Shimizu
 

La actualidad más candente (20)

JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
謎の言語Forthが謎なので実装した
謎の言語Forthが謎なので実装した謎の言語Forthが謎なので実装した
謎の言語Forthが謎なので実装した
 
java.lang.OutOfMemoryError #渋谷java
java.lang.OutOfMemoryError #渋谷javajava.lang.OutOfMemoryError #渋谷java
java.lang.OutOfMemoryError #渋谷java
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
Embedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile DevicesEmbedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile Devices
 
Final field semantics
Final field semanticsFinal field semantics
Final field semantics
 
20160906 pplss ishizaki public
20160906 pplss ishizaki public20160906 pplss ishizaki public
20160906 pplss ishizaki public
 
純粋関数型アルゴリズム入門
純粋関数型アルゴリズム入門純粋関数型アルゴリズム入門
純粋関数型アルゴリズム入門
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safe
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案
 
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」
「FPGA 開発入門:FPGA を用いたエッジ AI の高速化手法を学ぶ」
 
中3女子でもわかる constexpr
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexpr
 
Visual Studio を使わず .NET する
Visual Studio を使わず .NET するVisual Studio を使わず .NET する
Visual Studio を使わず .NET する
 
Glibc malloc internal
Glibc malloc internalGlibc malloc internal
Glibc malloc internal
 
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
C++でテスト駆動開発
C++でテスト駆動開発C++でテスト駆動開発
C++でテスト駆動開発
 

Destacado

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Kris Mok
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersLucas Jellema
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetCharles Nutter
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkCodeOps Technologies LLP
 
HBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHortonworks
 
MySQL技术分享:一步到位实现mysql优化
MySQL技术分享:一步到位实现mysql优化MySQL技术分享:一步到位实现mysql优化
MySQL技术分享:一步到位实现mysql优化Jinrong Ye
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at NetflixBrendan Gregg
 
App server4rp gd - German
App server4rp gd - GermanApp server4rp gd - German
App server4rp gd - GermanCOMMON Europe
 
Recovery: Job Growth and Education Requirements Through 2020
Recovery: Job Growth and Education Requirements Through 2020Recovery: Job Growth and Education Requirements Through 2020
Recovery: Job Growth and Education Requirements Through 2020CEW Georgetown
 
Digitized Student Development, Social Media, and Identity
Digitized Student Development, Social Media, and IdentityDigitized Student Development, Social Media, and Identity
Digitized Student Development, Social Media, and IdentityPaul Brown
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great InfographicsSlideShare
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShareKapost
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 

Destacado (20)

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Concurrecy techdrop
Concurrecy techdropConcurrecy techdrop
Concurrecy techdrop
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
 
Marketing_SBI_Booklet_NEW
Marketing_SBI_Booklet_NEWMarketing_SBI_Booklet_NEW
Marketing_SBI_Booklet_NEW
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin Yet
 
Scalaで実装するGC
Scalaで実装するGCScalaで実装するGC
Scalaで実装するGC
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
JVM-Reading-ParalleGC
JVM-Reading-ParalleGCJVM-Reading-ParalleGC
JVM-Reading-ParalleGC
 
HBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minute
 
MySQL技术分享:一步到位实现mysql优化
MySQL技术分享:一步到位实现mysql优化MySQL技术分享:一步到位实现mysql优化
MySQL技术分享:一步到位实现mysql优化
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at Netflix
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
App server4rp gd - German
App server4rp gd - GermanApp server4rp gd - German
App server4rp gd - German
 
Recovery: Job Growth and Education Requirements Through 2020
Recovery: Job Growth and Education Requirements Through 2020Recovery: Job Growth and Education Requirements Through 2020
Recovery: Job Growth and Education Requirements Through 2020
 
Digitized Student Development, Social Media, and Identity
Digitized Student Development, Social Media, and IdentityDigitized Student Development, Social Media, and Identity
Digitized Student Development, Social Media, and Identity
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 

Similar a Intrinsic Methods in HotSpot VM

A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.
A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.
A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.J On The Beach
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8jclingan
 
Ijaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinderIjaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinderijaprr_editor
 
Production Time Profiling Out of the Box
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the BoxMarcus Hirt
 
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...timfanelli
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllThomas Wuerthinger
 
Bci for Beginners
Bci for BeginnersBci for Beginners
Bci for BeginnersIainLewis
 
A Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark PerformanceA Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark PerformanceTim Ellison
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTrivadis
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuningJerry Kurian
 
Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019Shaun Smith
 
Building Large Java Projects Faster: Multicore javac and Makefile integration
Building Large Java Projects Faster: Multicore javac and Makefile integrationBuilding Large Java Projects Faster: Multicore javac and Makefile integration
Building Large Java Projects Faster: Multicore javac and Makefile integrationFredrik Öhrström
 
Synopsis on online shopping by sudeep singh
Synopsis on online shopping by  sudeep singhSynopsis on online shopping by  sudeep singh
Synopsis on online shopping by sudeep singhSudeep Singh
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...AMD Developer Central
 

Similar a Intrinsic Methods in HotSpot VM (20)

A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.
A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.
A Java Implementer's Guide to Boosting Apache Spark Performance by Tim Ellison.
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
Java 8
Java 8Java 8
Java 8
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
Ijaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinderIjaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinder
 
Production Time Profiling Out of the Box
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the Box
 
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
 
Hotspot & AOT
Hotspot & AOTHotspot & AOT
Hotspot & AOT
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
Bci for Beginners
Bci for BeginnersBci for Beginners
Bci for Beginners
 
A Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark PerformanceA Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark Performance
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance Interoperability
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019
 
Building Large Java Projects Faster: Multicore javac and Makefile integration
Building Large Java Projects Faster: Multicore javac and Makefile integrationBuilding Large Java Projects Faster: Multicore javac and Makefile integration
Building Large Java Projects Faster: Multicore javac and Makefile integration
 
Synopsis on online shopping by sudeep singh
Synopsis on online shopping by  sudeep singhSynopsis on online shopping by  sudeep singh
Synopsis on online shopping by sudeep singh
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
 

Último

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Último (20)

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Intrinsic Methods in HotSpot VM

  • 1. 1 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 2. Intrinsic Methods in HotSpot VM Krystal Mo Member of Technical Staff HotSpot JVM Compiler Team 2 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 3. 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. 3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 4. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 5. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 5 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 6. What is a Intrinsic Method?  In compiler theory, an intrinsic function is a function available for use in a given programming language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.  (via Wikipedia) 6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 7. Intrinsic Functions in Native Compilers Examples  Microsoft Visual C/C++ Compiler – __debugbreak()  inserts an “int 3” instruction for breaking into debugger  GCC – __builtin_ia32_pause()  inserts a “pause” instruction and necessary compiler barriers to prevent the instruction from floating around 7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 8. Intrinsic Methods in JVMs  Specific to JVM implementations – can’t assume a method is intrinsic across JVMs in general – mostly implemented in JVM compilers 8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 9. Intrinsic Methods in JVMs  Compatible – appear to be no different from normal Java methods on Java source level; all special handling is done within JVM – can fallback to normal (non-intrinsic) version on JVMs that don’t intrinsify them 9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 10. Intrinsic Methods in JVMs  Reliable – are good “anchor” points for JVM optimizations for common code patterns – e.g. java.lang.System.arraycopy()  easier to recognize than matching an explicit array-copying loop 10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 11. Intrinsic Methods in JVMs  Extend Java semantics – the same way native methods do, but usually more performant  reliably inlined  no JNI overhead – e.g. sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64  no Java bytecode can express its semantics  without intrinsics: implemented in native via JNI (Unsafe_CompareAndSwapInt())  with intrinsics: a direct cmpxchg instruction, inlined to caller 11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 12. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 13. Intrinsic Methods in HotSpot VM What to intrinsify?  Commonly used public APIs in JDK core library – to speed up common code patterns – so use JDK core library methods whenever you can  they may be better optimized!  Special internal methods – to implement special semantics – the “secret sauce” to allow more parts of the Java core library be implemented in Java – may be exposed indirectly via ease-of-use APIs, e.g. j.u.c.atomic.* 13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 14. Intrinsic Methods in HotSpot VM How to intrinsify?  Declare intrinsic methods in vmSymbols  Implement intrinsic methods in – Interpreter  currently only implements intrinsics for – some math functions – a few MethodHandle internals for bootstrapping – Client Compiler (C1) – Server Compiler (C2) 14 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 15. Intrinsic Methods in HotSpot VM Example: java.lang.System.currentTimeMillis() on Linux  Interpreter – not intrinsified – java.lang.System.currentTimeMillis() (Java / core library)  (-> through normal JNI call path)  JVM_CurrentTimeMillis() (C++ / HotSpot VM)  os::javaTimeMillis() (C++ / HotSpot VM)  gettimeofday() (C / Linux) 15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 16. Intrinsic Methods in HotSpot VM Example: java.lang.System.currentTimeMillis() on Linux  C1 – intrinsified – inlined to caller as a direct call to os::javaTimeMillis()  C2 – same as in C1  (Intrinsification eliminates JNI overhead in compiled code) 16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 17. Intrinsic Methods in HotSpot VM Example: sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64  Interpreter – not intrinsified – sun.misc.Unsafe.compareAndSwapInt() (Java / core library)  (-> through normal JNI call path)  Unsafe_CompareAndSwapInt() (C++ / HotSpot VM)  Atomic::cmpxchg() (C++ inline asm / HotSpot VM)  lock cmpxchgl 17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 18. Intrinsic Methods in HotSpot VM Example: sun.misc.Unsafe.compareAndSwapInt() on x86/AMD64  C1 – intrinsified – inlined into caller as a plain “lock cmpxchgl” instruction  C2 – same as in C1  (Intrinsification easily leverages special hardware instructions) 18 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 19. Intrinsic Methods in HotSpot VM Example: java.lang.Math.log() on x86/AMD64  Interpreter – intrinsified – java.lang.Math.log() (Java / core library)  (-> through special interpreter method entry)  “flog” x87 instruction 19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 20. Intrinsic Methods in HotSpot VM Example: java.lang.Math.log() on x86/AMD64  C1 and C2 – intrinsified – inlined into caller as “flog” x87 instruction  (Intrinsification ignores Java-level implementation) – java.lang.Math.log() is implemented in pure Java in JDK core library – HotSpot VM ignores that implementation on platforms where hardware floating point instructions are available 20 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 21. Intrinsic Methods in HotSpot VM Other intrinsic methods of interest (on AMD64)  java.lang.Thread.currentThread() – mov reg, [r15 + java_thread_offset]  java.lang.String.indexOf()/compareTo()/equals() – use STTNI instructions in SSE4.2  com.sun.crypto.provider.AESCrypt.encryptBlock()/decryptBlock() – use AES instructions 21 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 22. Intrinsic Methods in HotSpot VM Find out if you’re using intrinsics in compiled code  -XX:+PrintCompilation -XX:+PrintInlining – (prepend -XX:+UnlockDiagnosticVMOptions when running on product VM) 22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 23. Intrinsic Methods in HotSpot VM Find out if you’re using intrinsics in compiled code: example public class Foo { private static Object bar() { return Thread.currentThread(); } public static void main(String[] args) { while (true) { bar(); } } } 23 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 24. Intrinsic Methods in HotSpot VM Find out if you’re using intrinsics in compiled code: example $ java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand='exclude,Foo,main' -XX:+PrintCompilation -XX:+PrintInlining Foo CompilerOracle: exclude Foo.main 50 1 n java.lang.Thread::currentThread (0 bytes) (static) ### Excluding compile: static Foo::main 50 2 Foo::bar (4 bytes) @ 0 java.lang.Thread::currentThread (0 bytes) (intrinsic) 24 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 25. Intrinsic Methods in HotSpot VM Find out what intrinsic compiled into  -XX:+PrintAssembly – (prepend -XX:+UnlockDiagnosticVMOptions when running on product VM) – requires hsdis disassembler plugin 25 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 26. Intrinsic Methods in HotSpot VM Find out what intrinsic compiled into: example $ java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand='exclude,Foo,main' -XX:+PrintAssembly Foo ... # {method} 'bar' '()Ljava/lang/Object;' in 'Foo' # [sp+0x20] (sp of caller) 0x00007f91cd061bc0: sub $0x18,%rsp 0x00007f91cd061bc7: mov %rbp,0x10(%rsp) ;*synchronization entry ; - Foo::bar@-1 (line 3) 0x00007f91cd061bcc: mov 0x1b0(%r15),%rax ;*invokestatic currentThread ; - Foo::bar@0 (line 3) 0x00007f91cd061bd3: add $0x10,%rsp 0x00007f91cd061bd7: pop %rbp 0x00007f91cd061bd8: test %eax,0xb7ed422(%rip) # 0x00007f91d884f000 ; {poll_return} 0x00007f91cd061bde: retq 0x00007f91cd061bdf: hlt 26 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 27. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 27 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 28. Instrinsic Methods Added in TaobaoJDK Why make your own custom intrinsic method?  Make better use of new instructions available on new hardware – In Taobao’s case, new instructions on Westmere/Sandy Bridge  Eliminate JNI overhead when having to invoke hot native methods – Instead of calling a native method through normal JNI, implement it as an intrinsic method (this section is material from Taobao; TaobaoJDK is a custom version of OpenJDK from Taobao) 28 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 29. Instrinsic Methods Added in TaobaoJDK A few examples  TCrc32.xxx – crc32c instruction in SSE4.2  Unsafe.byteArrayCompare() – byte array comparison via packed compare instructions  Unsafe.pause() – insert “pause” instruction before backedge of spinlock-like loop … 29 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 30. Instrinsic Methods Added in TaobaoJDK crc32c  Used in Hadoop – throughput in TestDFSIO benchmark increased by 40%-180% 30 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 31. JVM Instrinsics Added in TaobaoJDK crc32c 31 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 32. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 32 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 33. Implementing an Intrinsic in C1 Example  Implement java.lang.Class.isInstance() intrinsic in C1 – https://gist.github.com/rednaxelafx/2830194  Note: starting point at GraphBuilder::try_inline_intrinsics() 33 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 34. Implementing an Intrinsic in C2 Example  Implement a simple intrinsic demo in C2 – https://gist.github.com/rednaxelafx/1986224  Implement a prototype for java.lang.Math.addExact() intrinsic in C2 – https://gist.github.com/rednaxelafx/db03ab15ef8b76246b84  Note: starting point at LibraryCallKit::try_to_inline() 34 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 35. Agenda  Background  Intrinsic Methods in HotSpot VM  Intrinsic Methods added in TaobaoJDK  Experiment: Implement Your Own Intrinsic  Further Experiment 35 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 36. Further Experiment Introducing Graal  Experiment with implementing your own language-/library-specific intrinsic in HotSpot VM, but don’t want to write C++ or build HotSpot VM? – Graal (from Oracle Labs) is the answer to your call!  bytecode-to-native compiler implemented in Java, can be plugged into HotSpot VM  OpenJDK project page  Graal introduction (from JVM Language Summit 2011) 36 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 37. Q&A 37 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013
  • 38. 38 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 02/22/2013