JDK-8311508 : ZGC: RAII use of IntelJccErratumAlignment
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-07-05
  • Updated: 2023-08-14
  • Resolved: 2023-08-10
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 22
22 masterFixed
Related Reports
Relates :  
Description
SonarCloud reports the potential bug in the code below:
 Name this temporary "IntelJccErratumAlignment" object if you want to use it in for RAII.

```
static void emit_store_fast_path_check_c2(MacroAssembler* masm, Address ref_addr, bool is_atomic, Label& medium_path) {
#ifdef COMPILER2
  // This is a JCC erratum mitigation wrapper for calling the inner check
  int size = store_fast_path_check_size(masm, ref_addr, is_atomic, medium_path);
  // Emit JCC erratum mitigation nops with the right size
  IntelJccErratumAlignment(*masm, size);  // <----------- COMPLAINS HERE
  // Emit the JCC erratum mitigation guarded code
  emit_store_fast_path_check(masm, ref_addr, is_atomic, medium_path);
#endif
```

The comment seems to imply that `emit_store_fast_path_check` needs to be guarded by `IntelJccErratumAlignment`. I think it is innocuous at this point, as `~IntelJccErratumAlignment` only carries the assert. Is this use correct, though?
Comments
Changeset: e080a0b4 Author: Axel Boldt-Christmas <aboldtch@openjdk.org> Date: 2023-08-10 07:18:31 +0000 URL: https://git.openjdk.org/jdk/commit/e080a0b4c0878dc19f40ef0f51e645f3a4708c62
10-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15191 Date: 2023-08-08 13:49:24 +0000
08-08-2023

Naming it and creating a correct scope for RAII semantics seems to be more correct from an assert point of view. Maybe the IntelJccErratumAlignment should assert and disallow a jcc_size of 0, and assert in destructor that 'pc() - _start_pc > 0'. The same issue seems to exist in z_x86_64.ad file in z_load_barrier.
06-07-2023