Slide 1

Slide 1 text

Bachelor Thesis Presentation Konrad Johannes Reiche Supervised by Prof. Dr. Marcel Kyas Profiling Concurrency

Slide 2

Slide 2 text

2 Threads are everywhere • Writing correct programs is hard • But, writing correct concurrent programs is even harder • Sharing resources without synchronization: Concurrency Bugs Non-deterministic Scheduling • Example: NetBeans – trying to patch a single class over 14 times for fixing a thread related problem Profiling Concurrency, August 18, 2011

Slide 3

Slide 3 text

3 Quality Assurance • quality assurance cannot only reached by carefully considered design • instead: use testing tools – Analytical Quality Assurance Profiler Dynamic Program Analysis • measure program routines and memory consumption • monitor and trace events, measure the costs • kind of measured values depends on the requirements Profiling Concurrency, August 18, 2011

Slide 4

Slide 4 text

4 Problem Statement • trace information about threads • trace information about their interactions with each other • make access to synchronized data visible • reveal information about classes thread-safety • measure events related to monitors and higher synchronization primitives – Semaphore, Barrier, etc. • visualize the collected data Profiling Concurrency, August 18, 2011 What should be achieved?

Slide 5

Slide 5 text

5 JVMTI Java Virtual Machine Tool Interface Profiling Concurrency, August 18, 2011

Slide 6

Slide 6 text

6 JVMTI Naive approach: direct profiling with printf debugging Better: JVMTI decouples JVM and presentation of the profiling information Profiling Concurrency, August 18, 2011 Profiler Process Profiler Front End JVM Process Java Virtual Machine Profiling Agent Tool Interface Event Control Communication Protocol

Slide 7

Slide 7 text

7 Event-Based Profiling Instrumentation: Ability to monitor or measure the product’s performance and diagnose possible errors What kind of events? … and many more Profiling Concurrency, August 18, 2011 Thread Start/End Method Entry/Exit Monitor Contention

Slide 8

Slide 8 text

8 How do you measure concurrent program execution? Profiling Concurrency, August 18, 2011

Slide 9

Slide 9 text

9 Design Profiling Concurrency, August 18, 2011 Profiler Process Profiler Front End JVM Process Java Virtual Machine Profiling Agent Tool Interface Event Control Communication Protocol C++ Shared Library Event Callbacks Message Service Utilities View Controller Model Service protobuf

Slide 10

Slide 10 text

10 FUNCTIONALITY What are the results? Profiling Concurrency, August 18, 2011

Slide 11

Slide 11 text

11 public class EnhancedSynchronizedList { public List list = Collections.synchronizedList(new ArrayList()); public boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Use Case: Extending a Thread-Safe Class Profiling Concurrency, August 18, 2011 synchronized

Slide 12

Slide 12 text

12 public class EnhancedSynchronizedList { public List list = Collections.synchronizedList(new ArrayList()); public boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Use Case: Extending a Thread-Safe Class Profiling Concurrency, August 18, 2011 synchronized Is it still thread-safe?

Slide 13

Slide 13 text

13 Start the Profiling Profiling Concurrency, August 18, 2011

Slide 14

Slide 14 text

14 General View Profiling Concurrency, August 18, 2011

Slide 15

Slide 15 text

15 Monitor Log Profiling Concurrency, August 18, 2011

Slide 16

Slide 16 text

16 Monitor Log Profiling Concurrency, August 18, 2011

Slide 17

Slide 17 text

17 Monitor Profiling Concurrency, August 18, 2011

Slide 18

Slide 18 text

18 Deadlock Detection Profiling Concurrency, August 18, 2011

Slide 19

Slide 19 text

19 Method Profiling Profiling Concurrency, August 18, 2011

Slide 20

Slide 20 text

20 Method Profiling Profiling Concurrency, August 18, 2011

Slide 21

Slide 21 text

21 Use Case: Extending a Thread-Safe Class public class EnhancedSynchronizedList { public List list = Collections.synchronizedList(new ArrayList()); public synchronized boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Profiling Concurrency, August 18, 2011 Class Context EnhancedSynchronizedList EnhancedSynchronizedList.putIfAbsent java.util.Collections$SynchronizedCollection Collections$SynchronizedCollection.add

Slide 22

Slide 22 text

22 Use Case: Extending a Thread-Safe Class public class EnhancedSynchronizedList { public List list = Collections.synchronizedList(new ArrayList()); Profiling Concurrency, August 18, 2011 Class Context EnhancedSynchronizedList EnhancedSynchronizedList.putIfAbsent java.util.Collections$SynchronizedCollection Collections$SynchronizedCollection.add public boolean putIfAbsent(T x) { synchronized (list) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } } return isAbsent; }

Slide 23

Slide 23 text

23 EVALUATION How can it be evaluated? Profiling Concurrency, August 18, 2011

Slide 24

Slide 24 text

24 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Already little information helps to identify design flaws

Slide 25

Slide 25 text

25 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiling many threads leads to information overload Solution: introducing filters

Slide 26

Slide 26 text

26 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Stack traces put the traced events into a context

Slide 27

Slide 27 text

27 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiling many threads leads to information overload Solution: introducing filters

Slide 28

Slide 28 text

28 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Method profiling can lead to huge overhead Application took over 240 times longer to execute

Slide 29

Slide 29 text

29 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Relying on event callbacks only is not sufficient in order to profile higher synchronization primitives

Slide 30

Slide 30 text

30 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiler is able to detect deadlocks dynamically

Slide 31

Slide 31 text

31 Use Cases Profiling Concurrency, August 18, 2011 • Extending a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Already little information helps to identify design flaws

Slide 32

Slide 32 text

32 CONCLUSION What is the bottom line? Profiling Concurrency, August 18, 2011

Slide 33

Slide 33 text

33 Conclusion Profiling Concurrency, August 18, 2011 • noticeable information gain • successful tracking of synchronization events • reveals information about thread-safety • can inspect a past state of the program • visualization helps to examine the data • depending on the application: overhead • fails for higher synchronization primitives • limited to tracking monitor events and performing method profiling

Slide 34

Slide 34 text

34 Summary and Further Work • JVMTI eases development of a decoupled profiler • tracing events is easy when the type of event is supported • using event callbacks only is not sufficient and inefficient • overhead can be reduced through heavy use of filters and byte code instrumentation • extend profiler by using bytecode instrumentation • record scheduling decisions • reduce overhead • compare with alternative profiling methods Profiling Concurrency, August 18, 2011

Slide 35

Slide 35 text

35 Thank you! Feel free to clone my project on GitHub: https://github.com/platzhirsch/Profiling-Concurrency Profiling Concurrency, August 18, 2011