Skip to content
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

8267370: [Vector API] Fix several crashes after JDK-8256973 #4109

Closed
wants to merge 2 commits into from

Conversation

DamonFool
Copy link
Member

@DamonFool DamonFool commented May 19, 2021

Hi all,

Several vector tests fail with UseAVX=1 after JDK-8256973.
The reason is that vpmovmskb [1] can be only used with UseAVX > 1 [2].
The fix just disables the intrinsics when UseAVX < 2.

Testing:

  • jdk/incubator/vector with UseAVX={0/1/2/3} on Linux/x64

Thanks.
Best regards,
Jie

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp#L3785
[2] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/assembler_x86.cpp#L4127


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8267370: [Vector API] Fix several crashes after JDK-8256973

Reviewers

Contributors

  • Jatin Bhateja <jbhateja@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4109/head:pull/4109
$ git checkout pull/4109

Update a local copy of the PR:
$ git checkout pull/4109
$ git pull https://git.openjdk.java.net/jdk pull/4109/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4109

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4109.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 19, 2021

👋 Welcome back jiefu! 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 May 19, 2021
@openjdk
Copy link

openjdk bot commented May 19, 2021

@DamonFool 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 May 19, 2021
@mlbridge
Copy link

mlbridge bot commented May 19, 2021

Webrevs

Copy link

@neliasso neliasso 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
Copy link

openjdk bot commented May 19, 2021

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

8267370: [Vector API] Fix several crashes after JDK-8256973

Co-authored-by: Jatin Bhateja <jbhateja@openjdk.org>
Reviewed-by: neliasso, kvn

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

  • 83b3607: 8266642: improve ResolvedMethodTable hash function
  • 1c7a131: 8267350: Archived old interface extends interface with default method causes crash
  • 005d8a7: 8256372: [macos] Unexpected symbol was displayed on JTextField with Monospaced font
  • 81f39ed: 8261205: AssertionError: Cannot add metadata to an intersection type
  • 7b98400: 8267348: Rewrite gc/epsilon/TestClasses.java to use Metaspace with less classes
  • ca93399: 8267235: [macos_aarch64] InterpreterRuntime::throw_pending_exception messing up LR results in crash
  • b7b6acd: 8267481: Make sure table row has correct number of cells
  • f67847f: 8267396: Avoid recording "pc" in unhandled oops detector for better performance
  • 878d1b3: 8267434: Remove LinkOutput[Impl]
  • fc7f0a3: 8267480: Explicitly problemlist all runtime/os/TestTracePageSizes.java tests on linux-aarch64 to reduce noise
  • ... and 31 more: https://git.openjdk.java.net/jdk/compare/70f6c67051135ff1d9994089b88d8ea630932046...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 May 19, 2021
@jatin-bhateja
Copy link
Member

Hi @DamonFool ,

Thanks much for providing a quick fix. Problem here seems to be related to assert in following assembler routines which made an assumption that the instruction is only supported over AVX2 platforms.

void Assembler::vpmovmskb(Register dst, XMMRegister src) {
assert(VM_Version::supports_avx2(), "");

VEX.128.66.0F.WIG D7 /r VPMOVMSKB reg, xmm1 RM V/V AVX Move a byte mask of xmm1 to reg. The upper bits of r32 or r64 are filled with zeros.

But, its ok to limit the patch to AVX2 considering optimization is majorly aimed at modern server targets (which should supported AVX2).

An alternate fix is proposed below which does not restrict the optimization for AVX2 and still keep the changes minimal, since movmaskb is already used at several places in context of 256 bit vector argument.

diff --git a/src/hotspot/cpu/x86/assembler_x86.cpp b/src/hotspot/cpu/x86/assembler_x86.cpp
index d915c846d09..c695da12d42 100644
--- a/src/hotspot/cpu/x86/assembler_x86.cpp
+++ b/src/hotspot/cpu/x86/assembler_x86.cpp
@@ -4123,9 +4123,10 @@ void Assembler::pmovmskb(Register dst, XMMRegister src) {
   emit_int16((unsigned char)0xD7, (0xC0 | encode));
 }
 
-void Assembler::vpmovmskb(Register dst, XMMRegister src) {
-  assert(VM_Version::supports_avx2(), "");
-  InstructionAttr attributes(AVX_256bit, /* rex_w */ false, /* legacy_mode */ true, /* no_mask_reg */ true, /* uses_vl */ false);
+void Assembler::vpmovmskb(Register dst, XMMRegister src, int vec_enc) {
+  assert((VM_Version::supports_avx() && vec_enc == AVX_128bit) ||
+         (VM_Version::supports_avx2() && vec_enc  == AVX_256bit), "");
+  InstructionAttr attributes(vec_enc, /* rex_w */ false, /* legacy_mode */ true, /* no_mask_reg */ true, /* uses_vl */ false);
   int encode = vex_prefix_and_encode(dst->encoding(), 0, src->encoding(), VEX_SIMD_66, VEX_OPCODE_0F, &attributes);
   emit_int16((unsigned char)0xD7, (0xC0 | encode));
 }
diff --git a/src/hotspot/cpu/x86/assembler_x86.hpp b/src/hotspot/cpu/x86/assembler_x86.hpp
index 8526785eea1..a02fdf27582 100644
--- a/src/hotspot/cpu/x86/assembler_x86.hpp
+++ b/src/hotspot/cpu/x86/assembler_x86.hpp
@@ -1746,7 +1746,7 @@ private:
   void vpcmpgtq(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);
 
   void pmovmskb(Register dst, XMMRegister src);
-  void vpmovmskb(Register dst, XMMRegister src);
+  void vpmovmskb(Register dst, XMMRegister src, int vec_enc);
 
   // SSE 4.1 extract
   void pextrd(Register dst, XMMRegister src, int imm8);
diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
index 01212d790fb..310bbbfa150 100644
--- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
+++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
@@ -3782,7 +3782,7 @@ void C2_MacroAssembler::vector_mask_operation(int opc, Register dst, XMMRegister
   assert(VM_Version::supports_avx(), "");
   vpxor(xtmp, xtmp, xtmp, vec_enc);
   vpsubb(xtmp, xtmp, mask, vec_enc);
-  vpmovmskb(tmp, xtmp);
+  vpmovmskb(tmp, xtmp, vec_enc);
   switch(opc) {
     case Op_VectorMaskTrueCount:
       popcntq(dst, tmp);
diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
index 7c37899b456..3e95aa64a41 100644
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
@@ -3216,9 +3216,9 @@ void MacroAssembler::vpmovzxbw(XMMRegister dst, Address src, int vector_len) {
   Assembler::vpmovzxbw(dst, src, vector_len);
 }
 
-void MacroAssembler::vpmovmskb(Register dst, XMMRegister src) {
+void MacroAssembler::vpmovmskb(Register dst, XMMRegister src, int vector_len) {
   assert((src->encoding() < 16),"XMM register should be 0-15");
-  Assembler::vpmovmskb(dst, src);
+  Assembler::vpmovmskb(dst, src, vector_len);
 }
 
 void MacroAssembler::vpmullw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.hpp b/src/hotspot/cpu/x86/macroAssembler_x86.hpp
index 074d4a61601..64f4d6e157b 100644
--- a/src/hotspot/cpu/x86/macroAssembler_x86.hpp
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.hpp
@@ -1303,7 +1303,7 @@ public:
   void vpmovzxbw(XMMRegister dst, Address src, int vector_len);
   void vpmovzxbw(XMMRegister dst, XMMRegister src, int vector_len) { Assembler::vpmovzxbw(dst, src, vector_len); }
 
-  void vpmovmskb(Register dst, XMMRegister src);
+  void vpmovmskb(Register dst, XMMRegister src, int vector_len = Assembler::AVX_256bit);
 
   void vpmullw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);
   void vpmullw(XMMRegister dst, XMMRegister nds, Address src, int vector_len);

@DamonFool
Copy link
Member Author

/contributor add @jatin-bhateja

@openjdk
Copy link

openjdk bot commented May 19, 2021

@DamonFool
Contributor Jatin Bhateja <jbhateja@openjdk.org> successfully added.

@DamonFool
Copy link
Member Author

Thanks much for providing a quick fix. Problem here seems to be related to assert in following assembler routines which made an assumption that the instruction is only supported over AVX2 platforms.

Good catch! @jatin-bhateja
It makes sense to enable 128-bit vectors for vpmovmskb.
Updated.

More testing is in progress.
Will let you know once finished.
Thanks.

@DamonFool
Copy link
Member Author

/test

@openjdk
Copy link

openjdk bot commented May 19, 2021

@DamonFool you need to get approval to run the tests in tier1 for commits up until efc2372

@openjdk openjdk bot added the test-request label May 19, 2021
@DamonFool
Copy link
Member Author

The vector tests passed on our Linux/x64 machine.

@neliasso , please let me know if you're also fine with the updated change.
Thanks.

@DamonFool
Copy link
Member Author

Could someone help to review this fix?

I've noticed that JDK-8267519 was also filed about the same crash just now.
Thanks.

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.

@DamonFool
Copy link
Member Author

Good.

Thanks @vnkozlov .
/integrate

@openjdk openjdk bot closed this May 20, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 20, 2021
@openjdk
Copy link

openjdk bot commented May 20, 2021

@DamonFool Since your change was applied there have been 41 commits pushed to the master branch:

  • 83b3607: 8266642: improve ResolvedMethodTable hash function
  • 1c7a131: 8267350: Archived old interface extends interface with default method causes crash
  • 005d8a7: 8256372: [macos] Unexpected symbol was displayed on JTextField with Monospaced font
  • 81f39ed: 8261205: AssertionError: Cannot add metadata to an intersection type
  • 7b98400: 8267348: Rewrite gc/epsilon/TestClasses.java to use Metaspace with less classes
  • ca93399: 8267235: [macos_aarch64] InterpreterRuntime::throw_pending_exception messing up LR results in crash
  • b7b6acd: 8267481: Make sure table row has correct number of cells
  • f67847f: 8267396: Avoid recording "pc" in unhandled oops detector for better performance
  • 878d1b3: 8267434: Remove LinkOutput[Impl]
  • fc7f0a3: 8267480: Explicitly problemlist all runtime/os/TestTracePageSizes.java tests on linux-aarch64 to reduce noise
  • ... and 31 more: https://git.openjdk.java.net/jdk/compare/70f6c67051135ff1d9994089b88d8ea630932046...master

Your commit was automatically rebased without conflicts.

Pushed as commit 7a63ff7.

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

@DamonFool DamonFool deleted the JDK-8267370 branch May 21, 2021 00:07
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 test-request
4 participants