java.c revision 16
0N/A/*
0N/A * Copyright 1995-2007 Sun Microsystems, Inc. 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
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun 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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any 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
0N/A * CheckJVMType removes vm style options and TranslateApplicationArgs
0N/A * removes "-J" prefixes. On unix platforms, the
0N/A * CreateExecutionEnvironment function from the unix java_md.c file
0N/A * processes and removes -d<n> options. However, in case
0N/A * CreateExecutionEnvironment does not need to exec because
0N/A * LD_LIBRARY_PATH is set acceptably and the data model does not need
0N/A * to be changed, ParseArguments will screen out the redundant -d<n>
0N/A * options and prevent them from being passed to the vm; this is done
0N/A * by RemovableOption.
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
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*/
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);
0N/Astatic jboolean ParseArguments(int *pargc, char ***pargv, char **pjarfile,
0N/A char **pclassname, int *pret, const char *jvmpath);
0N/Astatic jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
0N/A InvocationFunctions *ifn);
0N/Astatic jstring NewPlatformString(JNIEnv *env, char *s);
0N/Astatic jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
0N/Astatic jclass LoadClass(JNIEnv *env, char *name);
0N/Astatic jstring GetMainClassName(JNIEnv *env, char *jarname);
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);
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 void ShowSplashScreen();
0N/Astatic jboolean IsWildCardEnabled();
0N/A
0N/A#define ARG_CHECK(n, f, a) if (n < 1) { \
0N/A 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 */
0N/Astatic jlong threadStackSize = 0; /* stack size of the new thread */
0N/A
0N/Aint JNICALL JavaMain(void * args); /* entry point */
0N/A
0N/Atypedef struct {
0N/A int argc;
0N/A char ** argv;
0N/A char * jarfile;
0N/A char * classname;
0N/A InvocationFunctions ifn;
0N/A} JavaMainArgs;
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{
0N/A char *jarfile = 0;
0N/A char *classname = 0;
0N/A char *cpath = 0;
0N/A char *main_class = NULL;
0N/A int ret;
0N/A InvocationFunctions ifn;
0N/A jlong start, end;
0N/A char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN];
0N/A char ** original_argv = argv;
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();
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 /* copy original argv */
0N/A JLI_TraceLauncher("Command line Args:\n");
0N/A original_argv = (JLI_CopyArgs(argc, (const char**)argv));
0N/A
0N/A CreateExecutionEnvironment(&argc, &argv,
0N/A jrepath, sizeof(jrepath),
0N/A jvmpath, sizeof(jvmpath),
0N/A original_argv);
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
0N/A /*
0N/A * Parse command line options; if the return value of
0N/A * ParseArguments is false, the program should exit.
0N/A */
0N/A if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret, jvmpath)) {
0N/A return(ret);
0N/A }
0N/A
0N/A /* Override class path if -jar flag was specified */
0N/A if (jarfile != 0) {
0N/A SetClassPath(jarfile);
0N/A }
0N/A
0N/A /* set the -Dsun.java.command pseudo property */
0N/A SetJavaCommandLineProp(classname, jarfile, 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
0N/A /* Show the splash screen if needed */
0N/A ShowSplashScreen();
0N/A
0N/A return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
0N/A
0N/A}
0N/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;
0N/A char *jarfile = args->jarfile;
0N/A char *classname = args->classname;
0N/A InvocationFunctions ifn = args->ifn;
0N/A
0N/A JavaVM *vm = 0;
0N/A JNIEnv *env = 0;
0N/A jstring mainClassName;
0N/A jclass mainClass;
0N/A jmethodID mainID;
0N/A jobjectArray mainArgs;
0N/A int ret = 0;
0N/A jlong start, end;
0N/A
0N/A
0N/A /* Initialize the virtual machine */
0N/A
0N/A start = CounterGet();
0N/A if (!InitializeJVM(&vm, &env, &ifn)) {
0N/A ReportErrorMessage(JVM_ERROR1);
0N/A exit(1);
0N/A }
0N/A
0N/A if (printVersion || showVersion) {
0N/A PrintJavaVersion(env, showVersion);
0N/A if ((*env)->ExceptionOccurred(env)) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A if (printVersion) {
0N/A ret = 0;
0N/A goto leave;
0N/A }
0N/A }
0N/A
0N/A /* If the user specified neither a class name nor a JAR file */
0N/A if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
0N/A PrintUsage(env, printXUsage);
0N/A if ((*env)->ExceptionOccurred(env)) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A ret=1;
0N/A }
0N/A goto 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
0N/A /* At this stage, argc/argv have the applications' arguments */
0N/A if (JLI_IsTraceLauncher()){
0N/A int i;
0N/A printf("Main-Class is '%s'\n", classname ? classname : "");
0N/A printf("Apps' 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 */
0N/A if (jarfile != 0) {
0N/A mainClassName = GetMainClassName(env, jarfile);
0N/A if ((*env)->ExceptionOccurred(env)) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A if (mainClassName == NULL) {
0N/A ReportErrorMessage(JAR_ERROR1,jarfile, GEN_ERROR);
0N/A goto leave;
0N/A }
0N/A classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
0N/A if (classname == NULL) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A mainClass = LoadClass(env, classname);
0N/A if(mainClass == NULL) { /* exception occured */
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(CLS_ERROR1);
0N/A goto leave;
0N/A }
0N/A (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
0N/A } else {
0N/A mainClassName = NewPlatformString(env, classname);
0N/A if (mainClassName == NULL) {
0N/A ReportErrorMessage(CLS_ERROR2, classname, GEN_ERROR);
0N/A goto leave;
0N/A }
0N/A classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
0N/A if (classname == NULL) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A mainClass = LoadClass(env, classname);
0N/A if(mainClass == NULL) { /* exception occured */
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(CLS_ERROR1);
0N/A goto leave;
0N/A }
0N/A (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
0N/A }
0N/A
0N/A /* Get the application's main method */
0N/A mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
0N/A "([Ljava/lang/String;)V");
0N/A if (mainID == NULL) {
0N/A if ((*env)->ExceptionOccurred(env)) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A } else {
0N/A ReportErrorMessage(CLS_ERROR3);
0N/A }
0N/A goto leave;
0N/A }
0N/A
0N/A { /* Make sure the main method is public */
0N/A jint mods;
0N/A jmethodID mid;
0N/A jobject obj = (*env)->ToReflectedMethod(env, mainClass,
0N/A mainID, JNI_TRUE);
0N/A
0N/A if( obj == NULL) { /* exception occurred */
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A
0N/A mid =
0N/A (*env)->GetMethodID(env,
0N/A (*env)->GetObjectClass(env, obj),
0N/A "getModifiers", "()I");
0N/A if ((*env)->ExceptionOccurred(env)) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
0N/A
0N/A mods = (*env)->CallIntMethod(env, obj, mid);
0N/A if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */
0N/A ReportErrorMessage(CLS_ERROR4);
0N/A goto leave;
0N/A }
0N/A }
0N/A
0N/A /* Build argument array */
0N/A mainArgs = NewPlatformStringArray(env, argv, argc);
0N/A if (mainArgs == NULL) {
0N/A ReportExceptionDescription(env);
0N/A ReportErrorMessage(JNI_ERROR);
0N/A goto leave;
0N/A }
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;
0N/A
0N/A /*
0N/A * Detach the main thread so that it appears to have ended when
0N/A * the application's main method exits. This will invoke the
0N/A * uncaught exception handler machinery if main threw an
0N/A * exception. An uncaught exception handler cannot change the
0N/A * launcher's return code except by calling System.exit.
0N/A */
0N/A if ((*vm)->DetachCurrentThread(vm) != 0) {
0N/A ReportErrorMessage(JVM_ERROR2);
0N/A ret = 1;
0N/A goto leave;
0N/A }
0N/A
0N/A leave:
0N/A /*
0N/A * Wait for all non-daemon threads to end, then destroy the VM.
0N/A * This will actually create a trivial new Java waiter thread
0N/A * named "DestroyJavaVM", but this will be seen as a different
0N/A * thread from the one that executed main, even though they are
0N/A * the same C thread. This allows mainThread.join() and
0N/A * mainThread.isAlive() to work as expected.
0N/A */
0N/A (*vm)->DestroyJavaVM(vm);
0N/A
0N/A return ret;
0N/A}
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) {
0N/A 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) {
0N/A 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) {
0N/A 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) {
0N/A 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
0N/Aparse_stack_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) {
0N/A jlong tmp;
0N/A if (parse_stack_size(str + 4, &tmp)) {
0N/A threadStackSize = tmp;
0N/A }
0N/A }
0N/A}
0N/A
0N/Astatic void
0N/ASetClassPath(const char *s)
0N/A{
0N/A char *def;
0N/A s = JLI_WildcardExpandClasspath(s);
0N/A def = JLI_MemAlloc(JLI_StrLen(s) + 40);
0N/A sprintf(def, "-Djava.class.path=%s", s);
0N/A AddOption(def, NULL);
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)
0N/A ReportErrorMessage(JAR_ERROR2, operand);
0N/A else
0N/A 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)) {
0N/A 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 {
0N/A 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 */
0N/A if (info.main_class != NULL)
0N/A (void)JLI_StrCat(env_entry, info.main_class);
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
0N/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
0N/AParseArguments(int *pargc, char ***pargv, char **pjarfile,
0N/A char **pclassname, int *pret, const char *jvmpath)
0N/A{
0N/A int argc = *pargc;
0N/A char **argv = *pargv;
0N/A jboolean jarflag = JNI_FALSE;
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);
0N/A argv++; --argc;
0N/A } else if (JLI_StrCmp(arg, "-jar") == 0) {
0N/A ARG_CHECK (argc, ARG_ERROR2, arg);
0N/A jarflag = JNI_TRUE;
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/*
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) {
0N/A 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 */
0N/A 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 */
0N/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) {
0N/A if (jarflag) {
0N/A *pjarfile = *argv++;
0N/A *pclassname = 0;
0N/A } else {
0N/A *pjarfile = 0;
0N/A *pclassname = *argv++;
0N/A }
0N/A *pargc = argc;
0N/A *pargv = argv;
0N/A }
0N/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
0N/A
0N/A#define NULL_CHECK0(e) if ((e) == 0) { \
0N/A ReportErrorMessage(JNI_ERROR); \
0N/A return 0; \
0N/A }
0N/A
0N/A#define NULL_CHECK(e) if ((e) == 0) { \
0N/A ReportErrorMessage(JNI_ERROR); \
0N/A return; \
0N/A }
0N/A
0N/Astatic jstring platformEncoding = NULL;
0N/Astatic jstring getPlatformEncoding(JNIEnv *env) {
0N/A if (platformEncoding == NULL) {
0N/A jstring propname = (*env)->NewStringUTF(env, "sun.jnu.encoding");
0N/A if (propname) {
0N/A jclass cls;
0N/A jmethodID mid;
0N/A NULL_CHECK0 (cls = (*env)->FindClass(env, "java/lang/System"));
0N/A NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
0N/A env, cls,
0N/A "getProperty",
0N/A "(Ljava/lang/String;)Ljava/lang/String;"));
0N/A platformEncoding = (*env)->CallStaticObjectMethod (
0N/A env, cls, mid, propname);
0N/A }
0N/A }
0N/A return platformEncoding;
0N/A}
0N/A
0N/Astatic jboolean isEncodingSupported(JNIEnv *env, jstring enc) {
0N/A jclass cls;
0N/A jmethodID mid;
0N/A NULL_CHECK0 (cls = (*env)->FindClass(env, "java/nio/charset/Charset"));
0N/A NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
0N/A env, cls,
0N/A "isSupported",
0N/A "(Ljava/lang/String;)Z"));
0N/A return (*env)->CallStaticBooleanMethod(env, cls, mid, enc);
0N/A}
0N/A
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 jclass cls;
0N/A jmethodID mid;
0N/A jbyteArray ary;
0N/A jstring enc;
0N/A
0N/A if (s == NULL)
0N/A return 0;
0N/A enc = getPlatformEncoding(env);
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)) {
0N/A if (isEncodingSupported(env, enc) == JNI_TRUE) {
0N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
0N/A "([BLjava/lang/String;)V"));
0N/A str = (*env)->NewObject(env, cls, mid, ary, enc);
0N/A } else {
0N/A /*If the encoding specified in sun.jnu.encoding is not
0N/A endorsed by "Charset.isSupported" we have to fall back
0N/A to use String(byte[]) explicitly here without specifying
0N/A the encoding name, in which the StringCoding class will
0N/A pickup the iso-8859-1 as the fallback converter for us.
0N/A */
0N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
0N/A "([B)V"));
0N/A str = (*env)->NewObject(env, cls, mid, ary);
0N/A }
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 */
0N/Astatic jobjectArray
0N/ANewPlatformStringArray(JNIEnv *env, char **strv, int strc)
0N/A{
0N/A jarray cls;
0N/A jarray ary;
0N/A int i;
0N/A
0N/A NULL_CHECK0(cls = (*env)->FindClass(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/*
0N/A * Loads a class, convert the '.' to '/'.
0N/A */
0N/Astatic jclass
0N/ALoadClass(JNIEnv *env, char *name)
0N/A{
0N/A char *buf = JLI_MemAlloc(JLI_StrLen(name) + 1);
0N/A char *s = buf, *t = name, c;
0N/A jclass cls;
0N/A jlong start, end;
0N/A
0N/A if (JLI_IsTraceLauncher())
0N/A start = CounterGet();
0N/A
0N/A do {
0N/A c = *t++;
0N/A *s++ = (c == '.') ? '/' : c;
0N/A } while (c != '\0');
0N/A cls = (*env)->FindClass(env, buf);
0N/A JLI_MemFree(buf);
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));
0N/A printf("----_JAVA_LAUNCHER_DEBUG----\n");
0N/A }
0N/A
0N/A return cls;
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Returns the main class name for the specified jar file.
0N/A */
0N/Astatic jstring
0N/AGetMainClassName(JNIEnv *env, char *jarname)
0N/A{
0N/A#define MAIN_CLASS "Main-Class"
0N/A jclass cls;
0N/A jmethodID mid;
0N/A jobject jar, man, attr;
0N/A jstring str, result = 0;
0N/A
0N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/util/jar/JarFile"));
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
0N/A "(Ljava/lang/String;)V"));
0N/A NULL_CHECK0(str = NewPlatformString(env, jarname));
0N/A NULL_CHECK0(jar = (*env)->NewObject(env, cls, mid, str));
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "getManifest",
0N/A "()Ljava/util/jar/Manifest;"));
0N/A man = (*env)->CallObjectMethod(env, jar, mid);
0N/A if (man != 0) {
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env,
0N/A (*env)->GetObjectClass(env, man),
0N/A "getMainAttributes",
0N/A "()Ljava/util/jar/Attributes;"));
0N/A attr = (*env)->CallObjectMethod(env, man, mid);
0N/A if (attr != 0) {
0N/A NULL_CHECK0(mid = (*env)->GetMethodID(env,
0N/A (*env)->GetObjectClass(env, attr),
0N/A "getValue",
0N/A "(Ljava/lang/String;)Ljava/lang/String;"));
0N/A NULL_CHECK0(str = NewPlatformString(env, MAIN_CLASS));
0N/A result = (*env)->CallObjectMethod(env, attr, mid, str);
0N/A }
0N/A }
0N/A return result;
0N/A}
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') {
0N/A 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))) {
0N/A 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
0N/ASetJavaCommandLineProp(char *classname, char *jarfile,
0N/A 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
0N/A if (classname == NULL && jarfile == 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 /* if the class name is not set, then use the jarfile name */
0N/A if (classname == NULL) {
0N/A classname = jarfile;
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 */
0N/A len = JLI_StrLen(classname);
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);
0N/A JLI_StrCat(javaCommand, classname);
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 */
0N/Avoid SetJavaLauncherProp() {
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
0N/A NULL_CHECK(ver = (*env)->FindClass(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/*
0N/A * Prints default usage or the Xusage message, see sun.launcher.LauncherHelp.java
0N/A */
0N/Astatic void
0N/APrintUsage(JNIEnv* env, jboolean doXUsage)
0N/A{
0N/A jclass cls;
0N/A jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage;
0N/A jstring jprogname, vm1, vm2;
0N/A int i;
0N/A
0N/A NULL_CHECK(cls = (*env)->FindClass(env, "sun/launcher/LauncherHelp"));
0N/A
0N/A
0N/A if (doXUsage) {
0N/A NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,
0N/A "printXUsageMessage", "(Z)V"));
0N/A (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, JNI_TRUE);
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*/
0N/A (*env)->CallStaticVoidMethod(env, cls, printHelp, JNI_TRUE);
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
0N/AReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative)
0N/A{
0N/A FILE *jvmCfg;
0N/A char jvmCfgName[MAXPATHLEN+20];
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 JLI_StrCpy(jvmCfgName, jrepath);
0N/A JLI_StrCat(jvmCfgName, FILESEP "lib" FILESEP);
0N/A JLI_StrCat(jvmCfgName, arch);
0N/A JLI_StrCat(jvmCfgName, FILESEP "jvm.cfg");
0N/A
0N/A jvmCfg = fopen(jvmCfgName, "r");
0N/A if (jvmCfg == NULL) {
0N/A if (!speculative) {
0N/A 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] != '-') {
0N/A 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) {
0N/A 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) {
0N/A 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) {
0N/A 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) {
0N/A 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 {
0N/A 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 */
0N/Astatic void
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
0N/Astatic int
0N/AContinueInNewThread(InvocationFunctions* ifn, int argc,
0N/A char **argv, char *jarfile, char *classname, 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;
0N/A args.jarfile = jarfile;
0N/A args.classname = classname;
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:
0N/A * 1) LD_LIBRARY_PATH does _not_ need to be reset and
0N/A * 2) -d32 or -d64 is passed to a binary with a matching data model
0N/A * (the exec in SetLibraryPath removes -d<n> options and points the
0N/A * exec to the proper binary). When this exec is not done, these options
0N/A * would end up getting passed onto 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
0N/AReportMessage(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}