On Mon, 5 Jun 2023 22:34:23 GMT, Chen Liang <li...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java line >> 84: >> >>> 82: paramTypes = new ClassDesc[paramCount]; >>> 83: for (int i = 0; i < paramCount; i++) { >>> 84: paramTypes[i] = >>> validateParameter(ClassDesc.ofDescriptor(types.get(i + 1))); >> >> It seems useful to have a static factory method to take a trusted copy of >> parameter types and it will validate the parameters before constructing >> `MethodTypeDescImpl` instance. Parameter validation in one single place. >> Several methods doing the validation can simply call this factory method >> and the code would be cleaner. >> >> `insertParameterTypes` can call it as well and overhead of re-validating >> existing parameter types isn't a big issue. > > Should I just keep track of the slot count of MethodTypeDesc instead? Having > a slot count implicitly requires validating the parameters, and the slot > count can be used to eagerly reject `resolveConstantDesc` on MTD with over > 255 slots. I don't think `resolveConstantDesc` is performance-sensitive that needs the eager checking of the number of parameter slots. Also the common case is to resolve a good MethodType with <= 255 parameter slots. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/13186#discussion_r1218681876