JDK-8255550 : x86: Assembler::cmpq(Address dst, Register src) encoding is incorrect
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,11,15,16
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-10-28
  • Updated: 2021-01-13
  • Resolved: 2020-10-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 16
11.0.10Fixed 16 b23Fixed
Related Reports
Blocks :  
Description
Compare:

void Assembler::cmpq(Address dst, Register src) {
  InstructionMark im(this);
  emit_int16(get_prefixq(dst, src), 0x3B);
  emit_operand(src, dst);
}

void Assembler::cmpq(Register dst, Address src) {
  InstructionMark im(this);
  emit_int16(get_prefixq(src, dst), 0x3B);
  emit_operand(dst, src);
}

They use the same opcode -- 0x3B, which is for "CMP r, r/m". While cmpq(Address,Register) actually should be using 0x39 for "CMP r/m, r". I also suspect they emit basically the same instruction, because the get_prefixq and emit_operand order is irrelevant.

AFAIU, it does not break horribly, because the cmpq(Address,Register) is not used anywhere except the new code in MacroAssembler::safepoint_poll, added by JDK-8253180. This was found by Zhengyu, when he was trying to enable that new code on x86_32.

We should either encode this cmpq properly, or remove cmpq(Address,Register) and use the other one, cmpq(Register,Address) consistently.
Comments
Fix Request (11u) Fixes the landmine in encoding. There are no uses that I can see, so backporting for Oracle parity (I see 11.0.11-oracle). 11u RFR (acked by phh): https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2020-November/004127.html
12-11-2020

Changeset: 9e5bbff5 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2020-10-29 14:19:56 +0000 URL: https://git.openjdk.java.net/jdk/commit/9e5bbff5
29-10-2020