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

ExE Boss duke at openjdk.org
Mon Aug 19 06:32:26 UTC 2024


On Fri, 16 Aug 2024 08:53:38 GMT, Shaojin Wen <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;

src/java.base/share/classes/jdk/internal/constant/PrimitiveClassDescImpl.java line 68:

> 66: 
> 67:     /** {@link ClassDesc} representing the primitive type {@code void} */
> 68:     public static final PrimitiveClassDescImpl CD_void = new PrimitiveClassDescImpl("V");

Since all the `PrimitiveClassDescImpl` instances are now created in this class, the constructor can probably be made `private`.

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

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


More information about the core-libs-dev mailing list