[PATCH][jdk8u] hotspot: Avoid calling vm_update with a NULL name

Siddhesh Poyarekar siddhesh at gotplt.org
Thu Dec 20 13:32:57 UTC 2018


Hi,

gcc 7.x gives the following warning when building jdk8u:

/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/runtime/fprofiler.cpp: 
In member function ‘void ThreadProfiler::vm_update(TickPosition)’:
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/runtime/fprofiler.cpp:638:56: 
warning: argument 1 null where non-null expected [-Wnonnull]
    bool vm_match(const char* name) const { return strcmp(name, _name) 
== 0; }
                                                   ~~~~~~^~~~~~~~~~~~~
In file included from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp:35:0,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/utilities/globalDefinitions.hpp:33,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/utilities/debug.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/runtime/globals.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/memory/allocation.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/memory/iterator.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/memory/genOopClosures.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/oops/klass.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/runtime/handles.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/memory/universe.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/code/oopRecorder.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/asm/codeBuffer.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/asm/assembler.hpp:28,
                  from 
/home/ubuntu/openjdk/jdk8u/hotspot/src/share/vm/precompiled/precompiled.hpp:29:
/usr/include/string.h:136:12: note: in a call to function ‘int 
strcmp(const char*, const char*)’ declared here
  extern int strcmp (const char *__s1, const char *__s2)
             ^~~~~~

This appears to be because vm_update with a single argument calls its 
sibling function with a NULL name, which is not safe.  A safer and 
compatible alternative is to call vm_update with an empty string; it 
results in exactly the same hash as a NULL string, i.e. 0.

Attached patch does that.

Siddhesh

PS: Is there interest in fixing such warnings and more in jdk8u?  I 
found a few more warnings with gcc8 too that I could work on fixing.
-------------- next part --------------
diff -r c747935d0dc6 src/share/vm/runtime/fprofiler.cpp
--- a/src/share/vm/runtime/fprofiler.cpp	Tue Nov 13 11:21:32 2018 -0500
+++ b/src/share/vm/runtime/fprofiler.cpp	Thu Dec 20 12:38:32 2018 +0000
@@ -775,7 +775,7 @@
 }
 
 void ThreadProfiler::vm_update(TickPosition where) {
-  vm_update(NULL, where);
+  vm_update("", where);
 }
 
 void ThreadProfiler::vm_update(const char* name, TickPosition where) {


More information about the jdk8u-dev mailing list