-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.
- [JDK-8037595] Enable type speculation by default - Java Bug System
- [JDK-8038636] speculative traps break when classes are redefined - Java Bug System
- [JDK-8040237] nsk/jvmti/RetransformClasses/retransform001 crashed the VM on all platforms when run with with -server -Xcomp - Java Bug System
Essentially this bug in the JVM optimization feature can cause the JVM to crash.
-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.