Title: nminoru@nminoru.jp http://www.nminoru.jp/~nminoru/
1??????????????????????????????
- ?? ?
- nminoru_at_nminoru.jp http//www.nminoru.jp/nminoru/
2????????
- ??????????????
- Java VM?????GCJIT??????????
- Java??????????
- ???IA-64??????
- ??? Web ???????????????????
- ???????? Binary Hacks ????????????
3Binary Hacks 94??????????????????
- CPU ? Out-of-order ??
- ??????? load/store ?????????
- Load ????? (????)
- Store ????? (Store buffering)
- ?????????(memory ordering)
- CPU ???????????????
- ???????????????????????(??????)???
4Binary Hacks 94??????????????????
- Store Buffer
- Store ?????????????????
Register
Store Buffer
Store buffer
Store3
Load
Store2
Cache
Store1
Main memory/cache
Main memory
5Binary Hacks 94??????????????????
- ???????
- ??????????????????????????????????????
- Pthread ? mutex ? IPC ? semaphore ????????
- Cmpxchg ?????????
- ????????
- ?????????????????????????????????? Lock-free
synchronization ??? - ???????????????????????????????????? orz
6???????????
- ??????????????????
- ????????? (Web?????)
- ????????????
- ???????????/??? ? ????????????????
- ??????????
?
?????? ??GC??
7???????????????
- ??????? mutex ??????????(??)
- ?????????(conflict)???
- ???????????????????????
??
?????
CPU
CPU
CPU
CPU
CPU
CPU
Thread
Thread
Thread
Thread
Thread
Thread
Thread
Thread
Thread
Thread
8Mutex ? spin lock ?????? ???????????????
??!! Lock-free synchronization
9Lock-free synchronization
- ??
- ???????????????
- ?????????????????????
- ????
- ????????????????
- CAS (compare and swap) ? x86 ?? cmpxchg??
- LL/SC (load linked/store conditional)
- ??????????????
- Deque, FIFO, LIFO
- ??????,??????, Set, Hash
- ??? lock-free ??????????????
10Sequence lock
- Optimistic lock (???????)
- ?????? counter
- ???????????? lock-free
- ????????? lock ???
- Counter ????????????????
????
????
counter
- Read counter
- Read data
- Read counter
- ?????1?????
- 1?3?????
- data ?????????
- Counter ????? CAS ??? 1
- data ?????
- Counter ???? 1
data
11Read Copy Update (RCU)
- ??????
- ??????????
- ??????????
Reader
Writer
12Read Copy Update (RCU)
- ??????
- ??????????
- ??????????
Reader
copy
Writer
13Read Copy Update (RCU)
- ??????
- ??????????
- ??????????
Reader
Writer
14Read Copy Update (RCU)
- ??????
- ??????????
- ??????????
GC???
Writer
15Double-ended Queue (Deque)
- N.Arora et al.,Thread scheduling for
multiprogrammed multiprocessors,SPAA 1998 - OS ?????????????????? deque
- ??????????????????????
- ????????????? push ???
- Push?pop?lock-free ?????????????????
- Sun HotSpot VM ???GC???????????
Other threads
Owner thread
16???
- Deque
- M.Micheal, CAS-based lock-free algorithm for
shared dequeues, EuroPar 2003 - ??????
- H.Sundell, Lock-free and practical doubly
linked list-based deques using single-word
compare-and-swap, OPODIS 2004 - NOBLE - a library of non-blocking synchronization
protocolshttp//www.cs.chalmers.se/noble/
17??????????????
- ???????????!!
- Lock-free synchronization?????????????????????????
?????? - ?????????
- Ross Bencina ?????
- http//www.audiomulch.com/rossb/code/lockfree
- Lock-free wait-free ????????????????
- Lock-free library
- http//www.cl.cam.ac.uk/research/srg/netos/lock-fr
ee/ - Alpha, MIPS, IA-64, x86, PPC, SPARC ???
- GPL ???????
- ???????
- ???? wikipedia ???
- http//en.wikipedia.org/wiki/Lock-free_and_wait-fr
ee_algorithms
18??????
- ??(conflict)????????????mutex ????????
- ?????????
- ??????????
- ????????????????
- ??????
- CPU ? out-of-order ?????????????????
- ???????????????????? (_)/
19Sequence lock
- Optimistic lock (???????)
- ?????? counter
- ???????????? lock-free
- ????????? lock ???
- Counter ????????????????
3?? read ????????????????????? ?????????
????
????
counter
- Read counter
- Read data
- Read counter
- ?????1?????
- 1?3?????
- data ?????????
- Counter ????? CAS ??? 1
- data ?????
- Counter ???? 1
data
20x86?????????????
21x86 CPU ??????????
- X86 ????????????????????? CPU ?????????
RAR WAR WAW RAW
i386
i486,Pentium
P6
Opteron
?A? ? After ?
?????????
22x86 CPU????????
- ????????
- CPUID, Lock ???????
- ??????Store buffer ????????????????????????????
- ???
- ????????
- SFENCE ?? (Pentium3??)
- Store ? Store ????
- LFENCE ?? (Pentium4??)
- Load ? Load ????
- MFENCE ?? (Pentium4??)
- ????????????
23C/C ?????????????
- ??????????
- volatile ??????????? ABI ???
- ex. IA-64 ABI
- C0x ??????!
define mb() asm volatile ("mfencememory)
define rmb() asm volatile (lfencememory)
define wmb() asm volatile (sfencememory)
Evolution working group issue list ES066.
Support for parallel programming For example,
locks, threading, memory barrier, static local
initialization.
24???
- ?????????
- Mutex/spin lock ??????? (??????) Lock-free
synchronization ???? - Memory ordering
- ?????????????????????
- ??????????????????????????
??????????????