I want to instrument ScalaCheck compiled with/for scala 2.12, using JDI.
By running javap
I have concluded that scalac 2.12.x emits invokedynamic instructions (for some values of x) where scala 2.11 used to generate inner classes, in particular for nested methods/functions.
This presents a challenge, since for performance reasons I would like to set and unset breakpoints on some particular nested functions (result(x: T)
in Prop.forAllShrink
, to be particular).
Is it possible to instrument invokedynamic
code with JDI? If so, how?
I'm new to invokedynamic
and unclear about how that mechanism works. My understanding is that your code (the code emitted by scalac in my example) makes a linking decision at every invokedynamic
invocation, except that for performance reasons this decision is cached based on a user-specifiable criterion. However, no run-time code generation is performed. This suggests that in principle invokedynamic
code should be instrumentable.
I also saw a scary name in some scalac output: deserializeLambda
. I'm not quite sure what it entails, but I don't think it means I'm going to have an easy time.