RFR: 8366455: Move VarHandles.GuardMethodGenerator to execute on build

Paul Sandoz psandoz at openjdk.org
Tue Sep 2 15:32:50 UTC 2025


On Fri, 29 Aug 2025 19:13:27 GMT, Chen Liang <liach at openjdk.org> wrote:

> Currently, java.lang.invoke.VarHandles$GuardMethodGenerator is in a weird state: when VarHandleGuards needs to be updated, we uncomment it, build JDK, run it as a main class, and paste the generated VarHandleGuards class.
> 
> This process is complex and error-prone, and having a huge chunk of commented out code is not good for maintenance and verification too.
> 
> Looking at how i18n and charsets generate, we can move this generator to the build system, and have VarHandleGuards completely automatically generated like the other VarHandle implementation classes or CharacterData.
> 
> <details>
> <summary>
> Diff from new to old (backwards):
> </summary>
> 
> 
> liach at liach-Precision-5690:~$ git diff --no-index /home/liach/java/jdk-5/build/linux-x64/support/gensrc/java.base/java/lang/invoke/VarHandleGuards.java /home/liach/java/jdk/open/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java
> diff --git a/home/liach/java/jdk-5/build/linux-x64/support/gensrc/java.base/java/lang/invoke/VarHandleGuards.java b/home/liach/java/jdk/open/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java
> index 13ef65b..49408a2 100644
> --- a/home/liach/java/jdk-5/build/linux-x64/support/gensrc/java.base/java/lang/invoke/VarHandleGuards.java
> +++ b/home/liach/java/jdk/open/src/java.base/share/classes/java/lang/invoke/VarHandleGuards.java
> @@ -28,8 +28,7 @@ import jdk.internal.vm.annotation.AOTSafeClassInitializer;
>  import jdk.internal.vm.annotation.ForceInline;
>  import jdk.internal.vm.annotation.Hidden;
>  
> -// This file is generated by build.tools.methodhandle.VarHandleGuardMethodGenerator.
> -// Do not edit!
> +// This class is auto-generated by java.lang.invoke.VarHandles$GuardMethodGenerator. Do not edit.
>  @AOTSafeClassInitializer
>  final class VarHandleGuards {
>  
> 
> 
> </details>
> 
> Testing: java/lang/invoke.

Looks good. Suggested fixes for a few typos that I think were present in the original documentation.

make/jdk/src/classes/build/tools/methodhandle/VarHandleGuardMethodGenerator.java line 53:

> 51:  * <p>
> 52:  * The generated class essentially encapsulates pre-compiled LambdaForms,
> 53:  * one for each method, for the most set of common method signatures.

Suggestion:

 * one for each method, for common method signatures.

make/jdk/src/classes/build/tools/methodhandle/VarHandleGuardMethodGenerator.java line 64:

> 62:  * long, float, double), and 3 shapes then a maximum of 60 methods will be
> 63:  * generated.  However, the number is likely to be less since there
> 64:  * be duplicate signatures.

Suggestion:

 * will be duplicate signatures.

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

Marked as reviewed by psandoz (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27009#pullrequestreview-3177077405
PR Review Comment: https://git.openjdk.org/jdk/pull/27009#discussion_r2316436550
PR Review Comment: https://git.openjdk.org/jdk/pull/27009#discussion_r2316438118


More information about the core-libs-dev mailing list