SlideShare a Scribd company logo
Java Performance
            artdb@ex-em.com | performeister.tistory.com | twitter @novathinker




Thread Synchronization
Java Performance
                                                                                     2

                            artdb@ex-em.com | performeister.tistory.com | twitter @novathinker




Thread Synchronization
  1)   Java Thread
  2)   Thread Synchronization
  3)   Cooperation
  4)   Mutual execution
  5)   Light-Weight Lock
Hotspot Synchronization
  1) Light-Weight Lock
  2) Biased Locking
IBM JVM Synchronization
  1) Thin Lock
  2) Lock Reservation
Java Performance
         artdb@ex-em.com | performeister.tistory.com | twitter @novathinker




    Thread
Synchnonization
Java Performance
                                                                      4
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Java             Thread
  – Green Thread
        • JVM                 Created, scheduling          Thread
        • 1.1                    JVM              Thread model
        • OS Thread             n:1
        •                  OS Thread
        • CPU
  – Native Thread
        • OS Kernel                       Thread
        • 1.3                   Default
Java Performance
                                                                      5
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Thread Synchronization
  – Monitor : Java                 Synchronization Mechanism
  – Monitor
        • Cooperation
               – Class object      wait(),notify()
               – Thread
        • Mutual Exclusion
               – Class class
               –
Java Performance
                                                                      6
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Cooperation
  – Cooperation
        •


                                                  wait()
             Reader
             Thread
                                                Buffer empty
             Listen               notify()
             Thread

                                  Buffer full
Java Performance
                                                                      7
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Cooperation
  – Monitor
                                   Monitor




                                                  Critical Section




       Monitor                suspend
Java Performance
                                                                      8
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Cooperation
  – Monitor
Java Performance
                                                                      9
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Mutual Exclusion
  – Shared Data
        • Runtime Data Area              Data           Thread

        • Heap  Instance Variables
        • Method Area  Class Variables
        •   Object Class Monitor lock
        • Mutex                                  object lock
        • Object Lock
               –            Thread    Object
Java Performance
                                                                      10
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Mutual Exclusion
  – Object Lock
       • Class file                      java.lang.class instance

       • Object lock           object(instance)        locking
       •   Thread                 object                locking
       •        object         lock counter
              – Lock              count
              – Lock            count
              – Count = 0            thread     lock
       • Thread            Critical Section                lock
Java Performance
                                                                      11
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Mutual Exclusion
  – Critical Section
        • Critical Section
               – Synchronized statement
               – Synchronized method
        • Critical section object reference
        • Critical section    instruction                            thread
                       object lock
        • Critical section         lock                          release
        • Object Lock                                         critical
          section               JVM
Java Performance
                                                                        12
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Thread Synchronization




• Light-Weight Lock
  – light-weight lock
       •                   JVM     Light-Weight Lock
       •   Object      OS Mutex                                       heavy-
         weight lock
       •          locking


                                 No              Atomic Operation
                                                Enter, Exit monitor

             Contended

                                               Heavy-Weight OS Lock
                                 Yes
Java Performance
         artdb@ex-em.com | performeister.tistory.com | twitter @novathinker




    Hotspot
Synchronization
Java Performance
                                                                                         14
                          Java Performance Fundamental | twitter @novathinker
                                       artdb@ex-em.com | performeister.tistory.com
         Hotspot Synchronization




   • Light-Weight Lock
        – Object Header
               • Object Header                    word      Mark Work

                  Mark Word                        Hash Code (0)        Age     Biased        Tag
                                                  Thread ID, epoch(1)

                                                       23 bit           6 bit   1 bit         2 bit


Hash Code (0)            Age       Biased   Tag   Biased bit Tag
Thread ID, epoch(1)
                                                       0         01 Unlocked
      (000) Lock Record Address                        0         00 Light-weight locked

         (010) Monitor Address                         0         10 Heavy-weight locked
                                                       0         11 Marked for GC
    (011) Forwarding Address                           1         01 Biased / Biasable
Java Performance
                                                                      15
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Light-Weight Lock
  – Light-Weight Locking
        • Object Header                word      Mark Work
        • Atomic compare-and-swap(CAS) instruction
          lock
        • CAS                     thread lock
        • CAS                     heavy weight lock
        • Object lock        thread stack frame                       mark
          word move (displaced mark          )
        • Lock           Mark Word
Java Performance
                                                                                     16
                          Java Performance Fundamental | twitter @novathinker
                                       artdb@ex-em.com | performeister.tistory.com
         Hotspot Synchronization




   • Light-Weight Lock
         – Light-Weight Locking

            Execution                                          Execution
              Stack                                              Stack
                                                    Locking
             Method                                             Method
            Activation                                         Activation
                                   Mark word   01                                Stack pointer

 Lock     Displaced hdr                                       Mark word     01

Record                                Object                                        Object
               owner                                             owner
Java Performance
                                                                          17
                       Java Performance Fundamental | twitter @novathinker
                                    artdb@ex-em.com | performeister.tistory.com
      Hotspot Synchronization




  • Light-Weight Lock
     – Light-Weight Locking


    Unlock
                                Hash Code     Age         0   01

                                                      Recursive lock

Light weight lock                Pointer to lock record       00        Unlock




heavy weight lock                Pointer to heavyweight       10
Java Performance
                                                                      18
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Light-Weight Lock
  – Light-Weight Locking
        • Atomic Operation                multiprocessor

        •                 lock                         Thread
                      locking
        •          Thread     Lock

        •                    Thread      lock

               –
Java Performance
                                                                      19
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Biased Locking
  – Java 6                   default
        • Java 5 update 6
  – Light Weight lock
        •                    Object    lock             thread             lock

        •                                     CAS
  – Biased lock
        •             lock                    CAS
        •                          Thread           (biased)     lock
                             CAS
Java Performance
                                                                                  20
                    Java Performance Fundamental | twitter @novathinker
                                 artdb@ex-em.com | performeister.tistory.com
   Hotspot Synchronization




• Biased Locking
                                        Object
                                       Allocate
                     Bias enabled                     Bias disabled
Unlock                                                                            Unlock

   0         epoch Age        1   01              Hash Code     Age    0     01

                                                                Recursive lock
       Initial
        lock             Rebias   Revoke
                                   bias           Pointer to lock record     00
 locked
Thread
  ID
             epoch      Age   1 01
                                                  Pointer to heavyweight
                                                          monitor            10
           Lock / Unlock
Java Performance
                                                                      21
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Biased Locking
  – Biased lock
        • Mark word tag 1
        • 101  biased or biasable
               (thread id 0    unlocked)
  – Bias revocation
        • Lock         Thread                        Thread      lock
                  light weight lock
        • Owner thread        bias
        • Object            mark word
               –                 Thread    suspend      expensive
Java Performance
                                                                      22
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Biased Locking
  – Bulk Revocation
        •            Class     revocation
        •        Class       instance          bias     invalid
  – Bulk Rebiasing
        •                                           Thread
          lock                    class
        •    class           instance          bias    invalid
Java Performance
                                                                      23
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  Hotspot Synchronization




• Biased Locking
  – Option
        • -XX:+UseBiasedLocking                        (Java5 update
          6~)
          : biased lock
            java 6     default
        • -XX:BiasedLockingStartupDelay=0
          (Java6~)
          : JVM      Delay second
        • -XX:+TraceBiasedLocking
          (Java6~)
          : Biased Lock Debugging
Java Performance
         artdb@ex-em.com | performeister.tistory.com | twitter @novathinker




   IBM JVM
Synchronization
Java Performance
                                                                      25
                   Java Performance Fundamental | twitter @novathinker
                                artdb@ex-em.com | performeister.tistory.com
  IBM JVM Synchronization




• Thin Lock
  – Thin lock                  Fat lock
        • Fat Lock : heavy-weight locking system
        • Thin Lock : Light-weight locking system
              – Object lock
              – Recursive lock
        • Lock              default   thin
        • Lock
        • IBM JDK 1.1.2
Java Performance
                        Java Performance Fundamental | twitter @novathinker
       IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com         26




   • Thin Lock
       – Object Layout for Thin Lock
             • Lock Word
                                                                   Garbage Collection
                                                                   (2bits) bit (2bits)
                                                                   Pinned
                                          Object Size        G P
                                        (double word)                Array bit (1bit)
                                     Class pointer or array size
Monitor Shape bit                    Thread index count
     (1bit)                      S                        H T A
                                        Monitor index                Type
                                                                   Hash code state (2bits)
                                            Object Data


                                            Hash code
Java Performance
                   Java Performance Fundamental | twitter @novathinker
  IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com27




• Thin Lock
  – Object Layout for Thin Lock
       •        Object       Lock Word              24 bit
       • Lock Word                bit    Lock
              – Monitor Shape Lock
              – 0  Thin lock
              – 1  Fat lock
       • Thin Lock                              •Recursive (nested) lock count
                                                •Maximum 255 nested lock


                                    Count
        0 Thread ID (15 bits)
                                    (8bits)
Java Performance
                      Java Performance Fundamental | twitter @novathinker
     IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com   28




 • Thin Lock
                                                                             Spin
     – Thin Locking                                                          lock
                                                                             loop

                          Fail        Own            No          Get
          CAS
                                      Lock?                     Lock?       No
            Success                         YES                      YES

     0                             Nested Lock                Lock
24bit monitor shape,               Count
 count   0                           Lock Release         Fat lock
   Thread ID                                          Monitor index        monitor
                                    Count
     Lock Release                                          index

  Lock word
    CAS                                                   Monitor shape      1
Java Performance
                   Java Performance Fundamental | twitter @novathinker
  IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com
                                                                         29




• Lock Reservation
  – Java 5
  – Atomic Operation
        • 75%                             Lock                    thread

        •                   Performance
  –              Idea
        • Object            Lock        (reserve)                   cost
Java Performance
                   Java Performance Fundamental | twitter @novathinker
  IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com
                                                                         30




• Lock Reservation
  – Object Layout
       • Object Header               Lock Word
       • LRV bit : Lock             reserved
              –1           Reserved
              –0               locking System                     LRV bit


    Thread ID                               Recursion Cnt*     1



    (defined by base locking algorithm)                         0
Java Performance
                   Java Performance Fundamental | twitter @novathinker
  IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com
                                                                         31




• Lock Reservation
  – Reserved mode
        • Reserve             Thread ID
        • Recursion Count             Lock Acquisition



   Thread ID                    0        1    Reserved, Released


   Thread ID                    >0       1    Reserved ,


   0                            0        1    Reserved
Java Performance
                   Java Performance Fundamental | twitter @novathinker
  IBM JVM Synchronization       artdb@ex-em.com | performeister.tistory.com
                                                                         32




• Lock Reservation
  – Locking
        • Reserved mode                   atomic operation
          Recursion count
        •            Thread                         Reservation cancel
                                               unreserve
            0         0 1      Thread ID 0 1               aaaaaa    0
                              acquire     release
                   acquire                     unreserve
                               Thread ID 1 1               bbbbbb    0
                              acquire     release
                                               unreserve
                               Thread ID 2 1               ccccccc   0


                Reserved Mode                              Base Mode
Java Performance
                                                   33
Java Performance Fundamental | twitter @novathinker
             artdb@ex-em.com | performeister.tistory.com

More Related Content

What's hot

Java Online Training
Java Online TrainingJava Online Training
Java Online Training
Srihitha Technologies
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuning
Igor Igoroshka
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-land
Kresten Krab Thorup
 
JDK7: Improved support for dynamic languages
JDK7: Improved support for dynamic languagesJDK7: Improved support for dynamic languages
JDK7: Improved support for dynamic languages
Sander Mak (@Sander_Mak)
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
Charles Nutter
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
Ayushman Jain
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
weili_at_slideshare
 
JavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI MigratJavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI Migrat
SAP HANA Cloud Platform
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & Tuning
Muhammed Shakir
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
Amol Pujari
 
Course syllabus from ingenious
Course syllabus from ingeniousCourse syllabus from ingenious
Course syllabus from ingenious
Colege Buz
 
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning TalksBuilding Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Atlassian
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 

What's hot (18)

Java Online Training
Java Online TrainingJava Online Training
Java Online Training
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuning
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-land
 
JDK7: Improved support for dynamic languages
JDK7: Improved support for dynamic languagesJDK7: Improved support for dynamic languages
JDK7: Improved support for dynamic languages
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
JavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI MigratJavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI Migrat
 
Java J2EE Training in Chennai, Tambaram
Java J2EE  Training in Chennai, TambaramJava J2EE  Training in Chennai, Tambaram
Java J2EE Training in Chennai, Tambaram
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & Tuning
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Course syllabus from ingenious
Course syllabus from ingeniousCourse syllabus from ingenious
Course syllabus from ingenious
 
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning TalksBuilding Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
 
MJB Technologies
MJB TechnologiesMJB Technologies
MJB Technologies
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 

Viewers also liked

Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
김 한도
 
In memory as a data innovation
In memory as a data innovationIn memory as a data innovation
In memory as a data innovation
김 한도
 
Correct and efficient synchronization of java thread
Correct and efficient synchronization of java threadCorrect and efficient synchronization of java thread
Correct and efficient synchronization of java thread
outofmemoryerror
 
Learning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and SynchronizationLearning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and Synchronization
caswenson
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
실시간 빅데이터와 머신 데이터
실시간 빅데이터와 머신 데이터실시간 빅데이터와 머신 데이터
실시간 빅데이터와 머신 데이터
김 한도
 
Interface
InterfaceInterface
Interface
kamal kotecha
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
Hareem Naz
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 

Viewers also liked (20)

Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
 
In memory as a data innovation
In memory as a data innovationIn memory as a data innovation
In memory as a data innovation
 
Correct and efficient synchronization of java thread
Correct and efficient synchronization of java threadCorrect and efficient synchronization of java thread
Correct and efficient synchronization of java thread
 
Learning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and SynchronizationLearning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and Synchronization
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
실시간 빅데이터와 머신 데이터
실시간 빅데이터와 머신 데이터실시간 빅데이터와 머신 데이터
실시간 빅데이터와 머신 데이터
 
Interface
InterfaceInterface
Interface
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 

Similar to 6장 Thread Synchronization

Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
Thread model of java
Thread model of javaThread model of java
Thread model of javamyrajendra
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
Martijn Verburg
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
Scotas - Oracle Open World Sao Pablo
Scotas - Oracle Open World Sao PabloScotas - Oracle Open World Sao Pablo
Scotas - Oracle Open World Sao PabloJulian Arocena
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
Martijn Verburg
 
Introduction to Napa.js
Introduction to Napa.jsIntroduction to Napa.js
Introduction to Napa.js
Daiyi Peng
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
Scala profiling
Scala profilingScala profiling
Scala profiling
Filippo Pacifici
 
Java Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVMJava Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVM
odnoklassniki.ru
 
Dependency injection
Dependency injectionDependency injection
Dependency injectionhousecor
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
Scheidt & Bachmann
 
Introduction to java by priti sajja
Introduction to java by priti sajjaIntroduction to java by priti sajja
Introduction to java by priti sajja
Priti Srinivas Sajja
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornMiroslav Resetar
 
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav RešetarJavantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Practical maven-slides 2
Practical maven-slides 2Practical maven-slides 2
Practical maven-slides 2Will Iverson
 
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
srisatish ambati
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
Core java 5 days workshop stuff
Core java 5 days workshop stuffCore java 5 days workshop stuff
Core java 5 days workshop stuffRajiv Gupta
 

Similar to 6장 Thread Synchronization (20)

Spring framework
Spring frameworkSpring framework
Spring framework
 
Thread model of java
Thread model of javaThread model of java
Thread model of java
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Scotas - Oracle Open World Sao Pablo
Scotas - Oracle Open World Sao PabloScotas - Oracle Open World Sao Pablo
Scotas - Oracle Open World Sao Pablo
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Introduction to Napa.js
Introduction to Napa.jsIntroduction to Napa.js
Introduction to Napa.js
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
Scala profiling
Scala profilingScala profiling
Scala profiling
 
Java Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVMJava Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVM
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Introduction to java by priti sajja
Introduction to java by priti sajjaIntroduction to java by priti sajja
Introduction to java by priti sajja
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript Nashorn
 
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav RešetarJavantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
 
Practical maven-slides 2
Practical maven-slides 2Practical maven-slides 2
Practical maven-slides 2
 
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
 
Core java 5 days workshop stuff
Core java 5 days workshop stuffCore java 5 days workshop stuff
Core java 5 days workshop stuff
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 

6장 Thread Synchronization

  • 1. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Thread Synchronization
  • 2. Java Performance 2 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Thread Synchronization 1) Java Thread 2) Thread Synchronization 3) Cooperation 4) Mutual execution 5) Light-Weight Lock Hotspot Synchronization 1) Light-Weight Lock 2) Biased Locking IBM JVM Synchronization 1) Thin Lock 2) Lock Reservation
  • 3. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Thread Synchnonization
  • 4. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Java Thread – Green Thread • JVM Created, scheduling Thread • 1.1 JVM Thread model • OS Thread n:1 • OS Thread • CPU – Native Thread • OS Kernel Thread • 1.3 Default
  • 5. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Thread Synchronization – Monitor : Java Synchronization Mechanism – Monitor • Cooperation – Class object wait(),notify() – Thread • Mutual Exclusion – Class class –
  • 6. Java Performance 6 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Cooperation – Cooperation • wait() Reader Thread Buffer empty Listen notify() Thread Buffer full
  • 7. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Cooperation – Monitor Monitor Critical Section Monitor suspend
  • 8. Java Performance 8 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Cooperation – Monitor
  • 9. Java Performance 9 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Mutual Exclusion – Shared Data • Runtime Data Area Data Thread • Heap  Instance Variables • Method Area  Class Variables • Object Class Monitor lock • Mutex object lock • Object Lock – Thread Object
  • 10. Java Performance 10 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Mutual Exclusion – Object Lock • Class file java.lang.class instance • Object lock object(instance) locking • Thread object locking • object lock counter – Lock count – Lock count – Count = 0 thread lock • Thread Critical Section lock
  • 11. Java Performance 11 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Mutual Exclusion – Critical Section • Critical Section – Synchronized statement – Synchronized method • Critical section object reference • Critical section instruction thread object lock • Critical section lock release • Object Lock critical section JVM
  • 12. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Thread Synchronization • Light-Weight Lock – light-weight lock • JVM Light-Weight Lock • Object OS Mutex heavy- weight lock • locking No Atomic Operation Enter, Exit monitor Contended Heavy-Weight OS Lock Yes
  • 13. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Hotspot Synchronization
  • 14. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Light-Weight Lock – Object Header • Object Header word Mark Work Mark Word Hash Code (0) Age Biased Tag Thread ID, epoch(1) 23 bit 6 bit 1 bit 2 bit Hash Code (0) Age Biased Tag Biased bit Tag Thread ID, epoch(1) 0 01 Unlocked (000) Lock Record Address 0 00 Light-weight locked (010) Monitor Address 0 10 Heavy-weight locked 0 11 Marked for GC (011) Forwarding Address 1 01 Biased / Biasable
  • 15. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Light-Weight Lock – Light-Weight Locking • Object Header word Mark Work • Atomic compare-and-swap(CAS) instruction lock • CAS thread lock • CAS heavy weight lock • Object lock thread stack frame mark word move (displaced mark ) • Lock Mark Word
  • 16. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Light-Weight Lock – Light-Weight Locking Execution Execution Stack Stack Locking Method Method Activation Activation Mark word 01 Stack pointer Lock Displaced hdr Mark word 01 Record Object Object owner owner
  • 17. Java Performance 17 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Light-Weight Lock – Light-Weight Locking Unlock Hash Code Age 0 01 Recursive lock Light weight lock Pointer to lock record 00 Unlock heavy weight lock Pointer to heavyweight 10
  • 18. Java Performance 18 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Light-Weight Lock – Light-Weight Locking • Atomic Operation multiprocessor • lock Thread locking • Thread Lock • Thread lock –
  • 19. Java Performance 19 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Biased Locking – Java 6 default • Java 5 update 6 – Light Weight lock • Object lock thread lock • CAS – Biased lock • lock CAS • Thread (biased) lock CAS
  • 20. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Biased Locking Object Allocate Bias enabled Bias disabled Unlock Unlock 0 epoch Age 1 01 Hash Code Age 0 01 Recursive lock Initial lock Rebias Revoke bias Pointer to lock record 00 locked Thread ID epoch Age 1 01 Pointer to heavyweight monitor 10 Lock / Unlock
  • 21. Java Performance 21 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Biased Locking – Biased lock • Mark word tag 1 • 101  biased or biasable (thread id 0 unlocked) – Bias revocation • Lock Thread Thread lock light weight lock • Owner thread bias • Object mark word – Thread suspend  expensive
  • 22. Java Performance 22 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Biased Locking – Bulk Revocation • Class revocation • Class instance bias invalid – Bulk Rebiasing • Thread lock class • class instance bias invalid
  • 23. Java Performance 23 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Synchronization • Biased Locking – Option • -XX:+UseBiasedLocking (Java5 update 6~) : biased lock java 6 default • -XX:BiasedLockingStartupDelay=0 (Java6~) : JVM Delay second • -XX:+TraceBiasedLocking (Java6~) : Biased Lock Debugging
  • 24. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker IBM JVM Synchronization
  • 25. Java Performance 25 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JVM Synchronization • Thin Lock – Thin lock Fat lock • Fat Lock : heavy-weight locking system • Thin Lock : Light-weight locking system – Object lock – Recursive lock • Lock default thin • Lock • IBM JDK 1.1.2
  • 26. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 26 • Thin Lock – Object Layout for Thin Lock • Lock Word Garbage Collection (2bits) bit (2bits) Pinned Object Size G P (double word) Array bit (1bit) Class pointer or array size Monitor Shape bit Thread index count (1bit) S H T A Monitor index Type Hash code state (2bits) Object Data Hash code
  • 27. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com27 • Thin Lock – Object Layout for Thin Lock • Object Lock Word 24 bit • Lock Word bit Lock – Monitor Shape Lock – 0  Thin lock – 1  Fat lock • Thin Lock •Recursive (nested) lock count •Maximum 255 nested lock Count 0 Thread ID (15 bits) (8bits)
  • 28. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 28 • Thin Lock Spin – Thin Locking lock loop Fail Own No Get CAS Lock? Lock? No Success YES YES 0 Nested Lock Lock 24bit monitor shape, Count count 0 Lock Release Fat lock Thread ID Monitor index monitor Count Lock Release index Lock word CAS Monitor shape 1
  • 29. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 29 • Lock Reservation – Java 5 – Atomic Operation • 75% Lock thread • Performance – Idea • Object Lock (reserve) cost
  • 30. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 30 • Lock Reservation – Object Layout • Object Header Lock Word • LRV bit : Lock reserved –1 Reserved –0 locking System LRV bit Thread ID Recursion Cnt* 1 (defined by base locking algorithm) 0
  • 31. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 31 • Lock Reservation – Reserved mode • Reserve Thread ID • Recursion Count Lock Acquisition Thread ID 0 1 Reserved, Released Thread ID >0 1 Reserved , 0 0 1 Reserved
  • 32. Java Performance Java Performance Fundamental | twitter @novathinker IBM JVM Synchronization artdb@ex-em.com | performeister.tistory.com 32 • Lock Reservation – Locking • Reserved mode atomic operation Recursion count • Thread Reservation cancel unreserve 0 0 1 Thread ID 0 1 aaaaaa 0 acquire release acquire unreserve Thread ID 1 1 bbbbbb 0 acquire release unreserve Thread ID 2 1 ccccccc 0 Reserved Mode Base Mode
  • 33. Java Performance 33 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com