jokerconf Joker 2016 (14.10.2016 — 15.10.2016)

HotSpot Internals: Safepoints, NullPointers and StackOverflows

img

In this session Volker will demonstrate how the HotSpot virtual machine implements features like null pointer dereferencing, out of bound array accesses and stack overflows and how the JIT compiler magically optimizes away most of the associated overhead. But Volker will also look at corner cases where some of the optimizations may fail.

In contrast to unmanaged languages like C/C++, Java is more secure because it catches frequent programming errors like null pointer dereferencing, out of bound array accesses or stack overflows. Of course, this security comes at a certain cost and earned Java the reputation of being slow. But current Java implementations are quite smart and can implement many of these checks at virtually zero costs.

Using small and simple examples, this session will demonstrate how the HotSpot virtual machine implements these features, and the JIT compiler magically optimizes away most of the associated overhead. Volker will also look at corner cases where some of the optimizations may fail.

Safepoints:

  • what is a safepoint;

  • why do we need safepoints;

  • what does the VM do at safepoints;

  • how do we reach a safepoint and how can we implement this efficiently;

  • safepoints and JNI/native code (accessing Java objects through handles);

NullPointer checks:

  • how can we implement them efficiently or eliminate them;

  • using OS signals and page faults when reading/writing from/to 0x0;

  • problems with compressed oops (0x0 will be mapped to start of heap);

  • field offset must be smaller than page size for implicit null checks;

  • some platforms (i.e. ppc64) require traps for null checks.

StackOverflow checks:

  • stack banging (yellow, red pages, ..);

  • problems when calling to native;

  • JEP 270: Reserved Stack Areas for Critical Sections.

  • If time allows, Volker will also take a look on ArrayBoundChecks.

As always, Volker will provide some small Java programs and use them to demonstrate the above points from Java down to bytecode and assembler.