Skip to content

Conversation

@sarannat
Copy link
Contributor

@sarannat sarannat commented Aug 5, 2025

Issue
An error, assert(data->is_ReceiverTypeData()) failed: bad profile data type, is encountered during C2 compilation due to bad profile data. This occurs when the code is compiled with TypeProfileCasts option disabled.

Analysis
The assertion failure occurs in record_profiled_receiver_for_speculation that analyzes the profiling information in the method data to determine whether a null value has been observed in the instanceof operation. This information is encoded in the BitData during profiling. When the method identifies that a null has been seen, it proceeds to inspect the associated ReceiverTypeData to see if the type check is always performed against null. However, in this scenario, the incoming profiling data is of type BitData rather than ReceiverTypeData, leading to the assertion failure.

The profiling information for null seen for operations aastore, instanceof, and checkcast is recorded by the method profile_null_seen (insrc/hotspot/cpu/x86/templateTable_x86.cpp). On investigating this method, it can be observed that the method data pointer is not updated for VirtualCallData (which is a subclass of ReceiverTypeData) when the TypeProfileCasts option is disabled.

Solution
My proposal is to inspect the ReceiverTypeData in function record_profiled_receiver_for_speculation only if TypeProfileCasts is enabled (this is based on the fact that the relevant method data pointer is not updated when TypeProfileCasts is disabled).

Question to reviewers
Do you think this is a reasonable fix ?

Testing
GitHub Actions
tier1 to tier3 on windows-x64, linux-x64, linux-aarch64, macosx-x64, and macosx-aarch64.


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-8358781: C2 fails with assert "bad profile data type" when TypeProfileCasts is disabled (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26640

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 5, 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 Aug 5, 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:

8358781: C2 fails with assert "bad profile data type" when TypeProfileCasts is disabled

Reviewed-by: mhaessig, kvn, 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 125 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 (@mhaessig, @dafedafe, @vnkozlov) 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
Copy link

openjdk bot commented Aug 5, 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 Aug 5, 2025
@sarannat sarannat marked this pull request as ready for review August 6, 2025 21:38
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 6, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 6, 2025

Webrevs

Copy link
Contributor

@mhaessig mhaessig left a comment

Choose a reason for hiding this comment

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

Thank you for working on this, @sarannat! The fix seems reasonable to me since GraphKit::maybe_cast_profiled_receiver has a similar exception.

However, you are missing a regression test or a noreg-* label in JBS. However, in this case, I think a small regression test is warranted.

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 fixing this @sarannat. Apart from the missing regression test already mentioned by @mhaessig the fix looks good to me.
Just a quick question: did you try to run some testing with -XX:-TypeProfileCasts?

@sarannat
Copy link
Contributor Author

@mhaessig and @dafedafe : Thank you for the review. I have now added a test case.
@dafedafe : I have tested -XX:-TypeProfileCasts with few examples.I want to highlight the example of the test in /test/hotspot/jtreg/compiler/tiered/TypeProfileCasts.java. When I ran this with -XX:-TypeProfileCasts option and TieredCompilation disabled, it did crash with the same error.

Copy link
Contributor

@mhaessig mhaessig left a comment

Choose a reason for hiding this comment

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

Thank you for adding the test. Apart from my question, this looks good to me.

}

public static void main(String[] args) {
for (int i = 0; i < 100_000; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need 100'000 iterations to get it to compile or can you reduce it a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reduced this to 100 after I checked that the (new) test fails without the current fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent, thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use -XX:CompileThresholdScaling=f (specify f as 0.1, for example) flag to trigger compilation early to make sure 100 is enough.

Copy link
Contributor Author

@sarannat sarannat Aug 13, 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 suggestion. The test works without this addition. However, I have added
-XX:CompileThresholdScaling=0.01 to be on safe side.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Looks good.

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

Thank you for the review. Please sponsor

@sarannat
Copy link
Contributor Author

/integrate

@mhaessig
Copy link
Contributor

/sponsor

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

openjdk bot commented Aug 18, 2025

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

@openjdk
Copy link

openjdk bot commented Aug 18, 2025

Going to push as commit 2b756ab.
Since your change was applied there have been 125 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 18, 2025
@openjdk openjdk bot closed this Aug 18, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 18, 2025
@openjdk openjdk bot removed rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Aug 18, 2025
@openjdk
Copy link

openjdk bot commented Aug 18, 2025

@mhaessig @sarannat Pushed as commit 2b756ab.

💡 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.

4 participants