Code health is important for Google, and team have many tools to help Google's Java developers write correct and performant code. The following presentation presents two such tools: Java ThreadSanitizer and Heap Profiling. Java ThreadSanitizer is used during testing, and helps to find data races. Heap Profiling is used in production, and is concerned with efficient monitoring of heap usage. Both dive into the depths of the JVM, with many interesting technical challenges.
ThreadSanitizer (TSAN) is a well-known dynamic data race detection tool based on LLVM. . For many years, Google's Java developers had no tool to detect data races. There is a strong desire to see data races across the Java/JNI boundary to facilitate debugging. Hence, team have added enough instrumentation in the JVM and the JDK to allow the TSAN runtime to understand Java synchronization and see Java fields.
Some of challenges encountered:
- adapting to TSAN's fixed-offset instrumentation when Java objects get moved,
- the need to track *all* sources of user-visible synchronization in the JVM (including j.u.concurrent),
- the need to annotate JDK classes for correct-by-JMM races,
- correct forwarding of signal handling,
- symbolization of race reports.
Despite this, there has been a steady stream of adoption by internal teams over the years. Another aspect of Google tooling is understanding the memory footprint and how to effectively reduce it. One constraint is having the mechanism on by default and, as a
consequence, the system must have a low overhead. The solution is the second tool called Heap Profiling. The solution provides users with statistical information about where the Java program is allocating its memory by providing stacktraces. It tracks via the Garbage Collection's passes what objects have been collected to offer insight on objects that are heavily churning and those that are remaining in the heap. This information allows users to understand what allocation hotspots exist, which are causes for heap growth, and what objects are often Garbage Collected. To push the feature forward, a JEP was created (JDK-8171119) and work has gone at a steady pace to provide heap allocation understanding with a low overhead. The following presentation will showcase the system, what tools were built on top of the data, how it is used in Google, and why it is important for Java engineers.
In conclusion, both tools presented provide insight on the JVM: Java ThreadSanitizer helps understand thread concurrency and Heap Monitoring provides insight the memory allocation.