jdk/src/java.base/share/native/libjli/java.c
changeset 45062 37ed4313c8c1
parent 43498 fd3e0590219e
child 45067 668772ef409f
equal deleted inserted replaced
45061:74b09ee3cd55 45062:37ed4313c8c1
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   121 static void ListModules(JNIEnv* env, char *optString);
   121 static void ListModules(JNIEnv* env, char *optString);
   122 
   122 
   123 static void SetPaths(int argc, char **argv);
   123 static void SetPaths(int argc, char **argv);
   124 
   124 
   125 static void DumpState();
   125 static void DumpState();
   126 static jboolean RemovableOption(char *option);
       
   127 
   126 
   128 enum OptionKind {
   127 enum OptionKind {
   129     LAUNCHER_OPTION = 0,
   128     LAUNCHER_OPTION = 0,
   130     LAUNCHER_OPTION_WITH_ARGUMENT,
   129     LAUNCHER_OPTION_WITH_ARGUMENT,
   131     LAUNCHER_MAIN_OPTION,
   130     LAUNCHER_MAIN_OPTION,
   740 
   739 
   741     return jvmtype;
   740     return jvmtype;
   742 }
   741 }
   743 
   742 
   744 /*
   743 /*
   745  * static void SetJvmEnvironment(int argc, char **argv);
   744  * This method must be called before the VM is loaded, primarily
   746  *   Is called just before the JVM is loaded.  We can set env variables
   745  * used to parse and set any VM related options or env variables.
   747  *   that are consumed by the JVM.  This function is non-destructive,
   746  * This function is non-destructive leaving the argument list intact.
   748  *   leaving the arg list intact.  The first use is for the JVM flag
       
   749  *   -XX:NativeMemoryTracking=value.
       
   750  */
   747  */
   751 static void
   748 static void
   752 SetJvmEnvironment(int argc, char **argv) {
   749 SetJvmEnvironment(int argc, char **argv) {
   753 
   750 
   754     static const char*  NMT_Env_Name    = "NMT_LEVEL_";
   751     static const char*  NMT_Env_Name    = "NMT_LEVEL_";
   755     int i;
   752     int i;
       
   753     /* process only the launcher arguments */
   756     for (i = 0; i < argc; i++) {
   754     for (i = 0; i < argc; i++) {
   757         char *arg = argv[i];
   755         char *arg = argv[i];
   758         /*
   756         /*
   759          * Since this must be a VM flag we stop processing once we see
   757          * Since this must be a VM flag we stop processing once we see
   760          * an argument the launcher would not have processed beyond (such
   758          * an argument the launcher would not have processed beyond (such
   809                     printf("TRACER_MARKER: NativeMemoryTracking: putenv arg %s\n",pbuf);
   807                     printf("TRACER_MARKER: NativeMemoryTracking: putenv arg %s\n",pbuf);
   810                     envBuf = getenv(envName);
   808                     envBuf = getenv(envName);
   811                     printf("TRACER_MARKER: NativeMemoryTracking: got value %s\n",envBuf);
   809                     printf("TRACER_MARKER: NativeMemoryTracking: got value %s\n",envBuf);
   812                     free(envName);
   810                     free(envName);
   813                 }
   811                 }
   814 
       
   815             }
   812             }
   816 
   813         }
   817         }
       
   818 
       
   819     }
   814     }
   820 }
   815 }
   821 
   816 
   822 /* copied from HotSpot function "atomll()" */
   817 /* copied from HotSpot function "atomll()" */
   823 static int
   818 static int
  1381             JLI_ReportErrorMessage(ARG_WARN, arg);
  1376             JLI_ReportErrorMessage(ARG_WARN, arg);
  1382         } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
  1377         } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
  1383             ; /* Ignore machine independent options already handled */
  1378             ; /* Ignore machine independent options already handled */
  1384         } else if (ProcessPlatformOption(arg)) {
  1379         } else if (ProcessPlatformOption(arg)) {
  1385             ; /* Processing of platform dependent options */
  1380             ; /* Processing of platform dependent options */
  1386         } else if (RemovableOption(arg)) {
       
  1387             ; /* Do not pass option to vm. */
       
  1388         } else {
  1381         } else {
  1389             /* java.class.path set on the command line */
  1382             /* java.class.path set on the command line */
  1390             if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) {
  1383             if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) {
  1391                 _have_classpath = JNI_TRUE;
  1384                 _have_classpath = JNI_TRUE;
  1392             }
  1385             }
  2261     printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
  2254     printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
  2262     printf("\tfullversion:%s\n", GetFullVersion());
  2255     printf("\tfullversion:%s\n", GetFullVersion());
  2263 }
  2256 }
  2264 
  2257 
  2265 /*
  2258 /*
  2266  * Return JNI_TRUE for an option string that has no effect but should
       
  2267  * _not_ be passed on to the vm; return JNI_FALSE otherwise.  On
       
  2268  * Solaris SPARC, this screening needs to be done if:
       
  2269  *    -d32 or -d64 is passed to a binary with an unmatched data model
       
  2270  *    (the exec in CreateExecutionEnvironment removes -d<n> options and points the
       
  2271  *    exec to the proper binary).  In the case of when the data model and the
       
  2272  *    requested version is matched, an exec would not occur, and these options
       
  2273  *    were erroneously passed to the vm.
       
  2274  */
       
  2275 jboolean
       
  2276 RemovableOption(char * option)
       
  2277 {
       
  2278   /*
       
  2279    * Unconditionally remove both -d32 and -d64 options since only
       
  2280    * the last such options has an effect; e.g.
       
  2281    * java -d32 -d64 -d32 -version
       
  2282    * is equivalent to
       
  2283    * java -d32 -version
       
  2284    */
       
  2285 
       
  2286   if( (JLI_StrCCmp(option, "-d32")  == 0 ) ||
       
  2287       (JLI_StrCCmp(option, "-d64")  == 0 ) )
       
  2288     return JNI_TRUE;
       
  2289   else
       
  2290     return JNI_FALSE;
       
  2291 }
       
  2292 
       
  2293 /*
       
  2294  * A utility procedure to always print to stderr
  2259  * A utility procedure to always print to stderr
  2295  */
  2260  */
  2296 void
  2261 void
  2297 JLI_ReportMessage(const char* fmt, ...)
  2262 JLI_ReportMessage(const char* fmt, ...)
  2298 {
  2263 {