src/share/bin/java.c

Print this page
rev 9771 : 8042469 : Launcher changes for native memory tracking scalability enhancement

@@ -1002,10 +1002,11 @@
 {
     int argc = *pargc;
     char **argv = *pargv;
     int mode = LM_UNKNOWN;
     char *arg;
+    static const char*  NMT_Env_Name    = "NMT_LEVEL_";
 
     *pret = 0;
 
     while ((arg = *argv) != 0 && *arg == '-') {
         argv++; --argc;

@@ -1029,10 +1030,47 @@
             showVersion = JNI_TRUE;
         } else if (JLI_StrCmp(arg, "-X") == 0) {
             printXUsage = JNI_TRUE;
             return JNI_TRUE;
 /*
+ * The following case checks for "-XX:NativeMemoryTracking=value".
+ * If value is non null, an environmental variable set to this value
+ * will be created to be used by the JVM.
+ * The argument is passed to the JVM, which will check validity.
+ */
+        } else if (JLI_StrCCmp(arg, "-XX:NativeMemoryTracking=") == 0) {
+            int retval;
+            // get what follows this parameter, include "="
+            size_t pnlen = JLI_StrLen("-XX:NativeMemoryTracking=");
+            if (JLI_StrLen(arg) > pnlen) {
+                char* value = arg + pnlen;
+                size_t pbuflen = pnlen + JLI_StrLen(value) + 10; // 10 max pid#
+                // ensures that malloc successful
+                char * pbuf = (char*)JLI_MemAlloc(pbuflen);
+                JLI_Snprintf(pbuf, pbuflen, "%s%d=%s", NMT_Env_Name, JLI_GetPid(), value);
+                retval = JLI_PutEnv(pbuf);
+                if (JLI_IsTraceLauncher()) {
+                    char* envName;
+                    char* envBuf;
+
+                    // ensures that malloc successful
+                    envName = (char*)JLI_MemAlloc(pbuflen);
+                    JLI_Snprintf(envName, pbuflen, "%s%d", NMT_Env_Name, JLI_GetPid());
+                    
+                    printf("TRACER_MARKER: NativeMemoryTracking: env var is %s\n",envName);
+                    printf("TRACER_MARKER: NativeMemoryTracking: putenv arg %s\n",pbuf);
+                    envBuf = getenv(envName);
+                    printf("TRACER_MARKER: NativeMemoryTracking: got value %s\n",envBuf);
+                    free(envName);
+                }
+
+                free(pbuf);
+            }
+
+            // The argument is passed to JVM for comment.
+            AddOption(arg, NULL);
+/*
  * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
  * In the latter case, any SUBOPT value not recognized will default to "all"
  */
         } else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||
                 JLI_StrCCmp(arg, "-XshowSettings:") == 0) {