8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
authorsla
Fri, 21 Mar 2014 09:38:04 +0100
changeset 23566 760a74c1b589
parent 23565 b28f771b8cbe
child 23567 3d38400b44a2
8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries Reviewed-by: alanb
jdk/make/lib/ServiceabilityLibraries.gmk
jdk/src/share/back/SDE.c
jdk/src/share/back/eventHandler.c
jdk/src/share/back/log_messages.c
jdk/src/share/instrument/InvocationAdapter.c
jdk/src/share/instrument/PathCharsValidator.c
jdk/src/solaris/back/util_md.h
jdk/src/solaris/native/sun/management/MacosxOperatingSystem.c
jdk/src/windows/back/linker_md.c
jdk/src/windows/back/proc_md.h
--- a/jdk/make/lib/ServiceabilityLibraries.gmk	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/make/lib/ServiceabilityLibraries.gmk	Fri Mar 21 09:38:04 2014 +0100
@@ -49,7 +49,7 @@
     EXCLUDE_FILES := $(LIBATTACH_EXCLUDE_FILES), \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB), \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS), \
     CFLAGS_windows := /Gy, \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libattach/mapfile-$(OPENJDK_TARGET_OS), \
     VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
@@ -79,7 +79,7 @@
         $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/socket, \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_CFLAGS_WARNINGS_ARE_ERRORS) -DUSE_MMAP \
         -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
         -I$(JDK_TOPDIR)/src/share/transport/socket \
         -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/socket \
@@ -115,7 +115,7 @@
           $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/shmem, \
       LANG := C, \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
+      CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) -DUSE_MMAP \
           -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
           -I$(JDK_TOPDIR)/src/share/transport/shmem \
           -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/shmem \
@@ -144,7 +144,7 @@
     SRC := $(JDK_TOPDIR)/src/share/back $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/back, \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -DJDWP_LOGGING \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) -DJDWP_LOGGING \
         -I$(JDK_TOPDIR)/src/share/transport/export \
         -I$(JDK_TOPDIR)/src/share/back/export \
         -I$(JDK_TOPDIR)/src/share/npt \
@@ -179,7 +179,7 @@
         $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/tracing/dtrace, \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) \
         -I$(JDK_TOPDIR)/src/share/native/sun/tracing/dtrace, \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjsdt/mapfile-vers, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
@@ -248,7 +248,7 @@
     INCLUDE_FILES := $(LIBINSTRUMENT_FILES), \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(LIBINSTRUMENT_CFLAGS), \
+    CFLAGS := $(LIBINSTRUMENT_CFLAGS) $(CFLAGS_WARNINGS_ARE_ERRORS), \
     CFLAGS_debug := -DJPLIS_LOGGING, \
     CFLAGS_release := -DNO_JPLIS_LOGGING, \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libinstrument/mapfile-vers, \
@@ -316,7 +316,7 @@
     EXCLUDE_FILES := $(BUILD_LIBMANAGEMENT_EXCLUDES), \
     LANG := C, \
     OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \
-    CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBMANAGEMENT_CFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) $(BUILD_LIBMANAGEMENT_CFLAGS), \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -364,7 +364,7 @@
     SRC := $(BUILD_LIBHPROF_SRC), \
     LANG := C, \
     OPTIMIZATION := $(LIBHPROF_OPTIMIZATION), \
-    CFLAGS := $(CFLAGS_JDKLIB) \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) \
         $(BUILD_LIBHPROF_CFLAGS), \
     CFLAGS_debug := -DHPROF_LOGGING, \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libhprof/mapfile-vers, \
@@ -392,7 +392,7 @@
     SRC := $(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo, \
     LANG := C, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) \
+    CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) \
         -I$(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo, \
     MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjava_crw_demo/mapfile-vers, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
@@ -419,7 +419,7 @@
         SRC := $(JDK_TOPDIR)/src/closed/share/native/oracle/jfr, \
         LANG := C, \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
+        CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) \
             -I$(JDK_TOPDIR)/src/closed/share/javavm/export, \
         MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjfr/mapfile-vers, \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
--- a/jdk/src/share/back/SDE.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/share/back/SDE.c	Fri Mar 21 09:38:04 2014 +0100
@@ -48,8 +48,6 @@
 #define BASE_STRATUM_NAME "Java"
 
 #define null NULL
-#define true JNI_TRUE
-#define false JNI_FALSE
 #define String char *
 #define private static
 
@@ -147,7 +145,7 @@
             defaultStratumId = null;
             defaultStratumIndex = -1;
             baseStratumIndex = -2; /* so as not to match -1 above */
-            sourceMapIsValid = false;
+            sourceMapIsValid = JNI_FALSE;
 
             if (getSourceDebugExtension(clazz, &sourceDebugExtension) ==
                 JVMTI_ERROR_NONE) {
@@ -667,7 +665,7 @@
         jplsFilename = readLine();
         defaultStratumId = readLine();
         createJavaStratum();
-        while (true) {
+        while (1) {
             if (sdeRead() != '*') {
                 syntax("expected '*'");
             }
@@ -684,7 +682,7 @@
                 case 'E':
                     /* set end points */
                     storeStratum("*terminator*");
-                    sourceMapIsValid = true;
+                    sourceMapIsValid = JNI_TRUE;
                     return;
                 default:
                     ignoreSection();
--- a/jdk/src/share/back/eventHandler.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/share/back/eventHandler.c	Fri Mar 21 09:38:04 2014 +0100
@@ -1682,7 +1682,7 @@
 eventHandler_createPermanentInternal(EventIndex ei, HandlerFunction func)
 {
     return createInternal(ei, func, NULL,
-                          NULL, NULL, (jlocation)NULL, JNI_TRUE);
+                          NULL, NULL, 0, JNI_TRUE);
 }
 
 HandlerNode *
@@ -1691,7 +1691,7 @@
                                       jthread thread)
 {
     return createInternal(ei, func, thread,
-                          NULL, NULL, (jlocation)NULL, JNI_FALSE);
+                          NULL, NULL, 0, JNI_FALSE);
 }
 
 HandlerNode *
--- a/jdk/src/share/back/log_messages.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/share/back/log_messages.c	Fri Mar 21 09:38:04 2014 +0100
@@ -56,17 +56,24 @@
 static void
 get_time_stamp(char *tbuf, size_t ltbuf)
 {
-    char format[MAXLEN_TIMESTAMP+1];
+    char timestamp_prefix[MAXLEN_TIMESTAMP+1];
+    char timestamp_postfix[MAXLEN_TIMESTAMP+1];
     unsigned millisecs = 0;
     time_t t = 0;
 
     GETMILLSECS(millisecs);
-    if ( time(&t) == (time_t)(-1) )
+    if ( time(&t) == (time_t)(-1) ) {
         t = 0;
-    (void)strftime(format, sizeof(format),
-                /* Break this string up for SCCS's sake */
-                "%" "d.%" "m.%" "Y %" "T.%%.3d %" "Z", localtime(&t));
-    (void)snprintf(tbuf, ltbuf, format, (int)(millisecs));
+    }
+    /* Break this up so that the format strings are string literals
+       and we avoid a compiler warning. */
+    (void)strftime(timestamp_prefix, sizeof(timestamp_prefix),
+                "%d.%m.%Y %T", localtime(&t));
+    (void)strftime(timestamp_postfix, sizeof(timestamp_postfix),
+                "%Z", localtime(&t));
+    (void)snprintf(tbuf, ltbuf,
+                   "%s.%.3d %s", timestamp_prefix,
+                   (int)(millisecs), timestamp_postfix);
 }
 
 /* Get basename of filename */
@@ -175,7 +182,7 @@
                         "LOC=%s;PID=%d;THR=t@%d",
                         location_stamp,
                         (int)processPid,
-                        (int)tid);
+                        (int)(intptr_t)tid);
 
             /* Construct message string. */
             va_start(ap, format);
--- a/jdk/src/share/instrument/InvocationAdapter.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/share/instrument/InvocationAdapter.c	Fri Mar 21 09:38:04 2014 +0100
@@ -359,7 +359,7 @@
          * class name. The manifest is in UTF8 so need to convert to
          * modified UTF8 (see JNI spec).
          */
-        oldLen = strlen(agentClass);
+        oldLen = (int)strlen(agentClass);
         newLen = modifiedUtf8LengthOfUtf8(agentClass, oldLen);
         if (newLen == oldLen) {
             agentClass = strdup(agentClass);
--- a/jdk/src/share/instrument/PathCharsValidator.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/share/instrument/PathCharsValidator.c	Fri Mar 21 09:38:04 2014 +0100
@@ -46,9 +46,9 @@
 
 /* Compute the low-order mask for the characters in the given string */
 static jlong lowMask(char* s) {
-    int n = strlen(s);
+    size_t n = strlen(s);
     jlong m = 0;
-    int i;
+    size_t i;
     for (i = 0; i < n; i++) {
         int c = (int)s[i];
         if (c < 64)
@@ -59,9 +59,9 @@
 
 /* Compute the high-order mask for the characters in the given string */
 static jlong highMask(char* s) {
-    int n = strlen(s);
+    size_t n = strlen(s);
     jlong m = 0;
-    int i;
+    size_t i;
     for (i = 0; i < n; i++) {
         int c = (int)s[i];
         if ((c >= 64) && (c < 128))
@@ -168,7 +168,7 @@
  * illegal characters. Returns 0 if only validate characters are present.
  */
 int validatePathChars(const char* path) {
-    int i, n;
+    size_t i, n;
 
     /* initialize on first usage */
     if (L_HEX == 0) {
--- a/jdk/src/solaris/back/util_md.h	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/solaris/back/util_md.h	Fri Mar 21 09:38:04 2014 +0100
@@ -62,13 +62,13 @@
                    (((UNSIGNED_JINT)(x & 0xff000000)) >> 24))
 #define HOST_TO_JAVA_LONG(x)                                            \
                   ((x << 56) |                                          \
-                   ((x & 0x000000000000ff00) << 40) |                   \
-                   ((x & 0x0000000000ff0000) << 24) |                   \
-                   ((x & 0x00000000ff000000) << 8) |                    \
-                   ((x & 0x000000ff00000000) >> 8) |                    \
-                   ((x & 0x0000ff0000000000) >> 24) |                   \
-                   ((x & 0x00ff000000000000) >> 40) |                   \
-                   (((UNSIGNED_JLONG)(x & 0xff00000000000000)) >> 56))
+                   ((x & 0x000000000000ff00LL) << 40) |                 \
+                   ((x & 0x0000000000ff0000LL) << 24) |                 \
+                   ((x & 0x00000000ff000000LL) << 8) |                  \
+                   ((x & 0x000000ff00000000LL) >> 8) |                  \
+                   ((x & 0x0000ff0000000000LL) >> 24) |                 \
+                   ((x & 0x00ff000000000000LL) >> 40) |                 \
+                   (((UNSIGNED_JLONG)(x & 0xff00000000000000ULL)) >> 56))
 #define HOST_TO_JAVA_FLOAT(x) stream_encodeFloat(x)
 #define HOST_TO_JAVA_DOUBLE(x) stream_encodeDouble(x)
 
--- a/jdk/src/solaris/native/sun/management/MacosxOperatingSystem.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/solaris/native/sun/management/MacosxOperatingSystem.c	Fri Mar 21 09:38:04 2014 +0100
@@ -29,6 +29,7 @@
 #include <mach/mach.h>
 #include <mach/task_info.h>
 
+#include "jvm.h"
 
 JNIEXPORT jdouble JNICALL
 Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
--- a/jdk/src/windows/back/linker_md.c	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/windows/back/linker_md.c	Fri Mar 21 09:38:04 2014 +0100
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <errno.h>
 #include <io.h>
+#include <stdlib.h>
 
 #include "sys.h"
 
--- a/jdk/src/windows/back/proc_md.h	Fri Mar 21 00:57:23 2014 +0000
+++ b/jdk/src/windows/back/proc_md.h	Fri Mar 21 09:38:04 2014 +0100
@@ -27,6 +27,7 @@
 
 #include <process.h>
 #include <time.h>
+#include <Windows.h>
 
 #define MUTEX_T         int
 #define MUTEX_INIT      0
@@ -40,4 +41,4 @@
 
 #define popen   _popen
 #define pclose  _pclose
-#define sleep   _sleep
+#define sleep(s)  Sleep((s)*1000)