0N/A/*
4609N/A * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * Shared source for 'java' command line tool.
0N/A *
0N/A * If JAVA_ARGS is defined, then acts as a launcher for applications. For
0N/A * instance, the JDK command line tools such as javac and javadoc (see
0N/A * makefiles for more details) are built with this program. Any arguments
0N/A * prefixed with '-J' will be passed directly to the 'java' command.
0N/A */
0N/A
0N/A/*
0N/A * One job of the launcher is to remove command line options which the
0N/A * vm does not understand and will not process. These options include
0N/A * options which select which style of vm is run (e.g. -client and
0N/A * -server) as well as options which select the data model to use.
0N/A * Additionally, for tools which invoke an underlying vm "-J-foo"
0N/A * options are turned into "-foo" options to the vm. This option
0N/A * filtering is handled in a number of places in the launcher, some of
0N/A * it in machine-dependent code. In this file, the function
1945N/A * CheckJvmType removes vm style options and TranslateApplicationArgs
1945N/A * removes "-J" prefixes. The CreateExecutionEnvironment function processes
1945N/A * and removes -d<n> options. On unix, there is a possibility that the running
1945N/A * data model may not match to the desired data model, in this case an exec is
1945N/A * required to start the desired model. If the data models match, then
1945N/A * ParseArguments will remove the -d<n> flags. If the data models do not match
1945N/A * the CreateExecutionEnviroment will remove the -d<n> flags.
0N/A */
0N/A
0N/A
0N/A#include "java.h"
0N/A
0N/A/*
0N/A * A NOTE TO DEVELOPERS: For performance reasons it is important that
0N/A * the program image remain relatively small until after SelectVersion
0N/A * CreateExecutionEnvironment have finished their possibly recursive
0N/A * processing. Watch everything, but resist all temptations to use Java
0N/A * interfaces.
0N/A */
0N/A
3777N/A/* we always print to stderr */
3777N/A#define USE_STDERR JNI_TRUE
3777N/A
0N/Astatic jboolean printVersion = JNI_FALSE; /* print and exit */
0N/Astatic jboolean showVersion = JNI_FALSE; /* print but continue */
0N/Astatic jboolean printUsage = JNI_FALSE; /* print and exit*/
0N/Astatic jboolean printXUsage = JNI_FALSE; /* print and exit*/
3131N/Astatic char *showSettings = NULL; /* print but continue */
0N/A
0N/Astatic const char *_program_name;
0N/Astatic const char *_launcher_name;
0N/Astatic jboolean _is_java_args = JNI_FALSE;
0N/Astatic const char *_fVersion;
0N/Astatic const char *_dVersion;
0N/Astatic jboolean _wc_enabled = JNI_FALSE;
0N/Astatic jint _ergo_policy = DEFAULT_POLICY;
0N/A
0N/A/*
0N/A * Entries for splash screen environment variables.
0N/A * putenv is performed in SelectVersion. We need
0N/A * them in memory until UnsetEnv, so they are made static
0N/A * global instead of auto local.
0N/A */
0N/Astatic char* splash_file_entry = NULL;
0N/Astatic char* splash_jar_entry = NULL;
0N/A
0N/A/*
0N/A * List of VM options to be specified when the VM is created.
0N/A */
0N/Astatic JavaVMOption *options;
0N/Astatic int numOptions, maxOptions;
0N/A
0N/A/*
0N/A * Prototypes for functions internal to launcher.
0N/A */
0N/Astatic void SetClassPath(const char *s);
0N/Astatic void SelectVersion(int argc, char **argv, char **main_class);
3408N/Astatic jboolean ParseArguments(int *pargc, char ***pargv,
3408N/A int *pmode, char **pwhat,
3408N/A int *pret, const char *jrepath);
0N/Astatic jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
0N/A InvocationFunctions *ifn);
0N/Astatic jstring NewPlatformString(JNIEnv *env, char *s);
3408N/Astatic jclass LoadMainClass(JNIEnv *env, int mode, char *name);
0N/A
0N/Astatic void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv);
0N/Astatic jboolean AddApplicationOptions(int cpathc, const char **cpathv);
0N/Astatic void SetApplicationClassPath(const char**);
0N/A
0N/Astatic void PrintJavaVersion(JNIEnv *env, jboolean extraLF);
0N/Astatic void PrintUsage(JNIEnv* env, jboolean doXUsage);
3131N/Astatic void ShowSettings(JNIEnv* env, char *optString);
0N/A
0N/Astatic void SetPaths(int argc, char **argv);
0N/A
0N/Astatic void DumpState();
0N/Astatic jboolean RemovableOption(char *option);
0N/A
0N/A/* Maximum supported entries from jvm.cfg. */
0N/A#define INIT_MAX_KNOWN_VMS 10
0N/A
0N/A/* Values for vmdesc.flag */
0N/Aenum vmdesc_flag {
0N/A VM_UNKNOWN = -1,
0N/A VM_KNOWN,
0N/A VM_ALIASED_TO,
0N/A VM_WARN,
0N/A VM_ERROR,
0N/A VM_IF_SERVER_CLASS,
0N/A VM_IGNORE
0N/A};
0N/A
0N/Astruct vmdesc {
0N/A char *name;
0N/A int flag;
0N/A char *alias;
0N/A char *server_class;
0N/A};
0N/Astatic struct vmdesc *knownVMs = NULL;
0N/Astatic int knownVMsCount = 0;
0N/Astatic int knownVMsLimit = 0;
0N/A
0N/Astatic void GrowKnownVMs();
0N/Astatic int KnownVMIndex(const char* name);
0N/Astatic void FreeKnownVMs();
0N/Astatic jboolean IsWildCardEnabled();
0N/A
0N/A#define ARG_CHECK(n, f, a) if (n < 1) { \
517N/A JLI_ReportErrorMessage(f, a); \
0N/A printUsage = JNI_TRUE; \
0N/A *pret = 1; \
0N/A return JNI_TRUE; \
0N/A}
0N/A
0N/A/*
0N/A * Running Java code in primordial thread caused many problems. We will
0N/A * create a new thread to invoke JVM. See 6316197 for more information.
0N/A */
5270N/Astatic jlong threadStackSize = 0; /* stack size of the new thread */
3330N/Astatic jlong maxHeapSize = 0; /* max heap size */
3330N/Astatic jlong initialHeapSize = 0; /* inital heap size */
0N/A
0N/A/*
0N/A * Entry point.
0N/A */
0N/Aint
0N/AJLI_Launch(int argc, char ** argv, /* main argc, argc */
0N/A int jargc, const char** jargv, /* java args */
0N/A int appclassc, const char** appclassv, /* app classpath */
0N/A const char* fullversion, /* full version defined */
0N/A const char* dotversion, /* dot version defined */
0N/A const char* pname, /* program name */
0N/A const char* lname, /* launcher name */
0N/A jboolean javaargs, /* JAVA_ARGS */
0N/A jboolean cpwildcard, /* classpath wildcard*/
0N/A jboolean javaw, /* windows-only javaw */
0N/A jint ergo /* ergonomics class policy */
0N/A)
0N/A{
3408N/A int mode = LM_UNKNOWN;
3408N/A char *what = NULL;
0N/A char *cpath = 0;
0N/A char *main_class = NULL;
0N/A int ret;
0N/A InvocationFunctions ifn;
0N/A jlong start, end;
2581N/A char jvmpath[MAXPATHLEN];
2581N/A char jrepath[MAXPATHLEN];
4680N/A char jvmcfg[MAXPATHLEN];
0N/A
0N/A _fVersion = fullversion;
0N/A _dVersion = dotversion;
0N/A _launcher_name = lname;
0N/A _program_name = pname;
0N/A _is_java_args = javaargs;
0N/A _wc_enabled = cpwildcard;
0N/A _ergo_policy = ergo;
0N/A
16N/A InitLauncher(javaw);
0N/A DumpState();
5270N/A if (JLI_IsTraceLauncher()) {
5270N/A int i;
5270N/A printf("Command line args:\n");
5270N/A for (i = 0; i < argc ; i++) {
5270N/A printf("argv[%d] = %s\n", i, argv[i]);
5270N/A }
5270N/A AddOption("-Dsun.java.launcher.diag=true", NULL);
5270N/A }
0N/A
0N/A /*
0N/A * Make sure the specified version of the JRE is running.
0N/A *
0N/A * There are three things to note about the SelectVersion() routine:
0N/A * 1) If the version running isn't correct, this routine doesn't
0N/A * return (either the correct version has been exec'd or an error
0N/A * was issued).
0N/A * 2) Argc and Argv in this scope are *not* altered by this routine.
0N/A * It is the responsibility of subsequent code to ignore the
0N/A * arguments handled by this routine.
0N/A * 3) As a side-effect, the variable "main_class" is guaranteed to
0N/A * be set (if it should ever be set). This isn't exactly the
0N/A * poster child for structured programming, but it is a small
0N/A * price to pay for not processing a jar file operand twice.
0N/A * (Note: This side effect has been disabled. See comment on
0N/A * bugid 5030265 below.)
0N/A */
0N/A SelectVersion(argc, argv, &main_class);
0N/A
0N/A CreateExecutionEnvironment(&argc, &argv,
0N/A jrepath, sizeof(jrepath),
4680N/A jvmpath, sizeof(jvmpath),
4680N/A jvmcfg, sizeof(jvmcfg));
0N/A
0N/A ifn.CreateJavaVM = 0;
0N/A ifn.GetDefaultJavaVMInitArgs = 0;
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A start = CounterGet();
0N/A }
0N/A
0N/A if (!LoadJavaVM(jvmpath, &ifn)) {
0N/A return(6);
0N/A }
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A end = CounterGet();
0N/A }
0N/A
0N/A JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
0N/A (long)(jint)Counter2Micros(end-start));
0N/A
0N/A ++argv;
0N/A --argc;
0N/A
0N/A if (IsJavaArgs()) {
0N/A /* Preprocess wrapper arguments */
0N/A TranslateApplicationArgs(jargc, jargv, &argc, &argv);
0N/A if (!AddApplicationOptions(appclassc, appclassv)) {
0N/A return(1);
0N/A }
0N/A } else {
0N/A /* Set default CLASSPATH */
0N/A cpath = getenv("CLASSPATH");
0N/A if (cpath == NULL) {
0N/A cpath = ".";
0N/A }
0N/A SetClassPath(cpath);
0N/A }
0N/A
3408N/A /* Parse command line options; if the return value of
3408N/A * ParseArguments is false, the program should exit.
0N/A */
3408N/A if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
3408N/A {
0N/A return(ret);
0N/A }
0N/A
0N/A /* Override class path if -jar flag was specified */
3408N/A if (mode == LM_JAR) {
3408N/A SetClassPath(what); /* Override class path */
0N/A }
0N/A
0N/A /* set the -Dsun.java.command pseudo property */
3408N/A SetJavaCommandLineProp(what, argc, argv);
0N/A
0N/A /* Set the -Dsun.java.launcher pseudo property */
0N/A SetJavaLauncherProp();
0N/A
0N/A /* set the -Dsun.java.launcher.* platform properties */
0N/A SetJavaLauncherPlatformProps();
0N/A
4680N/A return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
0N/A}
2581N/A/*
2581N/A * Always detach the main thread so that it appears to have ended when
2581N/A * the application's main method exits. This will invoke the
2581N/A * uncaught exception handler machinery if main threw an
2581N/A * exception. An uncaught exception handler cannot change the
2581N/A * launcher's return code except by calling System.exit.
2581N/A *
2581N/A * Wait for all non-daemon threads to end, then destroy the VM.
2581N/A * This will actually create a trivial new Java waiter thread
2581N/A * named "DestroyJavaVM", but this will be seen as a different
2581N/A * thread from the one that executed main, even though they are
2581N/A * the same C thread. This allows mainThread.join() and
2581N/A * mainThread.isAlive() to work as expected.
2581N/A */
2581N/A#define LEAVE() \
2581N/A if ((*vm)->DetachCurrentThread(vm) != 0) { \
2581N/A JLI_ReportErrorMessage(JVM_ERROR2); \
2581N/A ret = 1; \
2581N/A } \
2581N/A (*vm)->DestroyJavaVM(vm); \
2581N/A return ret \
0N/A
647N/A#define CHECK_EXCEPTION_NULL_LEAVE(e) \
647N/A if ((*env)->ExceptionOccurred(env)) { \
647N/A JLI_ReportExceptionDescription(env); \
2581N/A LEAVE(); \
647N/A } \
647N/A if ((e) == NULL) { \
647N/A JLI_ReportErrorMessage(JNI_ERROR); \
2581N/A LEAVE(); \
647N/A }
647N/A
647N/A#define CHECK_EXCEPTION_LEAVE(rv) \
647N/A if ((*env)->ExceptionOccurred(env)) { \
647N/A JLI_ReportExceptionDescription(env); \
647N/A ret = (rv); \
2581N/A LEAVE(); \
647N/A }
0N/A
0N/Aint JNICALL
0N/AJavaMain(void * _args)
0N/A{
0N/A JavaMainArgs *args = (JavaMainArgs *)_args;
0N/A int argc = args->argc;
0N/A char **argv = args->argv;
3408N/A int mode = args->mode;
3408N/A char *what = args->what;
0N/A InvocationFunctions ifn = args->ifn;
0N/A
0N/A JavaVM *vm = 0;
0N/A JNIEnv *env = 0;
3408N/A jclass mainClass = NULL;
0N/A jmethodID mainID;
0N/A jobjectArray mainArgs;
0N/A int ret = 0;
0N/A jlong start, end;
0N/A
4680N/A RegisterThread();
4632N/A
0N/A /* Initialize the virtual machine */
0N/A start = CounterGet();
0N/A if (!InitializeJVM(&vm, &env, &ifn)) {
517N/A JLI_ReportErrorMessage(JVM_ERROR1);
0N/A exit(1);
0N/A }
0N/A
4842N/A if (showSettings != NULL) {
4842N/A ShowSettings(env, showSettings);
4842N/A CHECK_EXCEPTION_LEAVE(1);
4842N/A }
4842N/A
0N/A if (printVersion || showVersion) {
0N/A PrintJavaVersion(env, showVersion);
647N/A CHECK_EXCEPTION_LEAVE(0);
0N/A if (printVersion) {
2581N/A LEAVE();
0N/A }
0N/A }
0N/A
0N/A /* If the user specified neither a class name nor a JAR file */
3408N/A if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) {
0N/A PrintUsage(env, printXUsage);
647N/A CHECK_EXCEPTION_LEAVE(1);
2581N/A LEAVE();
0N/A }
0N/A
0N/A FreeKnownVMs(); /* after last possible PrintUsage() */
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A end = CounterGet();
0N/A JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
0N/A (long)(jint)Counter2Micros(end-start));
0N/A }
0N/A
3408N/A /* At this stage, argc/argv have the application's arguments */
0N/A if (JLI_IsTraceLauncher()){
0N/A int i;
3408N/A printf("%s is '%s'\n", launchModeNames[mode], what);
3408N/A printf("App's argc is %d\n", argc);
0N/A for (i=0; i < argc; i++) {
0N/A printf(" argv[%2d] = '%s'\n", i, argv[i]);
0N/A }
0N/A }
0N/A
0N/A ret = 1;
0N/A
0N/A /*
0N/A * Get the application's main class.
0N/A *
0N/A * See bugid 5030265. The Main-Class name has already been parsed
0N/A * from the manifest, but not parsed properly for UTF-8 support.
0N/A * Hence the code here ignores the value previously extracted and
0N/A * uses the pre-existing code to reextract the value. This is
0N/A * possibly an end of release cycle expedient. However, it has
0N/A * also been discovered that passing some character sets through
0N/A * the environment has "strange" behavior on some variants of
0N/A * Windows. Hence, maybe the manifest parsing code local to the
0N/A * launcher should never be enhanced.
0N/A *
0N/A * Hence, future work should either:
0N/A * 1) Correct the local parsing code and verify that the
0N/A * Main-Class attribute gets properly passed through
0N/A * all environments,
0N/A * 2) Remove the vestages of maintaining main_class through
0N/A * the environment (and remove these comments).
0N/A */
3408N/A mainClass = LoadMainClass(env, mode, what);
647N/A CHECK_EXCEPTION_NULL_LEAVE(mainClass);
4680N/A PostJVMInit(env, mainClass, vm);
647N/A /*
647N/A * The LoadMainClass not only loads the main class, it will also ensure
647N/A * that the main method's signature is correct, therefore further checking
647N/A * is not required. The main method is invoked here so that extraneous java
647N/A * stacks are not in the application stack trace.
647N/A */
0N/A mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
0N/A "([Ljava/lang/String;)V");
647N/A CHECK_EXCEPTION_NULL_LEAVE(mainID);
0N/A
5270N/A /* Build platform specific argument array */
5270N/A mainArgs = CreateApplicationArgs(env, argv, argc);
647N/A CHECK_EXCEPTION_NULL_LEAVE(mainArgs);
0N/A
0N/A /* Invoke main method. */
0N/A (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
0N/A
0N/A /*
0N/A * The launcher's exit code (in the absence of calls to
0N/A * System.exit) will be non-zero if main threw an exception.
0N/A */
0N/A ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
2581N/A LEAVE();
0N/A}
0N/A
0N/A/*
0N/A * Checks the command line options to find which JVM type was
0N/A * specified. If no command line option was given for the JVM type,
0N/A * the default type is used. The environment variable
0N/A * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
0N/A * checked as ways of specifying which JVM type to invoke.
0N/A */
0N/Achar *
0N/ACheckJvmType(int *pargc, char ***argv, jboolean speculative) {
0N/A int i, argi;
0N/A int argc;
0N/A char **newArgv;
0N/A int newArgvIdx = 0;
0N/A int isVMType;
0N/A int jvmidx = -1;
0N/A char *jvmtype = getenv("JDK_ALTERNATE_VM");
0N/A
0N/A argc = *pargc;
0N/A
0N/A /* To make things simpler we always copy the argv array */
0N/A newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));
0N/A
0N/A /* The program name is always present */
0N/A newArgv[newArgvIdx++] = (*argv)[0];
0N/A
0N/A for (argi = 1; argi < argc; argi++) {
0N/A char *arg = (*argv)[argi];
0N/A isVMType = 0;
0N/A
0N/A if (IsJavaArgs()) {
0N/A if (arg[0] != '-') {
0N/A newArgv[newArgvIdx++] = arg;
0N/A continue;
0N/A }
0N/A } else {
0N/A if (JLI_StrCmp(arg, "-classpath") == 0 ||
0N/A JLI_StrCmp(arg, "-cp") == 0) {
0N/A newArgv[newArgvIdx++] = arg;
0N/A argi++;
0N/A if (argi < argc) {
0N/A newArgv[newArgvIdx++] = (*argv)[argi];
0N/A }
0N/A continue;
0N/A }
0N/A if (arg[0] != '-') break;
0N/A }
0N/A
0N/A /* Did the user pass an explicit VM type? */
0N/A i = KnownVMIndex(arg);
0N/A if (i >= 0) {
0N/A jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */
0N/A isVMType = 1;
0N/A *pargc = *pargc - 1;
0N/A }
0N/A
0N/A /* Did the user specify an "alternate" VM? */
0N/A else if (JLI_StrCCmp(arg, "-XXaltjvm=") == 0 || JLI_StrCCmp(arg, "-J-XXaltjvm=") == 0) {
0N/A isVMType = 1;
0N/A jvmtype = arg+((arg[1]=='X')? 10 : 12);
0N/A jvmidx = -1;
0N/A }
0N/A
0N/A if (!isVMType) {
0N/A newArgv[newArgvIdx++] = arg;
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Finish copying the arguments if we aborted the above loop.
0N/A * NOTE that if we aborted via "break" then we did NOT copy the
0N/A * last argument above, and in addition argi will be less than
0N/A * argc.
0N/A */
0N/A while (argi < argc) {
0N/A newArgv[newArgvIdx++] = (*argv)[argi];
0N/A argi++;
0N/A }
0N/A
0N/A /* argv is null-terminated */
0N/A newArgv[newArgvIdx] = 0;
0N/A
0N/A /* Copy back argv */
0N/A *argv = newArgv;
0N/A *pargc = newArgvIdx;
0N/A
0N/A /* use the default VM type if not specified (no alias processing) */
0N/A if (jvmtype == NULL) {
0N/A char* result = knownVMs[0].name+1;
0N/A /* Use a different VM type if we are on a server class machine? */
0N/A if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) &&
0N/A (ServerClassMachine() == JNI_TRUE)) {
0N/A result = knownVMs[0].server_class+1;
0N/A }
0N/A JLI_TraceLauncher("Default VM: %s\n", result);
0N/A return result;
0N/A }
0N/A
0N/A /* if using an alternate VM, no alias processing */
0N/A if (jvmidx < 0)
0N/A return jvmtype;
0N/A
0N/A /* Resolve aliases first */
0N/A {
0N/A int loopCount = 0;
0N/A while (knownVMs[jvmidx].flag == VM_ALIASED_TO) {
0N/A int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias);
0N/A
0N/A if (loopCount > knownVMsCount) {
0N/A if (!speculative) {
517N/A JLI_ReportErrorMessage(CFG_ERROR1);
0N/A exit(1);
0N/A } else {
0N/A return "ERROR";
0N/A /* break; */
0N/A }
0N/A }
0N/A
0N/A if (nextIdx < 0) {
0N/A if (!speculative) {
517N/A JLI_ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);
0N/A exit(1);
0N/A } else {
0N/A return "ERROR";
0N/A }
0N/A }
0N/A jvmidx = nextIdx;
0N/A jvmtype = knownVMs[jvmidx].name+1;
0N/A loopCount++;
0N/A }
0N/A }
0N/A
0N/A switch (knownVMs[jvmidx].flag) {
0N/A case VM_WARN:
0N/A if (!speculative) {
517N/A JLI_ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);
0N/A }
0N/A /* fall through */
0N/A case VM_IGNORE:
0N/A jvmtype = knownVMs[jvmidx=0].name + 1;
0N/A /* fall through */
0N/A case VM_KNOWN:
0N/A break;
0N/A case VM_ERROR:
0N/A if (!speculative) {
517N/A JLI_ReportErrorMessage(CFG_ERROR3, jvmtype);
0N/A exit(1);
0N/A } else {
0N/A return "ERROR";
0N/A }
0N/A }
0N/A
0N/A return jvmtype;
0N/A}
0N/A
0N/A/* copied from HotSpot function "atomll()" */
0N/Astatic int
3131N/Aparse_size(const char *s, jlong *result) {
0N/A jlong n = 0;
0N/A int args_read = sscanf(s, jlong_format_specifier(), &n);
0N/A if (args_read != 1) {
0N/A return 0;
0N/A }
0N/A while (*s != '\0' && *s >= '0' && *s <= '9') {
0N/A s++;
0N/A }
0N/A // 4705540: illegal if more characters are found after the first non-digit
0N/A if (JLI_StrLen(s) > 1) {
0N/A return 0;
0N/A }
0N/A switch (*s) {
0N/A case 'T': case 't':
0N/A *result = n * GB * KB;
0N/A return 1;
0N/A case 'G': case 'g':
0N/A *result = n * GB;
0N/A return 1;
0N/A case 'M': case 'm':
0N/A *result = n * MB;
0N/A return 1;
0N/A case 'K': case 'k':
0N/A *result = n * KB;
0N/A return 1;
0N/A case '\0':
0N/A *result = n;
0N/A return 1;
0N/A default:
0N/A /* Create JVM with default stack and let VM handle malformed -Xss string*/
0N/A return 0;
0N/A }
0N/A}
0N/A
0N/A/*
0N/A * Adds a new VM option with the given given name and value.
0N/A */
0N/Avoid
0N/AAddOption(char *str, void *info)
0N/A{
0N/A /*
0N/A * Expand options array if needed to accommodate at least one more
0N/A * VM option.
0N/A */
0N/A if (numOptions >= maxOptions) {
0N/A if (options == 0) {
0N/A maxOptions = 4;
0N/A options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
0N/A } else {
0N/A JavaVMOption *tmp;
0N/A maxOptions *= 2;
0N/A tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
0N/A memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
0N/A JLI_MemFree(options);
0N/A options = tmp;
0N/A }
0N/A }
0N/A options[numOptions].optionString = str;
0N/A options[numOptions++].extraInfo = info;
0N/A
0N/A if (JLI_StrCCmp(str, "-Xss") == 0) {
3131N/A jlong tmp;
3131N/A if (parse_size(str + 4, &tmp)) {
3131N/A threadStackSize = tmp;
3131N/A }
3131N/A }
3131N/A
3131N/A if (JLI_StrCCmp(str, "-Xmx") == 0) {
3131N/A jlong tmp;
3131N/A if (parse_size(str + 4, &tmp)) {
3330N/A maxHeapSize = tmp;
3330N/A }
3330N/A }
3330N/A
3330N/A if (JLI_StrCCmp(str, "-Xms") == 0) {
3330N/A jlong tmp;
3330N/A if (parse_size(str + 4, &tmp)) {
3408N/A initialHeapSize = tmp;
3131N/A }
0N/A }
0N/A}
0N/A
0N/Astatic void
0N/ASetClassPath(const char *s)
0N/A{
0N/A char *def;
1308N/A const char *orig = s;
1308N/A static const char format[] = "-Djava.class.path=%s";
5271N/A /*
5271N/A * usually we should not get a null pointer, but there are cases where
5271N/A * we might just get one, in which case we simply ignore it, and let the
5271N/A * caller deal with it
5271N/A */
5271N/A if (s == NULL)
5271N/A return;
0N/A s = JLI_WildcardExpandClasspath(s);
1308N/A def = JLI_MemAlloc(sizeof(format)
1308N/A - 2 /* strlen("%s") */
1308N/A + JLI_StrLen(s));
1308N/A sprintf(def, format, s);
0N/A AddOption(def, NULL);
1308N/A if (s != orig)
1308N/A JLI_MemFree((char *) s);
0N/A}
0N/A
0N/A/*
0N/A * The SelectVersion() routine ensures that an appropriate version of
0N/A * the JRE is running. The specification for the appropriate version
0N/A * is obtained from either the manifest of a jar file (preferred) or
0N/A * from command line options.
0N/A * The routine also parses splash screen command line options and
0N/A * passes on their values in private environment variables.
0N/A */
0N/Astatic void
0N/ASelectVersion(int argc, char **argv, char **main_class)
0N/A{
0N/A char *arg;
0N/A char **new_argv;
0N/A char **new_argp;
0N/A char *operand;
0N/A char *version = NULL;
0N/A char *jre = NULL;
0N/A int jarflag = 0;
0N/A int headlessflag = 0;
0N/A int restrict_search = -1; /* -1 implies not known */
0N/A manifest_info info;
0N/A char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "=";
0N/A char *splash_file_name = NULL;
0N/A char *splash_jar_name = NULL;
0N/A char *env_in;
0N/A int res;
0N/A
0N/A /*
0N/A * If the version has already been selected, set *main_class
0N/A * with the value passed through the environment (if any) and
0N/A * simply return.
0N/A */
0N/A if ((env_in = getenv(ENV_ENTRY)) != NULL) {
0N/A if (*env_in != '\0')
0N/A *main_class = JLI_StringDup(env_in);
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * Scan through the arguments for options relevant to multiple JRE
0N/A * support. For reference, the command line syntax is defined as:
0N/A *
0N/A * SYNOPSIS
0N/A * java [options] class [argument...]
0N/A *
0N/A * java [options] -jar file.jar [argument...]
0N/A *
0N/A * As the scan is performed, make a copy of the argument list with
0N/A * the version specification options (new to 1.5) removed, so that
0N/A * a version less than 1.5 can be exec'd.
0N/A *
0N/A * Note that due to the syntax of the native Windows interface
0N/A * CreateProcess(), processing similar to the following exists in
0N/A * the Windows platform specific routine ExecJRE (in java_md.c).
0N/A * Changes here should be reproduced there.
0N/A */
0N/A new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*));
0N/A new_argv[0] = argv[0];
0N/A new_argp = &new_argv[1];
0N/A argc--;
0N/A argv++;
0N/A while ((arg = *argv) != 0 && *arg == '-') {
0N/A if (JLI_StrCCmp(arg, "-version:") == 0) {
0N/A version = arg + 9;
0N/A } else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) {
0N/A restrict_search = 1;
0N/A } else if (JLI_StrCmp(arg, "-no-jre-restrict-search") == 0) {
0N/A restrict_search = 0;
0N/A } else {
0N/A if (JLI_StrCmp(arg, "-jar") == 0)
0N/A jarflag = 1;
0N/A /* deal with "unfortunate" classpath syntax */
0N/A if ((JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) &&
0N/A (argc >= 2)) {
0N/A *new_argp++ = arg;
0N/A argc--;
0N/A argv++;
0N/A arg = *argv;
0N/A }
0N/A
0N/A /*
0N/A * Checking for headless toolkit option in the some way as AWT does:
0N/A * "true" means true and any other value means false
0N/A */
0N/A if (JLI_StrCmp(arg, "-Djava.awt.headless=true") == 0) {
0N/A headlessflag = 1;
0N/A } else if (JLI_StrCCmp(arg, "-Djava.awt.headless=") == 0) {
0N/A headlessflag = 0;
0N/A } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
0N/A splash_file_name = arg+8;
0N/A }
0N/A *new_argp++ = arg;
0N/A }
0N/A argc--;
0N/A argv++;
0N/A }
0N/A if (argc <= 0) { /* No operand? Possibly legit with -[full]version */
0N/A operand = NULL;
0N/A } else {
0N/A argc--;
0N/A *new_argp++ = operand = *argv++;
0N/A }
0N/A while (argc-- > 0) /* Copy over [argument...] */
0N/A *new_argp++ = *argv++;
0N/A *new_argp = NULL;
0N/A
0N/A /*
0N/A * If there is a jar file, read the manifest. If the jarfile can't be
0N/A * read, the manifest can't be read from the jar file, or the manifest
0N/A * is corrupt, issue the appropriate error messages and exit.
0N/A *
0N/A * Even if there isn't a jar file, construct a manifest_info structure
0N/A * containing the command line information. It's a convenient way to carry
0N/A * this data around.
0N/A */
0N/A if (jarflag && operand) {
0N/A if ((res = JLI_ParseManifest(operand, &info)) != 0) {
0N/A if (res == -1)
517N/A JLI_ReportErrorMessage(JAR_ERROR2, operand);
0N/A else
517N/A JLI_ReportErrorMessage(JAR_ERROR3, operand);
0N/A exit(1);
0N/A }
0N/A
0N/A /*
0N/A * Command line splash screen option should have precedence
0N/A * over the manifest, so the manifest data is used only if
0N/A * splash_file_name has not been initialized above during command
0N/A * line parsing
0N/A */
0N/A if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) {
0N/A splash_file_name = info.splashscreen_image_file_name;
0N/A splash_jar_name = operand;
0N/A }
0N/A } else {
0N/A info.manifest_version = NULL;
0N/A info.main_class = NULL;
0N/A info.jre_version = NULL;
0N/A info.jre_restrict_search = 0;
0N/A }
0N/A
0N/A /*
0N/A * Passing on splash screen info in environment variables
0N/A */
0N/A if (splash_file_name && !headlessflag) {
0N/A char* splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1);
0N/A JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");
0N/A JLI_StrCat(splash_file_entry, splash_file_name);
0N/A putenv(splash_file_entry);
0N/A }
0N/A if (splash_jar_name && !headlessflag) {
0N/A char* splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1);
0N/A JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");
0N/A JLI_StrCat(splash_jar_entry, splash_jar_name);
0N/A putenv(splash_jar_entry);
0N/A }
0N/A
0N/A /*
0N/A * The JRE-Version and JRE-Restrict-Search values (if any) from the
0N/A * manifest are overwritten by any specified on the command line.
0N/A */
0N/A if (version != NULL)
0N/A info.jre_version = version;
0N/A if (restrict_search != -1)
0N/A info.jre_restrict_search = restrict_search;
0N/A
0N/A /*
0N/A * "Valid" returns (other than unrecoverable errors) follow. Set
0N/A * main_class as a side-effect of this routine.
0N/A */
0N/A if (info.main_class != NULL)
0N/A *main_class = JLI_StringDup(info.main_class);
0N/A
0N/A /*
0N/A * If no version selection information is found either on the command
0N/A * line or in the manifest, simply return.
0N/A */
0N/A if (info.jre_version == NULL) {
0N/A JLI_FreeManifest();
0N/A JLI_MemFree(new_argv);
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * Check for correct syntax of the version specification (JSR 56).
0N/A */
0N/A if (!JLI_ValidVersionString(info.jre_version)) {
517N/A JLI_ReportErrorMessage(SPC_ERROR1, info.jre_version);
0N/A exit(1);
0N/A }
0N/A
0N/A /*
0N/A * Find the appropriate JVM on the system. Just to be as forgiving as
0N/A * possible, if the standard algorithms don't locate an appropriate
0N/A * jre, check to see if the one running will satisfy the requirements.
0N/A * This can happen on systems which haven't been set-up for multiple
0N/A * JRE support.
0N/A */
0N/A jre = LocateJRE(&info);
0N/A JLI_TraceLauncher("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n",
0N/A (info.jre_version?info.jre_version:"null"),
0N/A (info.jre_restrict_search?"true":"false"), (jre?jre:"null"));
0N/A
0N/A if (jre == NULL) {
0N/A if (JLI_AcceptableRelease(GetFullVersion(), info.jre_version)) {
0N/A JLI_FreeManifest();
0N/A JLI_MemFree(new_argv);
0N/A return;
0N/A } else {
517N/A JLI_ReportErrorMessage(CFG_ERROR4, info.jre_version);
0N/A exit(1);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * If I'm not the chosen one, exec the chosen one. Returning from
0N/A * ExecJRE indicates that I am indeed the chosen one.
0N/A *
0N/A * The private environment variable _JAVA_VERSION_SET is used to
0N/A * prevent the chosen one from re-reading the manifest file and
0N/A * using the values found within to override the (potential) command
0N/A * line flags stripped from argv (because the target may not
0N/A * understand them). Passing the MainClass value is an optimization
0N/A * to avoid locating, expanding and parsing the manifest extra
0N/A * times.
0N/A */
1113N/A if (info.main_class != NULL) {
1113N/A if (JLI_StrLen(info.main_class) <= MAXNAMELEN) {
1113N/A (void)JLI_StrCat(env_entry, info.main_class);
1113N/A } else {
1139N/A JLI_ReportErrorMessage(CLS_ERROR5, MAXNAMELEN);
1113N/A exit(1);
1113N/A }
1113N/A }
0N/A (void)putenv(env_entry);
0N/A ExecJRE(jre, new_argv);
0N/A JLI_FreeManifest();
0N/A JLI_MemFree(new_argv);
0N/A return;
0N/A}
0N/A
0N/A/*
0N/A * Parses command line arguments. Returns JNI_FALSE if launcher
0N/A * should exit without starting vm, returns JNI_TRUE if vm needs
3408N/A * to be started to process given options. *pret (the launcher
0N/A * process return value) is set to 0 for a normal exit.
0N/A */
0N/Astatic jboolean
3408N/AParseArguments(int *pargc, char ***pargv,
3408N/A int *pmode, char **pwhat,
3408N/A int *pret, const char *jrepath)
0N/A{
0N/A int argc = *pargc;
0N/A char **argv = *pargv;
3408N/A int mode = LM_UNKNOWN;
0N/A char *arg;
0N/A
0N/A *pret = 0;
0N/A
0N/A while ((arg = *argv) != 0 && *arg == '-') {
0N/A argv++; --argc;
0N/A if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) {
0N/A ARG_CHECK (argc, ARG_ERROR1, arg);
0N/A SetClassPath(*argv);
3408N/A mode = LM_CLASS;
0N/A argv++; --argc;
0N/A } else if (JLI_StrCmp(arg, "-jar") == 0) {
0N/A ARG_CHECK (argc, ARG_ERROR2, arg);
3408N/A mode = LM_JAR;
0N/A } else if (JLI_StrCmp(arg, "-help") == 0 ||
0N/A JLI_StrCmp(arg, "-h") == 0 ||
0N/A JLI_StrCmp(arg, "-?") == 0) {
0N/A printUsage = JNI_TRUE;
0N/A return JNI_TRUE;
0N/A } else if (JLI_StrCmp(arg, "-version") == 0) {
0N/A printVersion = JNI_TRUE;
0N/A return JNI_TRUE;
0N/A } else if (JLI_StrCmp(arg, "-showversion") == 0) {
0N/A showVersion = JNI_TRUE;
0N/A } else if (JLI_StrCmp(arg, "-X") == 0) {
0N/A printXUsage = JNI_TRUE;
0N/A return JNI_TRUE;
0N/A/*
3131N/A * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
3131N/A * In the latter case, any SUBOPT value not recognized will default to "all"
3131N/A */
3131N/A } else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||
3131N/A JLI_StrCCmp(arg, "-XshowSettings:") == 0) {
3131N/A showSettings = arg;
3487N/A } else if (JLI_StrCmp(arg, "-Xdiag") == 0) {
3487N/A AddOption("-Dsun.java.launcher.diag=true", NULL);
3131N/A/*
0N/A * The following case provide backward compatibility with old-style
0N/A * command line options.
0N/A */
0N/A } else if (JLI_StrCmp(arg, "-fullversion") == 0) {
517N/A JLI_ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());
0N/A return JNI_FALSE;
0N/A } else if (JLI_StrCmp(arg, "-verbosegc") == 0) {
0N/A AddOption("-verbose:gc", NULL);
0N/A } else if (JLI_StrCmp(arg, "-t") == 0) {
0N/A AddOption("-Xt", NULL);
0N/A } else if (JLI_StrCmp(arg, "-tm") == 0) {
0N/A AddOption("-Xtm", NULL);
0N/A } else if (JLI_StrCmp(arg, "-debug") == 0) {
0N/A AddOption("-Xdebug", NULL);
0N/A } else if (JLI_StrCmp(arg, "-noclassgc") == 0) {
0N/A AddOption("-Xnoclassgc", NULL);
0N/A } else if (JLI_StrCmp(arg, "-Xfuture") == 0) {
0N/A AddOption("-Xverify:all", NULL);
0N/A } else if (JLI_StrCmp(arg, "-verify") == 0) {
0N/A AddOption("-Xverify:all", NULL);
0N/A } else if (JLI_StrCmp(arg, "-verifyremote") == 0) {
0N/A AddOption("-Xverify:remote", NULL);
0N/A } else if (JLI_StrCmp(arg, "-noverify") == 0) {
0N/A AddOption("-Xverify:none", NULL);
0N/A } else if (JLI_StrCCmp(arg, "-prof") == 0) {
0N/A char *p = arg + 5;
0N/A char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 50);
0N/A if (*p) {
0N/A sprintf(tmp, "-Xrunhprof:cpu=old,file=%s", p + 1);
0N/A } else {
0N/A sprintf(tmp, "-Xrunhprof:cpu=old,file=java.prof");
0N/A }
0N/A AddOption(tmp, NULL);
0N/A } else if (JLI_StrCCmp(arg, "-ss") == 0 ||
0N/A JLI_StrCCmp(arg, "-oss") == 0 ||
0N/A JLI_StrCCmp(arg, "-ms") == 0 ||
0N/A JLI_StrCCmp(arg, "-mx") == 0) {
0N/A char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 6);
0N/A sprintf(tmp, "-X%s", arg + 1); /* skip '-' */
0N/A AddOption(tmp, NULL);
0N/A } else if (JLI_StrCmp(arg, "-checksource") == 0 ||
0N/A JLI_StrCmp(arg, "-cs") == 0 ||
0N/A JLI_StrCmp(arg, "-noasyncgc") == 0) {
0N/A /* No longer supported */
517N/A JLI_ReportErrorMessage(ARG_WARN, arg);
0N/A } else if (JLI_StrCCmp(arg, "-version:") == 0 ||
0N/A JLI_StrCmp(arg, "-no-jre-restrict-search") == 0 ||
0N/A JLI_StrCmp(arg, "-jre-restrict-search") == 0 ||
0N/A JLI_StrCCmp(arg, "-splash:") == 0) {
0N/A ; /* Ignore machine independent options already handled */
4680N/A } else if (ProcessPlatformOption(arg)) {
4680N/A ; /* Processing of platform dependent options */
4680N/A } else if (RemovableOption(arg)) {
0N/A ; /* Do not pass option to vm. */
0N/A } else {
0N/A AddOption(arg, NULL);
0N/A }
0N/A }
0N/A
0N/A if (--argc >= 0) {
3408N/A *pwhat = *argv++;
3408N/A }
3408N/A
3408N/A if (*pwhat == NULL) {
3408N/A *pret = 1;
3408N/A } else if (mode == LM_UNKNOWN) {
3408N/A /* default to LM_CLASS if -jar and -cp option are
3408N/A * not specified */
3408N/A mode = LM_CLASS;
3408N/A }
3408N/A
3408N/A if (argc >= 0) {
0N/A *pargc = argc;
0N/A *pargv = argv;
0N/A }
3408N/A
3408N/A *pmode = mode;
3408N/A
0N/A return JNI_TRUE;
0N/A}
0N/A
0N/A/*
0N/A * Initializes the Java Virtual Machine. Also frees options array when
0N/A * finished.
0N/A */
0N/Astatic jboolean
0N/AInitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
0N/A{
0N/A JavaVMInitArgs args;
0N/A jint r;
0N/A
0N/A memset(&args, 0, sizeof(args));
0N/A args.version = JNI_VERSION_1_2;
0N/A args.nOptions = numOptions;
0N/A args.options = options;
0N/A args.ignoreUnrecognized = JNI_FALSE;
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A int i = 0;
0N/A printf("JavaVM args:\n ");
0N/A printf("version 0x%08lx, ", (long)args.version);
0N/A printf("ignoreUnrecognized is %s, ",
0N/A args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");
0N/A printf("nOptions is %ld\n", (long)args.nOptions);
0N/A for (i = 0; i < numOptions; i++)
0N/A printf(" option[%2d] = '%s'\n",
0N/A i, args.options[i].optionString);
0N/A }
0N/A
0N/A r = ifn->CreateJavaVM(pvm, (void **)penv, &args);
0N/A JLI_MemFree(options);
0N/A return r == JNI_OK;
0N/A}
0N/A
3777N/Astatic jclass helperClass = NULL;
3777N/A
5270N/Ajclass
5270N/AGetLauncherHelperClass(JNIEnv *env)
5270N/A{
3777N/A if (helperClass == NULL) {
3777N/A NULL_CHECK0(helperClass = FindBootStrapClass(env,
3777N/A "sun/launcher/LauncherHelper"));
0N/A }
3777N/A return helperClass;
0N/A}
0N/A
3777N/Astatic jmethodID makePlatformStringMID = NULL;
0N/A/*
0N/A * Returns a new Java string object for the specified platform string.
0N/A */
0N/Astatic jstring
0N/ANewPlatformString(JNIEnv *env, char *s)
0N/A{
0N/A int len = (int)JLI_StrLen(s);
0N/A jbyteArray ary;
3777N/A jclass cls = GetLauncherHelperClass(env);
3777N/A NULL_CHECK0(cls);
0N/A if (s == NULL)
0N/A return 0;
0N/A
0N/A ary = (*env)->NewByteArray(env, len);
0N/A if (ary != 0) {
0N/A jstring str = 0;
0N/A (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);
0N/A if (!(*env)->ExceptionOccurred(env)) {
3777N/A if (makePlatformStringMID == NULL) {
3777N/A NULL_CHECK0(makePlatformStringMID = (*env)->GetStaticMethodID(env,
3777N/A cls, "makePlatformString", "(Z[B)Ljava/lang/String;"));
0N/A }
3777N/A str = (*env)->CallStaticObjectMethod(env, cls,
3777N/A makePlatformStringMID, USE_STDERR, ary);
0N/A (*env)->DeleteLocalRef(env, ary);
0N/A return str;
0N/A }
0N/A }
0N/A return 0;
0N/A}
0N/A
0N/A/*
0N/A * Returns a new array of Java string objects for the specified
0N/A * array of platform strings.
0N/A */
5270N/AjobjectArray
0N/ANewPlatformStringArray(JNIEnv *env, char **strv, int strc)
0N/A{
0N/A jarray cls;
0N/A jarray ary;
0N/A int i;
0N/A
647N/A NULL_CHECK0(cls = FindBootStrapClass(env, "java/lang/String"));
0N/A NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0));
0N/A for (i = 0; i < strc; i++) {
0N/A jstring str = NewPlatformString(env, *strv++);
0N/A NULL_CHECK0(str);
0N/A (*env)->SetObjectArrayElement(env, ary, i, str);
0N/A (*env)->DeleteLocalRef(env, str);
0N/A }
0N/A return ary;
0N/A}
0N/A
0N/A/*
647N/A * Loads a class and verifies that the main class is present and it is ok to
647N/A * call it for more details refer to the java implementation.
0N/A */
0N/Astatic jclass
3408N/ALoadMainClass(JNIEnv *env, int mode, char *name)
0N/A{
647N/A jmethodID mid;
647N/A jstring str;
647N/A jobject result;
0N/A jlong start, end;
3777N/A jclass cls = GetLauncherHelperClass(env);
3777N/A NULL_CHECK0(cls);
647N/A if (JLI_IsTraceLauncher()) {
0N/A start = CounterGet();
647N/A }
3777N/A NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
3777N/A "checkAndLoadMain",
3777N/A "(ZILjava/lang/String;)Ljava/lang/Class;"));
3777N/A
4609N/A str = NewPlatformString(env, name);
3777N/A result = (*env)->CallStaticObjectMethod(env, cls, mid, USE_STDERR, mode, str);
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A end = CounterGet();
0N/A printf("%ld micro seconds to load main class\n",
0N/A (long)(jint)Counter2Micros(end-start));
5270N/A printf("----%s----\n", JLDEBUG_ENV_ENTRY);
0N/A }
0N/A
647N/A return (jclass)result;
0N/A}
0N/A
0N/A/*
0N/A * For tools, convert command line args thus:
0N/A * javac -cp foo:foo/"*" -J-ms32m ...
0N/A * java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ...
0N/A *
0N/A * Takes 4 parameters, and returns the populated arguments
0N/A */
0N/Astatic void
0N/ATranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv)
0N/A{
0N/A int argc = *pargc;
0N/A char **argv = *pargv;
0N/A int nargc = argc + jargc;
0N/A char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *));
0N/A int i;
0N/A
0N/A *pargc = nargc;
0N/A *pargv = nargv;
0N/A
0N/A /* Copy the VM arguments (i.e. prefixed with -J) */
0N/A for (i = 0; i < jargc; i++) {
0N/A const char *arg = jargv[i];
0N/A if (arg[0] == '-' && arg[1] == 'J') {
0N/A *nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);
0N/A }
0N/A }
0N/A
0N/A for (i = 0; i < argc; i++) {
0N/A char *arg = argv[i];
0N/A if (arg[0] == '-' && arg[1] == 'J') {
0N/A if (arg[2] == '\0') {
517N/A JLI_ReportErrorMessage(ARG_ERROR3);
0N/A exit(1);
0N/A }
0N/A *nargv++ = arg + 2;
0N/A }
0N/A }
0N/A
0N/A /* Copy the rest of the arguments */
0N/A for (i = 0; i < jargc ; i++) {
0N/A const char *arg = jargv[i];
0N/A if (arg[0] != '-' || arg[1] != 'J') {
0N/A *nargv++ = (arg == NULL) ? NULL : JLI_StringDup(arg);
0N/A }
0N/A }
0N/A for (i = 0; i < argc; i++) {
0N/A char *arg = argv[i];
0N/A if (arg[0] == '-') {
0N/A if (arg[1] == 'J')
0N/A continue;
0N/A if (IsWildCardEnabled() && arg[1] == 'c'
0N/A && (JLI_StrCmp(arg, "-cp") == 0 ||
0N/A JLI_StrCmp(arg, "-classpath") == 0)
0N/A && i < argc - 1) {
0N/A *nargv++ = arg;
0N/A *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
0N/A i++;
0N/A continue;
0N/A }
0N/A }
0N/A *nargv++ = arg;
0N/A }
0N/A *nargv = 0;
0N/A}
0N/A
0N/A/*
0N/A * For our tools, we try to add 3 VM options:
0N/A * -Denv.class.path=<envcp>
0N/A * -Dapplication.home=<apphome>
0N/A * -Djava.class.path=<appcp>
0N/A * <envcp> is the user's setting of CLASSPATH -- for instance the user
0N/A * tells javac where to find binary classes through this environment
0N/A * variable. Notice that users will be able to compile against our
0N/A * tools classes (sun.tools.javac.Main) only if they explicitly add
0N/A * tools.jar to CLASSPATH.
0N/A * <apphome> is the directory where the application is installed.
0N/A * <appcp> is the classpath to where our apps' classfiles are.
0N/A */
0N/Astatic jboolean
0N/AAddApplicationOptions(int cpathc, const char **cpathv)
0N/A{
0N/A char *envcp, *appcp, *apphome;
0N/A char home[MAXPATHLEN]; /* application home */
0N/A char separator[] = { PATH_SEPARATOR, '\0' };
0N/A int size, i;
0N/A
0N/A {
0N/A const char *s = getenv("CLASSPATH");
0N/A if (s) {
0N/A s = (char *) JLI_WildcardExpandClasspath(s);
0N/A /* 40 for -Denv.class.path= */
0N/A envcp = (char *)JLI_MemAlloc(JLI_StrLen(s) + 40);
0N/A sprintf(envcp, "-Denv.class.path=%s", s);
0N/A AddOption(envcp, NULL);
0N/A }
0N/A }
0N/A
0N/A if (!GetApplicationHome(home, sizeof(home))) {
517N/A JLI_ReportErrorMessage(CFG_ERROR5);
0N/A return JNI_FALSE;
0N/A }
0N/A
0N/A /* 40 for '-Dapplication.home=' */
0N/A apphome = (char *)JLI_MemAlloc(JLI_StrLen(home) + 40);
0N/A sprintf(apphome, "-Dapplication.home=%s", home);
0N/A AddOption(apphome, NULL);
0N/A
0N/A /* How big is the application's classpath? */
0N/A size = 40; /* 40: "-Djava.class.path=" */
0N/A for (i = 0; i < cpathc; i++) {
0N/A size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */
0N/A }
0N/A appcp = (char *)JLI_MemAlloc(size + 1);
0N/A JLI_StrCpy(appcp, "-Djava.class.path=");
0N/A for (i = 0; i < cpathc; i++) {
0N/A JLI_StrCat(appcp, home); /* c:\program files\myapp */
0N/A JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */
0N/A JLI_StrCat(appcp, separator); /* ; */
0N/A }
0N/A appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */
0N/A AddOption(appcp, NULL);
0N/A return JNI_TRUE;
0N/A}
0N/A
0N/A/*
0N/A * inject the -Dsun.java.command pseudo property into the args structure
0N/A * this pseudo property is used in the HotSpot VM to expose the
0N/A * Java class name and arguments to the main method to the VM. The
0N/A * HotSpot VM uses this pseudo property to store the Java class name
0N/A * (or jar file name) and the arguments to the class's main method
0N/A * to the instrumentation memory region. The sun.java.command pseudo
0N/A * property is not exported by HotSpot to the Java layer.
0N/A */
0N/Avoid
3408N/ASetJavaCommandLineProp(char *what, int argc, char **argv)
0N/A{
0N/A
0N/A int i = 0;
0N/A size_t len = 0;
0N/A char* javaCommand = NULL;
0N/A char* dashDstr = "-Dsun.java.command=";
0N/A
3408N/A if (what == NULL) {
0N/A /* unexpected, one of these should be set. just return without
0N/A * setting the property
0N/A */
0N/A return;
0N/A }
0N/A
0N/A /* determine the amount of memory to allocate assuming
0N/A * the individual components will be space separated
0N/A */
3408N/A len = JLI_StrLen(what);
0N/A for (i = 0; i < argc; i++) {
0N/A len += JLI_StrLen(argv[i]) + 1;
0N/A }
0N/A
0N/A /* allocate the memory */
0N/A javaCommand = (char*) JLI_MemAlloc(len + JLI_StrLen(dashDstr) + 1);
0N/A
0N/A /* build the -D string */
0N/A *javaCommand = '\0';
0N/A JLI_StrCat(javaCommand, dashDstr);
3408N/A JLI_StrCat(javaCommand, what);
0N/A
0N/A for (i = 0; i < argc; i++) {
0N/A /* the components of the string are space separated. In
0N/A * the case of embedded white space, the relationship of
0N/A * the white space separated components to their true
0N/A * positional arguments will be ambiguous. This issue may
0N/A * be addressed in a future release.
0N/A */
0N/A JLI_StrCat(javaCommand, " ");
0N/A JLI_StrCat(javaCommand, argv[i]);
0N/A }
0N/A
0N/A AddOption(javaCommand, NULL);
0N/A}
0N/A
0N/A/*
0N/A * JVM would like to know if it's created by a standard Sun launcher, or by
0N/A * user native application, the following property indicates the former.
0N/A */
3408N/Avoid
3408N/ASetJavaLauncherProp() {
0N/A AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL);
0N/A}
0N/A
0N/A/*
0N/A * Prints the version information from the java.version and other properties.
0N/A */
0N/Astatic void
0N/APrintJavaVersion(JNIEnv *env, jboolean extraLF)
0N/A{
0N/A jclass ver;
0N/A jmethodID print;
0N/A
647N/A NULL_CHECK(ver = FindBootStrapClass(env, "sun/misc/Version"));
0N/A NULL_CHECK(print = (*env)->GetStaticMethodID(env,
0N/A ver,
0N/A (extraLF == JNI_TRUE) ? "println" : "print",
0N/A "()V"
0N/A )
0N/A );
0N/A
0N/A (*env)->CallStaticVoidMethod(env, ver, print);
0N/A}
0N/A
0N/A/*
3131N/A * Prints all the Java settings, see the java implementation for more details.
3131N/A */
3131N/Astatic void
3131N/AShowSettings(JNIEnv *env, char *optString)
3131N/A{
3131N/A jmethodID showSettingsID;
3131N/A jstring joptString;
3777N/A jclass cls = GetLauncherHelperClass(env);
3777N/A NULL_CHECK(cls);
3131N/A NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
3330N/A "showSettings", "(ZLjava/lang/String;JJJZ)V"));
3131N/A joptString = (*env)->NewStringUTF(env, optString);
3131N/A (*env)->CallStaticVoidMethod(env, cls, showSettingsID,
3777N/A USE_STDERR,
3131N/A joptString,
3330N/A (jlong)initialHeapSize,
3330N/A (jlong)maxHeapSize,
3131N/A (jlong)threadStackSize,
3131N/A ServerClassMachine());
3131N/A}
3131N/A
3131N/A/*
647N/A * Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java
0N/A */
0N/Astatic void
0N/APrintUsage(JNIEnv* env, jboolean doXUsage)
0N/A{
0N/A jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage;
0N/A jstring jprogname, vm1, vm2;
0N/A int i;
3777N/A jclass cls = GetLauncherHelperClass(env);
3777N/A NULL_CHECK(cls);
0N/A if (doXUsage) {
0N/A NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,
0N/A "printXUsageMessage", "(Z)V"));
3777N/A (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, USE_STDERR);
0N/A } else {
0N/A NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls,
0N/A "initHelpMessage", "(Ljava/lang/String;)V"));
0N/A
0N/A NULL_CHECK(vmSelect = (*env)->GetStaticMethodID(env, cls, "appendVmSelectMessage",
0N/A "(Ljava/lang/String;Ljava/lang/String;)V"));
0N/A
0N/A NULL_CHECK(vmSynonym = (*env)->GetStaticMethodID(env, cls,
0N/A "appendVmSynonymMessage",
0N/A "(Ljava/lang/String;Ljava/lang/String;)V"));
0N/A NULL_CHECK(vmErgo = (*env)->GetStaticMethodID(env, cls,
0N/A "appendVmErgoMessage", "(ZLjava/lang/String;)V"));
0N/A
0N/A NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls,
0N/A "printHelpMessage", "(Z)V"));
0N/A
0N/A jprogname = (*env)->NewStringUTF(env, _program_name);
0N/A
0N/A /* Initialize the usage message with the usual preamble */
0N/A (*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname);
0N/A
0N/A
0N/A /* Assemble the other variant part of the usage */
0N/A if ((knownVMs[0].flag == VM_KNOWN) ||
0N/A (knownVMs[0].flag == VM_IF_SERVER_CLASS)) {
0N/A vm1 = (*env)->NewStringUTF(env, knownVMs[0].name);
0N/A vm2 = (*env)->NewStringUTF(env, knownVMs[0].name+1);
0N/A (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
0N/A }
0N/A for (i=1; i<knownVMsCount; i++) {
0N/A if (knownVMs[i].flag == VM_KNOWN) {
0N/A vm1 = (*env)->NewStringUTF(env, knownVMs[i].name);
0N/A vm2 = (*env)->NewStringUTF(env, knownVMs[i].name+1);
0N/A (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
0N/A }
0N/A }
0N/A for (i=1; i<knownVMsCount; i++) {
0N/A if (knownVMs[i].flag == VM_ALIASED_TO) {
0N/A vm1 = (*env)->NewStringUTF(env, knownVMs[i].name);
0N/A vm2 = (*env)->NewStringUTF(env, knownVMs[i].alias+1);
0N/A (*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2);
0N/A }
0N/A }
0N/A
0N/A /* The first known VM is the default */
0N/A {
0N/A jboolean isServerClassMachine = ServerClassMachine();
0N/A
0N/A const char* defaultVM = knownVMs[0].name+1;
0N/A if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && isServerClassMachine) {
0N/A defaultVM = knownVMs[0].server_class+1;
0N/A }
0N/A
0N/A vm1 = (*env)->NewStringUTF(env, defaultVM);
0N/A (*env)->CallStaticVoidMethod(env, cls, vmErgo, isServerClassMachine, vm1);
0N/A }
0N/A
0N/A /* Complete the usage message and print to stderr*/
3777N/A (*env)->CallStaticVoidMethod(env, cls, printHelp, USE_STDERR);
0N/A }
0N/A return;
0N/A}
0N/A
0N/A/*
0N/A * Read the jvm.cfg file and fill the knownJVMs[] array.
0N/A *
0N/A * The functionality of the jvm.cfg file is subject to change without
0N/A * notice and the mechanism will be removed in the future.
0N/A *
0N/A * The lexical structure of the jvm.cfg file is as follows:
0N/A *
0N/A * jvmcfg := { vmLine }
0N/A * vmLine := knownLine
0N/A * | aliasLine
0N/A * | warnLine
0N/A * | ignoreLine
0N/A * | errorLine
0N/A * | predicateLine
0N/A * | commentLine
0N/A * knownLine := flag "KNOWN" EOL
0N/A * warnLine := flag "WARN" EOL
0N/A * ignoreLine := flag "IGNORE" EOL
0N/A * errorLine := flag "ERROR" EOL
0N/A * aliasLine := flag "ALIASED_TO" flag EOL
0N/A * predicateLine := flag "IF_SERVER_CLASS" flag EOL
0N/A * commentLine := "#" text EOL
0N/A * flag := "-" identifier
0N/A *
0N/A * The semantics are that when someone specifies a flag on the command line:
0N/A * - if the flag appears on a knownLine, then the identifier is used as
0N/A * the name of the directory holding the JVM library (the name of the JVM).
0N/A * - if the flag appears as the first flag on an aliasLine, the identifier
0N/A * of the second flag is used as the name of the JVM.
0N/A * - if the flag appears on a warnLine, the identifier is used as the
0N/A * name of the JVM, but a warning is generated.
0N/A * - if the flag appears on an ignoreLine, the identifier is recognized as the
0N/A * name of a JVM, but the identifier is ignored and the default vm used
0N/A * - if the flag appears on an errorLine, an error is generated.
0N/A * - if the flag appears as the first flag on a predicateLine, and
0N/A * the machine on which you are running passes the predicate indicated,
0N/A * then the identifier of the second flag is used as the name of the JVM,
0N/A * otherwise the identifier of the first flag is used as the name of the JVM.
0N/A * If no flag is given on the command line, the first vmLine of the jvm.cfg
0N/A * file determines the name of the JVM.
0N/A * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
0N/A * since they only make sense if someone hasn't specified the name of the
0N/A * JVM on the command line.
0N/A *
0N/A * The intent of the jvm.cfg file is to allow several JVM libraries to
0N/A * be installed in different subdirectories of a single JRE installation,
0N/A * for space-savings and convenience in testing.
0N/A * The intent is explicitly not to provide a full aliasing or predicate
0N/A * mechanism.
0N/A */
0N/Ajint
4680N/AReadKnownVMs(const char *jvmCfgName, jboolean speculative)
0N/A{
0N/A FILE *jvmCfg;
0N/A char line[MAXPATHLEN+20];
0N/A int cnt = 0;
0N/A int lineno = 0;
0N/A jlong start, end;
0N/A int vmType;
0N/A char *tmpPtr;
0N/A char *altVMName = NULL;
0N/A char *serverClassVMName = NULL;
0N/A static char *whiteSpace = " \t";
0N/A if (JLI_IsTraceLauncher()) {
0N/A start = CounterGet();
0N/A }
0N/A
0N/A jvmCfg = fopen(jvmCfgName, "r");
0N/A if (jvmCfg == NULL) {
0N/A if (!speculative) {
517N/A JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);
0N/A exit(1);
0N/A } else {
0N/A return -1;
0N/A }
0N/A }
0N/A while (fgets(line, sizeof(line), jvmCfg) != NULL) {
0N/A vmType = VM_UNKNOWN;
0N/A lineno++;
0N/A if (line[0] == '#')
0N/A continue;
0N/A if (line[0] != '-') {
517N/A JLI_ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);
0N/A }
0N/A if (cnt >= knownVMsLimit) {
0N/A GrowKnownVMs(cnt);
0N/A }
0N/A line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */
0N/A tmpPtr = line + JLI_StrCSpn(line, whiteSpace);
0N/A if (*tmpPtr == 0) {
517N/A JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
0N/A } else {
0N/A /* Null-terminate this string for JLI_StringDup below */
0N/A *tmpPtr++ = 0;
0N/A tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
0N/A if (*tmpPtr == 0) {
517N/A JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
0N/A } else {
0N/A if (!JLI_StrCCmp(tmpPtr, "KNOWN")) {
0N/A vmType = VM_KNOWN;
0N/A } else if (!JLI_StrCCmp(tmpPtr, "ALIASED_TO")) {
0N/A tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
0N/A if (*tmpPtr != 0) {
0N/A tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
0N/A }
0N/A if (*tmpPtr == 0) {
517N/A JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
0N/A } else {
0N/A /* Null terminate altVMName */
0N/A altVMName = tmpPtr;
0N/A tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
0N/A *tmpPtr = 0;
0N/A vmType = VM_ALIASED_TO;
0N/A }
0N/A } else if (!JLI_StrCCmp(tmpPtr, "WARN")) {
0N/A vmType = VM_WARN;
0N/A } else if (!JLI_StrCCmp(tmpPtr, "IGNORE")) {
0N/A vmType = VM_IGNORE;
0N/A } else if (!JLI_StrCCmp(tmpPtr, "ERROR")) {
0N/A vmType = VM_ERROR;
0N/A } else if (!JLI_StrCCmp(tmpPtr, "IF_SERVER_CLASS")) {
0N/A tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
0N/A if (*tmpPtr != 0) {
0N/A tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
0N/A }
0N/A if (*tmpPtr == 0) {
517N/A JLI_ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName);
0N/A } else {
0N/A /* Null terminate server class VM name */
0N/A serverClassVMName = tmpPtr;
0N/A tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
0N/A *tmpPtr = 0;
0N/A vmType = VM_IF_SERVER_CLASS;
0N/A }
0N/A } else {
517N/A JLI_ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);
0N/A vmType = VM_KNOWN;
0N/A }
0N/A }
0N/A }
0N/A
0N/A JLI_TraceLauncher("jvm.cfg[%d] = ->%s<-\n", cnt, line);
0N/A if (vmType != VM_UNKNOWN) {
0N/A knownVMs[cnt].name = JLI_StringDup(line);
0N/A knownVMs[cnt].flag = vmType;
0N/A switch (vmType) {
0N/A default:
0N/A break;
0N/A case VM_ALIASED_TO:
0N/A knownVMs[cnt].alias = JLI_StringDup(altVMName);
0N/A JLI_TraceLauncher(" name: %s vmType: %s alias: %s\n",
0N/A knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias);
0N/A break;
0N/A case VM_IF_SERVER_CLASS:
0N/A knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName);
0N/A JLI_TraceLauncher(" name: %s vmType: %s server_class: %s\n",
0N/A knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class);
0N/A break;
0N/A }
0N/A cnt++;
0N/A }
0N/A }
0N/A fclose(jvmCfg);
0N/A knownVMsCount = cnt;
0N/A
0N/A if (JLI_IsTraceLauncher()) {
0N/A end = CounterGet();
0N/A printf("%ld micro seconds to parse jvm.cfg\n",
0N/A (long)(jint)Counter2Micros(end-start));
0N/A }
0N/A
0N/A return cnt;
0N/A}
0N/A
0N/A
0N/Astatic void
0N/AGrowKnownVMs(int minimum)
0N/A{
0N/A struct vmdesc* newKnownVMs;
0N/A int newMax;
0N/A
0N/A newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit));
0N/A if (newMax <= minimum) {
0N/A newMax = minimum;
0N/A }
0N/A newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc));
0N/A if (knownVMs != NULL) {
0N/A memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc));
0N/A }
0N/A JLI_MemFree(knownVMs);
0N/A knownVMs = newKnownVMs;
0N/A knownVMsLimit = newMax;
0N/A}
0N/A
0N/A
0N/A/* Returns index of VM or -1 if not found */
0N/Astatic int
0N/AKnownVMIndex(const char* name)
0N/A{
0N/A int i;
0N/A if (JLI_StrCCmp(name, "-J") == 0) name += 2;
0N/A for (i = 0; i < knownVMsCount; i++) {
0N/A if (!JLI_StrCmp(name, knownVMs[i].name)) {
0N/A return i;
0N/A }
0N/A }
0N/A return -1;
0N/A}
0N/A
0N/Astatic void
0N/AFreeKnownVMs()
0N/A{
0N/A int i;
0N/A for (i = 0; i < knownVMsCount; i++) {
0N/A JLI_MemFree(knownVMs[i].name);
0N/A knownVMs[i].name = NULL;
0N/A }
0N/A JLI_MemFree(knownVMs);
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Displays the splash screen according to the jar file name
0N/A * and image file names stored in environment variables
0N/A */
4680N/Avoid
0N/AShowSplashScreen()
0N/A{
0N/A const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
0N/A const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY);
0N/A int data_size;
0N/A void *image_data;
0N/A if (jar_name) {
0N/A image_data = JLI_JarUnpackFile(jar_name, file_name, &data_size);
0N/A if (image_data) {
0N/A DoSplashInit();
0N/A DoSplashLoadMemory(image_data, data_size);
0N/A JLI_MemFree(image_data);
0N/A }
0N/A } else if (file_name) {
0N/A DoSplashInit();
0N/A DoSplashLoadFile(file_name);
0N/A } else {
0N/A return;
0N/A }
0N/A DoSplashSetFileJarName(file_name, jar_name);
0N/A
0N/A /*
0N/A * Done with all command line processing and potential re-execs so
0N/A * clean up the environment.
0N/A */
0N/A (void)UnsetEnv(ENV_ENTRY);
0N/A (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);
0N/A (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);
0N/A
0N/A JLI_MemFree(splash_jar_entry);
0N/A JLI_MemFree(splash_file_entry);
0N/A
0N/A}
0N/A
0N/Aconst char*
0N/AGetDotVersion()
0N/A{
0N/A return _dVersion;
0N/A}
0N/A
0N/Aconst char*
0N/AGetFullVersion()
0N/A{
0N/A return _fVersion;
0N/A}
0N/A
0N/Aconst char*
0N/AGetProgramName()
0N/A{
0N/A return _program_name;
0N/A}
0N/A
0N/Aconst char*
0N/AGetLauncherName()
0N/A{
0N/A return _launcher_name;
0N/A}
0N/A
0N/Ajint
0N/AGetErgoPolicy()
0N/A{
0N/A return _ergo_policy;
0N/A}
0N/A
0N/Ajboolean
0N/AIsJavaArgs()
0N/A{
0N/A return _is_java_args;
0N/A}
0N/A
0N/Astatic jboolean
0N/AIsWildCardEnabled()
0N/A{
0N/A return _wc_enabled;
0N/A}
0N/A
4680N/Aint
4680N/AContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
4680N/A int argc, char **argv,
3408N/A int mode, char *what, int ret)
0N/A{
0N/A
0N/A /*
0N/A * If user doesn't specify stack size, check if VM has a preference.
0N/A * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
0N/A * return its default stack size through the init args structure.
0N/A */
0N/A if (threadStackSize == 0) {
0N/A struct JDK1_1InitArgs args1_1;
0N/A memset((void*)&args1_1, 0, sizeof(args1_1));
0N/A args1_1.version = JNI_VERSION_1_1;
0N/A ifn->GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */
0N/A if (args1_1.javaStackSize > 0) {
0N/A threadStackSize = args1_1.javaStackSize;
0N/A }
0N/A }
0N/A
0N/A { /* Create a new thread to create JVM and invoke main method */
0N/A JavaMainArgs args;
0N/A int rslt;
0N/A
0N/A args.argc = argc;
0N/A args.argv = argv;
3408N/A args.mode = mode;
3408N/A args.what = what;
0N/A args.ifn = *ifn;
0N/A
0N/A rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args);
0N/A /* If the caller has deemed there is an error we
0N/A * simply return that, otherwise we return the value of
0N/A * the callee
0N/A */
0N/A return (ret != 0) ? ret : rslt;
0N/A }
0N/A}
0N/A
0N/Astatic void
0N/ADumpState()
0N/A{
0N/A if (!JLI_IsTraceLauncher()) return ;
0N/A printf("Launcher state:\n");
0N/A printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");
0N/A printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");
0N/A printf("\tprogram name:%s\n", GetProgramName());
0N/A printf("\tlauncher name:%s\n", GetLauncherName());
0N/A printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
0N/A printf("\tfullversion:%s\n", GetFullVersion());
0N/A printf("\tdotversion:%s\n", GetDotVersion());
0N/A printf("\tergo_policy:");
0N/A switch(GetErgoPolicy()) {
0N/A case NEVER_SERVER_CLASS:
0N/A printf("NEVER_ACT_AS_A_SERVER_CLASS_MACHINE\n");
0N/A break;
0N/A case ALWAYS_SERVER_CLASS:
0N/A printf("ALWAYS_ACT_AS_A_SERVER_CLASS_MACHINE\n");
0N/A break;
0N/A default:
0N/A printf("DEFAULT_ERGONOMICS_POLICY\n");
0N/A }
0N/A}
0N/A
0N/A/*
0N/A * Return JNI_TRUE for an option string that has no effect but should
0N/A * _not_ be passed on to the vm; return JNI_FALSE otherwise. On
0N/A * Solaris SPARC, this screening needs to be done if:
1945N/A * -d32 or -d64 is passed to a binary with an unmatched data model
1945N/A * (the exec in CreateExecutionEnvironment removes -d<n> options and points the
1945N/A * exec to the proper binary). In the case of when the data model and the
1945N/A * requested version is matched, an exec would not occur, and these options
1945N/A * were erroneously passed to the vm.
0N/A */
0N/Ajboolean
0N/ARemovableOption(char * option)
0N/A{
0N/A /*
0N/A * Unconditionally remove both -d32 and -d64 options since only
0N/A * the last such options has an effect; e.g.
0N/A * java -d32 -d64 -d32 -version
0N/A * is equivalent to
0N/A * java -d32 -version
0N/A */
0N/A
0N/A if( (JLI_StrCCmp(option, "-d32") == 0 ) ||
0N/A (JLI_StrCCmp(option, "-d64") == 0 ) )
0N/A return JNI_TRUE;
0N/A else
0N/A return JNI_FALSE;
0N/A}
0N/A
0N/A/*
0N/A * A utility procedure to always print to stderr
0N/A */
0N/Avoid
517N/AJLI_ReportMessage(const char* fmt, ...)
0N/A{
0N/A va_list vl;
0N/A va_start(vl, fmt);
0N/A vfprintf(stderr, fmt, vl);
0N/A fprintf(stderr, "\n");
0N/A va_end(vl);
0N/A}