RFR: 8338532: Speed up the ClassFile API MethodTypeDesc#ofDescriptor
Shaojin Wen
duke at openjdk.org
Mon Aug 19 06:32:26 UTC 2024
On Sat, 17 Aug 2024 12:04:20 GMT, ExE Boss <duke at openjdk.org> wrote:
>> The current implementation of ofDescriptor puts return type and parameter types together in an ArrayList, and then splits them into return type and array of parameter types. This ArrayList creation is unnecessary, considering most descriptors only have few parameter types.
>>
>> By splitting return type and parameter types separately and scanning the descriptor first to get the number of parameters, we can just allocate an exact, trusted array for the resulting MethodTypeDesc without copy.
>
> src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java line 154:
>
>> 152: if (num >= 0) {
>> 153: int shift = num << 3;
>> 154: len = (int) ((lengths & (0xFFL << shift)) >> shift) & 0xFF;
>
> The `0xFFL << shift` step is unnecessary with the trailing `& 0xFF`:
> Suggestion:
>
> len = (int) (lengths >>> shift) & 0xFF;
Under MacBook M1 Pro, the performance of running the scenario `(Ljava/lang/Object;Ljava/lang/String;)I` multiple times is very different. The above code is rollback verification, but it is found that the problem is not solved.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20611#discussion_r1720767948
More information about the core-libs-dev
mailing list