Skip to content

8324734: Relax too-strict assert(VM_Version::supports_evex()) in Assembler::locate_operand() #17590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

rkennke
Copy link
Contributor

@rkennke rkennke commented Jan 26, 2024

Details see bug report. The gist is that HotSpot downgrades to UseAVX=2 on some processors, and reports supports_evex() == false, but the instruction decoder can still encounter EVEX instructions when (e.g.) hitting a SIGBUS in memset() - which does have EVEX instructions.

Testing:

  • runtime/Unsafe/InternalErrorTest.java
  • tier1

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-8324734: Relax too-strict assert(VM_Version::supports_evex()) in Assembler::locate_operand() (Bug - P3)

Reviewers

Contributors

  • Vladimir Kozlov <kvn@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17590

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 26, 2024

👋 Welcome back rkennke! 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 openjdk bot added the rfr Pull request is ready for review label Jan 26, 2024
@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@rkennke 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 Jan 26, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 26, 2024

Webrevs

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.

The assert is there to make sure HotSpot generates correct code.
What output you get in your test case with this change? You still crash in memset.

@rkennke
Copy link
Contributor Author

rkennke commented Jan 26, 2024

The assert is there to make sure HotSpot generates correct code.

I understand, but the decoder here tries to decode non-HotSpot code, which can legitimately use EVEX instructions.

What output you get in your test case with this change? You still crash in memset.

The test-case passes with the change. The test provokes a SIGBUS and checks that it is propely turned into an InternalError. Without the change, it would crash with the assert, with the change the SIGBUS would be handled and turned into the expected InternalError.

What we could do is what Jorn suggests in JBS:
"As a long term solution, maybe VM_Version could distinguish between CPU features that are supported by the CPU, and features that are enabled. Then, the decoder could check whether evex is supported, while other code could be changed to check whether use of evex is enabled for hotspot's own code gen."
However, that seems more complex than what I'm currently willing to spend time on. ;-)

@vnkozlov
Copy link
Contributor

VM_Version could distinguish between CPU features that are supported by the CPU
We can start with just EVEX check. It is not big change:

$ git diff
diff --git a/src/hotspot/cpu/x86/vm_version_x86.cpp b/src/hotspot/cpu/x86/vm_version_x86.cpp
index df1ea6edd30..8b4ca442b5a 100644
--- a/src/hotspot/cpu/x86/vm_version_x86.cpp
+++ b/src/hotspot/cpu/x86/vm_version_x86.cpp
@@ -809,7 +809,8 @@ void VM_Version::get_processor_features() {
   _stepping = cpu_stepping();
 
   if (cpu_family() > 4) { // it supports CPUID
-    _features = feature_flags();
+    _features = feature_flags(); // It can be changed by VM flags
+    _cpu_features = _features;   // Preserve features
     // Logical processors are only available on P4s and above,
     // and only if hyperthreading is available.
     _logical_processors_per_package = logical_processor_count();
diff --git a/src/hotspot/cpu/x86/vm_version_x86.hpp b/src/hotspot/cpu/x86/vm_version_x86.hpp
index e521a6ee3bc..de86ce51541 100644
--- a/src/hotspot/cpu/x86/vm_version_x86.hpp
+++ b/src/hotspot/cpu/x86/vm_version_x86.hpp
@@ -640,7 +640,7 @@ class VM_Version : public Abstract_VM_Version {
   }
 
   //
-  // Feature identification
+  // Feature identification which can be affected by VM flags
   //
   static bool supports_cpuid()        { return _features  != 0; }
   static bool supports_cmov()         { return (_features & CPU_CMOV) != 0; }
@@ -703,6 +703,11 @@ class VM_Version : public Abstract_VM_Version {
   static bool supports_cet_ss()       { return (_features & CPU_CET_SS) != 0; }
   static bool supports_cet_ibt()      { return (_features & CPU_CET_IBT) != 0; }
 
+  //
+  // Feature identification not affected by VM flags
+  //
+  static bool cpu_supports_evex()         { return (_cpu_features & CPU_AVX512F) != 0; }
+
   // Intel features
   static bool is_intel_family_core() { return is_intel() &&
                                        extended_cpu_family() == CPU_FAMILY_INTEL_CORE; }
diff --git a/src/hotspot/share/runtime/abstract_vm_version.hpp b/src/hotspot/share/runtime/abstract_vm_version.hpp
index d8ffca8de81..05675cc683a 100644
--- a/src/hotspot/share/runtime/abstract_vm_version.hpp
+++ b/src/hotspot/share/runtime/abstract_vm_version.hpp
@@ -54,10 +54,13 @@ class Abstract_VM_Version: AllStatic {
   static const char*  _s_vm_release;
   static const char*  _s_internal_vm_info_string;
 
-  // CPU feature flags.
+  // CPU feature flags which can be restricted by VM flags.
   static uint64_t _features;
   static const char* _features_string;
 
+  // CPU feature flags not affected by VM flags.
+  static uint64_t _cpu_features;
+
   // These are set by machine-dependent initializations
 #ifndef SUPPORTS_NATIVE_CX8
   static bool         _supports_cx8;

@rkennke
Copy link
Contributor Author

rkennke commented Jan 29, 2024

/contributor add @vnkozlov

@openjdk
Copy link

openjdk bot commented Jan 29, 2024

@rkennke
Contributor Vladimir Kozlov <kvn@openjdk.org> successfully added.

@rkennke
Copy link
Contributor Author

rkennke commented Jan 29, 2024

VM_Version could distinguish between CPU features that are supported by the CPU
We can start with just EVEX check. It is not big change:

$ git diff
diff --git a/src/hotspot/cpu/x86/vm_version_x86.cpp b/src/hotspot/cpu/x86/vm_version_x86.cpp
index df1ea6edd30..8b4ca442b5a 100644
--- a/src/hotspot/cpu/x86/vm_version_x86.cpp
+++ b/src/hotspot/cpu/x86/vm_version_x86.cpp
@@ -809,7 +809,8 @@ void VM_Version::get_processor_features() {
   _stepping = cpu_stepping();
 
   if (cpu_family() > 4) { // it supports CPUID
-    _features = feature_flags();
+    _features = feature_flags(); // It can be changed by VM flags
+    _cpu_features = _features;   // Preserve features
     // Logical processors are only available on P4s and above,
     // and only if hyperthreading is available.
     _logical_processors_per_package = logical_processor_count();
diff --git a/src/hotspot/cpu/x86/vm_version_x86.hpp b/src/hotspot/cpu/x86/vm_version_x86.hpp
index e521a6ee3bc..de86ce51541 100644
--- a/src/hotspot/cpu/x86/vm_version_x86.hpp
+++ b/src/hotspot/cpu/x86/vm_version_x86.hpp
@@ -640,7 +640,7 @@ class VM_Version : public Abstract_VM_Version {
   }
 
   //
-  // Feature identification
+  // Feature identification which can be affected by VM flags
   //
   static bool supports_cpuid()        { return _features  != 0; }
   static bool supports_cmov()         { return (_features & CPU_CMOV) != 0; }
@@ -703,6 +703,11 @@ class VM_Version : public Abstract_VM_Version {
   static bool supports_cet_ss()       { return (_features & CPU_CET_SS) != 0; }
   static bool supports_cet_ibt()      { return (_features & CPU_CET_IBT) != 0; }
 
+  //
+  // Feature identification not affected by VM flags
+  //
+  static bool cpu_supports_evex()         { return (_cpu_features & CPU_AVX512F) != 0; }
+
   // Intel features
   static bool is_intel_family_core() { return is_intel() &&
                                        extended_cpu_family() == CPU_FAMILY_INTEL_CORE; }
diff --git a/src/hotspot/share/runtime/abstract_vm_version.hpp b/src/hotspot/share/runtime/abstract_vm_version.hpp
index d8ffca8de81..05675cc683a 100644
--- a/src/hotspot/share/runtime/abstract_vm_version.hpp
+++ b/src/hotspot/share/runtime/abstract_vm_version.hpp
@@ -54,10 +54,13 @@ class Abstract_VM_Version: AllStatic {
   static const char*  _s_vm_release;
   static const char*  _s_internal_vm_info_string;
 
-  // CPU feature flags.
+  // CPU feature flags which can be restricted by VM flags.
   static uint64_t _features;
   static const char* _features_string;
 
+  // CPU feature flags not affected by VM flags.
+  static uint64_t _cpu_features;
+
   // These are set by machine-dependent initializations
 #ifndef SUPPORTS_NATIVE_CX8
   static bool         _supports_cx8;

Nice, thank you! That works (with some minor modification). I've changed the PR from removing the assert to relaxing it to CPU feature check.

@rkennke rkennke changed the title 8324734: Remove too-strict assert(VM_Version::supports_evex()) in Assembler::locate_operand() 8324734: Relax too-strict assert(VM_Version::supports_evex()) in Assembler::locate_operand() Jan 29, 2024
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.

Good. I will submit our testing before approval.
And this needs second review.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

This looks fine, with nits.

/reviewers 2

@openjdk
Copy link

openjdk bot commented Jan 29, 2024

@rkennke 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:

8324734: Relax too-strict assert(VM_Version::supports_evex()) in Assembler::locate_operand()

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

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 33 new commits pushed to the master branch:

  • fd8adf3: 8324856: Serial: Move Generation::is_in to DefNewGeneration
  • a1d65eb: 8324125: Improve class initialization barrier in TemplateTable::_new for RISC-V
  • b6d364a: 8324865: windows-x64-slowdebug still does not build after JDK-8324840
  • 64c3642: 8242564: javadoc crashes:: class cast exception com.sun.tools.javac.code.Symtab$6
  • e999dfc: 8323503: x86: Shorter movptr(reg, imm) for 32-bit unsigned immediates
  • 84deeb6: 8324667: fold Parse::seems_stable_comparison()
  • fb07bbe: 8324717: Remove HotSpotJVMCICompilerFactory
  • d1e6763: 8324733: [macos14] Problem list tests which fail due to macOS bug described in JDK-8322653
  • c1281e6: 8324678: Replace NULL with nullptr in HotSpot gtests
  • a6bdee4: 8324681: Replace NULL with nullptr in HotSpot jtreg test native code files
  • ... and 23 more: https://git.openjdk.org/jdk/compare/62b3293df0442b06cd00488774db7b608baca774...master

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 ready Pull request is ready to be integrated label Jan 29, 2024
@openjdk
Copy link

openjdk bot commented Jan 29, 2024

@shipilev
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jan 29, 2024
rkennke and others added 5 commits January 29, 2024 19:39
Co-authored-by: Aleksey Shipilëv <shipilev@amazon.de>
Co-authored-by: Aleksey Shipilëv <shipilev@amazon.de>
Co-authored-by: Aleksey Shipilëv <shipilev@amazon.de>
Co-authored-by: Aleksey Shipilëv <shipilev@amazon.de>
@rkennke
Copy link
Contributor Author

rkennke commented Jan 29, 2024

This looks fine, with nits.

Thanks for the review! I fixed all the mentioned issues.

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.

My testing passed.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 29, 2024
Copy link
Member

@shipilev shipilev 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 to me.

@rkennke
Copy link
Contributor Author

rkennke commented Jan 30, 2024

Thanks, Vladimir and Aleksey!

/intergrate

@openjdk
Copy link

openjdk bot commented Jan 30, 2024

@rkennke Unknown command intergrate - for a list of valid commands use /help.

@rkennke
Copy link
Contributor Author

rkennke commented Jan 30, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Jan 30, 2024

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

  • fd8adf3: 8324856: Serial: Move Generation::is_in to DefNewGeneration
  • a1d65eb: 8324125: Improve class initialization barrier in TemplateTable::_new for RISC-V
  • b6d364a: 8324865: windows-x64-slowdebug still does not build after JDK-8324840
  • 64c3642: 8242564: javadoc crashes:: class cast exception com.sun.tools.javac.code.Symtab$6
  • e999dfc: 8323503: x86: Shorter movptr(reg, imm) for 32-bit unsigned immediates
  • 84deeb6: 8324667: fold Parse::seems_stable_comparison()
  • fb07bbe: 8324717: Remove HotSpotJVMCICompilerFactory
  • d1e6763: 8324733: [macos14] Problem list tests which fail due to macOS bug described in JDK-8322653
  • c1281e6: 8324678: Replace NULL with nullptr in HotSpot gtests
  • a6bdee4: 8324681: Replace NULL with nullptr in HotSpot jtreg test native code files
  • ... and 23 more: https://git.openjdk.org/jdk/compare/62b3293df0442b06cd00488774db7b608baca774...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 30, 2024
@openjdk openjdk bot closed this Jan 30, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 30, 2024
@openjdk
Copy link

openjdk bot commented Jan 30, 2024

@rkennke Pushed as commit f0024f5.

💡 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