SlideShare a Scribd company logo
1 of 38
Download to read offline
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

More Related Content

What's hot

JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
Panamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶPanamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶYasumasa Suenaga
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교JungWoon Lee
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksLucidworks
 
Javaday Paris 2022 - Java en 2022 : profiter de Java 17
Javaday Paris 2022 - Java en 2022 : profiter de Java 17Javaday Paris 2022 - Java en 2022 : profiter de Java 17
Javaday Paris 2022 - Java en 2022 : profiter de Java 17Jean-Michel Doudoux
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevOracle Developers
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight RecorderYoshiro Tokumasu
 
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51Takakiyo Tanaka
 
20160906 pplss ishizaki public
20160906 pplss ishizaki public20160906 pplss ishizaki public
20160906 pplss ishizaki publicKazuaki Ishizaki
 
Linux : The Common Mailbox Framework
Linux : The Common Mailbox FrameworkLinux : The Common Mailbox Framework
Linux : The Common Mailbox FrameworkMr. Vengineer
 
20160215 04 java ee7徹底入門 jbatch
20160215 04 java ee7徹底入門 jbatch20160215 04 java ee7徹底入門 jbatch
20160215 04 java ee7徹底入門 jbatchJun Inose
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうKoichi Sakata
 
スレッドダンプの読み方
スレッドダンプの読み方スレッドダンプの読み方
スレッドダンプの読み方Funato Takashi
 

What's hot (20)

JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Panamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶPanamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶ
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, Lucidworks
 
Javaday Paris 2022 - Java en 2022 : profiter de Java 17
Javaday Paris 2022 - Java en 2022 : profiter de Java 17Javaday Paris 2022 - Java en 2022 : profiter de Java 17
Javaday Paris 2022 - Java en 2022 : profiter de Java 17
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajev
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder
 
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
 
Learn C Programming Language by Using GDB
Learn C Programming Language by Using GDBLearn C Programming Language by Using GDB
Learn C Programming Language by Using GDB
 
Embedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile DevicesEmbedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile Devices
 
20160906 pplss ishizaki public
20160906 pplss ishizaki public20160906 pplss ishizaki public
20160906 pplss ishizaki public
 
Final field semantics
Final field semanticsFinal field semantics
Final field semantics
 
Linux : The Common Mailbox Framework
Linux : The Common Mailbox FrameworkLinux : The Common Mailbox Framework
Linux : The Common Mailbox Framework
 
20160215 04 java ee7徹底入門 jbatch
20160215 04 java ee7徹底入門 jbatch20160215 04 java ee7徹底入門 jbatch
20160215 04 java ee7徹底入門 jbatch
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
 
スレッドダンプの読み方
スレッドダンプの読み方スレッドダンプの読み方
スレッドダンプの読み方
 

Viewers also liked

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
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris 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
 

Viewers also liked (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
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
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
 

Similar to 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 to 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 ...
 

Recently uploaded

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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