Approaches To Synchronization and GC
Approaches To Synchronization and GC
Ideal
Resources
1105163444 2
Scalability Inhibitors
1105163444 3
Application Lifetime
Performance
Time
1105163444 4
Where Is Your Application
Spending or Wasting Time?
1105163444 5
Don’t Get Blind-sided!
1105163444 6
Threads
1105163444 7
Threads: The Good News
1105163444 8
Threads: The Bad News
1105163444 9
Thread Implementations
1105163444 10
Tips: Thread Usage
1105163444 11
Synchronization
1105163444 12
To Synchronize or Not
1105163444 13
Synchronized Methods
1105163444 14
Synchronized Blocks
this.y_ = y; ..
} MonitorExit
} ..
..
}
1105163444 15
Monitors
1105163444 16
Tips
1105163444 17
Splitting Monitors
1105163444 18
Example: Unnecessary
Contention on ‘This’
…
public synchronized void insertLowPriority(QueueElement q) {
…
…
}
public synchronized void insertHighPriority(QueueElement q) {
…
…
}
}
1105163444 19
Example: Split Monitor
1105163444 20
Internal VM Synchronization
Mechanisms Can Hurt Too!
• JIT Compilers
– May need to lock various structures shared with
the VM
• Heap Lock
– Global object allocation must synchronize access
to the shared heap, and may cause contention
1105163444 21
Memory Management
1105163444 22
Allocation and Collection
• Allocation
– Heap Lock
– Data Locality
– Stack Allocation
– Thread-local
1105163444 23
Garbage Collection
Frequently Frees up Memory?
1105163444 24
Garbage Collection Does
Not Free up Much Memory
1105163444 25
Software Stack
• File/Network
• Graphics
– Is the graphics API scalable
• RMI
– May spawn threads behind your back
• Middleware
– Some may invoke Runtime.gc()too often
1105163444 26
Conclusions
1105163444 27
References
1105163444 28
1105163444 29