SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Java Performance Fundamental 세미나 자료입니다. 6장은 Thread Synchronization를 다루고 있습니다. 여기서는 Java에서 Thread라는 것은 어떻게 관리되어 왔으며 동기화는 어떤 역할을 하는지를 설명합니다. 더 나아가 JVM의 버전이 올라가면서 추가된 Hotspot JVM의 Biased Lock이나 IBM JVM의 Lock Reservation에 대해서도 설명하고 있습니다.
Java Performance Fundamental 세미나 자료입니다. 6장은 Thread Synchronization를 다루고 있습니다. 여기서는 Java에서 Thread라는 것은 어떻게 관리되어 왔으며 동기화는 어떤 역할을 하는지를 설명합니다. 더 나아가 JVM의 버전이 올라가면서 추가된 Hotspot JVM의 Biased Lock이나 IBM JVM의 Lock Reservation에 대해서도 설명하고 있습니다.
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
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