On Fri, 26 May 2023 20:41:36 GMT, Mandy Chung <mch...@openjdk.org> wrote:

>> Chen Liang has refreshed the contents of this pull request, and previous 
>> commits have been removed. Incremental views are not available.
>
> The microbenchmark shows the performance of using the `MethodTypeDesc` 
> factory methods.  With [#13671](https://github.com/openjdk/jdk/pull/13671), 
> `MethodTypeDesc` is cached and I wonder if this is no longer the bottleneck 
> of ClassFile API performance.   
> 
> [JDK-8304932](https://bugs.openjdk.org/browse/JDK-8304932) is a bug that can 
> simply be fixed by 
> 
> diff --git 
> a/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java 
> b/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
> index 738c4d68a43..ed23887c9ef 100644
> --- a/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
> +++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
> @@ -95,7 +95,7 @@ public sealed interface MethodTypeDesc
>       * {@link ClassDesc} for {@code void}
>       */
>      static MethodTypeDesc of(ClassDesc returnDesc, ClassDesc... paramDescs) {
> -        return new MethodTypeDescImpl(returnDesc, paramDescs);
> +        return new MethodTypeDescImpl(returnDesc, paramDescs.clone());
>      }
>  
>      /**
> diff --git 
> a/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java 
> b/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java
> index 4341c3fb56f..8586bfb5926 100644
> --- a/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java
> +++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java
> @@ -41,7 +41,7 @@ import static java.util.Objects.requireNonNull;
>   */
>  final class MethodTypeDescImpl implements MethodTypeDesc {
>      private final ClassDesc returnType;
> -    private final ClassDesc[] argTypes;
> +    private final ClassDesc[] argTypes;     // trusted array
>  
>      /**
>       * Constructs a {@linkplain MethodTypeDesc} with the specified return 
> type
> @@ -102,14 +102,14 @@ final class MethodTypeDescImpl implements 
> MethodTypeDesc {
>  
>      @Override
>      public MethodTypeDesc changeReturnType(ClassDesc returnType) {
> -        return MethodTypeDesc.of(returnType, argTypes);
> +        return new MethodTypeDescImpl(returnType, argTypes);
>      }
>  
>      @Override
>      public MethodTypeDesc changeParameterType(int index, ClassDesc 
> paramType) {
>          ClassDesc[] newArgs = argTypes.clone();
>          newArgs[index] = paramType;
> -        return MethodTypeDesc.of(returnType, newArgs);
> +        return new MethodTypeDescImpl(returnType, newArgs);
>      }
>  
>      @Override
> @@ -120,7 +120,7 @@ final class MethodTypeDescImpl implements MethodTypeDesc {
>          Cl...

@mlchung I have updated this patch to no longer change the array to a list. 
Could you take a look? I wish this to be integrated into JDK 21 as it does 
bring a lot of performance benefits.

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

PR Comment: https://git.openjdk.org/jdk/pull/13186#issuecomment-1575808993

Reply via email to