RFR: 8338532: Speed up the ClassFile API MethodTypeDesc#ofDescriptor

Chen Liang liach at openjdk.org
Mon Aug 19 06:32:24 UTC 2024


On Mon, 19 Aug 2024 00:20:40 GMT, Chen Liang <liach 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/ConstantUtils.java line 296:
> 
>> 294:         // objectDesc appears a lot during the bootstrap process, so optimize it
>> 295:         String objectDesc = "Ljava/lang/Object;";
>> 296:         if (len == objectDesc.length() && descriptor.regionMatches(start, objectDesc, 0, len)) {
> 
> Note that from my bytestack investigations, `regionMatches` can be CPU-intensive like hashCode calculation. Running this trick against `Ljava/lang/String;` (same length) might cause a lot of misses and waste a lot of CPU time. Can you try on a case with many `Ljava/lang/String;` descriptors and see the results compared to the build without this special case?

Also `Double` `Module` `Number` `Record` `Thread` `System` are susceptible to taking more time in `regionMatches`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20611#discussion_r1721104536


More information about the core-libs-dev mailing list