Movatterモバイル変換


[0]ホーム

URL:


김 한도, profile picture
Uploaded by김 한도
KEY, PDF5,637 views

6장 Thread Synchronization

The document discusses thread synchronization in Java. It covers Java threads, synchronization mechanisms like monitors and locks, cooperation between threads using wait() and notify(), and mutual exclusion with synchronized blocks and methods. It also describes lightweight locking techniques used in Hotspot like biased locking, and thin locks and lock reservation in IBM's JVM.

Embed presentation

Downloaded 182 times
Java Performance            artdb@ex-em.com | performeister.tistory.com | twitter @novathinkerThread Synchronization
Java Performance                                                                                     2                            artdb@ex-em.com | performeister.tistory.com | twitter @novathinkerThread Synchronization  1)   Java Thread  2)   Thread Synchronization  3)   Cooperation  4)   Mutual execution  5)   Light-Weight LockHotspot Synchronization  1) Light-Weight Lock  2) Biased LockingIBM JVM Synchronization  1) Thin Lock  2) Lock Reservation
Java Performance         artdb@ex-em.com | performeister.tistory.com | twitter @novathinker    ThreadSynchnonization
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    HotspotSynchronization
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 bitHash Code (0)            Age       Biased   Tag   Biased bit TagThread 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     01Record                                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 lockLight weight lock                Pointer to lock record       00        Unlockheavy 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 disabledUnlock                                                                            Unlock   0         epoch Age        1   01              Hash Code     Age    0     01                                                                Recursive lock       Initial        lock             Rebias   Revoke                                   bias           Pointer to lock record     00 lockedThread  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 JVMSynchronization
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 sizeMonitor 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                Lock24bit 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                                                   33Java Performance Fundamental | twitter @novathinker             artdb@ex-em.com | performeister.tistory.com

Recommended

KEY
2장. Runtime Data Areas
KEY
1장 Java란 무엇인가.key
KEY
3장. Garbage Collection
KEY
4장. Class Loader
KEY
5장. Execution Engine
KEY
7장 Oracle As Datasource
DOC
Java Classroom Training
DOC
J2EE Online Training
DOC
Java Online Training
PDF
Java 8 selected updates
PPT
Jvm performance tuning
PDF
Polyglot Plugin Programming
KEY
Erjang - A journey into Erlang-land
PDF
JDK7: Improved support for dynamic languages
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PDF
Invokedynamic in 45 Minutes
PDF
How to train the jdt dragon
PDF
Build Java Web Application Using Apache Struts
PDF
JavaOne 2010: OSGI Migrat
DOCX
Java J2EE Training in Chennai, Tambaram
PPT
Java Performance Monitoring & Tuning
PPT
Ruby on rails
DOC
Course syllabus from ingenious
PDF
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
PDF
MJB Technologies
PPTX
Top 50 java ee 7 best practices [con5669]
PDF
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
PDF
In memory as a data innovation
PDF
Correct and efficient synchronization of java thread
PPT
Learning Java 3 – Threads and Synchronization

More Related Content

KEY
2장. Runtime Data Areas
KEY
1장 Java란 무엇인가.key
KEY
3장. Garbage Collection
KEY
4장. Class Loader
KEY
5장. Execution Engine
KEY
7장 Oracle As Datasource
DOC
Java Classroom Training
DOC
J2EE Online Training
2장. Runtime Data Areas
1장 Java란 무엇인가.key
3장. Garbage Collection
4장. Class Loader
5장. Execution Engine
7장 Oracle As Datasource
Java Classroom Training
J2EE Online Training

What's hot

DOC
Java Online Training
PDF
Java 8 selected updates
PPT
Jvm performance tuning
PDF
Polyglot Plugin Programming
KEY
Erjang - A journey into Erlang-land
PDF
JDK7: Improved support for dynamic languages
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PDF
Invokedynamic in 45 Minutes
PDF
How to train the jdt dragon
PDF
Build Java Web Application Using Apache Struts
PDF
JavaOne 2010: OSGI Migrat
DOCX
Java J2EE Training in Chennai, Tambaram
PPT
Java Performance Monitoring & Tuning
PPT
Ruby on rails
DOC
Course syllabus from ingenious
PDF
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
PDF
MJB Technologies
PPTX
Top 50 java ee 7 best practices [con5669]
Java Online Training
Java 8 selected updates
Jvm performance tuning
Polyglot Plugin Programming
Erjang - A journey into Erlang-land
JDK7: Improved support for dynamic languages
Java 7 Whats New(), Whats Next() from Oredev
Invokedynamic in 45 Minutes
How to train the jdt dragon
Build Java Web Application Using Apache Struts
JavaOne 2010: OSGI Migrat
Java J2EE Training in Chennai, Tambaram
Java Performance Monitoring & Tuning
Ruby on rails
Course syllabus from ingenious
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
MJB Technologies
Top 50 java ee 7 best practices [con5669]

Viewers also liked

PDF
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
PDF
In memory as a data innovation
PDF
Correct and efficient synchronization of java thread
PPT
Learning Java 3 – Threads and Synchronization
PDF
Java Thread Synchronization
PPT
Java Arrays
PPT
Java: Introduction to Arrays
PPTX
Arrays in Java
PDF
Constructors and Destructors
PDF
실시간 빅데이터와 머신 데이터
PPS
Interface
PPTX
PPTX
Constructors & destructors
PPTX
Inheritance in JAVA PPT
PDF
Introduction to Java Programming
PPTX
Arrays in java language
PPT
Core java slides
PPT
Java interfaces
PDF
Constructor and Destructor
PPTX
Constructor ppt
Big Data Myth 1. 우리 회사엔 빅데이터가 없어요
In memory as a data innovation
Correct and efficient synchronization of java thread
Learning Java 3 – Threads and Synchronization
Java Thread Synchronization
Java Arrays
Java: Introduction to Arrays
Arrays in Java
Constructors and Destructors
실시간 빅데이터와 머신 데이터
Interface
Constructors & destructors
Inheritance in JAVA PPT
Introduction to Java Programming
Arrays in java language
Core java slides
Java interfaces
Constructor and Destructor
Constructor ppt

Similar to 6장 Thread Synchronization

PPTX
Threading in java - a pragmatic primer
PPT
Programming - Java-Threads-and-Synchronization.ppt
PDF
Programming with Threads in Java
PPS
Java session13
PPTX
Thread model of java
PPT
Java Performance, Threading and Concurrent Data Structures
PDF
Concurrency: Best Practices
PPTX
Java class 6
PDF
Java Threads: Lightweight Processes
PPT
Java multi threading
PPTX
Concurrency in Java
PPTX
Basics of Java Concurrency
PPTX
THREADALLABOUTCOMOUTERHOWTOYHISDOTH.pptx
PPTX
MULTITHREADING PROGRAMMING AND I/O THREAD
PPTX
Concurrency with java
PPTX
Concurrency with java
PPTX
Concurrency with java
PPTX
Concurrency with java
PPTX
Concurrency with java
PPTX
Concurrency with java
Threading in java - a pragmatic primer
Programming - Java-Threads-and-Synchronization.ppt
Programming with Threads in Java
Java session13
Thread model of java
Java Performance, Threading and Concurrent Data Structures
Concurrency: Best Practices
Java class 6
Java Threads: Lightweight Processes
Java multi threading
Concurrency in Java
Basics of Java Concurrency
THREADALLABOUTCOMOUTERHOWTOYHISDOTH.pptx
MULTITHREADING PROGRAMMING AND I/O THREAD
Concurrency with java
Concurrency with java
Concurrency with java
Concurrency with java
Concurrency with java
Concurrency with java

Recently uploaded

PDF
Session 1 - Solving Semi-Structured Documents with Document Understanding
PDF
Usage Control for Process Discovery through a Trusted Execution Environment
PPTX
Chapter 3 Introduction to number system.pptx
PPTX
AI in Cybersecurity: Digital Defense by Yasir Naveed Riaz
PDF
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
PPTX
From Backup to Resilience: How MSPs Are Preparing for 2026
 
PDF
Zero Trust & Defense-in-Depth: The Future of Critical Infrastructure Security
PPTX
Cybercrime in the Digital Age: Risks, Impact & Protection
PPTX
Data Privacy and Protection: Safeguarding Information in a Connected World
PDF
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
PDF
Energy Storage Landscape Clean Energy Ministerial
PDF
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
PPTX
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
PPTX
Unit-4-ARTIFICIAL NEURAL NETWORKS.pptx ANN ppt Artificial neural network
DOCX
Introduction to the World of Computers (Hardware & Software)
PDF
Day 2 - Network Security ~ 2nd Sight Lab ~ Cloud Security Class ~ 2020
PDF
The year in review - MarvelClient in 2025
PDF
Vibe Coding vs. Spec-Driven Development [Free Meetup]
PDF
DIGITAL FORENSICS - Notes for Everything.pdf
PDF
The major tech developments for 2026 by Pluralsight, a research and training ...
Session 1 - Solving Semi-Structured Documents with Document Understanding
Usage Control for Process Discovery through a Trusted Execution Environment
Chapter 3 Introduction to number system.pptx
AI in Cybersecurity: Digital Defense by Yasir Naveed Riaz
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
From Backup to Resilience: How MSPs Are Preparing for 2026
 
Zero Trust & Defense-in-Depth: The Future of Critical Infrastructure Security
Cybercrime in the Digital Age: Risks, Impact & Protection
Data Privacy and Protection: Safeguarding Information in a Connected World
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
Energy Storage Landscape Clean Energy Ministerial
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
Unit-4-ARTIFICIAL NEURAL NETWORKS.pptx ANN ppt Artificial neural network
Introduction to the World of Computers (Hardware & Software)
Day 2 - Network Security ~ 2nd Sight Lab ~ Cloud Security Class ~ 2020
The year in review - MarvelClient in 2025
Vibe Coding vs. Spec-Driven Development [Free Meetup]
DIGITAL FORENSICS - Notes for Everything.pdf
The major tech developments for 2026 by Pluralsight, a research and training ...

6장 Thread Synchronization

  • 1.
    Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinkerThread Synchronization
  • 2.
    Java Performance 2 artdb@ex-em.com | performeister.tistory.com | twitter @novathinkerThread Synchronization 1) Java Thread 2) Thread Synchronization 3) Cooperation 4) Mutual execution 5) Light-Weight LockHotspot Synchronization 1) Light-Weight Lock 2) Biased LockingIBM JVM Synchronization 1) Thin Lock 2) Lock Reservation
  • 3.
    Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker ThreadSynchnonization
  • 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 HotspotSynchronization
  • 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 bitHash Code (0) Age Biased Tag Biased bit TagThread 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 01Record 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 lockLight weight lock Pointer to lock record 00 Unlockheavy 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 disabledUnlock Unlock 0 epoch Age 1 01 Hash Code Age 0 01 Recursive lock Initial lock Rebias Revoke bias Pointer to lock record 00 lockedThread 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 JVMSynchronization
  • 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 sizeMonitor 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 Lock24bit 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 33Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com

[8]ページ先頭

©2009-2025 Movatter.jp