Skip to content

8381975: CPU feature verification in AOTCodeCache should check for exact match#30796

Closed
ashu-mehra wants to merge 5 commits intoopenjdk:masterfrom
ashu-mehra:8381975-cpu-feature-exact-match
Closed

8381975: CPU feature verification in AOTCodeCache should check for exact match#30796
ashu-mehra wants to merge 5 commits intoopenjdk:masterfrom
ashu-mehra:8381975-cpu-feature-exact-match

Conversation

@ashu-mehra
Copy link
Copy Markdown
Contributor

@ashu-mehra ashu-mehra commented Apr 17, 2026

Update cpu feature verification in AOTCodeCache to check for exact match of runtime cpu features with the cached cpu features. Note that on x86-64, HT (hyperthreading) cpu feature bit is intentionally cleared out because it should not cause AOTCodeCache incompatibility.
While the earlier code allowed production run system to have more cpu features than the cached list, now with this patch it will result in AOTCodeCache load failure. AOTCodeCPUFeatureIncompatibilityTest.java has been updated accordingly. aarch64 test has also been added.



Progress

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

Issue

  • JDK-8381975: CPU feature verification in AOTCodeCache should check for exact match (Enhancement - P4) ⚠️ Issue is already resolved. Consider making this a "backport pull request" by setting the PR title to Backport <hash> with the hash of the original commit. See Backports.

Reviewers

Contributors

  • Vladimir Kozlov <kvn@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30796

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

Using diff file

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

Using Webrev

Link to Webrev Comment

…act match

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Apr 17, 2026

👋 Welcome back asmehra! 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
Copy Markdown

openjdk Bot commented Apr 17, 2026

@ashu-mehra 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:

8381975: CPU feature verification in AOTCodeCache should check for exact match

Co-authored-by: Vladimir Kozlov <kvn@openjdk.org>
Reviewed-by: kvn, iklam, adinn

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

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot added the hotspot hotspot-dev@openjdk.org label Apr 17, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 17, 2026

@ashu-mehra The following label will be automatically applied to this pull request:

  • hotspot

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
Copy link
Copy Markdown

openjdk Bot commented Apr 17, 2026

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 17, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Apr 17, 2026

Webrevs

@vnkozlov
Copy link
Copy Markdown
Contributor

@ashu-mehra

I have next changes in my AOT code cache patch. I think it could be included in your changes:

diff --git a/src/hotspot/share/code/aotCodeCache.cpp b/src/hotspot/share/code/aotCodeCache.cpp
index d4f12936e96..f76b1c92e16 100644
--- a/src/hotspot/share/code/aotCodeCache.cpp
+++ b/src/hotspot/share/code/aotCodeCache.cpp
@@ -83,15 +83,24 @@ const char* aot_code_entry_kind_name[] = {
 static LogStream& load_failure_log() {
   static LogStream err_stream(LogLevel::Error, LogTagSetMapping<LOG_TAGS(aot, codecache, init)>::tagset());
   static LogStream dbg_stream(LogLevel::Debug, LogTagSetMapping<LOG_TAGS(aot, codecache, init)>::tagset());
-  if (RequireSharedSpaces) {
+  if (RequireSharedSpaces || AbortVMOnAOTCodeFailure) {
     return err_stream;
   } else {
     return dbg_stream;
   }
 }
 
+// Report AOT code cache failure and exit VM
+// if (AOTMode is `on` and AbortVMOnAOTCodeFailure is default)
+//     or AbortVMOnAOTCodeFailure is `true`.
+//
+// Note, specifying -XX:-AbortVMOnAOTCodeFailure on command line
+// will prevent aborting VM when AOTMode is `on`. It is used for testing.
+
 static void report_load_failure() {
-  if (AbortVMOnAOTCodeFailure) {
+  bool abort_vm = AbortVMOnAOTCodeFailure ||
+                  (FLAG_IS_DEFAULT(AbortVMOnAOTCodeFailure) && RequireSharedSpaces);
+  if (abort_vm) {
     vm_exit_during_initialization("Unable to use AOT Code Cache.", nullptr);
   }
   load_failure_log().print_cr("Unable to use AOT Code Cache.");
@@ -99,7 +108,9 @@ static void report_load_failure() {
 }
 
 static void report_store_failure() {
-  if (AbortVMOnAOTCodeFailure) {
+  bool abort_vm = AbortVMOnAOTCodeFailure || 
+                  (FLAG_IS_DEFAULT(AbortVMOnAOTCodeFailure) && RequireSharedSpaces);
+  if (abort_vm) {
     tty->print_cr("Unable to create AOT Code Cache.");
     vm_abort(false);
   }
diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotCode/AOTCodeCPUFeatureIncompatibilityTest.java b/test/hotspot/jtreg/runtime/cds/appcds/aotCode/AOTCodeCPUFeatureIncompatibilityTest.java
index aa7becdb6f8..557f2a78850 100644
--- a/test/hotspot/jtreg/runtime/cds/appcds/aotCode/AOTCodeCPUFeatureIncompatibilityTest.java
+++ b/test/hotspot/jtreg/runtime/cds/appcds/aotCode/AOTCodeCPUFeatureIncompatibilityTest.java
@@ -72,7 +72,12 @@ public static void testIncompatibleFeature(String vmOption, String featureName)
             @Override
             public String[] vmArgs(RunMode runMode) {
                 if (runMode == RunMode.PRODUCTION) {
-                    return new String[] {vmOption, "-Xlog:aot+codecache*=debug"};
+                    return new String[] {vmOption,
+                                         "-XX:+UnlockDiagnosticVMOptions",
+                                         // Prevent exiting VM on failure
+                                         "-XX:-AbortVMOnAOTCodeFailure",
+                                         "-Xlog:aot+codecache*=debug"};
+
                 } else {
                     return new String[] {"-Xlog:aot+codecache*=debug"};
                 }

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

@vnkozlov I think report_store_failure is only called during assembly phase where AOTMode=on is not applicable, right? So do we need RequireSharedSpaces check in report_store_failure()?

@vnkozlov
Copy link
Copy Markdown
Contributor

@vnkozlov I think report_store_failure is only called during assembly phase where AOTMode=on is not applicable, right? So do we need RequireSharedSpaces check in report_store_failure()?

You are right. We don't need it in report_store_failure().

Interesting, for some reason I thought we could specify AOTMode=on with AOTMode=create to exit VM if some thing is wrong during assembly phase. But it is exclusive - you can only select one value.

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@ashu-mehra
Copy link
Copy Markdown
Contributor Author

@vnkozlov I added a commit to include your patch minus the changes to report_store_failure().

@vnkozlov
Copy link
Copy Markdown
Contributor

We need to add -XX:-AbortVMOnAOTCodeFailure flag to AOTCodeCompressedOopsTest.java test too:

2026-04-20T19:43:57.3467830Z [0.020s][error][aot,codecache,init] AOT Code Cache disabled: it was created with CompressedOops::shift() = 0 vs current 3
2026-04-20T19:43:57.3469130Z Error occurred during initialization of VM
2026-04-20T19:43:57.3469835Z Unable to use AOT Code Cache.

Signed-off-by: Ashutosh Mehra <asmehra@redhat.com>
@ashu-mehra
Copy link
Copy Markdown
Contributor Author

We need to add -XX:-AbortVMOnAOTCodeFailure flag to AOTCodeCompressedOopsTest.java test too:

Updated the test as suggested.

@vnkozlov
Copy link
Copy Markdown
Contributor

Good. I submitted testing.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

windows-x64 tier1 failure looks like an infra issue. Tests didn't even start.

@vnkozlov
Copy link
Copy Markdown
Contributor

My testing hit an other unexpected issue. For "JEP 516: Ahead-of-Time GC Agnostic Object Archiving" we allow different GCs in assembly and production if AOTStreamableObjects flag is on which is switched on if Compressed oops are disabled or Z GC is used: https://github.com/openjdk/jdk/blob/master/src/hotspot/share/cds/heapShared.cpp#L369

@vnkozlov
Copy link
Copy Markdown
Contributor

May be we should add this exception and simple skip AOT code instead of aborting VM. Lets talk about this on this week meeting.

@vnkozlov
Copy link
Copy Markdown
Contributor

@iklam suggested to pass -XX:-AbortVMOnAOTCodeFailure into our testing with different GCs. And I am inclining to agree.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

@iklam suggested to pass -XX:-AbortVMOnAOTCodeFailure into our testing with different GCs. And I am inclining to agree.

@vnkozlov For testing purpose we can pass -XX:-AbortVMOnAOTCodeFailure, but we still need to decide how to handle it if it happens in the production run. Is the current behavior to abort the VM acceptable, even though metadata and profile information is usable? IMO it should be fine, because the contract of AOTMode=on is to fail immediately if anything goes wrong with the AOTCache.

btw do you have a list of tests that are failing and need -XX:-AbortVMOnAOTCodeFailure to be added?

@vnkozlov
Copy link
Copy Markdown
Contributor

I talked with @iklam and @katyapav and suggestion was to add -XX:-AOTCodeCaching to our testing environment when we know that we can't use AOT code. As in failing case when GCs are different. I will go ahead with this change.

btw do you have a list of tests that are failing and need -XX:-AbortVMOnAOTCodeFailure to be added?

So far I found only this case with different GCs and only because it has AOTMode=on. When we run testing with JTREG="AOT_JDK=[one|two]step" we don't use AOTMode=on`. If AOT code can't be used it is silently ignored and does not affect tests execution.

I submitted 2 more tiers for testing.

@vnkozlov
Copy link
Copy Markdown
Contributor

add -XX:-AOTCodeCaching to our testing environment

I think we should switch off stubs and adapters caching too.

@vnkozlov
Copy link
Copy Markdown
Contributor

I have to restart testing because I used -XX:-AOTCodeCaching in our testing settings. But this flag does not exist yet in current VM sources. It caused testing failure.

Copy link
Copy Markdown
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.

I pushed closed changes to our testing settings to skip AOT code when GCs are different.

Now testing results are good.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

I need one more review. @iklam @adinn may be?

@vnkozlov
Copy link
Copy Markdown
Contributor

@ashu-mehra JBS marked as fixed because I used the same JBS id for testing setting changes in closed repo.
It is fine - just push your changes when you get 2nd review.

Copy link
Copy Markdown
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Apr 24, 2026
Copy link
Copy Markdown
Contributor

@adinn adinn left a comment

Choose a reason for hiding this comment

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

Looks fine.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

@adinn @iklam @vnkozlov thanks for the reviews.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

/contributor add @vnkozlov

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 24, 2026

@ashu-mehra
Contributor Vladimir Kozlov <kvn@openjdk.org> successfully added.

@ashu-mehra
Copy link
Copy Markdown
Contributor Author

/integrate

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 24, 2026

Going to push as commit 5596e81.
Since your change was applied there have been 137 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 Apr 24, 2026
@openjdk openjdk Bot closed this Apr 24, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 24, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 24, 2026

@ashu-mehra Pushed as commit 5596e81.

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

@ashu-mehra ashu-mehra deleted the 8381975-cpu-feature-exact-match branch April 24, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

4 participants