On Dec 2, 2020, at 2:53 AM, Remi Forax <fo...@univ-mlv.fr> wrote: > > There is one case where i dynamically patch a method descriptor so I can > select how many arguments will be sent to a closure, > i.e. in the bytecode i put all arguments on the stack but because i've > patched the callee descriptor, only some of them will be used.
One workaround out of many: Put a switch in your class template, one case per supported arity (limited by the number of stacked items). Then use a fixed descriptor for the call on each arm. Drive the switch from a condy. BTW, if you need to down-cast from Object, use Class::cast on a dynamic Class constant. In the JIT those fold up the same as checkcast. Or just use asType. I’m guessing you are calling MH::invokeExact or some other low-level “erased” API point, so casting is not strictly necessary but it may help the JIT. — John