Skip to content

Conversation

sarannat
Copy link
Contributor

@sarannat sarannat commented Jul 30, 2025

Issue

The existing test (compiler/debug/TestStress.java) verifies that compiler stress options produce consistent traces when using the same seed. However, there is currently no test to ensure that different seeds result in different traces.

Solution

Added a test case to assess the distinctness of traces generated from different seeds. This fix addresses the fragility concern highlighted in JDK-8325482 by verifying that traces produced using N (in this case 10) distinct seeds are all not identical.

Changes to compiler/debug/TestStress.java

While investigating this issue, I observed that in compiler/debug/TestStress.java, the stress options for macro expansion and macro elimination were not being triggered because there were fewer than 2 macro nodes. Note that the shuffle_macro_nodes() in compile.cpp is only meaningful when there are more than two macro nodes. The generated traces for macro expansion and macro elimination in TestStress.java were empty. I have proposed changes to address this problem.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8325482: Test that distinct seeds produce distinct traces for compiler stress flags (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26554/head:pull/26554
$ git checkout pull/26554

Update a local copy of the PR:
$ git checkout pull/26554
$ git pull https://git.openjdk.org/jdk.git pull/26554/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26554

View PR using the GUI difftool:
$ git pr show -t 26554

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26554.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 30, 2025

👋 Welcome back snatarajan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 30, 2025

@sarannat This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8325482: Test that distinct seeds produce distinct traces for compiler stress flags

Reviewed-by: chagedorn, dfenacci

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 76 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@chhagedorn, @dafedafe) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot changed the title JDK-8325482: Test that distinct seeds produce distinct traces for compiler stress flags 8325482: Test that distinct seeds produce distinct traces for compiler stress flags Jul 30, 2025
@openjdk
Copy link

openjdk bot commented Jul 30, 2025

@sarannat The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Jul 30, 2025
@sarannat sarannat marked this pull request as ready for review July 31, 2025 07:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 31, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 31, 2025

Webrevs

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding such a test. A few comments, otherwise, it looks good!

Comment on lines 35 to 36
* @requires vm.debug == true & vm.compiler2.enabled
* @requires vm.flagless
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be merged:

Suggested change
* @requires vm.debug == true & vm.compiler2.enabled
* @requires vm.flagless
* @requires vm.debug == true & vm.compiler2.enabled & vm.flagless

* @key stress randomness
* @requires vm.debug == true & vm.compiler2.enabled
* @requires vm.flagless
* @summary Tests that stress compilations with the N different seed yield different
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @summary Tests that stress compilations with the N different seed yield different
* @summary Tests that stress compilations with the N different seeds yield different

Comment on lines 99 to 102
igvnTraceSet.add(igvnTrace(s));
ccpTraceSet.add(ccpTrace(s));
macroExpansionTraceSet.add(macroExpansionTrace(s));
macroEliminationTraceSet.add(macroEliminationTrace(s));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion, do you also want to check here that two runs with the same seed produce the same result to show that different seeds really produce different results due to the seed and not just some indeterminism with the test itself? How long does your test need now and afterwards with a fastdebug build? Maybe we can also lower the number of seeds if it takes too long or only do the equality-test for a single seed.

Copy link
Contributor Author

@sarannat sarannat Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review.

This is a very good point. I implemented and tested what you suggested. Below are some numbers that I obtained from running the test compiler/debug/TestStressDistinctSeed.java with jtreg -vt

  • commit 513ab6d [with no check for same seed -> same trace ]
    slowdebug
    build: 7.205 seconds
    driver: 32.111 seconds
    fastdebug
    build: 0.002 seconds
    driver: 9.102 seconds

  • commit 7eff4d5 [with check for same seed -> same trace and N = 10 ]
    slowdebug**
    build: 7.55 seconds
    driver: 63.108 seconds
    fastdebug
    build: 0.0 seconds
    driver: 16.259 seconds

  • commit 14617e0 [with check for same seed -> same trace and N = 5 ]
    slowdebug

    build: 0.001 seconds
    driver: 31.946 seconds
    fastdebug
    build: 0.0 seconds
    driver: 8.596 seconds

I think N=5 for the updated test looks reasonable. Do you think this is okay ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update and the numbers! I agree that N=5 seems reasonable. Looks good!

Comment on lines 99 to 102
igvntrace = igvnTrace(s);
ccptrace = ccpTrace(s);
macroexpansiontrace = macroExpansionTrace(s);
macroeliminationtrace = macroEliminationTrace(s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You should probably use camelCase for readability of the variables.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 4, 2025
Copy link
Contributor

@dafedafe dafedafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @sarannat! I just left a couple of inline comments.

String igvntrace, ccptrace, macroexpansiontrace, macroeliminationtrace;
if (args.length == 0) {
for (int s = 0; s < 5; s++) {
igvntrace = igvnTrace(s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you choose the 0-4 seeds to be sure that there are at least a couple of different traces? I guess it wouldn't be so easy to exclude that with random values, right?

Copy link
Contributor Author

@sarannat sarannat Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review.
This comes from compiler/debug/TestStress.java and my reasoning is same as what you mentioned above.


/*
* @test
* @key stress randomness
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the test actually "randomised"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My argument for this comes from JDK-8270156 where stress and random keywords were added to all JTreg tests which use StressGCM, StressLCM and/or StressIGVN. This was extended to StressCCP, StressMacroExpansion, and StressMacroElimination.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 4, 2025
Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 5, 2025
static void sum(int n) {
int[] arr1 = new int[n];
for (int i = 0; i < n; i++) {
synchronized (TestStressDistinctSeed.class) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the synchronisation added to create a more "interesting" trace (the tests seem to be running sequentially anyway)?

Copy link
Contributor Author

@sarannat sarannat Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the stress options for macro expansion and macro elimination requires at least two macro nodes; otherwise, an empty trace is produced. Synchronisation was added solely to increase the number of macro nodes.

Copy link
Contributor

@dafedafe dafedafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this and for the clarifications @sarannat.
LGTM

@sarannat
Copy link
Contributor Author

sarannat commented Aug 5, 2025

Thank you for the reviews. Please sponsor.

@sarannat
Copy link
Contributor Author

sarannat commented Aug 5, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 5, 2025
@openjdk
Copy link

openjdk bot commented Aug 5, 2025

@sarannat
Your change (at version bca4a0e) is now ready to be sponsored by a Committer.

@dafedafe
Copy link
Contributor

dafedafe commented Aug 5, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Aug 5, 2025

Going to push as commit d25b9be.
Since your change was applied there have been 76 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 5, 2025
@openjdk openjdk bot closed this Aug 5, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 5, 2025
@openjdk openjdk bot removed rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Aug 5, 2025
@openjdk
Copy link

openjdk bot commented Aug 5, 2025

@dafedafe @sarannat Pushed as commit d25b9be.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants