Parametric-vm spec / unused CONSTANT_Parameter is illegal
john.r.rose at oracle.com
Wed Mar 10 22:25:09 UTC 2021
On Mar 10, 2021, at 1:59 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> Hi all,
> slowly reading the Parametric-vm spec.
> With my ASM hat,
> "As a structural constraint, it is illegal for a CONSTANT_Parameter constant to be unused."
> This is different of all other CONSTANTs and doesn't work well with the idea that you can patch a classfile by copying the existing constant pool and replace only the method(s) you want, because if i replace a parametric method by a non parametric one, the existing CONSTANT_Parameter will stay in the constant pool with no reference to it anymore.
> Being able to patch a classfile like this is very important in term of speed for some transformers / agents.
> If the VM is able to find that a CONSTANT_Parameter is unused, instead of throwing an error, why not ignoring it ?
That’s possible. I agree that this makes parametric constants
unusual, in a way that doesn’t buy much.
Here’s my motivation: The presence of a C_Param forces
the JVM to do more work than if it were absent, work that
is non-local (a dependency analysis over the CP). Some of
that analysis is likely to create detailed CP metadata
describing the parametricity of each constant. Having
parts of that metadata be unused feels like it could breed
bugs. But, it’s just a feeling. I’m not against your request,
and maybe I’ll write it into the next draft.
(I have a vague memory that there was another reason
that occurred to me during prototyping the CP analysis,
but it’s been a while now.)
More information about the valhalla-spec-observers