You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2020/08/24 18:08:25 UTC

[commons-daemon] branch master updated (2cb300b -> 833c9fe)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git.


    from 2cb300b  Use animal API version for Java 6
     new 7c1470e  Fix compilation error for release builds and remove trailing space
     new 833c9fe  Fix DAEMON-412 for Windows - Add NMT support for jvm mode

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/native/windows/apps/prunsrv/prunsrv.c | 63 +++++++++++++++++++++++++++++++
 src/native/windows/src/javajni.c          |  8 ++--
 2 files changed, 67 insertions(+), 4 deletions(-)


[commons-daemon] 01/02: Fix compilation error for release builds and remove trailing space

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 7c1470e55b64e5690d935ed33105211b00f4c30d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Aug 24 17:21:47 2020 +0100

    Fix compilation error for release builds and remove trailing space
---
 src/native/windows/src/javajni.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/native/windows/src/javajni.c b/src/native/windows/src/javajni.c
index c67831d..4da3e5e 100644
--- a/src/native/windows/src/javajni.c
+++ b/src/native/windows/src/javajni.c
@@ -287,13 +287,13 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
     _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle) &&
         GetFileAttributesW(dllJvmPath) != INVALID_FILE_ATTRIBUTES) {
+        WCHAR  crtBinPath[SIZ_PATHLEN];
+
         /* There is a file but cannot be loaded.
          * Try to load the MSVCRTxx.dll before JVM.dll
          */
         apxLogWrite(APXLOG_MARK_ERROR "Found '%S' but couldn't load it.", dllJvmPath);
 
-        WCHAR  crtBinPath[SIZ_PATHLEN];
-
         lstrlcpyW(jreBinPath, SIZ_PATHLEN, dllJvmPath);
         if(l == 2) {
             lstrlcpyW(crtBinPath, SIZ_PATHLEN, jreBinPath);
@@ -1150,10 +1150,10 @@ apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
 
     if (!lpJava->dwWorkerStatus && lpJava->hWorkerThread)
         return WAIT_OBJECT_0;
-    apxLogWrite(APXLOG_MARK_DEBUG "WaitForSingleObject 0x%p %d milliseconds (INFINITE=%d)...", 
+    apxLogWrite(APXLOG_MARK_DEBUG "WaitForSingleObject 0x%p %d milliseconds (INFINITE=%d)...",
         lpJava->hWorkerThread, dwMilliseconds, INFINITE);
     rv = WaitForSingleObject(lpJava->hWorkerThread, dwMilliseconds);
-    apxLogWrite(APXLOG_MARK_DEBUG "WaitForSingleObject 0x%p = %d (WAIT_TIMEOUT=%d)", 
+    apxLogWrite(APXLOG_MARK_DEBUG "WaitForSingleObject 0x%p = %d (WAIT_TIMEOUT=%d)",
         lpJava->hWorkerThread, rv, WAIT_TIMEOUT);
     if (rv == WAIT_TIMEOUT && bKill) {
         __apxJavaJniCallback(hJava, WM_CLOSE, 0, 0);


[commons-daemon] 02/02: Fix DAEMON-412 for Windows - Add NMT support for jvm mode

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 833c9fe7e54dcd485b3b9d22038470742c1d9c18
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Aug 24 18:57:00 2020 +0100

    Fix DAEMON-412 for Windows - Add NMT support for jvm mode
    
    https://issues.apache.org/jira/projects/DAEMON/issues/DAEMON-412
---
 src/native/windows/apps/prunsrv/prunsrv.c | 63 +++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 88c9102..21ad864 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -481,6 +481,64 @@ static void setInprocEnvironment9(LPCWSTR szOptions9)
     apxFree(e);
 }
 
+/* Sets environment variables required by some Java options
+ * Currently only Native Memory Tracking
+ */
+static void setInprocEnvironmentOptions(LPCWSTR szOptions)
+{
+    LPCWSTR p;
+    DWORD len;
+    LPWSTR e;
+
+	apxLogWrite(APXLOG_MARK_DEBUG "Checking Java options for environment variable requirements");
+
+    p = szOptions;
+    while (*p) {
+    	apxLogWrite(APXLOG_MARK_DEBUG "Checking '%S' for environment variable requirements", p);
+        if (wcsncmp(p, L"-XX:NativeMemoryTracking=", 25) == 0) {
+        	apxLogWrite(APXLOG_MARK_DEBUG "Match found '%S'", p);
+            /* Advance 25 characters to the start of the value */
+            p += 25;
+        	apxLogWrite(APXLOG_MARK_DEBUG "Setting is '%S'", p);
+            /* Ignore setting if it is off */
+            if (wcsncmp(p, L"off", 3)) {
+            	apxLogWrite(APXLOG_MARK_DEBUG "Creating environment entry");
+                /* Allocated space for the setting value */
+                len = lstrlen(p);
+                /* Expand space to include env var name less pid and '=' */
+                len += 11;
+                /* Expand spave to include pid (4 bytes, signed - up to 10 characters */
+                len += 10;
+                /* Expand space to include the null terminator */
+                len++;
+
+                /* Allocate the space */
+                e = apxPoolCalloc(gPool, len * sizeof(WCHAR));
+
+                /* Create the environment variable needed by NMT */
+                swprintf_s(e, len, L"NMT_LEVEL_%d=%s", GetCurrentProcessId(), p);
+
+            	apxLogWrite(APXLOG_MARK_DEBUG "Created environment entry '%S'", e);
+                /* Set the environment variable */
+               _wputenv(e);
+
+               apxFree(e);
+            }
+            return;
+        }
+
+        /* advance to the terminating null */
+        while(*p) {
+          p++;
+        }
+
+        /* advance to the start of the next entry
+         * will be null if there are no more entries
+         */
+        p++;
+    }
+}
+
 /* Load the configuration from Registry
  * loads only nonspecified items
  */
@@ -1243,6 +1301,10 @@ static DWORD serviceStart()
             /* Add LibraryPath to the PATH */
            apxAddToPathW(gPool, SO_LIBPATH);
         }
+        /* Some options require additional environment settings to be in place
+         * before Java is started
+         */
+        setInprocEnvironmentOptions(SO_JVMOPTIONS);
         /* Create the JVM global worker */
         gWorker = apxCreateJava(gPool, _jni_jvmpath, SO_JAVAHOME);
         if (IS_INVALID_HANDLE(gWorker)) {
@@ -1287,6 +1349,7 @@ static DWORD serviceStart()
         }
         /* Set the environment using putenv, so JVM can use it */
         apxSetInprocEnvironment();
+        /* Java 9 specific options need to be set via an environment variable */
         setInprocEnvironment9(SO_JVMOPTIONS9);
         /* Redirect process */
         gWorker = apxCreateProcessW(gPool,