SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassCODE WHITE GmbH
 
Tiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMTiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMIgor Veresov
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization VulnerabilitiesLuca Carettoni
 
Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksLucidworks
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksJignesh Shah
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術Kiyokuni Kawachiya
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうKoichi Sakata
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight RecorderYoshiro Tokumasu
 
In the DOM, no one will hear you scream
In the DOM, no one will hear you screamIn the DOM, no one will hear you scream
In the DOM, no one will hear you screamMario Heiderich
 
Zynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチZynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチMr. Vengineer
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016Russel Van Tuyl
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesChristopher Frohoff
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
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
 
Serviceability Toolsの裏側
Serviceability Toolsの裏側Serviceability Toolsの裏側
Serviceability Toolsの裏側Yasumasa Suenaga
 
Proxysql sharding
Proxysql shardingProxysql sharding
Proxysql shardingMarco Tusa
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMFrans Rosén
 

Tendances (20)

Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
Tiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMTiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVM
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, Lucidworks
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW Locks
 
Java仮想マシンの実装技術
Java仮想マシンの実装技術Java仮想マシンの実装技術
Java仮想マシンの実装技術
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
 
使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder使ってみよう!JDK Flight Recorder
使ってみよう!JDK Flight Recorder
 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
 
In the DOM, no one will hear you scream
In the DOM, no one will hear you screamIn the DOM, no one will hear you scream
In the DOM, no one will hear you scream
 
Zynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチZynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチ
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling Pickles
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
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
 
Serviceability Toolsの裏側
Serviceability Toolsの裏側Serviceability Toolsの裏側
Serviceability Toolsの裏側
 
Proxysql sharding
Proxysql shardingProxysql sharding
Proxysql sharding
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 

En vedette

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Kris Mok
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersLucas Jellema
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetCharles Nutter
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkCodeOps Technologies LLP
 
HBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHortonworks
 
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
 

En vedette (20)

Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Concurrecy techdrop
Concurrecy techdropConcurrecy techdrop
Concurrecy techdrop
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
 
Marketing_SBI_Booklet_NEW
Marketing_SBI_Booklet_NEWMarketing_SBI_Booklet_NEW
Marketing_SBI_Booklet_NEW
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin Yet
 
Scalaで実装するGC
Scalaで実装するGCScalaで実装するGC
Scalaで実装するGC
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
JVM-Reading-ParalleGC
JVM-Reading-ParalleGCJVM-Reading-ParalleGC
JVM-Reading-ParalleGC
 
HBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minuteHBase: How to get MTTR below 1 minute
HBase: How to get MTTR below 1 minute
 
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
 

Similaire à 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
 

Similaire à 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 ...
 

Dernier

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
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
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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
 
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...
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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