Using -XX:-UseTypeSpeculation with the OverOps Agent

What is -XX:-UseTypeSpeculation? Why does the OverOps agent need it when running our applications using Java 11 or higher?

Since JVM optimization was introduced in Java there was a bug originally discovered in Java 8, fixed in Java 9, and a new form of that bug was introduced in Java 11.

Essentially this bug in the JVM optimization feature can cause the JVM to crash.

The -XX:-UseTypeSpeculation argument disables the optimization.

It’s important to note that this is a very minor optimization, and disabling it should not have any noticeable impact on performance.

The optimization allows a method (i.e., method B) to make assumptions on the types of some arguments passed to it by another method (i.e., method A), only in case the JVM decides to inline method B in method A and if method A passes to method B polymorphic arguments.

When the above happens, the optimization allows method B to assume types instead of performing a cast-check or an instance-of.

For this reason, it is required to use this parameter when using the OverOps agent with any applications running on Java 11 or higher.