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