SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Parser combinatorってなんなのさ
Parser combinatorってなんなのさParser combinatorってなんなのさ
Parser combinatorってなんなのさcct-inc
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereJ On The Beach
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelPeter Hlavaty
 
JVMのGCアルゴリズムとチューニング
JVMのGCアルゴリズムとチューニングJVMのGCアルゴリズムとチューニング
JVMのGCアルゴリズムとチューニング佑哉 廣岡
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safeKumazaki Hiroki
 
Spark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideSpark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideIBM
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight RecorderYoshiro Tokumasu
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsBrendan Gregg
 
Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Masatoshi Tada
 
UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)Kris Mok
 
規格書で読むC++11のスレッド
規格書で読むC++11のスレッド規格書で読むC++11のスレッド
規格書で読むC++11のスレッドKohsuke Yuasa
 
【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All Things【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All ThingsUnityTechnologiesJapan002
 
Java Just-In-Timeコンパイラ
Java Just-In-TimeコンパイラJava Just-In-Timeコンパイラ
Java Just-In-TimeコンパイラKazuaki Ishizaki
 
katagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Cryptokatagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Cryptotrmr
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術Kiyokuni Kawachiya
 
より深く知るオプティマイザとそのチューニング
より深く知るオプティマイザとそのチューニングより深く知るオプティマイザとそのチューニング
より深く知るオプティマイザとそのチューニングYuto Hayamizu
 

Was ist angesagt? (20)

Parser combinatorってなんなのさ
Parser combinatorってなんなのさParser combinatorってなんなのさ
Parser combinatorってなんなのさ
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster Everywhere
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
JVMのGCアルゴリズムとチューニング
JVMのGCアルゴリズムとチューニングJVMのGCアルゴリズムとチューニング
JVMのGCアルゴリズムとチューニング
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Metaspace
MetaspaceMetaspace
Metaspace
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safe
 
Glibc malloc internal
Glibc malloc internalGlibc malloc internal
Glibc malloc internal
 
Spark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideSpark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting Guide
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame Graphs
 
Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-Java EE 8新機能解説 -Bean Validation 2.0編-
Java EE 8新機能解説 -Bean Validation 2.0編-
 
UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)
 
規格書で読むC++11のスレッド
規格書で読むC++11のスレッド規格書で読むC++11のスレッド
規格書で読むC++11のスレッド
 
【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All Things【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All Things
 
Java Just-In-Timeコンパイラ
Java Just-In-TimeコンパイラJava Just-In-Timeコンパイラ
Java Just-In-Timeコンパイラ
 
katagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Cryptokatagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Crypto
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術
 
より深く知るオプティマイザとそのチューニング
より深く知るオプティマイザとそのチューニングより深く知るオプティマイザとそのチューニング
より深く知るオプティマイザとそのチューニング
 

Andere mochten auch

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Kris Mok
 
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 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
 
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
 
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
 

Andere mochten auch (20)

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
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
 
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?
 
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
 

Ähnlich wie 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
 

Ähnlich wie 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 ...
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 

Kürzlich hochgeladen (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 

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