What is Java ThreadSanitizer and Heap Monitoring?

Video overview of useful Java tools from Google developers
07 August 2017   562


Popular general-purpose programming language and computing platform

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.

What is Web3j?

Small review of lightweight Java and Android library for integration with Ethereum clients
15 December 2017   829

What is webj3?

web3j is a lightweight, highly modular, reactive, type safe Java and Android library for working with Smart Contracts and integrating with clients (nodes) on the Ethereum network:

web3j architecture
Web3j Architecture

This allows you to work with the Ethereum blockchain, without the additional overhead of having to write your own integration code for the platform.

According to the developers, these are the features:

  • Complete implementation of Ethereum's JSON-RPC client API over HTTP and IPC
  • Ethereum wallet support
  • Auto-generation of Java smart contract wrappers to create, deploy, transact with and call smart contracts from native Java code (Solidity and Truffle definition formats supported)
  • Reactive-functional API for working with filters
  • Ethereum Name Service (ENS) support
  • Support for Parity's Personal, and Geth's Personal client APIs
  • Support for Infura, so you don't have to run an Ethereum client yourself
  • Comprehensive integration tests demonstrating a number of the above scenarios
  • Command line tools
  • Android compatible
  • Support for JP Morgan's Quorum via web3j-quorum

It has five runtime dependencies:

  • RxJava for its reactive-functional API
  • OKHttp for HTTP connections
  • Jackson Core for fast JSON serialisation/deserialisation
  • Bouncy Castle (Spongy Castle on Android) for crypto
  • Jnr-unixsocket for *nix IPC (not available on Android)

It also uses JavaPoet for generating smart contract wrappers.

Lear more at GitHub.