JDK-8310027 : Fix -Wconversion warnings in nmethod and compiledMethod related code
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-06-14
  • Updated: 2023-07-12
  • Resolved: 2023-06-20
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 b03Fixed
Related Reports
Relates :  
Relates :  
Description
The nmethod.hpp and compiledMethod.hpp files have implicit address to int conversions for returning offsets and sizes.Since hopefully an nmethod size should never exceed 32 bits, this seems safe to simply add explicit casts.

The question is which is better:

+  int oops_size         () const                  { return int((address)  oops_end         () - (address)  oops_begin         ()); }

Or

 +  int oops_size         () const                  { return (int)((address)  oops_end         () - (address)  oops_begin         ()); }

It doesn't seem like we should slow down compilation or add noise to make these

+  int oops_size         () const                  { return checked_cast<int>((address)  oops_end         () - (address)  oops_begin         ()); }

Compiling with -Wconversion and not -Werror gives these counts for warnings:

5523 /scratch/cphillim/hg/21more-conversion/src/hotspot/share/code/nmethod.hpp
5523 /scratch/cphillim/hg/21more-conversion/src/hotspot/share/code/compiledMethod.hpp
4150 /scratch/cphillim/hg/21more-conversion/src/hotspot/share/code/relocInfo.hpp


Comments
Changeset: e1906e76 Author: Coleen Phillimore <coleenp@openjdk.org> Date: 2023-06-20 13:35:11 +0000 URL: https://git.openjdk.org/jdk/commit/e1906e76412fa506cf72447dcb9adc896b92ae81
20-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14505 Date: 2023-06-15 22:49:36 +0000
16-06-2023

ILW = Conversion warnings in code (harmless), no issue observed, no workaround = MLH = P4
15-06-2023