RFR: 8304928: Optimize ClassDesc.resolveConstantDesc

Chen Liang liach at openjdk.org
Fri Mar 31 00:57:15 UTC 2023


On Thu, 30 Mar 2023 23:13:51 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> This patch optimizes ClassDesc.resolveConstantDesc for array classes. Otherwise, the performance of reference class resolution remain unchanged. https://jmh.morethan.io/?gist=111095eecf7a735fe8c96e4b952b58c1 It also includes a benchmark for MethodTypeDesc resolution, which currently does not yet depend on class desc resolution but can be later optimized if it does switch.
>
> src/java.base/share/classes/java/lang/constant/ConstantUtils.java line 130:
> 
>> 128: 
>> 129:     static boolean isPrimitiveArray(String referenceTypeDescriptorString) {
>> 130:         return referenceTypeDescriptorString.charAt(referenceTypeDescriptorString.length() - 1) != ';';
> 
> it also needs to check if it starts with `[`
> 
> 
> Suggestion:
> 
>         return referenceTypeDescriptorString.startsWith("[") &&  
>                referenceTypeDescriptorString.charAt(referenceTypeDescriptorString.length() - 1) != ';';

I intend this to be a `ReferenceClassDesc`-specifc check. I think moving `isPrimitiveArray` as a private method in `ReferenceClassDesc` would be better, as the `startsWith("[")` is already implied (at least before valhalla, non-array, i.e. class or interface descriptors must end with a semicolon.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13252#discussion_r1153916176


More information about the core-libs-dev mailing list