Path: blob/master/src/java.base/share/native/libjli/java.c
67743 views
/*1* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Shared source for 'java' command line tool.27*28* If JAVA_ARGS is defined, then acts as a launcher for applications. For29* instance, the JDK command line tools such as javac and javadoc (see30* makefiles for more details) are built with this program. Any arguments31* prefixed with '-J' will be passed directly to the 'java' command.32*/3334/*35* One job of the launcher is to remove command line options which the36* vm does not understand and will not process. These options include37* options which select which style of vm is run (e.g. -client and38* -server) as well as options which select the data model to use.39* Additionally, for tools which invoke an underlying vm "-J-foo"40* options are turned into "-foo" options to the vm. This option41* filtering is handled in a number of places in the launcher, some of42* it in machine-dependent code. In this file, the function43* CheckJvmType removes vm style options and TranslateApplicationArgs44* removes "-J" prefixes. The CreateExecutionEnvironment function processes45* and removes -d<n> options. On unix, there is a possibility that the running46* data model may not match to the desired data model, in this case an exec is47* required to start the desired model. If the data models match, then48* ParseArguments will remove the -d<n> flags. If the data models do not match49* the CreateExecutionEnviroment will remove the -d<n> flags.50*/515253#include "java.h"54#include "jni.h"5556/*57* A NOTE TO DEVELOPERS: For performance reasons it is important that58* the program image remain relatively small until after SelectVersion59* CreateExecutionEnvironment have finished their possibly recursive60* processing. Watch everything, but resist all temptations to use Java61* interfaces.62*/6364#define USE_STDERR JNI_TRUE /* we usually print to stderr */65#define USE_STDOUT JNI_FALSE6667static jboolean printVersion = JNI_FALSE; /* print and exit */68static jboolean showVersion = JNI_FALSE; /* print but continue */69static jboolean printUsage = JNI_FALSE; /* print and exit*/70static jboolean printTo = USE_STDERR; /* where to print version/usage */71static jboolean printXUsage = JNI_FALSE; /* print and exit*/72static jboolean dryRun = JNI_FALSE; /* initialize VM and exit */73static char *showSettings = NULL; /* print but continue */74static jboolean showResolvedModules = JNI_FALSE;75static jboolean listModules = JNI_FALSE;76static char *describeModule = NULL;77static jboolean validateModules = JNI_FALSE;7879static const char *_program_name;80static const char *_launcher_name;81static jboolean _is_java_args = JNI_FALSE;82static jboolean _have_classpath = JNI_FALSE;83static const char *_fVersion;84static jboolean _wc_enabled = JNI_FALSE;8586/*87* Entries for splash screen environment variables.88* putenv is performed in SelectVersion. We need89* them in memory until UnsetEnv, so they are made static90* global instead of auto local.91*/92static char* splash_file_entry = NULL;93static char* splash_jar_entry = NULL;9495/*96* List of VM options to be specified when the VM is created.97*/98static JavaVMOption *options;99static int numOptions, maxOptions;100101/*102* Prototypes for functions internal to launcher.103*/104static const char* GetFullVersion();105static jboolean IsJavaArgs();106static void SetJavaLauncherProp();107static void SetClassPath(const char *s);108static void SetMainModule(const char *s);109static void SelectVersion(int argc, char **argv, char **main_class);110static jboolean ParseArguments(int *pargc, char ***pargv,111int *pmode, char **pwhat,112int *pret, const char *jrepath);113static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,114InvocationFunctions *ifn);115static jstring NewPlatformString(JNIEnv *env, char *s);116static jclass LoadMainClass(JNIEnv *env, int mode, char *name);117static jclass GetApplicationClass(JNIEnv *env);118119static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv);120static jboolean AddApplicationOptions(int cpathc, const char **cpathv);121static void SetApplicationClassPath(const char**);122123static void PrintJavaVersion(JNIEnv *env, jboolean extraLF);124static void PrintUsage(JNIEnv* env, jboolean doXUsage);125static void ShowSettings(JNIEnv* env, char *optString);126static void ShowResolvedModules(JNIEnv* env);127static void ListModules(JNIEnv* env);128static void DescribeModule(JNIEnv* env, char* optString);129static jboolean ValidateModules(JNIEnv* env);130131static void SetPaths(int argc, char **argv);132133static void DumpState();134135enum OptionKind {136LAUNCHER_OPTION = 0,137LAUNCHER_OPTION_WITH_ARGUMENT,138LAUNCHER_MAIN_OPTION,139VM_LONG_OPTION,140VM_LONG_OPTION_WITH_ARGUMENT,141VM_OPTION142};143144static int GetOpt(int *pargc, char ***pargv, char **poption, char **pvalue);145static jboolean IsOptionWithArgument(int argc, char **argv);146147/* Maximum supported entries from jvm.cfg. */148#define INIT_MAX_KNOWN_VMS 10149150/* Values for vmdesc.flag */151enum vmdesc_flag {152VM_UNKNOWN = -1,153VM_KNOWN,154VM_ALIASED_TO,155VM_WARN,156VM_ERROR,157VM_IF_SERVER_CLASS,158VM_IGNORE159};160161struct vmdesc {162char *name;163int flag;164char *alias;165char *server_class;166};167static struct vmdesc *knownVMs = NULL;168static int knownVMsCount = 0;169static int knownVMsLimit = 0;170171static void GrowKnownVMs(int minimum);172static int KnownVMIndex(const char* name);173static void FreeKnownVMs();174static jboolean IsWildCardEnabled();175176177#define SOURCE_LAUNCHER_MAIN_ENTRY "jdk.compiler/com.sun.tools.javac.launcher.Main"178179/*180* This reports error. VM will not be created and no usage is printed.181*/182#define REPORT_ERROR(AC_ok, AC_failure_message, AC_questionable_arg) \183do { \184if (!AC_ok) { \185JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \186printUsage = JNI_FALSE; \187*pret = 1; \188return JNI_FALSE; \189} \190} while (JNI_FALSE)191192#define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \193do { \194if (AC_arg_count < 1) { \195JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \196printUsage = JNI_TRUE; \197*pret = 1; \198return JNI_TRUE; \199} \200} while (JNI_FALSE)201202/*203* Running Java code in primordial thread caused many problems. We will204* create a new thread to invoke JVM. See 6316197 for more information.205*/206static jlong threadStackSize = 0; /* stack size of the new thread */207static jlong maxHeapSize = 0; /* max heap size */208static jlong initialHeapSize = 0; /* initial heap size */209210/*211* A minimum initial-thread stack size suitable for most platforms.212* This is the minimum amount of stack needed to load the JVM such213* that it can reject a too small -Xss value. If this is too small214* JVM initialization would cause a StackOverflowError.215*/216#ifndef STACK_SIZE_MINIMUM217#define STACK_SIZE_MINIMUM (64 * KB)218#endif219220/*221* Entry point.222*/223JNIEXPORT int JNICALL224JLI_Launch(int argc, char ** argv, /* main argc, argv */225int jargc, const char** jargv, /* java args */226int appclassc, const char** appclassv, /* app classpath */227const char* fullversion, /* full version defined */228const char* dotversion, /* UNUSED dot version defined */229const char* pname, /* program name */230const char* lname, /* launcher name */231jboolean javaargs, /* JAVA_ARGS */232jboolean cpwildcard, /* classpath wildcard*/233jboolean javaw, /* windows-only javaw */234jint ergo /* unused */235)236{237int mode = LM_UNKNOWN;238char *what = NULL;239char *main_class = NULL;240int ret;241InvocationFunctions ifn;242jlong start = 0, end = 0;243char jvmpath[MAXPATHLEN];244char jrepath[MAXPATHLEN];245char jvmcfg[MAXPATHLEN];246247_fVersion = fullversion;248_launcher_name = lname;249_program_name = pname;250_is_java_args = javaargs;251_wc_enabled = cpwildcard;252253InitLauncher(javaw);254DumpState();255if (JLI_IsTraceLauncher()) {256int i;257printf("Java args:\n");258for (i = 0; i < jargc ; i++) {259printf("jargv[%d] = %s\n", i, jargv[i]);260}261printf("Command line args:\n");262for (i = 0; i < argc ; i++) {263printf("argv[%d] = %s\n", i, argv[i]);264}265AddOption("-Dsun.java.launcher.diag=true", NULL);266}267268/*269* SelectVersion() has several responsibilities:270*271* 1) Disallow specification of another JRE. With 1.9, another272* version of the JRE cannot be invoked.273* 2) Allow for a JRE version to invoke JDK 1.9 or later. Since274* all mJRE directives have been stripped from the request but275* the pre 1.9 JRE [ 1.6 thru 1.8 ], it is as if 1.9+ has been276* invoked from the command line.277*/278SelectVersion(argc, argv, &main_class);279280CreateExecutionEnvironment(&argc, &argv,281jrepath, sizeof(jrepath),282jvmpath, sizeof(jvmpath),283jvmcfg, sizeof(jvmcfg));284285ifn.CreateJavaVM = 0;286ifn.GetDefaultJavaVMInitArgs = 0;287288if (JLI_IsTraceLauncher()) {289start = CurrentTimeMicros();290}291292if (!LoadJavaVM(jvmpath, &ifn)) {293return(6);294}295296if (JLI_IsTraceLauncher()) {297end = CurrentTimeMicros();298}299300JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n", (long)(end-start));301302++argv;303--argc;304305if (IsJavaArgs()) {306/* Preprocess wrapper arguments */307TranslateApplicationArgs(jargc, jargv, &argc, &argv);308if (!AddApplicationOptions(appclassc, appclassv)) {309return(1);310}311} else {312/* Set default CLASSPATH */313char* cpath = getenv("CLASSPATH");314if (cpath != NULL) {315SetClassPath(cpath);316}317}318319/* Parse command line options; if the return value of320* ParseArguments is false, the program should exit.321*/322if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath)) {323return(ret);324}325326/* Override class path if -jar flag was specified */327if (mode == LM_JAR) {328SetClassPath(what); /* Override class path */329}330331/* set the -Dsun.java.command pseudo property */332SetJavaCommandLineProp(what, argc, argv);333334/* Set the -Dsun.java.launcher pseudo property */335SetJavaLauncherProp();336337return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);338}339/*340* Always detach the main thread so that it appears to have ended when341* the application's main method exits. This will invoke the342* uncaught exception handler machinery if main threw an343* exception. An uncaught exception handler cannot change the344* launcher's return code except by calling System.exit.345*346* Wait for all non-daemon threads to end, then destroy the VM.347* This will actually create a trivial new Java waiter thread348* named "DestroyJavaVM", but this will be seen as a different349* thread from the one that executed main, even though they are350* the same C thread. This allows mainThread.join() and351* mainThread.isAlive() to work as expected.352*/353#define LEAVE() \354do { \355if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \356JLI_ReportErrorMessage(JVM_ERROR2); \357ret = 1; \358} \359if (JNI_TRUE) { \360(*vm)->DestroyJavaVM(vm); \361return ret; \362} \363} while (JNI_FALSE)364365#define CHECK_EXCEPTION_NULL_LEAVE(CENL_exception) \366do { \367if ((*env)->ExceptionOccurred(env)) { \368JLI_ReportExceptionDescription(env); \369LEAVE(); \370} \371if ((CENL_exception) == NULL) { \372JLI_ReportErrorMessage(JNI_ERROR); \373LEAVE(); \374} \375} while (JNI_FALSE)376377#define CHECK_EXCEPTION_LEAVE(CEL_return_value) \378do { \379if ((*env)->ExceptionOccurred(env)) { \380JLI_ReportExceptionDescription(env); \381ret = (CEL_return_value); \382LEAVE(); \383} \384} while (JNI_FALSE)385386387int388JavaMain(void* _args)389{390JavaMainArgs *args = (JavaMainArgs *)_args;391int argc = args->argc;392char **argv = args->argv;393int mode = args->mode;394char *what = args->what;395InvocationFunctions ifn = args->ifn;396397JavaVM *vm = 0;398JNIEnv *env = 0;399jclass mainClass = NULL;400jclass appClass = NULL; // actual application class being launched401jmethodID mainID;402jobjectArray mainArgs;403int ret = 0;404jlong start = 0, end = 0;405406RegisterThread();407408/* Initialize the virtual machine */409start = CurrentTimeMicros();410if (!InitializeJVM(&vm, &env, &ifn)) {411JLI_ReportErrorMessage(JVM_ERROR1);412exit(1);413}414415if (showSettings != NULL) {416ShowSettings(env, showSettings);417CHECK_EXCEPTION_LEAVE(1);418}419420// show resolved modules and continue421if (showResolvedModules) {422ShowResolvedModules(env);423CHECK_EXCEPTION_LEAVE(1);424}425426// list observable modules, then exit427if (listModules) {428ListModules(env);429CHECK_EXCEPTION_LEAVE(1);430LEAVE();431}432433// describe a module, then exit434if (describeModule != NULL) {435DescribeModule(env, describeModule);436CHECK_EXCEPTION_LEAVE(1);437LEAVE();438}439440if (printVersion || showVersion) {441PrintJavaVersion(env, showVersion);442CHECK_EXCEPTION_LEAVE(0);443if (printVersion) {444LEAVE();445}446}447448// modules have been validated at startup so exit449if (validateModules) {450LEAVE();451}452453/* If the user specified neither a class name nor a JAR file */454if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) {455PrintUsage(env, printXUsage);456CHECK_EXCEPTION_LEAVE(1);457LEAVE();458}459460FreeKnownVMs(); /* after last possible PrintUsage */461462if (JLI_IsTraceLauncher()) {463end = CurrentTimeMicros();464JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n", (long)(end-start));465}466467/* At this stage, argc/argv have the application's arguments */468if (JLI_IsTraceLauncher()){469int i;470printf("%s is '%s'\n", launchModeNames[mode], what);471printf("App's argc is %d\n", argc);472for (i=0; i < argc; i++) {473printf(" argv[%2d] = '%s'\n", i, argv[i]);474}475}476477ret = 1;478479/*480* Get the application's main class. It also checks if the main481* method exists.482*483* See bugid 5030265. The Main-Class name has already been parsed484* from the manifest, but not parsed properly for UTF-8 support.485* Hence the code here ignores the value previously extracted and486* uses the pre-existing code to reextract the value. This is487* possibly an end of release cycle expedient. However, it has488* also been discovered that passing some character sets through489* the environment has "strange" behavior on some variants of490* Windows. Hence, maybe the manifest parsing code local to the491* launcher should never be enhanced.492*493* Hence, future work should either:494* 1) Correct the local parsing code and verify that the495* Main-Class attribute gets properly passed through496* all environments,497* 2) Remove the vestages of maintaining main_class through498* the environment (and remove these comments).499*500* This method also correctly handles launching existing JavaFX501* applications that may or may not have a Main-Class manifest entry.502*/503mainClass = LoadMainClass(env, mode, what);504CHECK_EXCEPTION_NULL_LEAVE(mainClass);505/*506* In some cases when launching an application that needs a helper, e.g., a507* JavaFX application with no main method, the mainClass will not be the508* applications own main class but rather a helper class. To keep things509* consistent in the UI we need to track and report the application main class.510*/511appClass = GetApplicationClass(env);512NULL_CHECK_RETURN_VALUE(appClass, -1);513514/* Build platform specific argument array */515mainArgs = CreateApplicationArgs(env, argv, argc);516CHECK_EXCEPTION_NULL_LEAVE(mainArgs);517518if (dryRun) {519ret = 0;520LEAVE();521}522523/*524* PostJVMInit uses the class name as the application name for GUI purposes,525* for example, on OSX this sets the application name in the menu bar for526* both SWT and JavaFX. So we'll pass the actual application class here527* instead of mainClass as that may be a launcher or helper class instead528* of the application class.529*/530PostJVMInit(env, appClass, vm);531CHECK_EXCEPTION_LEAVE(1);532533/*534* The LoadMainClass not only loads the main class, it will also ensure535* that the main method's signature is correct, therefore further checking536* is not required. The main method is invoked here so that extraneous java537* stacks are not in the application stack trace.538*/539mainID = (*env)->GetStaticMethodID(env, mainClass, "main",540"([Ljava/lang/String;)V");541CHECK_EXCEPTION_NULL_LEAVE(mainID);542543/* Invoke main method. */544(*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);545546/*547* The launcher's exit code (in the absence of calls to548* System.exit) will be non-zero if main threw an exception.549*/550ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;551552LEAVE();553}554555/*556* Test if the given name is one of the class path options.557*/558static jboolean559IsClassPathOption(const char* name) {560return JLI_StrCmp(name, "-classpath") == 0 ||561JLI_StrCmp(name, "-cp") == 0 ||562JLI_StrCmp(name, "--class-path") == 0;563}564565/*566* Test if the given name is a launcher option taking the main entry point.567*/568static jboolean569IsLauncherMainOption(const char* name) {570return JLI_StrCmp(name, "--module") == 0 ||571JLI_StrCmp(name, "-m") == 0;572}573574/*575* Test if the given name is a white-space launcher option.576*/577static jboolean578IsLauncherOption(const char* name) {579return IsClassPathOption(name) ||580IsLauncherMainOption(name) ||581JLI_StrCmp(name, "--describe-module") == 0 ||582JLI_StrCmp(name, "-d") == 0 ||583JLI_StrCmp(name, "--source") == 0;584}585586/*587* Test if the given name is a module-system white-space option that588* will be passed to the VM with its corresponding long-form option589* name and "=" delimiter.590*/591static jboolean592IsModuleOption(const char* name) {593return JLI_StrCmp(name, "--module-path") == 0 ||594JLI_StrCmp(name, "-p") == 0 ||595JLI_StrCmp(name, "--upgrade-module-path") == 0 ||596JLI_StrCmp(name, "--add-modules") == 0 ||597JLI_StrCmp(name, "--enable-native-access") == 0 ||598JLI_StrCmp(name, "--limit-modules") == 0 ||599JLI_StrCmp(name, "--add-exports") == 0 ||600JLI_StrCmp(name, "--add-opens") == 0 ||601JLI_StrCmp(name, "--add-reads") == 0 ||602JLI_StrCmp(name, "--patch-module") == 0;603}604605static jboolean606IsLongFormModuleOption(const char* name) {607return JLI_StrCCmp(name, "--module-path=") == 0 ||608JLI_StrCCmp(name, "--upgrade-module-path=") == 0 ||609JLI_StrCCmp(name, "--add-modules=") == 0 ||610JLI_StrCCmp(name, "--enable-native-access=") == 0 ||611JLI_StrCCmp(name, "--limit-modules=") == 0 ||612JLI_StrCCmp(name, "--add-exports=") == 0 ||613JLI_StrCCmp(name, "--add-reads=") == 0 ||614JLI_StrCCmp(name, "--patch-module=") == 0;615}616617/*618* Test if the given name has a white space option.619*/620jboolean621IsWhiteSpaceOption(const char* name) {622return IsModuleOption(name) ||623IsLauncherOption(name);624}625626/*627* Check if it is OK to set the mode.628* If the mode was previously set, and should not be changed,629* a fatal error is reported.630*/631static int632checkMode(int mode, int newMode, const char *arg) {633if (mode == LM_SOURCE) {634JLI_ReportErrorMessage(ARG_ERROR14, arg);635exit(1);636}637return newMode;638}639640/*641* Test if an arg identifies a source file.642*/643static jboolean IsSourceFile(const char *arg) {644struct stat st;645return (JLI_HasSuffix(arg, ".java") && stat(arg, &st) == 0);646}647648/*649* Checks the command line options to find which JVM type was650* specified. If no command line option was given for the JVM type,651* the default type is used. The environment variable652* JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also653* checked as ways of specifying which JVM type to invoke.654*/655char *656CheckJvmType(int *pargc, char ***argv, jboolean speculative) {657int i, argi;658int argc;659char **newArgv;660int newArgvIdx = 0;661int isVMType;662int jvmidx = -1;663char *jvmtype = getenv("JDK_ALTERNATE_VM");664665argc = *pargc;666667/* To make things simpler we always copy the argv array */668newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));669670/* The program name is always present */671newArgv[newArgvIdx++] = (*argv)[0];672673for (argi = 1; argi < argc; argi++) {674char *arg = (*argv)[argi];675isVMType = 0;676677if (IsJavaArgs()) {678if (arg[0] != '-') {679newArgv[newArgvIdx++] = arg;680continue;681}682} else {683if (IsWhiteSpaceOption(arg)) {684newArgv[newArgvIdx++] = arg;685argi++;686if (argi < argc) {687newArgv[newArgvIdx++] = (*argv)[argi];688}689continue;690}691if (arg[0] != '-') break;692}693694/* Did the user pass an explicit VM type? */695i = KnownVMIndex(arg);696if (i >= 0) {697jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */698isVMType = 1;699*pargc = *pargc - 1;700}701702/* Did the user specify an "alternate" VM? */703else if (JLI_StrCCmp(arg, "-XXaltjvm=") == 0 || JLI_StrCCmp(arg, "-J-XXaltjvm=") == 0) {704isVMType = 1;705jvmtype = arg+((arg[1]=='X')? 10 : 12);706jvmidx = -1;707}708709if (!isVMType) {710newArgv[newArgvIdx++] = arg;711}712}713714/*715* Finish copying the arguments if we aborted the above loop.716* NOTE that if we aborted via "break" then we did NOT copy the717* last argument above, and in addition argi will be less than718* argc.719*/720while (argi < argc) {721newArgv[newArgvIdx++] = (*argv)[argi];722argi++;723}724725/* argv is null-terminated */726newArgv[newArgvIdx] = 0;727728/* Copy back argv */729*argv = newArgv;730*pargc = newArgvIdx;731732/* use the default VM type if not specified (no alias processing) */733if (jvmtype == NULL) {734char* result = knownVMs[0].name+1;735JLI_TraceLauncher("Default VM: %s\n", result);736return result;737}738739/* if using an alternate VM, no alias processing */740if (jvmidx < 0)741return jvmtype;742743/* Resolve aliases first */744{745int loopCount = 0;746while (knownVMs[jvmidx].flag == VM_ALIASED_TO) {747int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias);748749if (loopCount > knownVMsCount) {750if (!speculative) {751JLI_ReportErrorMessage(CFG_ERROR1);752exit(1);753} else {754return "ERROR";755/* break; */756}757}758759if (nextIdx < 0) {760if (!speculative) {761JLI_ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);762exit(1);763} else {764return "ERROR";765}766}767jvmidx = nextIdx;768jvmtype = knownVMs[jvmidx].name+1;769loopCount++;770}771}772773switch (knownVMs[jvmidx].flag) {774case VM_WARN:775if (!speculative) {776JLI_ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);777}778/* fall through */779case VM_IGNORE:780jvmtype = knownVMs[jvmidx=0].name + 1;781/* fall through */782case VM_KNOWN:783break;784case VM_ERROR:785if (!speculative) {786JLI_ReportErrorMessage(CFG_ERROR3, jvmtype);787exit(1);788} else {789return "ERROR";790}791}792793return jvmtype;794}795796/* copied from HotSpot function "atomll()" */797static int798parse_size(const char *s, jlong *result) {799jlong n = 0;800int args_read = sscanf(s, JLONG_FORMAT_SPECIFIER, &n);801if (args_read != 1) {802return 0;803}804while (*s != '\0' && *s >= '0' && *s <= '9') {805s++;806}807// 4705540: illegal if more characters are found after the first non-digit808if (JLI_StrLen(s) > 1) {809return 0;810}811switch (*s) {812case 'T': case 't':813*result = n * GB * KB;814return 1;815case 'G': case 'g':816*result = n * GB;817return 1;818case 'M': case 'm':819*result = n * MB;820return 1;821case 'K': case 'k':822*result = n * KB;823return 1;824case '\0':825*result = n;826return 1;827default:828/* Create JVM with default stack and let VM handle malformed -Xss string*/829return 0;830}831}832833/*834* Adds a new VM option with the given name and value.835*/836void837AddOption(char *str, void *info)838{839/*840* Expand options array if needed to accommodate at least one more841* VM option.842*/843if (numOptions >= maxOptions) {844if (options == 0) {845maxOptions = 4;846options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));847} else {848JavaVMOption *tmp;849maxOptions *= 2;850tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));851memcpy(tmp, options, numOptions * sizeof(JavaVMOption));852JLI_MemFree(options);853options = tmp;854}855}856options[numOptions].optionString = str;857options[numOptions++].extraInfo = info;858859/*860* -Xss is used both by the JVM and here to establish the stack size of the thread861* created to launch the JVM. In the latter case we need to ensure we don't go862* below the minimum stack size allowed. If -Xss is zero that tells the JVM to use863* 'default' sizes (either from JVM or system configuration, e.g. 'ulimit -s' on linux),864* and is not itself a small stack size that will be rejected. So we ignore -Xss0 here.865*/866if (JLI_StrCCmp(str, "-Xss") == 0) {867jlong tmp;868if (parse_size(str + 4, &tmp)) {869threadStackSize = tmp;870if (threadStackSize > 0 && threadStackSize < (jlong)STACK_SIZE_MINIMUM) {871threadStackSize = STACK_SIZE_MINIMUM;872}873}874}875876if (JLI_StrCCmp(str, "-Xmx") == 0) {877jlong tmp;878if (parse_size(str + 4, &tmp)) {879maxHeapSize = tmp;880}881}882883if (JLI_StrCCmp(str, "-Xms") == 0) {884jlong tmp;885if (parse_size(str + 4, &tmp)) {886initialHeapSize = tmp;887}888}889}890891static void892SetClassPath(const char *s)893{894char *def;895const char *orig = s;896static const char format[] = "-Djava.class.path=%s";897/*898* usually we should not get a null pointer, but there are cases where899* we might just get one, in which case we simply ignore it, and let the900* caller deal with it901*/902if (s == NULL)903return;904s = JLI_WildcardExpandClasspath(s);905if (sizeof(format) - 2 + JLI_StrLen(s) < JLI_StrLen(s))906// s is became corrupted after expanding wildcards907return;908def = JLI_MemAlloc(sizeof(format)909- 2 /* strlen("%s") */910+ JLI_StrLen(s));911sprintf(def, format, s);912AddOption(def, NULL);913if (s != orig)914JLI_MemFree((char *) s);915_have_classpath = JNI_TRUE;916}917918static void919AddLongFormOption(const char *option, const char *arg)920{921static const char format[] = "%s=%s";922char *def;923size_t def_len;924925def_len = JLI_StrLen(option) + 1 + JLI_StrLen(arg) + 1;926def = JLI_MemAlloc(def_len);927JLI_Snprintf(def, def_len, format, option, arg);928AddOption(def, NULL);929}930931static void932SetMainModule(const char *s)933{934static const char format[] = "-Djdk.module.main=%s";935char* slash = JLI_StrChr(s, '/');936size_t s_len, def_len;937char *def;938939/* value may be <module> or <module>/<mainclass> */940if (slash == NULL) {941s_len = JLI_StrLen(s);942} else {943s_len = (size_t) (slash - s);944}945def_len = sizeof(format)946- 2 /* strlen("%s") */947+ s_len;948def = JLI_MemAlloc(def_len);949JLI_Snprintf(def, def_len, format, s);950AddOption(def, NULL);951}952953/*954* The SelectVersion() routine ensures that an appropriate version of955* the JRE is running. The specification for the appropriate version956* is obtained from either the manifest of a jar file (preferred) or957* from command line options.958* The routine also parses splash screen command line options and959* passes on their values in private environment variables.960*/961static void962SelectVersion(int argc, char **argv, char **main_class)963{964char *arg;965char *operand;966char *version = NULL;967char *jre = NULL;968int jarflag = 0;969int headlessflag = 0;970int restrict_search = -1; /* -1 implies not known */971manifest_info info;972char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "=";973char *splash_file_name = NULL;974char *splash_jar_name = NULL;975char *env_in;976int res;977jboolean has_arg;978979/*980* If the version has already been selected, set *main_class981* with the value passed through the environment (if any) and982* simply return.983*/984985/*986* This environmental variable can be set by mJRE capable JREs987* [ 1.5 thru 1.8 ]. All other aspects of mJRE processing have been988* stripped by those JREs. This environmental variable allows 1.9+989* JREs to be started by these mJRE capable JREs.990* Note that mJRE directives in the jar manifest file would have been991* ignored for a JRE started by another JRE...992* .. skipped for JRE 1.5 and beyond.993* .. not even checked for pre 1.5.994*/995if ((env_in = getenv(ENV_ENTRY)) != NULL) {996if (*env_in != '\0')997*main_class = JLI_StringDup(env_in);998return;999}10001001/*1002* Scan through the arguments for options relevant to multiple JRE1003* support. Multiple JRE support existed in JRE versions 1.5 thru 1.8.1004*1005* This capability is no longer available with JRE versions 1.9 and later.1006* These command line options are reported as errors.1007*/10081009argc--;1010argv++;1011while ((arg = *argv) != 0 && *arg == '-') {1012has_arg = IsOptionWithArgument(argc, argv);1013if (JLI_StrCCmp(arg, "-version:") == 0) {1014JLI_ReportErrorMessage(SPC_ERROR1);1015} else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) {1016JLI_ReportErrorMessage(SPC_ERROR2);1017} else if (JLI_StrCmp(arg, "-jre-no-restrict-search") == 0) {1018JLI_ReportErrorMessage(SPC_ERROR2);1019} else {1020if (JLI_StrCmp(arg, "-jar") == 0)1021jarflag = 1;1022if (IsWhiteSpaceOption(arg)) {1023if (has_arg) {1024argc--;1025argv++;1026arg = *argv;1027}1028}10291030/*1031* Checking for headless toolkit option in the some way as AWT does:1032* "true" means true and any other value means false1033*/1034if (JLI_StrCmp(arg, "-Djava.awt.headless=true") == 0) {1035headlessflag = 1;1036} else if (JLI_StrCCmp(arg, "-Djava.awt.headless=") == 0) {1037headlessflag = 0;1038} else if (JLI_StrCCmp(arg, "-splash:") == 0) {1039splash_file_name = arg+8;1040}1041}1042argc--;1043argv++;1044}1045if (argc <= 0) { /* No operand? Possibly legit with -[full]version */1046operand = NULL;1047} else {1048argc--;1049operand = *argv++;1050}10511052/*1053* If there is a jar file, read the manifest. If the jarfile can't be1054* read, the manifest can't be read from the jar file, or the manifest1055* is corrupt, issue the appropriate error messages and exit.1056*1057* Even if there isn't a jar file, construct a manifest_info structure1058* containing the command line information. It's a convenient way to carry1059* this data around.1060*/1061if (jarflag && operand) {1062if ((res = JLI_ParseManifest(operand, &info)) != 0) {1063if (res == -1)1064JLI_ReportErrorMessage(JAR_ERROR2, operand);1065else1066JLI_ReportErrorMessage(JAR_ERROR3, operand);1067exit(1);1068}10691070/*1071* Command line splash screen option should have precedence1072* over the manifest, so the manifest data is used only if1073* splash_file_name has not been initialized above during command1074* line parsing1075*/1076if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) {1077splash_file_name = info.splashscreen_image_file_name;1078splash_jar_name = operand;1079}1080} else {1081info.manifest_version = NULL;1082info.main_class = NULL;1083info.jre_version = NULL;1084info.jre_restrict_search = 0;1085}10861087/*1088* Passing on splash screen info in environment variables1089*/1090if (splash_file_name && !headlessflag) {1091splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1);1092JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");1093JLI_StrCat(splash_file_entry, splash_file_name);1094putenv(splash_file_entry);1095}1096if (splash_jar_name && !headlessflag) {1097splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1);1098JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");1099JLI_StrCat(splash_jar_entry, splash_jar_name);1100putenv(splash_jar_entry);1101}110211031104/*1105* "Valid" returns (other than unrecoverable errors) follow. Set1106* main_class as a side-effect of this routine.1107*/1108if (info.main_class != NULL)1109*main_class = JLI_StringDup(info.main_class);11101111if (info.jre_version == NULL) {1112JLI_FreeManifest();1113return;1114}11151116}11171118/*1119* Test if the current argv is an option, i.e. with a leading `-`1120* and followed with an argument without a leading `-`.1121*/1122static jboolean1123IsOptionWithArgument(int argc, char** argv) {1124char* option;1125char* arg;11261127if (argc <= 1)1128return JNI_FALSE;11291130option = *argv;1131arg = *(argv+1);1132return *option == '-' && *arg != '-';1133}11341135/*1136* Gets the option, and its argument if the option has an argument.1137* It will update *pargc, **pargv to the next option.1138*/1139static int1140GetOpt(int *pargc, char ***pargv, char **poption, char **pvalue) {1141int argc = *pargc;1142char** argv = *pargv;1143char* arg = *argv;11441145char* option = arg;1146char* value = NULL;1147char* equals = NULL;1148int kind = LAUNCHER_OPTION;1149jboolean has_arg = JNI_FALSE;11501151// check if this option may be a white-space option with an argument1152has_arg = IsOptionWithArgument(argc, argv);11531154argv++; --argc;1155if (IsLauncherOption(arg)) {1156if (has_arg) {1157value = *argv;1158argv++; --argc;1159}1160kind = IsLauncherMainOption(arg) ? LAUNCHER_MAIN_OPTION1161: LAUNCHER_OPTION_WITH_ARGUMENT;1162} else if (IsModuleOption(arg)) {1163kind = VM_LONG_OPTION_WITH_ARGUMENT;1164if (has_arg) {1165value = *argv;1166argv++; --argc;1167}11681169/*1170* Support short form alias1171*/1172if (JLI_StrCmp(arg, "-p") == 0) {1173option = "--module-path";1174}11751176} else if (JLI_StrCCmp(arg, "--") == 0 && (equals = JLI_StrChr(arg, '=')) != NULL) {1177value = equals+1;1178if (JLI_StrCCmp(arg, "--describe-module=") == 0 ||1179JLI_StrCCmp(arg, "--module=") == 0 ||1180JLI_StrCCmp(arg, "--class-path=") == 0||1181JLI_StrCCmp(arg, "--source=") == 0) {1182kind = LAUNCHER_OPTION_WITH_ARGUMENT;1183} else {1184kind = VM_LONG_OPTION;1185}1186}11871188*pargc = argc;1189*pargv = argv;1190*poption = option;1191*pvalue = value;1192return kind;1193}11941195/*1196* Parses command line arguments. Returns JNI_FALSE if launcher1197* should exit without starting vm, returns JNI_TRUE if vm needs1198* to be started to process given options. *pret (the launcher1199* process return value) is set to 0 for a normal exit.1200*/1201static jboolean1202ParseArguments(int *pargc, char ***pargv,1203int *pmode, char **pwhat,1204int *pret, const char *jrepath)1205{1206int argc = *pargc;1207char **argv = *pargv;1208int mode = LM_UNKNOWN;1209char *arg;12101211*pret = 0;12121213while ((arg = *argv) != 0 && *arg == '-') {1214char *option = NULL;1215char *value = NULL;1216int kind = GetOpt(&argc, &argv, &option, &value);1217jboolean has_arg = value != NULL && JLI_StrLen(value) > 0;1218jboolean has_arg_any_len = value != NULL;12191220/*1221* Option to set main entry point1222*/1223if (JLI_StrCmp(arg, "-jar") == 0) {1224ARG_CHECK(argc, ARG_ERROR2, arg);1225mode = checkMode(mode, LM_JAR, arg);1226} else if (JLI_StrCmp(arg, "--module") == 0 ||1227JLI_StrCCmp(arg, "--module=") == 0 ||1228JLI_StrCmp(arg, "-m") == 0) {1229REPORT_ERROR (has_arg, ARG_ERROR5, arg);1230SetMainModule(value);1231mode = checkMode(mode, LM_MODULE, arg);1232if (has_arg) {1233*pwhat = value;1234break;1235}1236} else if (JLI_StrCmp(arg, "--source") == 0 ||1237JLI_StrCCmp(arg, "--source=") == 0) {1238REPORT_ERROR (has_arg, ARG_ERROR13, arg);1239mode = LM_SOURCE;1240if (has_arg) {1241const char *prop = "-Djdk.internal.javac.source=";1242size_t size = JLI_StrLen(prop) + JLI_StrLen(value) + 1;1243char *propValue = (char *)JLI_MemAlloc(size);1244JLI_Snprintf(propValue, size, "%s%s", prop, value);1245AddOption(propValue, NULL);1246}1247} else if (JLI_StrCmp(arg, "--class-path") == 0 ||1248JLI_StrCCmp(arg, "--class-path=") == 0 ||1249JLI_StrCmp(arg, "-classpath") == 0 ||1250JLI_StrCmp(arg, "-cp") == 0) {1251REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);1252SetClassPath(value);1253if (mode != LM_SOURCE) {1254mode = LM_CLASS;1255}1256} else if (JLI_StrCmp(arg, "--list-modules") == 0) {1257listModules = JNI_TRUE;1258} else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {1259showResolvedModules = JNI_TRUE;1260} else if (JLI_StrCmp(arg, "--validate-modules") == 0) {1261AddOption("-Djdk.module.validation=true", NULL);1262validateModules = JNI_TRUE;1263} else if (JLI_StrCmp(arg, "--describe-module") == 0 ||1264JLI_StrCCmp(arg, "--describe-module=") == 0 ||1265JLI_StrCmp(arg, "-d") == 0) {1266REPORT_ERROR (has_arg_any_len, ARG_ERROR12, arg);1267describeModule = value;1268/*1269* Parse white-space options1270*/1271} else if (has_arg) {1272if (kind == VM_LONG_OPTION) {1273AddOption(option, NULL);1274} else if (kind == VM_LONG_OPTION_WITH_ARGUMENT) {1275AddLongFormOption(option, value);1276}1277/*1278* Error missing argument1279*/1280} else if (!has_arg && (JLI_StrCmp(arg, "--module-path") == 0 ||1281JLI_StrCmp(arg, "-p") == 0 ||1282JLI_StrCmp(arg, "--upgrade-module-path") == 0)) {1283REPORT_ERROR (has_arg, ARG_ERROR4, arg);12841285} else if (!has_arg && (IsModuleOption(arg) || IsLongFormModuleOption(arg))) {1286REPORT_ERROR (has_arg, ARG_ERROR6, arg);1287/*1288* The following cases will cause the argument parsing to stop1289*/1290} else if (JLI_StrCmp(arg, "-help") == 0 ||1291JLI_StrCmp(arg, "-h") == 0 ||1292JLI_StrCmp(arg, "-?") == 0) {1293printUsage = JNI_TRUE;1294return JNI_TRUE;1295} else if (JLI_StrCmp(arg, "--help") == 0) {1296printUsage = JNI_TRUE;1297printTo = USE_STDOUT;1298return JNI_TRUE;1299} else if (JLI_StrCmp(arg, "-version") == 0) {1300printVersion = JNI_TRUE;1301return JNI_TRUE;1302} else if (JLI_StrCmp(arg, "--version") == 0) {1303printVersion = JNI_TRUE;1304printTo = USE_STDOUT;1305return JNI_TRUE;1306} else if (JLI_StrCmp(arg, "-showversion") == 0) {1307showVersion = JNI_TRUE;1308} else if (JLI_StrCmp(arg, "--show-version") == 0) {1309showVersion = JNI_TRUE;1310printTo = USE_STDOUT;1311} else if (JLI_StrCmp(arg, "--dry-run") == 0) {1312dryRun = JNI_TRUE;1313} else if (JLI_StrCmp(arg, "-X") == 0) {1314printXUsage = JNI_TRUE;1315return JNI_TRUE;1316} else if (JLI_StrCmp(arg, "--help-extra") == 0) {1317printXUsage = JNI_TRUE;1318printTo = USE_STDOUT;1319return JNI_TRUE;1320/*1321* The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.1322* In the latter case, any SUBOPT value not recognized will default to "all"1323*/1324} else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||1325JLI_StrCCmp(arg, "-XshowSettings:") == 0) {1326showSettings = arg;1327} else if (JLI_StrCmp(arg, "-Xdiag") == 0) {1328AddOption("-Dsun.java.launcher.diag=true", NULL);1329} else if (JLI_StrCmp(arg, "--show-module-resolution") == 0) {1330AddOption("-Djdk.module.showModuleResolution=true", NULL);1331/*1332* The following case provide backward compatibility with old-style1333* command line options.1334*/1335} else if (JLI_StrCmp(arg, "-fullversion") == 0) {1336JLI_ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());1337return JNI_FALSE;1338} else if (JLI_StrCmp(arg, "--full-version") == 0) {1339JLI_ShowMessage("%s %s", _launcher_name, GetFullVersion());1340return JNI_FALSE;1341} else if (JLI_StrCmp(arg, "-verbosegc") == 0) {1342AddOption("-verbose:gc", NULL);1343} else if (JLI_StrCmp(arg, "-t") == 0) {1344AddOption("-Xt", NULL);1345} else if (JLI_StrCmp(arg, "-tm") == 0) {1346AddOption("-Xtm", NULL);1347} else if (JLI_StrCmp(arg, "-debug") == 0) {1348AddOption("-Xdebug", NULL);1349} else if (JLI_StrCmp(arg, "-noclassgc") == 0) {1350AddOption("-Xnoclassgc", NULL);1351} else if (JLI_StrCmp(arg, "-Xfuture") == 0) {1352JLI_ReportErrorMessage(ARG_DEPRECATED, "-Xfuture");1353AddOption("-Xverify:all", NULL);1354} else if (JLI_StrCmp(arg, "-verify") == 0) {1355AddOption("-Xverify:all", NULL);1356} else if (JLI_StrCmp(arg, "-verifyremote") == 0) {1357AddOption("-Xverify:remote", NULL);1358} else if (JLI_StrCmp(arg, "-noverify") == 0) {1359/*1360* Note that no 'deprecated' message is needed here because the VM1361* issues 'deprecated' messages for -noverify and -Xverify:none.1362*/1363AddOption("-Xverify:none", NULL);1364} else if (JLI_StrCCmp(arg, "-ss") == 0 ||1365JLI_StrCCmp(arg, "-oss") == 0 ||1366JLI_StrCCmp(arg, "-ms") == 0 ||1367JLI_StrCCmp(arg, "-mx") == 0) {1368char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 6);1369sprintf(tmp, "-X%s", arg + 1); /* skip '-' */1370AddOption(tmp, NULL);1371} else if (JLI_StrCmp(arg, "-checksource") == 0 ||1372JLI_StrCmp(arg, "-cs") == 0 ||1373JLI_StrCmp(arg, "-noasyncgc") == 0) {1374/* No longer supported */1375JLI_ReportErrorMessage(ARG_WARN, arg);1376} else if (JLI_StrCCmp(arg, "-splash:") == 0) {1377; /* Ignore machine independent options already handled */1378} else if (ProcessPlatformOption(arg)) {1379; /* Processing of platform dependent options */1380} else {1381/* java.class.path set on the command line */1382if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) {1383_have_classpath = JNI_TRUE;1384}1385AddOption(arg, NULL);1386}1387}13881389if (*pwhat == NULL && --argc >= 0) {1390*pwhat = *argv++;1391}13921393if (*pwhat == NULL) {1394/* LM_UNKNOWN okay for options that exit */1395if (!listModules && !describeModule && !validateModules) {1396*pret = 1;1397}1398} else if (mode == LM_UNKNOWN) {1399/* default to LM_CLASS if -m, -jar and -cp options are1400* not specified */1401if (!_have_classpath) {1402SetClassPath(".");1403}1404mode = IsSourceFile(arg) ? LM_SOURCE : LM_CLASS;1405} else if (mode == LM_CLASS && IsSourceFile(arg)) {1406/* override LM_CLASS mode if given a source file */1407mode = LM_SOURCE;1408}14091410if (mode == LM_SOURCE) {1411AddOption("--add-modules=ALL-DEFAULT", NULL);1412*pwhat = SOURCE_LAUNCHER_MAIN_ENTRY;1413// adjust (argc, argv) so that the name of the source file1414// is included in the args passed to the source launcher1415// main entry class1416*pargc = argc + 1;1417*pargv = argv - 1;1418} else {1419if (argc >= 0) {1420*pargc = argc;1421*pargv = argv;1422}1423}14241425*pmode = mode;14261427return JNI_TRUE;1428}14291430/*1431* Initializes the Java Virtual Machine. Also frees options array when1432* finished.1433*/1434static jboolean1435InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)1436{1437JavaVMInitArgs args;1438jint r;14391440memset(&args, 0, sizeof(args));1441args.version = JNI_VERSION_1_2;1442args.nOptions = numOptions;1443args.options = options;1444args.ignoreUnrecognized = JNI_FALSE;14451446if (JLI_IsTraceLauncher()) {1447int i = 0;1448printf("JavaVM args:\n ");1449printf("version 0x%08lx, ", (long)args.version);1450printf("ignoreUnrecognized is %s, ",1451args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");1452printf("nOptions is %ld\n", (long)args.nOptions);1453for (i = 0; i < numOptions; i++)1454printf(" option[%2d] = '%s'\n",1455i, args.options[i].optionString);1456}14571458r = ifn->CreateJavaVM(pvm, (void **)penv, &args);1459JLI_MemFree(options);1460return r == JNI_OK;1461}14621463static jclass helperClass = NULL;14641465jclass1466GetLauncherHelperClass(JNIEnv *env)1467{1468if (helperClass == NULL) {1469NULL_CHECK0(helperClass = FindBootStrapClass(env,1470"sun/launcher/LauncherHelper"));1471}1472return helperClass;1473}14741475static jmethodID makePlatformStringMID = NULL;1476/*1477* Returns a new Java string object for the specified platform string.1478*/1479static jstring1480NewPlatformString(JNIEnv *env, char *s)1481{1482int len = (int)JLI_StrLen(s);1483jbyteArray ary;1484jclass cls = GetLauncherHelperClass(env);1485NULL_CHECK0(cls);1486if (s == NULL)1487return 0;14881489ary = (*env)->NewByteArray(env, len);1490if (ary != 0) {1491jstring str = 0;1492(*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);1493if (!(*env)->ExceptionOccurred(env)) {1494if (makePlatformStringMID == NULL) {1495NULL_CHECK0(makePlatformStringMID = (*env)->GetStaticMethodID(env,1496cls, "makePlatformString", "(Z[B)Ljava/lang/String;"));1497}1498str = (*env)->CallStaticObjectMethod(env, cls,1499makePlatformStringMID, USE_STDERR, ary);1500CHECK_EXCEPTION_RETURN_VALUE(0);1501(*env)->DeleteLocalRef(env, ary);1502return str;1503}1504}1505return 0;1506}15071508/*1509* Returns a new array of Java string objects for the specified1510* array of platform strings.1511*/1512jobjectArray1513NewPlatformStringArray(JNIEnv *env, char **strv, int strc)1514{1515jarray cls;1516jarray ary;1517int i;15181519NULL_CHECK0(cls = FindBootStrapClass(env, "java/lang/String"));1520NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0));1521CHECK_EXCEPTION_RETURN_VALUE(0);1522for (i = 0; i < strc; i++) {1523jstring str = NewPlatformString(env, *strv++);1524NULL_CHECK0(str);1525(*env)->SetObjectArrayElement(env, ary, i, str);1526(*env)->DeleteLocalRef(env, str);1527}1528return ary;1529}15301531/*1532* Loads a class and verifies that the main class is present and it is ok to1533* call it for more details refer to the java implementation.1534*/1535static jclass1536LoadMainClass(JNIEnv *env, int mode, char *name)1537{1538jmethodID mid;1539jstring str;1540jobject result;1541jlong start = 0, end = 0;1542jclass cls = GetLauncherHelperClass(env);1543NULL_CHECK0(cls);1544if (JLI_IsTraceLauncher()) {1545start = CurrentTimeMicros();1546}1547NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,1548"checkAndLoadMain",1549"(ZILjava/lang/String;)Ljava/lang/Class;"));15501551NULL_CHECK0(str = NewPlatformString(env, name));1552NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid,1553USE_STDERR, mode, str));15541555if (JLI_IsTraceLauncher()) {1556end = CurrentTimeMicros();1557printf("%ld micro seconds to load main class\n", (long)(end-start));1558printf("----%s----\n", JLDEBUG_ENV_ENTRY);1559}15601561return (jclass)result;1562}15631564static jclass1565GetApplicationClass(JNIEnv *env)1566{1567jmethodID mid;1568jclass appClass;1569jclass cls = GetLauncherHelperClass(env);1570NULL_CHECK0(cls);1571NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,1572"getApplicationClass",1573"()Ljava/lang/Class;"));15741575appClass = (*env)->CallStaticObjectMethod(env, cls, mid);1576CHECK_EXCEPTION_RETURN_VALUE(0);1577return appClass;1578}15791580static char* expandWildcardOnLongOpt(char* arg) {1581char *p, *value;1582size_t optLen, valueLen;1583p = JLI_StrChr(arg, '=');15841585if (p == NULL || p[1] == '\0') {1586JLI_ReportErrorMessage(ARG_ERROR1, arg);1587exit(1);1588}1589p++;1590value = (char *) JLI_WildcardExpandClasspath(p);1591if (p == value) {1592// no wildcard1593return arg;1594}15951596optLen = p - arg;1597valueLen = JLI_StrLen(value);1598p = JLI_MemAlloc(optLen + valueLen + 1);1599memcpy(p, arg, optLen);1600memcpy(p + optLen, value, valueLen);1601p[optLen + valueLen] = '\0';1602return p;1603}16041605/*1606* For tools, convert command line args thus:1607* javac -cp foo:foo/"*" -J-ms32m ...1608* java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ...1609*1610* Takes 4 parameters, and returns the populated arguments1611*/1612static void1613TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv)1614{1615int argc = *pargc;1616char **argv = *pargv;1617int nargc = argc + jargc;1618char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *));1619int i;16201621*pargc = nargc;1622*pargv = nargv;16231624/* Copy the VM arguments (i.e. prefixed with -J) */1625for (i = 0; i < jargc; i++) {1626const char *arg = jargv[i];1627if (arg[0] == '-' && arg[1] == 'J') {1628*nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);1629}1630}16311632for (i = 0; i < argc; i++) {1633char *arg = argv[i];1634if (arg[0] == '-' && arg[1] == 'J') {1635if (arg[2] == '\0') {1636JLI_ReportErrorMessage(ARG_ERROR3);1637exit(1);1638}1639*nargv++ = arg + 2;1640}1641}16421643/* Copy the rest of the arguments */1644for (i = 0; i < jargc ; i++) {1645const char *arg = jargv[i];1646if (arg[0] != '-' || arg[1] != 'J') {1647*nargv++ = (arg == NULL) ? NULL : JLI_StringDup(arg);1648}1649}1650for (i = 0; i < argc; i++) {1651char *arg = argv[i];1652if (arg[0] == '-') {1653if (arg[1] == 'J')1654continue;1655if (IsWildCardEnabled()) {1656if (IsClassPathOption(arg) && i < argc - 1) {1657*nargv++ = arg;1658*nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);1659i++;1660continue;1661}1662if (JLI_StrCCmp(arg, "--class-path=") == 0) {1663*nargv++ = expandWildcardOnLongOpt(arg);1664continue;1665}1666}1667}1668*nargv++ = arg;1669}1670*nargv = 0;1671}16721673/*1674* For our tools, we try to add 3 VM options:1675* -Denv.class.path=<envcp>1676* -Dapplication.home=<apphome>1677* -Djava.class.path=<appcp>1678* <envcp> is the user's setting of CLASSPATH -- for instance the user1679* tells javac where to find binary classes through this environment1680* variable. Notice that users will be able to compile against our1681* tools classes (sun.tools.javac.Main) only if they explicitly add1682* tools.jar to CLASSPATH.1683* <apphome> is the directory where the application is installed.1684* <appcp> is the classpath to where our apps' classfiles are.1685*/1686static jboolean1687AddApplicationOptions(int cpathc, const char **cpathv)1688{1689char *envcp, *appcp, *apphome;1690char home[MAXPATHLEN]; /* application home */1691char separator[] = { PATH_SEPARATOR, '\0' };1692int size, i;16931694{1695const char *s = getenv("CLASSPATH");1696if (s) {1697s = (char *) JLI_WildcardExpandClasspath(s);1698/* 40 for -Denv.class.path= */1699if (JLI_StrLen(s) + 40 > JLI_StrLen(s)) { // Safeguard from overflow1700envcp = (char *)JLI_MemAlloc(JLI_StrLen(s) + 40);1701sprintf(envcp, "-Denv.class.path=%s", s);1702AddOption(envcp, NULL);1703}1704}1705}17061707if (!GetApplicationHome(home, sizeof(home))) {1708JLI_ReportErrorMessage(CFG_ERROR5);1709return JNI_FALSE;1710}17111712/* 40 for '-Dapplication.home=' */1713apphome = (char *)JLI_MemAlloc(JLI_StrLen(home) + 40);1714sprintf(apphome, "-Dapplication.home=%s", home);1715AddOption(apphome, NULL);17161717/* How big is the application's classpath? */1718if (cpathc > 0) {1719size = 40; /* 40: "-Djava.class.path=" */1720for (i = 0; i < cpathc; i++) {1721size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */1722}1723appcp = (char *)JLI_MemAlloc(size + 1);1724JLI_StrCpy(appcp, "-Djava.class.path=");1725for (i = 0; i < cpathc; i++) {1726JLI_StrCat(appcp, home); /* c:\program files\myapp */1727JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */1728JLI_StrCat(appcp, separator); /* ; */1729}1730appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */1731AddOption(appcp, NULL);1732}1733return JNI_TRUE;1734}17351736/*1737* inject the -Dsun.java.command pseudo property into the args structure1738* this pseudo property is used in the HotSpot VM to expose the1739* Java class name and arguments to the main method to the VM. The1740* HotSpot VM uses this pseudo property to store the Java class name1741* (or jar file name) and the arguments to the class's main method1742* to the instrumentation memory region. The sun.java.command pseudo1743* property is not exported by HotSpot to the Java layer.1744*/1745void1746SetJavaCommandLineProp(char *what, int argc, char **argv)1747{17481749int i = 0;1750size_t len = 0;1751char* javaCommand = NULL;1752char* dashDstr = "-Dsun.java.command=";17531754if (what == NULL) {1755/* unexpected, one of these should be set. just return without1756* setting the property1757*/1758return;1759}17601761/* determine the amount of memory to allocate assuming1762* the individual components will be space separated1763*/1764len = JLI_StrLen(what);1765for (i = 0; i < argc; i++) {1766len += JLI_StrLen(argv[i]) + 1;1767}17681769/* allocate the memory */1770javaCommand = (char*) JLI_MemAlloc(len + JLI_StrLen(dashDstr) + 1);17711772/* build the -D string */1773*javaCommand = '\0';1774JLI_StrCat(javaCommand, dashDstr);1775JLI_StrCat(javaCommand, what);17761777for (i = 0; i < argc; i++) {1778/* the components of the string are space separated. In1779* the case of embedded white space, the relationship of1780* the white space separated components to their true1781* positional arguments will be ambiguous. This issue may1782* be addressed in a future release.1783*/1784JLI_StrCat(javaCommand, " ");1785JLI_StrCat(javaCommand, argv[i]);1786}17871788AddOption(javaCommand, NULL);1789}17901791/*1792* JVM would like to know if it's created by a standard Sun launcher, or by1793* user native application, the following property indicates the former.1794*/1795static void SetJavaLauncherProp() {1796AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL);1797}17981799/*1800* Prints the version information from the java.version and other properties.1801*/1802static void1803PrintJavaVersion(JNIEnv *env, jboolean extraLF)1804{1805jclass ver;1806jmethodID print;18071808NULL_CHECK(ver = FindBootStrapClass(env, "java/lang/VersionProps"));1809NULL_CHECK(print = (*env)->GetStaticMethodID(env,1810ver,1811(extraLF == JNI_TRUE) ? "println" : "print",1812"(Z)V"1813)1814);18151816(*env)->CallStaticVoidMethod(env, ver, print, printTo);1817}18181819/*1820* Prints all the Java settings, see the java implementation for more details.1821*/1822static void1823ShowSettings(JNIEnv *env, char *optString)1824{1825jmethodID showSettingsID;1826jstring joptString;1827jclass cls = GetLauncherHelperClass(env);1828NULL_CHECK(cls);1829NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,1830"showSettings", "(ZLjava/lang/String;JJJ)V"));1831NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString));1832(*env)->CallStaticVoidMethod(env, cls, showSettingsID,1833USE_STDERR,1834joptString,1835(jlong)initialHeapSize,1836(jlong)maxHeapSize,1837(jlong)threadStackSize);1838}18391840/**1841* Show resolved modules1842*/1843static void1844ShowResolvedModules(JNIEnv *env)1845{1846jmethodID showResolvedModulesID;1847jclass cls = GetLauncherHelperClass(env);1848NULL_CHECK(cls);1849NULL_CHECK(showResolvedModulesID = (*env)->GetStaticMethodID(env, cls,1850"showResolvedModules", "()V"));1851(*env)->CallStaticVoidMethod(env, cls, showResolvedModulesID);1852}18531854/**1855* List observable modules1856*/1857static void1858ListModules(JNIEnv *env)1859{1860jmethodID listModulesID;1861jclass cls = GetLauncherHelperClass(env);1862NULL_CHECK(cls);1863NULL_CHECK(listModulesID = (*env)->GetStaticMethodID(env, cls,1864"listModules", "()V"));1865(*env)->CallStaticVoidMethod(env, cls, listModulesID);1866}18671868/**1869* Describe a module1870*/1871static void1872DescribeModule(JNIEnv *env, char *optString)1873{1874jmethodID describeModuleID;1875jstring joptString = NULL;1876jclass cls = GetLauncherHelperClass(env);1877NULL_CHECK(cls);1878NULL_CHECK(describeModuleID = (*env)->GetStaticMethodID(env, cls,1879"describeModule", "(Ljava/lang/String;)V"));1880NULL_CHECK(joptString = NewPlatformString(env, optString));1881(*env)->CallStaticVoidMethod(env, cls, describeModuleID, joptString);1882}18831884/*1885* Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java1886*/1887static void1888PrintUsage(JNIEnv* env, jboolean doXUsage)1889{1890jmethodID initHelp, vmSelect, vmSynonym, printHelp, printXUsageMessage;1891jstring jprogname, vm1, vm2;1892int i;1893jclass cls = GetLauncherHelperClass(env);1894NULL_CHECK(cls);1895if (doXUsage) {1896NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,1897"printXUsageMessage", "(Z)V"));1898(*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, printTo);1899} else {1900NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls,1901"initHelpMessage", "(Ljava/lang/String;)V"));19021903NULL_CHECK(vmSelect = (*env)->GetStaticMethodID(env, cls, "appendVmSelectMessage",1904"(Ljava/lang/String;Ljava/lang/String;)V"));19051906NULL_CHECK(vmSynonym = (*env)->GetStaticMethodID(env, cls,1907"appendVmSynonymMessage",1908"(Ljava/lang/String;Ljava/lang/String;)V"));19091910NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls,1911"printHelpMessage", "(Z)V"));19121913NULL_CHECK(jprogname = (*env)->NewStringUTF(env, _program_name));19141915/* Initialize the usage message with the usual preamble */1916(*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname);1917CHECK_EXCEPTION_RETURN();191819191920/* Assemble the other variant part of the usage */1921for (i=1; i<knownVMsCount; i++) {1922if (knownVMs[i].flag == VM_KNOWN) {1923NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[i].name));1924NULL_CHECK(vm2 = (*env)->NewStringUTF(env, knownVMs[i].name+1));1925(*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);1926CHECK_EXCEPTION_RETURN();1927}1928}1929for (i=1; i<knownVMsCount; i++) {1930if (knownVMs[i].flag == VM_ALIASED_TO) {1931NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[i].name));1932NULL_CHECK(vm2 = (*env)->NewStringUTF(env, knownVMs[i].alias+1));1933(*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2);1934CHECK_EXCEPTION_RETURN();1935}1936}19371938/* Complete the usage message and print to stderr*/1939(*env)->CallStaticVoidMethod(env, cls, printHelp, printTo);1940}1941return;1942}19431944/*1945* Read the jvm.cfg file and fill the knownJVMs[] array.1946*1947* The functionality of the jvm.cfg file is subject to change without1948* notice and the mechanism will be removed in the future.1949*1950* The lexical structure of the jvm.cfg file is as follows:1951*1952* jvmcfg := { vmLine }1953* vmLine := knownLine1954* | aliasLine1955* | warnLine1956* | ignoreLine1957* | errorLine1958* | predicateLine1959* | commentLine1960* knownLine := flag "KNOWN" EOL1961* warnLine := flag "WARN" EOL1962* ignoreLine := flag "IGNORE" EOL1963* errorLine := flag "ERROR" EOL1964* aliasLine := flag "ALIASED_TO" flag EOL1965* predicateLine := flag "IF_SERVER_CLASS" flag EOL1966* commentLine := "#" text EOL1967* flag := "-" identifier1968*1969* The semantics are that when someone specifies a flag on the command line:1970* - if the flag appears on a knownLine, then the identifier is used as1971* the name of the directory holding the JVM library (the name of the JVM).1972* - if the flag appears as the first flag on an aliasLine, the identifier1973* of the second flag is used as the name of the JVM.1974* - if the flag appears on a warnLine, the identifier is used as the1975* name of the JVM, but a warning is generated.1976* - if the flag appears on an ignoreLine, the identifier is recognized as the1977* name of a JVM, but the identifier is ignored and the default vm used1978* - if the flag appears on an errorLine, an error is generated.1979* - if the flag appears as the first flag on a predicateLine, and1980* the machine on which you are running passes the predicate indicated,1981* then the identifier of the second flag is used as the name of the JVM,1982* otherwise the identifier of the first flag is used as the name of the JVM.1983* If no flag is given on the command line, the first vmLine of the jvm.cfg1984* file determines the name of the JVM.1985* PredicateLines are only interpreted on first vmLine of a jvm.cfg file,1986* since they only make sense if someone hasn't specified the name of the1987* JVM on the command line.1988*1989* The intent of the jvm.cfg file is to allow several JVM libraries to1990* be installed in different subdirectories of a single JRE installation,1991* for space-savings and convenience in testing.1992* The intent is explicitly not to provide a full aliasing or predicate1993* mechanism.1994*/1995jint1996ReadKnownVMs(const char *jvmCfgName, jboolean speculative)1997{1998FILE *jvmCfg;1999char line[MAXPATHLEN+20];2000int cnt = 0;2001int lineno = 0;2002jlong start = 0, end = 0;2003int vmType;2004char *tmpPtr;2005char *altVMName = NULL;2006char *serverClassVMName = NULL;2007static char *whiteSpace = " \t";2008if (JLI_IsTraceLauncher()) {2009start = CurrentTimeMicros();2010}20112012jvmCfg = fopen(jvmCfgName, "r");2013if (jvmCfg == NULL) {2014if (!speculative) {2015JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);2016exit(1);2017} else {2018return -1;2019}2020}2021while (fgets(line, sizeof(line), jvmCfg) != NULL) {2022vmType = VM_UNKNOWN;2023lineno++;2024if (line[0] == '#')2025continue;2026if (line[0] != '-') {2027JLI_ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);2028}2029if (cnt >= knownVMsLimit) {2030GrowKnownVMs(cnt);2031}2032line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */2033tmpPtr = line + JLI_StrCSpn(line, whiteSpace);2034if (*tmpPtr == 0) {2035JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);2036} else {2037/* Null-terminate this string for JLI_StringDup below */2038*tmpPtr++ = 0;2039tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);2040if (*tmpPtr == 0) {2041JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);2042} else {2043if (!JLI_StrCCmp(tmpPtr, "KNOWN")) {2044vmType = VM_KNOWN;2045} else if (!JLI_StrCCmp(tmpPtr, "ALIASED_TO")) {2046tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);2047if (*tmpPtr != 0) {2048tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);2049}2050if (*tmpPtr == 0) {2051JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);2052} else {2053/* Null terminate altVMName */2054altVMName = tmpPtr;2055tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);2056*tmpPtr = 0;2057vmType = VM_ALIASED_TO;2058}2059} else if (!JLI_StrCCmp(tmpPtr, "WARN")) {2060vmType = VM_WARN;2061} else if (!JLI_StrCCmp(tmpPtr, "IGNORE")) {2062vmType = VM_IGNORE;2063} else if (!JLI_StrCCmp(tmpPtr, "ERROR")) {2064vmType = VM_ERROR;2065} else if (!JLI_StrCCmp(tmpPtr, "IF_SERVER_CLASS")) {2066/* ignored */2067} else {2068JLI_ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);2069vmType = VM_KNOWN;2070}2071}2072}20732074JLI_TraceLauncher("jvm.cfg[%d] = ->%s<-\n", cnt, line);2075if (vmType != VM_UNKNOWN) {2076knownVMs[cnt].name = JLI_StringDup(line);2077knownVMs[cnt].flag = vmType;2078switch (vmType) {2079default:2080break;2081case VM_ALIASED_TO:2082knownVMs[cnt].alias = JLI_StringDup(altVMName);2083JLI_TraceLauncher(" name: %s vmType: %s alias: %s\n",2084knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias);2085break;2086}2087cnt++;2088}2089}2090fclose(jvmCfg);2091knownVMsCount = cnt;20922093if (JLI_IsTraceLauncher()) {2094end = CurrentTimeMicros();2095printf("%ld micro seconds to parse jvm.cfg\n", (long)(end-start));2096}20972098return cnt;2099}210021012102static void2103GrowKnownVMs(int minimum)2104{2105struct vmdesc* newKnownVMs;2106int newMax;21072108newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit));2109if (newMax <= minimum) {2110newMax = minimum;2111}2112newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc));2113if (knownVMs != NULL) {2114memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc));2115}2116JLI_MemFree(knownVMs);2117knownVMs = newKnownVMs;2118knownVMsLimit = newMax;2119}212021212122/* Returns index of VM or -1 if not found */2123static int2124KnownVMIndex(const char* name)2125{2126int i;2127if (JLI_StrCCmp(name, "-J") == 0) name += 2;2128for (i = 0; i < knownVMsCount; i++) {2129if (!JLI_StrCmp(name, knownVMs[i].name)) {2130return i;2131}2132}2133return -1;2134}21352136static void2137FreeKnownVMs()2138{2139int i;2140for (i = 0; i < knownVMsCount; i++) {2141JLI_MemFree(knownVMs[i].name);2142knownVMs[i].name = NULL;2143}2144JLI_MemFree(knownVMs);2145}21462147/*2148* Displays the splash screen according to the jar file name2149* and image file names stored in environment variables2150*/2151void2152ShowSplashScreen()2153{2154const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);2155const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY);2156int data_size;2157void *image_data = NULL;2158float scale_factor = 1;2159char *scaled_splash_name = NULL;2160jboolean isImageScaled = JNI_FALSE;2161size_t maxScaledImgNameLength = 0;2162if (file_name == NULL){2163return;2164}21652166if (!DoSplashInit()) {2167goto exit;2168}21692170maxScaledImgNameLength = DoSplashGetScaledImgNameMaxPstfixLen(file_name);21712172scaled_splash_name = JLI_MemAlloc(2173maxScaledImgNameLength * sizeof(char));2174isImageScaled = DoSplashGetScaledImageName(jar_name, file_name,2175&scale_factor,2176scaled_splash_name, maxScaledImgNameLength);2177if (jar_name) {21782179if (isImageScaled) {2180image_data = JLI_JarUnpackFile(2181jar_name, scaled_splash_name, &data_size);2182}21832184if (!image_data) {2185scale_factor = 1;2186image_data = JLI_JarUnpackFile(2187jar_name, file_name, &data_size);2188}2189if (image_data) {2190DoSplashSetScaleFactor(scale_factor);2191DoSplashLoadMemory(image_data, data_size);2192JLI_MemFree(image_data);2193} else {2194DoSplashClose();2195}2196} else {2197if (isImageScaled) {2198DoSplashSetScaleFactor(scale_factor);2199DoSplashLoadFile(scaled_splash_name);2200} else {2201DoSplashLoadFile(file_name);2202}2203}2204JLI_MemFree(scaled_splash_name);22052206DoSplashSetFileJarName(file_name, jar_name);22072208exit:2209/*2210* Done with all command line processing and potential re-execs so2211* clean up the environment.2212*/2213(void)UnsetEnv(ENV_ENTRY);2214(void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);2215(void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);22162217JLI_MemFree(splash_jar_entry);2218JLI_MemFree(splash_file_entry);22192220}22212222static const char* GetFullVersion()2223{2224return _fVersion;2225}22262227static const char* GetProgramName()2228{2229return _program_name;2230}22312232static const char* GetLauncherName()2233{2234return _launcher_name;2235}22362237static jboolean IsJavaArgs()2238{2239return _is_java_args;2240}22412242static jboolean2243IsWildCardEnabled()2244{2245return _wc_enabled;2246}22472248int2249ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,2250int argc, char **argv,2251int mode, char *what, int ret)2252{2253if (threadStackSize == 0) {2254/*2255* If the user hasn't specified a non-zero stack size ask the JVM for its default.2256* A returned 0 means 'use the system default' for a platform, e.g., Windows.2257* Note that HotSpot no longer supports JNI_VERSION_1_1 but it will2258* return its default stack size through the init args structure.2259*/2260struct JDK1_1InitArgs args1_1;2261memset((void*)&args1_1, 0, sizeof(args1_1));2262args1_1.version = JNI_VERSION_1_1;2263ifn->GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */2264if (args1_1.javaStackSize > 0) {2265threadStackSize = args1_1.javaStackSize;2266}2267}22682269{ /* Create a new thread to create JVM and invoke main method */2270JavaMainArgs args;2271int rslt;22722273args.argc = argc;2274args.argv = argv;2275args.mode = mode;2276args.what = what;2277args.ifn = *ifn;22782279rslt = CallJavaMainInNewThread(threadStackSize, (void*)&args);2280/* If the caller has deemed there is an error we2281* simply return that, otherwise we return the value of2282* the callee2283*/2284return (ret != 0) ? ret : rslt;2285}2286}22872288static void2289DumpState()2290{2291if (!JLI_IsTraceLauncher()) return ;2292printf("Launcher state:\n");2293printf("\tFirst application arg index: %d\n", JLI_GetAppArgIndex());2294printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");2295printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");2296printf("\tprogram name:%s\n", GetProgramName());2297printf("\tlauncher name:%s\n", GetLauncherName());2298printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");2299printf("\tfullversion:%s\n", GetFullVersion());2300}23012302/*2303* A utility procedure to always print to stderr2304*/2305JNIEXPORT void JNICALL2306JLI_ReportMessage(const char* fmt, ...)2307{2308va_list vl;2309va_start(vl, fmt);2310vfprintf(stderr, fmt, vl);2311fprintf(stderr, "\n");2312va_end(vl);2313}23142315/*2316* A utility procedure to always print to stdout2317*/2318void2319JLI_ShowMessage(const char* fmt, ...)2320{2321va_list vl;2322va_start(vl, fmt);2323vfprintf(stdout, fmt, vl);2324fprintf(stdout, "\n");2325va_end(vl);2326}232723282329