JDK-8223186 : HotSpot compile warnings from GCC 9
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8,11,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2019-05-01
  • Updated: 2021-02-01
  • Resolved: 2019-05-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 11 JDK 13 Other
11.0.11Fixed 13 b21Fixed openjdk8u292Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
I saw following warnings when I compiled HotSpot with GCC 9 on Fedora 30:


/home/ysuenaga/OpenJDK/jdk/src/hotspot/os/linux/osContainer_linux.cpp: In static member function 'static jlong OSContainer::memory_limit_in_bytes()':
/home/ysuenaga/OpenJDK/jdk/src/hotspot/os/linux/osContainer_linux.cpp:470:22: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  470 |       char* format = "%s " JULONG_FORMAT;

/home/ysuenaga/OpenJDK/jdk/src/hotspot/os/linux/osContainer_linux.cpp: In static member function 'static jlong OSContainer::memory_and_swap_limit_in_bytes()':
/home/ysuenaga/OpenJDK/jdk/src/hotspot/os/linux/osContainer_linux.cpp:493:22: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  493 |       char* format = "%s " JULONG_FORMAT;

/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/gc/shared/ptrQueue.cpp: In constructor 'BufferNode::Allocator::Allocator(const char*, size_t)':
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/gc/shared/ptrQueue.cpp:97:10: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 120 equals destination size [-Wstringop-truncation]
   97 |   strncpy(_name, name, sizeof(_name));
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/compiler/disassembler.cpp: In constructor 'decode_env::decode_env(CodeBlob*, outputStream*, CodeStrings, ptrdiff_t)':
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/compiler/disassembler.cpp:365:32: warning: 'void* memset(void*, int, size_t)' clearing an object of non-trivial type 'class decode_env'; use assignment instead [-Wclass-memaccess]
  365 |   memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields.
      |                                ^
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/compiler/disassembler.cpp:153:7: note: 'class decode_env' declared here
  153 | class decode_env {
      |       ^~~~~~~~~~

In file included from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/runtime/thread.hpp:34,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/runtime/safepoint.hpp:30,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/gc/shared/collectedHeap.hpp:33,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/precompiled/precompiled.hpp:37:
In constructor 'JvmtiCodeBlobDesc::JvmtiCodeBlobDesc(const char*, address, address)',
    inlined from 'static void CodeBlobCollector::do_blob(CodeBlob*)' at /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp:141:94:
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiExport.hpp:423:12: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 64 equals destination size [-Wstringop-truncation]
  423 |     strncpy(_name, name, sizeof(_name));
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In constructor 'JvmtiCodeBlobDesc::JvmtiCodeBlobDesc(const char*, address, address)',
    inlined from 'void CodeBlobCollector::collect()' at /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp:177:94:
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiExport.hpp:423:12: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 64 equals destination size [-Wstringop-truncation]
  423 |     strncpy(_name, name, sizeof(_name));
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/runtime/thread.hpp:34,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/runtime/safepoint.hpp:30,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/gc/shared/collectedHeap.hpp:33,
                 from /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/precompiled/precompiled.hpp:37:
In constructor 'JvmtiCodeBlobDesc::JvmtiCodeBlobDesc(const char*, address, address)',
    inlined from 'void JvmtiDynamicCodeEventCollector::register_stub(const char*, address, address)' at /home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiExport.cpp:2825:60:
/home/ysuenaga/OpenJDK/jdk/src/hotspot/share/prims/jvmtiExport.hpp:423:12: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 64 equals destination size [-Wstringop-truncation]
  423 |     strncpy(_name, name, sizeof(_name));
      |
Comments
Fix request (8u) I'd like to have this fix in 8u, as it's affected in the same way than 11u was. The patch pushed to 11u applies cleanly to 8u, after replacing the file paths with their pre-modules equivalents. Tested that builds are successful with GCC 9.2.1 while treating warnings as errors.
20-01-2021

Fix request (11u) I'd like to have this enhancement approved for 11u. It will help to avoid warnings on some compilers -which, in case of being treated as errors, may abort the build process-; while improving the code quality at the same time. The jdk/jdk patch does not apply cleanly but the backport has been review-approved here: http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2021-January/004681.html
19-01-2021

11u RFR: http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2021-January/004677.html
18-01-2021

Suggested fix: http://hg.openjdk.java.net/jdk/submit/rev/4181f02a850b
01-05-2019