java.c revision 1934
1892N/A/*
1892N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1892N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1892N/A *
1892N/A * This code is free software; you can redistribute it and/or modify it
1892N/A * under the terms of the GNU General Public License version 2 only, as
1892N/A * published by the Free Software Foundation.
1892N/A *
1892N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1892N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1892N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1892N/A * version 2 for more details (a copy is included in the LICENSE file that
1892N/A * accompanied this code).
1892N/A *
1892N/A * You should have received a copy of the GNU General Public License version
1892N/A * 2 along with this work; if not, write to the Free Software Foundation,
1892N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1892N/A *
1892N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1892N/A * or visit www.oracle.com if you need additional information or have any
1892N/A * questions.
1892N/A *
1892N/A */
1892N/A
1892N/A/*
1892N/A * Gamma (Hotspot internal engineering test) launcher based on 6.0u22 JDK,
1892N/A * search "GAMMA" for gamma specific changes.
1892N/A *
1892N/A * GAMMA: gamma launcher is much simpler than regular java launcher in that
1892N/A * JVM is either statically linked in or it is installed in the
1892N/A * same directory where the launcher exists, so we don't have to
1892N/A * worry about choosing the right JVM based on command line flag, jar
1892N/A * file and/or ergonomics. Intead of removing unused logic from source
1892N/A * they are commented out with #ifndef GAMMA, hopefully it'll be easier
1892N/A * to maintain this file in sync with regular JDK launcher.
1892N/A */
1892N/A
1892N/A/*
1892N/A * Shared source for 'java' command line tool.
1892N/A *
1892N/A * If JAVA_ARGS is defined, then acts as a launcher for applications. For
1892N/A * instance, the JDK command line tools such as javac and javadoc (see
1892N/A * makefiles for more details) are built with this program. Any arguments
1892N/A * prefixed with '-J' will be passed directly to the 'java' command.
1892N/A */
1892N/A
1892N/A#ifdef GAMMA
1892N/A# ifdef JAVA_ARGS
1892N/A# error Do NOT define JAVA_ARGS when building gamma launcher
1892N/A# endif
1892N/A# if !defined(LINK_INTO_AOUT) && !defined(LINK_INTO_LIBJVM)
1892N/A# error Either LINK_INTO_AOUT or LINK_INTO_LIBJVM must be defined
1892N/A# endif
1892N/A#endif
1892N/A
1892N/A/*
1892N/A * One job of the launcher is to remove command line options which the
1892N/A * vm does not understand and will not process. These options include
1892N/A * options which select which style of vm is run (e.g. -client and
1892N/A * -server) as well as options which select the data model to use.
1892N/A * Additionally, for tools which invoke an underlying vm "-J-foo"
1892N/A * options are turned into "-foo" options to the vm. This option
1892N/A * filtering is handled in a number of places in the launcher, some of
1892N/A * it in machine-dependent code. In this file, the function
1892N/A * CheckJVMType removes vm style options and TranslateApplicationArgs
1892N/A * removes "-J" prefixes. On unix platforms, the
1892N/A * CreateExecutionEnvironment function from the unix java_md.c file
1892N/A * processes and removes -d<n> options. However, in case
1892N/A * CreateExecutionEnvironment does not need to exec because
1892N/A * LD_LIBRARY_PATH is set acceptably and the data model does not need
1892N/A * to be changed, ParseArguments will screen out the redundant -d<n>
1892N/A * options and prevent them from being passed to the vm; this is done
1892N/A * by using the machine-dependent call
1892N/A * RemovableMachineDependentOption.
1892N/A */
1892N/A
1892N/A#include <stdio.h>
1892N/A#include <stdlib.h>
1892N/A#include <string.h>
1892N/A
1892N/A#include <jni.h>
1892N/A#include <jvm.h>
1892N/A#include "java.h"
1892N/A#ifndef GAMMA
1892N/A#include "manifest_info.h"
1892N/A#include "version_comp.h"
1892N/A#include "splashscreen.h"
1892N/A#endif
1892N/A#include "wildcard.h"
1892N/A
1892N/A#ifndef FULL_VERSION
1892N/A#define FULL_VERSION JDK_MAJOR_VERSION "." JDK_MINOR_VERSION
1892N/A#endif
1892N/A
1892N/A/*
1892N/A * The following environment variable is used to influence the behavior
1892N/A * of the jre exec'd through the SelectVersion routine. The command line
1892N/A * options which specify the version are not passed to the exec'd version,
1892N/A * because that jre may be an older version which wouldn't recognize them.
1892N/A * This environment variable is known to this (and later) version and serves
1892N/A * to suppress the version selection code. This is not only for efficiency,
1892N/A * but also for correctness, since any command line options have been
1892N/A * removed which would cause any value found in the manifest to be used.
1892N/A * This would be incorrect because the command line options are defined
1892N/A * to take precedence.
1892N/A *
1892N/A * The value associated with this environment variable is the MainClass
1892N/A * name from within the executable jar file (if any). This is strictly a
1892N/A * performance enhancement to avoid re-reading the jar file manifest.
1892N/A *
1892N/A * A NOTE TO DEVELOPERS: For performance reasons it is important that
1892N/A * the program image remain relatively small until after SelectVersion
1892N/A * CreateExecutionEnvironment have finished their possibly recursive
1892N/A * processing. Watch everything, but resist all temptations to use Java
1892N/A * interfaces.
1892N/A */
1892N/A#define ENV_ENTRY "_JAVA_VERSION_SET"
1892N/A
1892N/A#ifndef GAMMA
1892N/A#define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE"
1892N/A#define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR"
1892N/A#endif
1892N/A
1892N/Astatic jboolean printVersion = JNI_FALSE; /* print and exit */
1892N/Astatic jboolean showVersion = JNI_FALSE; /* print but continue */
1892N/Astatic char *progname;
1892N/Ajboolean _launcher_debug = JNI_FALSE;
1892N/A
1892N/A#ifndef GAMMA
1892N/A/*
1892N/A * Entries for splash screen environment variables.
1892N/A * putenv is performed in SelectVersion. We need
1892N/A * them in memory until UnsetEnv, so they are made static
1892N/A * global instead of auto local.
1892N/A */
1892N/Astatic char* splash_file_entry = NULL;
1892N/Astatic char* splash_jar_entry = NULL;
1892N/A#endif
1892N/A
1892N/A/*
1892N/A * List of VM options to be specified when the VM is created.
1892N/A */
1892N/Astatic JavaVMOption *options;
1892N/Astatic int numOptions, maxOptions;
1892N/A
1892N/A/*
1892N/A * Prototypes for functions internal to launcher.
1892N/A */
1892N/Astatic void SetClassPath(const char *s);
1892N/Astatic void SelectVersion(int argc, char **argv, char **main_class);
1892N/Astatic jboolean ParseArguments(int *pargc, char ***pargv, char **pjarfile,
1892N/A char **pclassname, int *pret, const char *jvmpath);
1892N/Astatic jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
1892N/A InvocationFunctions *ifn);
1892N/Astatic jstring NewPlatformString(JNIEnv *env, char *s);
1892N/Astatic jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
1892N/Astatic jclass LoadClass(JNIEnv *env, char *name);
1892N/Astatic jstring GetMainClassName(JNIEnv *env, char *jarname);
1892N/Astatic void SetJavaCommandLineProp(char* classname, char* jarfile, int argc, char** argv);
1892N/Astatic void SetJavaLauncherProp(void);
1892N/A
1892N/A#ifdef JAVA_ARGS
1892N/Astatic void TranslateApplicationArgs(int *pargc, char ***pargv);
1892N/Astatic jboolean AddApplicationOptions(void);
1892N/A#endif
1892N/A
1892N/Astatic void PrintJavaVersion(JNIEnv *env);
1892N/Astatic void PrintUsage(void);
1892N/Astatic jint PrintXUsage(const char *jvmpath);
1892N/A
1892N/Astatic void SetPaths(int argc, char **argv);
1892N/A
1892N/A#ifndef GAMMA
1892N/A
1892N/A/* Maximum supported entries from jvm.cfg. */
1892N/A#define INIT_MAX_KNOWN_VMS 10
1892N/A/* Values for vmdesc.flag */
1892N/A#define VM_UNKNOWN -1
1892N/A#define VM_KNOWN 0
1892N/A#define VM_ALIASED_TO 1
1892N/A#define VM_WARN 2
1892N/A#define VM_ERROR 3
1892N/A#define VM_IF_SERVER_CLASS 4
1892N/A#define VM_IGNORE 5
1892N/Astruct vmdesc {
1892N/A char *name;
1892N/A int flag;
1892N/A char *alias;
1892N/A char *server_class;
1892N/A};
1892N/Astatic struct vmdesc *knownVMs = NULL;
1892N/Astatic int knownVMsCount = 0;
1892N/Astatic int knownVMsLimit = 0;
1892N/A
1892N/Astatic void GrowKnownVMs();
1892N/Astatic int KnownVMIndex(const char* name);
1892N/Astatic void FreeKnownVMs();
1892N/Astatic void ShowSplashScreen();
1892N/A
1892N/A#endif /* ifndef GAMMA */
1892N/A
1892N/Ajboolean ServerClassMachine();
1892N/A
1892N/A/* flag which if set suppresses error messages from the launcher */
1892N/Astatic int noExitErrorMessage = 0;
1892N/A
1892N/A/*
1892N/A * Running Java code in primordial thread caused many problems. We will
1892N/A * create a new thread to invoke JVM. See 6316197 for more information.
1892N/A */
1892N/Astatic jlong threadStackSize = 0; /* stack size of the new thread */
1892N/A
1892N/Aint JNICALL JavaMain(void * args); /* entry point */
1892N/A
1892N/Astruct JavaMainArgs {
1892N/A int argc;
1892N/A char ** argv;
1892N/A char * jarfile;
1892N/A char * classname;
1892N/A InvocationFunctions ifn;
1892N/A};
1892N/A
1892N/A/*
1892N/A * Entry point.
1892N/A */
1892N/Aint
1892N/Amain(int argc, char ** argv)
1892N/A{
1892N/A char *jarfile = 0;
1892N/A char *classname = 0;
1892N/A char *s = 0;
1892N/A char *main_class = NULL;
1892N/A int ret;
1892N/A InvocationFunctions ifn;
1892N/A jlong start, end;
1892N/A char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN];
1892N/A char ** original_argv = argv;
1892N/A
1892N/A if (getenv("_JAVA_LAUNCHER_DEBUG") != 0) {
1892N/A _launcher_debug = JNI_TRUE;
1892N/A printf("----_JAVA_LAUNCHER_DEBUG----\n");
1892N/A }
1892N/A
1892N/A#ifndef GAMMA
1892N/A /*
1892N/A * Make sure the specified version of the JRE is running.
1892N/A *
1892N/A * There are three things to note about the SelectVersion() routine:
1892N/A * 1) If the version running isn't correct, this routine doesn't
1892N/A * return (either the correct version has been exec'd or an error
1892N/A * was issued).
1892N/A * 2) Argc and Argv in this scope are *not* altered by this routine.
1892N/A * It is the responsibility of subsequent code to ignore the
1892N/A * arguments handled by this routine.
1892N/A * 3) As a side-effect, the variable "main_class" is guaranteed to
1892N/A * be set (if it should ever be set). This isn't exactly the
1892N/A * poster child for structured programming, but it is a small
1892N/A * price to pay for not processing a jar file operand twice.
1892N/A * (Note: This side effect has been disabled. See comment on
1892N/A * bugid 5030265 below.)
1892N/A */
1892N/A SelectVersion(argc, argv, &main_class);
1892N/A#endif /* ifndef GAMMA */
1892N/A
1892N/A /* copy original argv */
1892N/A {
1892N/A int i;
1892N/A original_argv = (char**)JLI_MemAlloc(sizeof(char*)*(argc+1));
1892N/A for(i = 0; i < argc+1; i++)
1892N/A original_argv[i] = argv[i];
1892N/A }
1892N/A
1892N/A CreateExecutionEnvironment(&argc, &argv,
1892N/A jrepath, sizeof(jrepath),
1892N/A jvmpath, sizeof(jvmpath),
1892N/A original_argv);
1892N/A
1934N/A printf("Using java runtime at: %s\n", jrepath);
1934N/A
1892N/A ifn.CreateJavaVM = 0;
1892N/A ifn.GetDefaultJavaVMInitArgs = 0;
1892N/A
1892N/A if (_launcher_debug)
1892N/A start = CounterGet();
1892N/A if (!LoadJavaVM(jvmpath, &ifn)) {
1892N/A exit(6);
1892N/A }
1892N/A if (_launcher_debug) {
1892N/A end = CounterGet();
1892N/A printf("%ld micro seconds to LoadJavaVM\n",
1892N/A (long)(jint)Counter2Micros(end-start));
1892N/A }
1892N/A
1892N/A#ifdef JAVA_ARGS /* javac, jar and friends. */
1892N/A progname = "java";
1892N/A#else /* java, oldjava, javaw and friends */
1892N/A#ifdef PROGNAME
1892N/A progname = PROGNAME;
1892N/A#else
1892N/A progname = *argv;
1892N/A if ((s = strrchr(progname, FILE_SEPARATOR)) != 0) {
1892N/A progname = s + 1;
1892N/A }
1892N/A#endif /* PROGNAME */
1892N/A#endif /* JAVA_ARGS */
1892N/A ++argv;
1892N/A --argc;
1892N/A
1892N/A#ifdef JAVA_ARGS
1892N/A /* Preprocess wrapper arguments */
1892N/A TranslateApplicationArgs(&argc, &argv);
1892N/A if (!AddApplicationOptions()) {
1892N/A exit(1);
1892N/A }
1892N/A#endif
1892N/A
1892N/A /* Set default CLASSPATH */
1892N/A if ((s = getenv("CLASSPATH")) == 0) {
1892N/A s = ".";
1892N/A }
1892N/A#ifndef JAVA_ARGS
1892N/A SetClassPath(s);
1892N/A#endif
1892N/A
1892N/A /*
1892N/A * Parse command line options; if the return value of
1892N/A * ParseArguments is false, the program should exit.
1892N/A */
1892N/A if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret, jvmpath)) {
1892N/A exit(ret);
1892N/A }
1892N/A
1892N/A /* Override class path if -jar flag was specified */
1892N/A if (jarfile != 0) {
1892N/A SetClassPath(jarfile);
1892N/A }
1892N/A
1892N/A /* set the -Dsun.java.command pseudo property */
1892N/A SetJavaCommandLineProp(classname, jarfile, argc, argv);
1892N/A
1892N/A /* Set the -Dsun.java.launcher pseudo property */
1892N/A SetJavaLauncherProp();
1892N/A
1892N/A /* set the -Dsun.java.launcher.* platform properties */
1892N/A SetJavaLauncherPlatformProps();
1892N/A
1892N/A#ifndef GAMMA
1892N/A /* Show the splash screen if needed */
1892N/A ShowSplashScreen();
1892N/A#endif
1892N/A
1892N/A /*
1892N/A * Done with all command line processing and potential re-execs so
1892N/A * clean up the environment.
1892N/A */
1892N/A (void)UnsetEnv(ENV_ENTRY);
1892N/A#ifndef GAMMA
1892N/A (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);
1892N/A (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);
1892N/A
1892N/A JLI_MemFree(splash_jar_entry);
1892N/A JLI_MemFree(splash_file_entry);
1892N/A#endif
1892N/A
1892N/A /*
1892N/A * If user doesn't specify stack size, check if VM has a preference.
1892N/A * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
1892N/A * return its default stack size through the init args structure.
1892N/A */
1892N/A if (threadStackSize == 0) {
1892N/A struct JDK1_1InitArgs args1_1;
1892N/A memset((void*)&args1_1, 0, sizeof(args1_1));
1892N/A args1_1.version = JNI_VERSION_1_1;
1892N/A ifn.GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */
1892N/A if (args1_1.javaStackSize > 0) {
1892N/A threadStackSize = args1_1.javaStackSize;
1892N/A }
1892N/A }
1892N/A
1892N/A { /* Create a new thread to create JVM and invoke main method */
1892N/A struct JavaMainArgs args;
1892N/A
1892N/A args.argc = argc;
1892N/A args.argv = argv;
1892N/A args.jarfile = jarfile;
1892N/A args.classname = classname;
1892N/A args.ifn = ifn;
1892N/A
1892N/A return ContinueInNewThread(JavaMain, threadStackSize, (void*)&args);
1892N/A }
1892N/A}
1892N/A
1892N/Aint JNICALL
1892N/AJavaMain(void * _args)
1892N/A{
1892N/A struct JavaMainArgs *args = (struct JavaMainArgs *)_args;
1892N/A int argc = args->argc;
1892N/A char **argv = args->argv;
1892N/A char *jarfile = args->jarfile;
1892N/A char *classname = args->classname;
1892N/A InvocationFunctions ifn = args->ifn;
1892N/A
1892N/A JavaVM *vm = 0;
1892N/A JNIEnv *env = 0;
1892N/A jstring mainClassName;
1892N/A jclass mainClass;
1892N/A jmethodID mainID;
1892N/A jobjectArray mainArgs;
1892N/A int ret = 0;
1892N/A jlong start, end;
1892N/A
1892N/A /*
1892N/A * Error message to print or display; by default the message will
1892N/A * only be displayed in a window.
1892N/A */
1892N/A char * message = "Fatal exception occurred. Program will exit.";
1892N/A jboolean messageDest = JNI_FALSE;
1892N/A
1892N/A /* Initialize the virtual machine */
1892N/A
1892N/A if (_launcher_debug)
1892N/A start = CounterGet();
1892N/A if (!InitializeJVM(&vm, &env, &ifn)) {
1892N/A ReportErrorMessage("Could not create the Java virtual machine.",
1892N/A JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A
1892N/A if (printVersion || showVersion) {
1892N/A PrintJavaVersion(env);
1892N/A if ((*env)->ExceptionOccurred(env)) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A if (printVersion) {
1892N/A ret = 0;
1892N/A message = NULL;
1892N/A goto leave;
1892N/A }
1892N/A if (showVersion) {
1892N/A fprintf(stderr, "\n");
1892N/A }
1892N/A }
1892N/A
1892N/A /* If the user specified neither a class name nor a JAR file */
1892N/A if (jarfile == 0 && classname == 0) {
1892N/A PrintUsage();
1892N/A message = NULL;
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A#ifndef GAMMA
1892N/A FreeKnownVMs(); /* after last possible PrintUsage() */
1892N/A#endif
1892N/A
1892N/A if (_launcher_debug) {
1892N/A end = CounterGet();
1892N/A printf("%ld micro seconds to InitializeJVM\n",
1892N/A (long)(jint)Counter2Micros(end-start));
1892N/A }
1892N/A
1892N/A /* At this stage, argc/argv have the applications' arguments */
1892N/A if (_launcher_debug) {
1892N/A int i = 0;
1892N/A printf("Main-Class is '%s'\n", classname ? classname : "");
1892N/A printf("Apps' argc is %d\n", argc);
1892N/A for (; i < argc; i++) {
1892N/A printf(" argv[%2d] = '%s'\n", i, argv[i]);
1892N/A }
1892N/A }
1892N/A
1892N/A ret = 1;
1892N/A
1892N/A /*
1892N/A * Get the application's main class.
1892N/A *
1892N/A * See bugid 5030265. The Main-Class name has already been parsed
1892N/A * from the manifest, but not parsed properly for UTF-8 support.
1892N/A * Hence the code here ignores the value previously extracted and
1892N/A * uses the pre-existing code to reextract the value. This is
1892N/A * possibly an end of release cycle expedient. However, it has
1892N/A * also been discovered that passing some character sets through
1892N/A * the environment has "strange" behavior on some variants of
1892N/A * Windows. Hence, maybe the manifest parsing code local to the
1892N/A * launcher should never be enhanced.
1892N/A *
1892N/A * Hence, future work should either:
1892N/A * 1) Correct the local parsing code and verify that the
1892N/A * Main-Class attribute gets properly passed through
1892N/A * all environments,
1892N/A * 2) Remove the vestages of maintaining main_class through
1892N/A * the environment (and remove these comments).
1892N/A */
1892N/A if (jarfile != 0) {
1892N/A mainClassName = GetMainClassName(env, jarfile);
1892N/A if ((*env)->ExceptionOccurred(env)) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A if (mainClassName == NULL) {
1892N/A const char * format = "Failed to load Main-Class manifest "
1892N/A "attribute from\n%s";
1892N/A message = (char*)JLI_MemAlloc((strlen(format) + strlen(jarfile)) *
1892N/A sizeof(char));
1892N/A sprintf(message, format, jarfile);
1892N/A messageDest = JNI_TRUE;
1892N/A goto leave;
1892N/A }
1892N/A classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
1892N/A if (classname == NULL) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A mainClass = LoadClass(env, classname);
1892N/A if(mainClass == NULL) { /* exception occured */
1892N/A const char * format = "Could not find the main class: %s. Program will exit.";
1892N/A ReportExceptionDescription(env);
1892N/A message = (char *)JLI_MemAlloc((strlen(format) +
1892N/A strlen(classname)) * sizeof(char) );
1892N/A messageDest = JNI_TRUE;
1892N/A sprintf(message, format, classname);
1892N/A goto leave;
1892N/A }
1892N/A (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
1892N/A } else {
1892N/A mainClassName = NewPlatformString(env, classname);
1892N/A if (mainClassName == NULL) {
1892N/A const char * format = "Failed to load Main Class: %s";
1892N/A message = (char *)JLI_MemAlloc((strlen(format) + strlen(classname)) *
1892N/A sizeof(char) );
1892N/A sprintf(message, format, classname);
1892N/A messageDest = JNI_TRUE;
1892N/A goto leave;
1892N/A }
1892N/A classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
1892N/A if (classname == NULL) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A mainClass = LoadClass(env, classname);
1892N/A if(mainClass == NULL) { /* exception occured */
1892N/A const char * format = "Could not find the main class: %s. Program will exit.";
1892N/A ReportExceptionDescription(env);
1892N/A message = (char *)JLI_MemAlloc((strlen(format) +
1892N/A strlen(classname)) * sizeof(char) );
1892N/A messageDest = JNI_TRUE;
1892N/A sprintf(message, format, classname);
1892N/A goto leave;
1892N/A }
1892N/A (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
1892N/A }
1892N/A
1892N/A /* Get the application's main method */
1892N/A mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
1892N/A "([Ljava/lang/String;)V");
1892N/A if (mainID == NULL) {
1892N/A if ((*env)->ExceptionOccurred(env)) {
1892N/A ReportExceptionDescription(env);
1892N/A } else {
1892N/A message = "No main method found in specified class.";
1892N/A messageDest = JNI_TRUE;
1892N/A }
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A { /* Make sure the main method is public */
1892N/A jint mods;
1892N/A jmethodID mid;
1892N/A jobject obj = (*env)->ToReflectedMethod(env, mainClass,
1892N/A mainID, JNI_TRUE);
1892N/A
1892N/A if( obj == NULL) { /* exception occurred */
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A mid =
1892N/A (*env)->GetMethodID(env,
1892N/A (*env)->GetObjectClass(env, obj),
1892N/A "getModifiers", "()I");
1892N/A if ((*env)->ExceptionOccurred(env)) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A mods = (*env)->CallIntMethod(env, obj, mid);
1892N/A if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */
1892N/A message = "Main method not public.";
1892N/A messageDest = JNI_TRUE;
1892N/A goto leave;
1892N/A }
1892N/A }
1892N/A
1892N/A /* Build argument array */
1892N/A mainArgs = NewPlatformStringArray(env, argv, argc);
1892N/A if (mainArgs == NULL) {
1892N/A ReportExceptionDescription(env);
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A /* Invoke main method. */
1892N/A (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
1892N/A
1892N/A /*
1892N/A * The launcher's exit code (in the absence of calls to
1892N/A * System.exit) will be non-zero if main threw an exception.
1892N/A */
1892N/A ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
1892N/A
1892N/A /*
1892N/A * Detach the main thread so that it appears to have ended when
1892N/A * the application's main method exits. This will invoke the
1892N/A * uncaught exception handler machinery if main threw an
1892N/A * exception. An uncaught exception handler cannot change the
1892N/A * launcher's return code except by calling System.exit.
1892N/A */
1892N/A if ((*vm)->DetachCurrentThread(vm) != 0) {
1892N/A message = "Could not detach main thread.";
1892N/A messageDest = JNI_TRUE;
1892N/A ret = 1;
1892N/A goto leave;
1892N/A }
1892N/A
1892N/A message = NULL;
1892N/A
1892N/A leave:
1892N/A /*
1892N/A * Wait for all non-daemon threads to end, then destroy the VM.
1892N/A * This will actually create a trivial new Java waiter thread
1892N/A * named "DestroyJavaVM", but this will be seen as a different
1892N/A * thread from the one that executed main, even though they are
1892N/A * the same C thread. This allows mainThread.join() and
1892N/A * mainThread.isAlive() to work as expected.
1892N/A */
1892N/A (*vm)->DestroyJavaVM(vm);
1892N/A
1892N/A if(message != NULL && !noExitErrorMessage)
1892N/A ReportErrorMessage(message, messageDest);
1892N/A return ret;
1892N/A}
1892N/A
1892N/A#ifndef GAMMA
1892N/A/*
1892N/A * Checks the command line options to find which JVM type was
1892N/A * specified. If no command line option was given for the JVM type,
1892N/A * the default type is used. The environment variable
1892N/A * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
1892N/A * checked as ways of specifying which JVM type to invoke.
1892N/A */
1892N/Achar *
1892N/ACheckJvmType(int *pargc, char ***argv, jboolean speculative) {
1892N/A int i, argi;
1892N/A int argc;
1892N/A char **newArgv;
1892N/A int newArgvIdx = 0;
1892N/A int isVMType;
1892N/A int jvmidx = -1;
1892N/A char *jvmtype = getenv("JDK_ALTERNATE_VM");
1892N/A
1892N/A argc = *pargc;
1892N/A
1892N/A /* To make things simpler we always copy the argv array */
1892N/A newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));
1892N/A
1892N/A /* The program name is always present */
1892N/A newArgv[newArgvIdx++] = (*argv)[0];
1892N/A
1892N/A for (argi = 1; argi < argc; argi++) {
1892N/A char *arg = (*argv)[argi];
1892N/A isVMType = 0;
1892N/A
1892N/A#ifdef JAVA_ARGS
1892N/A if (arg[0] != '-') {
1892N/A newArgv[newArgvIdx++] = arg;
1892N/A continue;
1892N/A }
1892N/A#else
1892N/A if (strcmp(arg, "-classpath") == 0 ||
1892N/A strcmp(arg, "-cp") == 0) {
1892N/A newArgv[newArgvIdx++] = arg;
1892N/A argi++;
1892N/A if (argi < argc) {
1892N/A newArgv[newArgvIdx++] = (*argv)[argi];
1892N/A }
1892N/A continue;
1892N/A }
1892N/A if (arg[0] != '-') break;
1892N/A#endif
1892N/A
1892N/A /* Did the user pass an explicit VM type? */
1892N/A i = KnownVMIndex(arg);
1892N/A if (i >= 0) {
1892N/A jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */
1892N/A isVMType = 1;
1892N/A *pargc = *pargc - 1;
1892N/A }
1892N/A
1892N/A /* Did the user specify an "alternate" VM? */
1892N/A else if (strncmp(arg, "-XXaltjvm=", 10) == 0 || strncmp(arg, "-J-XXaltjvm=", 12) == 0) {
1892N/A isVMType = 1;
1892N/A jvmtype = arg+((arg[1]=='X')? 10 : 12);
1892N/A jvmidx = -1;
1892N/A }
1892N/A
1892N/A if (!isVMType) {
1892N/A newArgv[newArgvIdx++] = arg;
1892N/A }
1892N/A }
1892N/A
1892N/A /*
1892N/A * Finish copying the arguments if we aborted the above loop.
1892N/A * NOTE that if we aborted via "break" then we did NOT copy the
1892N/A * last argument above, and in addition argi will be less than
1892N/A * argc.
1892N/A */
1892N/A while (argi < argc) {
1892N/A newArgv[newArgvIdx++] = (*argv)[argi];
1892N/A argi++;
1892N/A }
1892N/A
1892N/A /* argv is null-terminated */
1892N/A newArgv[newArgvIdx] = 0;
1892N/A
1892N/A /* Copy back argv */
1892N/A *argv = newArgv;
1892N/A *pargc = newArgvIdx;
1892N/A
1892N/A /* use the default VM type if not specified (no alias processing) */
1892N/A if (jvmtype == NULL) {
1892N/A char* result = knownVMs[0].name+1;
1892N/A /* Use a different VM type if we are on a server class machine? */
1892N/A if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) &&
1892N/A (ServerClassMachine() == JNI_TRUE)) {
1892N/A result = knownVMs[0].server_class+1;
1892N/A }
1892N/A if (_launcher_debug) {
1892N/A printf("Default VM: %s\n", result);
1892N/A }
1892N/A return result;
1892N/A }
1892N/A
1892N/A /* if using an alternate VM, no alias processing */
1892N/A if (jvmidx < 0)
1892N/A return jvmtype;
1892N/A
1892N/A /* Resolve aliases first */
1892N/A {
1892N/A int loopCount = 0;
1892N/A while (knownVMs[jvmidx].flag == VM_ALIASED_TO) {
1892N/A int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias);
1892N/A
1892N/A if (loopCount > knownVMsCount) {
1892N/A if (!speculative) {
1892N/A ReportErrorMessage("Error: Corrupt jvm.cfg file; cycle in alias list.",
1892N/A JNI_TRUE);
1892N/A exit(1);
1892N/A } else {
1892N/A return "ERROR";
1892N/A /* break; */
1892N/A }
1892N/A }
1892N/A
1892N/A if (nextIdx < 0) {
1892N/A if (!speculative) {
1892N/A ReportErrorMessage2("Error: Unable to resolve VM alias %s",
1892N/A knownVMs[jvmidx].alias, JNI_TRUE);
1892N/A exit(1);
1892N/A } else {
1892N/A return "ERROR";
1892N/A }
1892N/A }
1892N/A jvmidx = nextIdx;
1892N/A jvmtype = knownVMs[jvmidx].name+1;
1892N/A loopCount++;
1892N/A }
1892N/A }
1892N/A
1892N/A switch (knownVMs[jvmidx].flag) {
1892N/A case VM_WARN:
1892N/A if (!speculative) {
1892N/A fprintf(stderr, "Warning: %s VM not supported; %s VM will be used\n",
1892N/A jvmtype, knownVMs[0].name + 1);
1892N/A }
1892N/A /* fall through */
1892N/A case VM_IGNORE:
1892N/A jvmtype = knownVMs[jvmidx=0].name + 1;
1892N/A /* fall through */
1892N/A case VM_KNOWN:
1892N/A break;
1892N/A case VM_ERROR:
1892N/A if (!speculative) {
1892N/A ReportErrorMessage2("Error: %s VM not supported", jvmtype, JNI_TRUE);
1892N/A exit(1);
1892N/A } else {
1892N/A return "ERROR";
1892N/A }
1892N/A }
1892N/A
1892N/A return jvmtype;
1892N/A}
1892N/A#endif /* ifndef GAMMA */
1892N/A
1892N/A# define KB (1024UL)
1892N/A# define MB (1024UL * KB)
1892N/A# define GB (1024UL * MB)
1892N/A
1892N/A/* copied from HotSpot function "atomll()" */
1892N/Astatic int
1892N/Aparse_stack_size(const char *s, jlong *result) {
1892N/A jlong n = 0;
1892N/A int args_read = sscanf(s, jlong_format_specifier(), &n);
1892N/A if (args_read != 1) {
1892N/A return 0;
1892N/A }
1892N/A while (*s != '\0' && *s >= '0' && *s <= '9') {
1892N/A s++;
1892N/A }
1892N/A // 4705540: illegal if more characters are found after the first non-digit
1892N/A if (strlen(s) > 1) {
1892N/A return 0;
1892N/A }
1892N/A switch (*s) {
1892N/A case 'T': case 't':
1892N/A *result = n * GB * KB;
1892N/A return 1;
1892N/A case 'G': case 'g':
1892N/A *result = n * GB;
1892N/A return 1;
1892N/A case 'M': case 'm':
1892N/A *result = n * MB;
1892N/A return 1;
1892N/A case 'K': case 'k':
1892N/A *result = n * KB;
1892N/A return 1;
1892N/A case '\0':
1892N/A *result = n;
1892N/A return 1;
1892N/A default:
1892N/A /* Create JVM with default stack and let VM handle malformed -Xss string*/
1892N/A return 0;
1892N/A }
1892N/A}
1892N/A
1892N/A/*
1892N/A * Adds a new VM option with the given given name and value.
1892N/A */
1892N/Avoid
1892N/AAddOption(char *str, void *info)
1892N/A{
1892N/A /*
1892N/A * Expand options array if needed to accommodate at least one more
1892N/A * VM option.
1892N/A */
1892N/A if (numOptions >= maxOptions) {
1892N/A if (options == 0) {
1892N/A maxOptions = 4;
1892N/A options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
1892N/A } else {
1892N/A JavaVMOption *tmp;
1892N/A maxOptions *= 2;
1892N/A tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
1892N/A memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
1892N/A JLI_MemFree(options);
1892N/A options = tmp;
1892N/A }
1892N/A }
1892N/A options[numOptions].optionString = str;
1892N/A options[numOptions++].extraInfo = info;
1892N/A
1892N/A if (strncmp(str, "-Xss", 4) == 0) {
1892N/A jlong tmp;
1892N/A if (parse_stack_size(str + 4, &tmp)) {
1892N/A threadStackSize = tmp;
1892N/A }
1892N/A }
1892N/A}
1892N/A
1892N/Astatic void
1892N/ASetClassPath(const char *s)
1892N/A{
1892N/A char *def;
1892N/A s = JLI_WildcardExpandClasspath(s);
1892N/A def = JLI_MemAlloc(strlen(s) + 40);
1892N/A sprintf(def, "-Djava.class.path=%s", s);
1892N/A AddOption(def, NULL);
1892N/A}
1892N/A
1892N/A#ifndef GAMMA
1892N/A/*
1892N/A * The SelectVersion() routine ensures that an appropriate version of
1892N/A * the JRE is running. The specification for the appropriate version
1892N/A * is obtained from either the manifest of a jar file (preferred) or
1892N/A * from command line options.
1892N/A * The routine also parses splash screen command line options and
1892N/A * passes on their values in private environment variables.
1892N/A */
1892N/Astatic void
1892N/ASelectVersion(int argc, char **argv, char **main_class)
1892N/A{
1892N/A char *arg;
1892N/A char **new_argv;
1892N/A char **new_argp;
1892N/A char *operand;
1892N/A char *version = NULL;
1892N/A char *jre = NULL;
1892N/A int jarflag = 0;
1892N/A int headlessflag = 0;
1892N/A int restrict_search = -1; /* -1 implies not known */
1892N/A manifest_info info;
1892N/A char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "=";
1892N/A char *splash_file_name = NULL;
1892N/A char *splash_jar_name = NULL;
1892N/A char *env_in;
1892N/A int res;
1892N/A
1892N/A /*
1892N/A * If the version has already been selected, set *main_class
1892N/A * with the value passed through the environment (if any) and
1892N/A * simply return.
1892N/A */
1892N/A if ((env_in = getenv(ENV_ENTRY)) != NULL) {
1892N/A if (*env_in != '\0')
1892N/A *main_class = JLI_StringDup(env_in);
1892N/A return;
1892N/A }
1892N/A
1892N/A /*
1892N/A * Scan through the arguments for options relevant to multiple JRE
1892N/A * support. For reference, the command line syntax is defined as:
1892N/A *
1892N/A * SYNOPSIS
1892N/A * java [options] class [argument...]
1892N/A *
1892N/A * java [options] -jar file.jar [argument...]
1892N/A *
1892N/A * As the scan is performed, make a copy of the argument list with
1892N/A * the version specification options (new to 1.5) removed, so that
1892N/A * a version less than 1.5 can be exec'd.
1892N/A *
1892N/A * Note that due to the syntax of the native Windows interface
1892N/A * CreateProcess(), processing similar to the following exists in
1892N/A * the Windows platform specific routine ExecJRE (in java_md.c).
1892N/A * Changes here should be reproduced there.
1892N/A */
1892N/A new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*));
1892N/A new_argv[0] = argv[0];
1892N/A new_argp = &new_argv[1];
1892N/A argc--;
1892N/A argv++;
1892N/A while ((arg = *argv) != 0 && *arg == '-') {
1892N/A if (strncmp(arg, "-version:", 9) == 0) {
1892N/A version = arg + 9;
1892N/A } else if (strcmp(arg, "-jre-restrict-search") == 0) {
1892N/A restrict_search = 1;
1892N/A } else if (strcmp(arg, "-no-jre-restrict-search") == 0) {
1892N/A restrict_search = 0;
1892N/A } else {
1892N/A if (strcmp(arg, "-jar") == 0)
1892N/A jarflag = 1;
1892N/A /* deal with "unfortunate" classpath syntax */
1892N/A if ((strcmp(arg, "-classpath") == 0 || strcmp(arg, "-cp") == 0) &&
1892N/A (argc >= 2)) {
1892N/A *new_argp++ = arg;
1892N/A argc--;
1892N/A argv++;
1892N/A arg = *argv;
1892N/A }
1892N/A
1892N/A /*
1892N/A * Checking for headless toolkit option in the some way as AWT does:
1892N/A * "true" means true and any other value means false
1892N/A */
1892N/A if (strcmp(arg, "-Djava.awt.headless=true") == 0) {
1892N/A headlessflag = 1;
1892N/A } else if (strncmp(arg, "-Djava.awt.headless=", 20) == 0) {
1892N/A headlessflag = 0;
1892N/A } else if (strncmp(arg, "-splash:", 8) == 0) {
1892N/A splash_file_name = arg+8;
1892N/A }
1892N/A *new_argp++ = arg;
1892N/A }
1892N/A argc--;
1892N/A argv++;
1892N/A }
1892N/A if (argc <= 0) { /* No operand? Possibly legit with -[full]version */
1892N/A operand = NULL;
1892N/A } else {
1892N/A argc--;
1892N/A *new_argp++ = operand = *argv++;
1892N/A }
1892N/A while (argc-- > 0) /* Copy over [argument...] */
1892N/A *new_argp++ = *argv++;
1892N/A *new_argp = NULL;
1892N/A
1892N/A /*
1892N/A * If there is a jar file, read the manifest. If the jarfile can't be
1892N/A * read, the manifest can't be read from the jar file, or the manifest
1892N/A * is corrupt, issue the appropriate error messages and exit.
1892N/A *
1892N/A * Even if there isn't a jar file, construct a manifest_info structure
1892N/A * containing the command line information. It's a convenient way to carry
1892N/A * this data around.
1892N/A */
1892N/A if (jarflag && operand) {
1892N/A if ((res = JLI_ParseManifest(operand, &info)) != 0) {
1892N/A if (res == -1)
1892N/A ReportErrorMessage2("Unable to access jarfile %s",
1892N/A operand, JNI_TRUE);
1892N/A else
1892N/A ReportErrorMessage2("Invalid or corrupt jarfile %s",
1892N/A operand, JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A
1892N/A /*
1892N/A * Command line splash screen option should have precedence
1892N/A * over the manifest, so the manifest data is used only if
1892N/A * splash_file_name has not been initialized above during command
1892N/A * line parsing
1892N/A */
1892N/A if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) {
1892N/A splash_file_name = info.splashscreen_image_file_name;
1892N/A splash_jar_name = operand;
1892N/A }
1892N/A } else {
1892N/A info.manifest_version = NULL;
1892N/A info.main_class = NULL;
1892N/A info.jre_version = NULL;
1892N/A info.jre_restrict_search = 0;
1892N/A }
1892N/A
1892N/A /*
1892N/A * Passing on splash screen info in environment variables
1892N/A */
1892N/A if (splash_file_name && !headlessflag) {
1892N/A char* splash_file_entry = JLI_MemAlloc(strlen(SPLASH_FILE_ENV_ENTRY "=")+strlen(splash_file_name)+1);
1892N/A strcpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");
1892N/A strcat(splash_file_entry, splash_file_name);
1892N/A putenv(splash_file_entry);
1892N/A }
1892N/A if (splash_jar_name && !headlessflag) {
1892N/A char* splash_jar_entry = JLI_MemAlloc(strlen(SPLASH_JAR_ENV_ENTRY "=")+strlen(splash_jar_name)+1);
1892N/A strcpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");
1892N/A strcat(splash_jar_entry, splash_jar_name);
1892N/A putenv(splash_jar_entry);
1892N/A }
1892N/A
1892N/A /*
1892N/A * The JRE-Version and JRE-Restrict-Search values (if any) from the
1892N/A * manifest are overwritten by any specified on the command line.
1892N/A */
1892N/A if (version != NULL)
1892N/A info.jre_version = version;
1892N/A if (restrict_search != -1)
1892N/A info.jre_restrict_search = restrict_search;
1892N/A
1892N/A /*
1892N/A * "Valid" returns (other than unrecoverable errors) follow. Set
1892N/A * main_class as a side-effect of this routine.
1892N/A */
1892N/A if (info.main_class != NULL)
1892N/A *main_class = JLI_StringDup(info.main_class);
1892N/A
1892N/A /*
1892N/A * If no version selection information is found either on the command
1892N/A * line or in the manifest, simply return.
1892N/A */
1892N/A if (info.jre_version == NULL) {
1892N/A JLI_FreeManifest();
1892N/A JLI_MemFree(new_argv);
1892N/A return;
1892N/A }
1892N/A
1892N/A /*
1892N/A * Check for correct syntax of the version specification (JSR 56).
1892N/A */
1892N/A if (!JLI_ValidVersionString(info.jre_version)) {
1892N/A ReportErrorMessage2("Syntax error in version specification \"%s\"",
1892N/A info.jre_version, JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A
1892N/A /*
1892N/A * Find the appropriate JVM on the system. Just to be as forgiving as
1892N/A * possible, if the standard algorithms don't locate an appropriate
1892N/A * jre, check to see if the one running will satisfy the requirements.
1892N/A * This can happen on systems which haven't been set-up for multiple
1892N/A * JRE support.
1892N/A */
1892N/A jre = LocateJRE(&info);
1892N/A if (_launcher_debug)
1892N/A printf("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n",
1892N/A (info.jre_version?info.jre_version:"null"),
1892N/A (info.jre_restrict_search?"true":"false"), (jre?jre:"null"));
1892N/A if (jre == NULL) {
1892N/A if (JLI_AcceptableRelease(FULL_VERSION, info.jre_version)) {
1892N/A JLI_FreeManifest();
1892N/A JLI_MemFree(new_argv);
1892N/A return;
1892N/A } else {
1892N/A ReportErrorMessage2(
1892N/A "Unable to locate JRE meeting specification \"%s\"",
1892N/A info.jre_version, JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A }
1892N/A
1892N/A /*
1892N/A * If I'm not the chosen one, exec the chosen one. Returning from
1892N/A * ExecJRE indicates that I am indeed the chosen one.
1892N/A *
1892N/A * The private environment variable _JAVA_VERSION_SET is used to
1892N/A * prevent the chosen one from re-reading the manifest file and
1892N/A * using the values found within to override the (potential) command
1892N/A * line flags stripped from argv (because the target may not
1892N/A * understand them). Passing the MainClass value is an optimization
1892N/A * to avoid locating, expanding and parsing the manifest extra
1892N/A * times.
1892N/A */
1892N/A if (info.main_class != NULL) {
1892N/A if (strlen(info.main_class) <= MAXNAMELEN) {
1892N/A (void)strcat(env_entry, info.main_class);
1892N/A } else {
1892N/A ReportErrorMessage("Error: main-class: attribute exceeds system limits\n", JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A }
1892N/A (void)putenv(env_entry);
1892N/A ExecJRE(jre, new_argv);
1892N/A JLI_FreeManifest();
1892N/A JLI_MemFree(new_argv);
1892N/A return;
1892N/A}
1892N/A#endif /* ifndef GAMMA */
1892N/A
1892N/A/*
1892N/A * Parses command line arguments. Returns JNI_FALSE if launcher
1892N/A * should exit without starting vm (e.g. certain version and usage
1892N/A * options); returns JNI_TRUE if vm needs to be started to process
1892N/A * given options. *pret (the launcher process return value) is set to
1892N/A * 0 for a normal exit.
1892N/A */
1892N/Astatic jboolean
1892N/AParseArguments(int *pargc, char ***pargv, char **pjarfile,
1892N/A char **pclassname, int *pret, const char *jvmpath)
1892N/A{
1892N/A int argc = *pargc;
1892N/A char **argv = *pargv;
1892N/A jboolean jarflag = JNI_FALSE;
1892N/A char *arg;
1892N/A
1892N/A *pret = 1;
1892N/A while ((arg = *argv) != 0 && *arg == '-') {
1892N/A argv++; --argc;
1892N/A if (strcmp(arg, "-classpath") == 0 || strcmp(arg, "-cp") == 0) {
1892N/A if (argc < 1) {
1892N/A ReportErrorMessage2("%s requires class path specification",
1892N/A arg, JNI_TRUE);
1892N/A PrintUsage();
1892N/A return JNI_FALSE;
1892N/A }
1892N/A SetClassPath(*argv);
1892N/A argv++; --argc;
1892N/A } else if (strcmp(arg, "-jar") == 0) {
1892N/A jarflag = JNI_TRUE;
1892N/A } else if (strcmp(arg, "-help") == 0 ||
1892N/A strcmp(arg, "-h") == 0 ||
1892N/A strcmp(arg, "-?") == 0) {
1892N/A PrintUsage();
1892N/A *pret = 0;
1892N/A return JNI_FALSE;
1892N/A } else if (strcmp(arg, "-version") == 0) {
1892N/A printVersion = JNI_TRUE;
1892N/A return JNI_TRUE;
1892N/A } else if (strcmp(arg, "-showversion") == 0) {
1892N/A showVersion = JNI_TRUE;
1892N/A } else if (strcmp(arg, "-X") == 0) {
1892N/A *pret = PrintXUsage(jvmpath);
1892N/A return JNI_FALSE;
1892N/A/*
1892N/A * The following case provide backward compatibility with old-style
1892N/A * command line options.
1892N/A */
1892N/A } else if (strcmp(arg, "-fullversion") == 0) {
1892N/A fprintf(stderr, "%s full version \"%s\"\n", progname,
1892N/A FULL_VERSION);
1892N/A *pret = 0;
1892N/A return JNI_FALSE;
1892N/A } else if (strcmp(arg, "-verbosegc") == 0) {
1892N/A AddOption("-verbose:gc", NULL);
1892N/A } else if (strcmp(arg, "-t") == 0) {
1892N/A AddOption("-Xt", NULL);
1892N/A } else if (strcmp(arg, "-tm") == 0) {
1892N/A AddOption("-Xtm", NULL);
1892N/A } else if (strcmp(arg, "-debug") == 0) {
1892N/A AddOption("-Xdebug", NULL);
1892N/A } else if (strcmp(arg, "-noclassgc") == 0) {
1892N/A AddOption("-Xnoclassgc", NULL);
1892N/A } else if (strcmp(arg, "-Xfuture") == 0) {
1892N/A AddOption("-Xverify:all", NULL);
1892N/A } else if (strcmp(arg, "-verify") == 0) {
1892N/A AddOption("-Xverify:all", NULL);
1892N/A } else if (strcmp(arg, "-verifyremote") == 0) {
1892N/A AddOption("-Xverify:remote", NULL);
1892N/A } else if (strcmp(arg, "-noverify") == 0) {
1892N/A AddOption("-Xverify:none", NULL);
1892N/A } else if (strcmp(arg, "-XXsuppressExitMessage") == 0) {
1892N/A noExitErrorMessage = 1;
1892N/A } else if (strncmp(arg, "-prof", 5) == 0) {
1892N/A char *p = arg + 5;
1892N/A char *tmp = JLI_MemAlloc(strlen(arg) + 50);
1892N/A if (*p) {
1892N/A sprintf(tmp, "-Xrunhprof:cpu=old,file=%s", p + 1);
1892N/A } else {
1892N/A sprintf(tmp, "-Xrunhprof:cpu=old,file=java.prof");
1892N/A }
1892N/A AddOption(tmp, NULL);
1892N/A } else if (strncmp(arg, "-ss", 3) == 0 ||
1892N/A strncmp(arg, "-oss", 4) == 0 ||
1892N/A strncmp(arg, "-ms", 3) == 0 ||
1892N/A strncmp(arg, "-mx", 3) == 0) {
1892N/A char *tmp = JLI_MemAlloc(strlen(arg) + 6);
1892N/A sprintf(tmp, "-X%s", arg + 1); /* skip '-' */
1892N/A AddOption(tmp, NULL);
1892N/A } else if (strcmp(arg, "-checksource") == 0 ||
1892N/A strcmp(arg, "-cs") == 0 ||
1892N/A strcmp(arg, "-noasyncgc") == 0) {
1892N/A /* No longer supported */
1892N/A fprintf(stderr,
1892N/A "Warning: %s option is no longer supported.\n",
1892N/A arg);
1892N/A } else if (strncmp(arg, "-version:", 9) == 0 ||
1892N/A strcmp(arg, "-no-jre-restrict-search") == 0 ||
1892N/A strcmp(arg, "-jre-restrict-search") == 0 ||
1892N/A strncmp(arg, "-splash:", 8) == 0) {
1892N/A ; /* Ignore machine independent options already handled */
1892N/A } else if (RemovableMachineDependentOption(arg) ) {
1892N/A ; /* Do not pass option to vm. */
1892N/A }
1892N/A else {
1892N/A AddOption(arg, NULL);
1892N/A }
1892N/A }
1892N/A
1892N/A if (--argc >= 0) {
1892N/A if (jarflag) {
1892N/A *pjarfile = *argv++;
1892N/A *pclassname = 0;
1892N/A } else {
1892N/A *pjarfile = 0;
1892N/A *pclassname = *argv++;
1892N/A }
1892N/A *pargc = argc;
1892N/A *pargv = argv;
1892N/A }
1892N/A
1892N/A return JNI_TRUE;
1892N/A}
1892N/A
1892N/A/*
1892N/A * Initializes the Java Virtual Machine. Also frees options array when
1892N/A * finished.
1892N/A */
1892N/Astatic jboolean
1892N/AInitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
1892N/A{
1892N/A JavaVMInitArgs args;
1892N/A jint r;
1892N/A
1892N/A memset(&args, 0, sizeof(args));
1892N/A args.version = JNI_VERSION_1_2;
1892N/A args.nOptions = numOptions;
1892N/A args.options = options;
1892N/A args.ignoreUnrecognized = JNI_FALSE;
1892N/A
1892N/A if (_launcher_debug) {
1892N/A int i = 0;
1892N/A printf("JavaVM args:\n ");
1892N/A printf("version 0x%08lx, ", (long)args.version);
1892N/A printf("ignoreUnrecognized is %s, ",
1892N/A args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");
1892N/A printf("nOptions is %ld\n", (long)args.nOptions);
1892N/A for (i = 0; i < numOptions; i++)
1892N/A printf(" option[%2d] = '%s'\n",
1892N/A i, args.options[i].optionString);
1892N/A }
1892N/A
1892N/A r = ifn->CreateJavaVM(pvm, (void **)penv, &args);
1892N/A JLI_MemFree(options);
1892N/A return r == JNI_OK;
1892N/A}
1892N/A
1892N/A
1892N/A#define NULL_CHECK0(e) if ((e) == 0) return 0
1892N/A#define NULL_CHECK(e) if ((e) == 0) return
1892N/A
1892N/Astatic jstring platformEncoding = NULL;
1892N/Astatic jstring getPlatformEncoding(JNIEnv *env) {
1892N/A if (platformEncoding == NULL) {
1892N/A jstring propname = (*env)->NewStringUTF(env, "sun.jnu.encoding");
1892N/A if (propname) {
1892N/A jclass cls;
1892N/A jmethodID mid;
1892N/A NULL_CHECK0 (cls = (*env)->FindClass(env, "java/lang/System"));
1892N/A NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
1892N/A env, cls,
1892N/A "getProperty",
1892N/A "(Ljava/lang/String;)Ljava/lang/String;"));
1892N/A platformEncoding = (*env)->CallStaticObjectMethod (
1892N/A env, cls, mid, propname);
1892N/A }
1892N/A }
1892N/A return platformEncoding;
1892N/A}
1892N/A
1892N/Astatic jboolean isEncodingSupported(JNIEnv *env, jstring enc) {
1892N/A jclass cls;
1892N/A jmethodID mid;
1892N/A NULL_CHECK0 (cls = (*env)->FindClass(env, "java/nio/charset/Charset"));
1892N/A NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
1892N/A env, cls,
1892N/A "isSupported",
1892N/A "(Ljava/lang/String;)Z"));
1892N/A return (*env)->CallStaticBooleanMethod(env, cls, mid, enc);
1892N/A}
1892N/A
1892N/A/*
1892N/A * Returns a new Java string object for the specified platform string.
1892N/A */
1892N/Astatic jstring
1892N/ANewPlatformString(JNIEnv *env, char *s)
1892N/A{
1892N/A int len = (int)strlen(s);
1892N/A jclass cls;
1892N/A jmethodID mid;
1892N/A jbyteArray ary;
1892N/A jstring enc;
1892N/A
1892N/A if (s == NULL)
1892N/A return 0;
1892N/A enc = getPlatformEncoding(env);
1892N/A
1892N/A ary = (*env)->NewByteArray(env, len);
1892N/A if (ary != 0) {
1892N/A jstring str = 0;
1892N/A (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);
1892N/A if (!(*env)->ExceptionOccurred(env)) {
1892N/A if (isEncodingSupported(env, enc) == JNI_TRUE) {
1892N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1892N/A "([BLjava/lang/String;)V"));
1892N/A str = (*env)->NewObject(env, cls, mid, ary, enc);
1892N/A } else {
1892N/A /*If the encoding specified in sun.jnu.encoding is not
1892N/A endorsed by "Charset.isSupported" we have to fall back
1892N/A to use String(byte[]) explicitly here without specifying
1892N/A the encoding name, in which the StringCoding class will
1892N/A pickup the iso-8859-1 as the fallback converter for us.
1892N/A */
1892N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1892N/A "([B)V"));
1892N/A str = (*env)->NewObject(env, cls, mid, ary);
1892N/A }
1892N/A (*env)->DeleteLocalRef(env, ary);
1892N/A return str;
1892N/A }
1892N/A }
1892N/A return 0;
1892N/A}
1892N/A
1892N/A/*
1892N/A * Returns a new array of Java string objects for the specified
1892N/A * array of platform strings.
1892N/A */
1892N/Astatic jobjectArray
1892N/ANewPlatformStringArray(JNIEnv *env, char **strv, int strc)
1892N/A{
1892N/A jarray cls;
1892N/A jarray ary;
1892N/A int i;
1892N/A
1892N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1892N/A NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0));
1892N/A for (i = 0; i < strc; i++) {
1892N/A jstring str = NewPlatformString(env, *strv++);
1892N/A NULL_CHECK0(str);
1892N/A (*env)->SetObjectArrayElement(env, ary, i, str);
1892N/A (*env)->DeleteLocalRef(env, str);
1892N/A }
1892N/A return ary;
1892N/A}
1892N/A
1892N/A/*
1892N/A * Loads a class, convert the '.' to '/'.
1892N/A */
1892N/Astatic jclass
1892N/ALoadClass(JNIEnv *env, char *name)
1892N/A{
1892N/A char *buf = JLI_MemAlloc(strlen(name) + 1);
1892N/A char *s = buf, *t = name, c;
1892N/A jclass cls;
1892N/A jlong start, end;
1892N/A
1892N/A if (_launcher_debug)
1892N/A start = CounterGet();
1892N/A
1892N/A do {
1892N/A c = *t++;
1892N/A *s++ = (c == '.') ? '/' : c;
1892N/A } while (c != '\0');
1892N/A cls = (*env)->FindClass(env, buf);
1892N/A JLI_MemFree(buf);
1892N/A
1892N/A if (_launcher_debug) {
1892N/A end = CounterGet();
1892N/A printf("%ld micro seconds to load main class\n",
1892N/A (long)(jint)Counter2Micros(end-start));
1892N/A printf("----_JAVA_LAUNCHER_DEBUG----\n");
1892N/A }
1892N/A
1892N/A return cls;
1892N/A}
1892N/A
1892N/A
1892N/A/*
1892N/A * Returns the main class name for the specified jar file.
1892N/A */
1892N/Astatic jstring
1892N/AGetMainClassName(JNIEnv *env, char *jarname)
1892N/A{
1892N/A#define MAIN_CLASS "Main-Class"
1892N/A jclass cls;
1892N/A jmethodID mid;
1892N/A jobject jar, man, attr;
1892N/A jstring str, result = 0;
1892N/A
1892N/A NULL_CHECK0(cls = (*env)->FindClass(env, "java/util/jar/JarFile"));
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1892N/A "(Ljava/lang/String;)V"));
1892N/A NULL_CHECK0(str = NewPlatformString(env, jarname));
1892N/A NULL_CHECK0(jar = (*env)->NewObject(env, cls, mid, str));
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "getManifest",
1892N/A "()Ljava/util/jar/Manifest;"));
1892N/A man = (*env)->CallObjectMethod(env, jar, mid);
1892N/A if (man != 0) {
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env,
1892N/A (*env)->GetObjectClass(env, man),
1892N/A "getMainAttributes",
1892N/A "()Ljava/util/jar/Attributes;"));
1892N/A attr = (*env)->CallObjectMethod(env, man, mid);
1892N/A if (attr != 0) {
1892N/A NULL_CHECK0(mid = (*env)->GetMethodID(env,
1892N/A (*env)->GetObjectClass(env, attr),
1892N/A "getValue",
1892N/A "(Ljava/lang/String;)Ljava/lang/String;"));
1892N/A NULL_CHECK0(str = NewPlatformString(env, MAIN_CLASS));
1892N/A result = (*env)->CallObjectMethod(env, attr, mid, str);
1892N/A }
1892N/A }
1892N/A return result;
1892N/A}
1892N/A
1892N/A#ifdef JAVA_ARGS
1892N/Astatic char *java_args[] = JAVA_ARGS;
1892N/Astatic char *app_classpath[] = APP_CLASSPATH;
1892N/A
1892N/A/*
1892N/A * For tools, convert command line args thus:
1892N/A * javac -cp foo:foo/"*" -J-ms32m ...
1892N/A * java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ...
1892N/A */
1892N/Astatic void
1892N/ATranslateApplicationArgs(int *pargc, char ***pargv)
1892N/A{
1892N/A const int NUM_ARGS = (sizeof(java_args) / sizeof(char *));
1892N/A int argc = *pargc;
1892N/A char **argv = *pargv;
1892N/A int nargc = argc + NUM_ARGS;
1892N/A char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *));
1892N/A int i;
1892N/A
1892N/A *pargc = nargc;
1892N/A *pargv = nargv;
1892N/A
1892N/A /* Copy the VM arguments (i.e. prefixed with -J) */
1892N/A for (i = 0; i < NUM_ARGS; i++) {
1892N/A char *arg = java_args[i];
1892N/A if (arg[0] == '-' && arg[1] == 'J') {
1892N/A *nargv++ = arg + 2;
1892N/A }
1892N/A }
1892N/A
1892N/A for (i = 0; i < argc; i++) {
1892N/A char *arg = argv[i];
1892N/A if (arg[0] == '-' && arg[1] == 'J') {
1892N/A if (arg[2] == '\0') {
1892N/A ReportErrorMessage("Error: the -J option should not be "
1892N/A "followed by a space.", JNI_TRUE);
1892N/A exit(1);
1892N/A }
1892N/A *nargv++ = arg + 2;
1892N/A }
1892N/A }
1892N/A
1892N/A /* Copy the rest of the arguments */
1892N/A for (i = 0; i < NUM_ARGS; i++) {
1892N/A char *arg = java_args[i];
1892N/A if (arg[0] != '-' || arg[1] != 'J') {
1892N/A *nargv++ = arg;
1892N/A }
1892N/A }
1892N/A for (i = 0; i < argc; i++) {
1892N/A char *arg = argv[i];
1892N/A if (arg[0] == '-') {
1892N/A if (arg[1] == 'J')
1892N/A continue;
1892N/A#ifdef EXPAND_CLASSPATH_WILDCARDS
1892N/A if (arg[1] == 'c'
1892N/A && (strcmp(arg, "-cp") == 0 ||
1892N/A strcmp(arg, "-classpath") == 0)
1892N/A && i < argc - 1) {
1892N/A *nargv++ = arg;
1892N/A *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
1892N/A i++;
1892N/A continue;
1892N/A }
1892N/A#endif
1892N/A }
1892N/A *nargv++ = arg;
1892N/A }
1892N/A *nargv = 0;
1892N/A}
1892N/A
1892N/A/*
1892N/A * For our tools, we try to add 3 VM options:
1892N/A * -Denv.class.path=<envcp>
1892N/A * -Dapplication.home=<apphome>
1892N/A * -Djava.class.path=<appcp>
1892N/A * <envcp> is the user's setting of CLASSPATH -- for instance the user
1892N/A * tells javac where to find binary classes through this environment
1892N/A * variable. Notice that users will be able to compile against our
1892N/A * tools classes (sun.tools.javac.Main) only if they explicitly add
1892N/A * tools.jar to CLASSPATH.
1892N/A * <apphome> is the directory where the application is installed.
1892N/A * <appcp> is the classpath to where our apps' classfiles are.
1892N/A */
1892N/Astatic jboolean
1892N/AAddApplicationOptions()
1892N/A{
1892N/A const int NUM_APP_CLASSPATH = (sizeof(app_classpath) / sizeof(char *));
1892N/A char *envcp, *appcp, *apphome;
1892N/A char home[MAXPATHLEN]; /* application home */
1892N/A char separator[] = { PATH_SEPARATOR, '\0' };
1892N/A int size, i;
1892N/A int strlenHome;
1892N/A
1892N/A {
1892N/A const char *s = getenv("CLASSPATH");
1892N/A if (s) {
1892N/A s = (char *) JLI_WildcardExpandClasspath(s);
1892N/A /* 40 for -Denv.class.path= */
1892N/A envcp = (char *)JLI_MemAlloc(strlen(s) + 40);
1892N/A sprintf(envcp, "-Denv.class.path=%s", s);
1892N/A AddOption(envcp, NULL);
1892N/A }
1892N/A }
1892N/A
1892N/A if (!GetApplicationHome(home, sizeof(home))) {
1892N/A ReportErrorMessage("Can't determine application home", JNI_TRUE);
1892N/A return JNI_FALSE;
1892N/A }
1892N/A
1892N/A /* 40 for '-Dapplication.home=' */
1892N/A apphome = (char *)JLI_MemAlloc(strlen(home) + 40);
1892N/A sprintf(apphome, "-Dapplication.home=%s", home);
1892N/A AddOption(apphome, NULL);
1892N/A
1892N/A /* How big is the application's classpath? */
1892N/A size = 40; /* 40: "-Djava.class.path=" */
1892N/A strlenHome = (int)strlen(home);
1892N/A for (i = 0; i < NUM_APP_CLASSPATH; i++) {
1892N/A size += strlenHome + (int)strlen(app_classpath[i]) + 1; /* 1: separator */
1892N/A }
1892N/A appcp = (char *)JLI_MemAlloc(size + 1);
1892N/A strcpy(appcp, "-Djava.class.path=");
1892N/A for (i = 0; i < NUM_APP_CLASSPATH; i++) {
1892N/A strcat(appcp, home); /* c:\program files\myapp */
1892N/A strcat(appcp, app_classpath[i]); /* \lib\myapp.jar */
1892N/A strcat(appcp, separator); /* ; */
1892N/A }
1892N/A appcp[strlen(appcp)-1] = '\0'; /* remove trailing path separator */
1892N/A AddOption(appcp, NULL);
1892N/A return JNI_TRUE;
1892N/A}
1892N/A#endif /* JAVA_ARGS */
1892N/A
1892N/A/*
1892N/A * inject the -Dsun.java.command pseudo property into the args structure
1892N/A * this pseudo property is used in the HotSpot VM to expose the
1892N/A * Java class name and arguments to the main method to the VM. The
1892N/A * HotSpot VM uses this pseudo property to store the Java class name
1892N/A * (or jar file name) and the arguments to the class's main method
1892N/A * to the instrumentation memory region. The sun.java.command pseudo
1892N/A * property is not exported by HotSpot to the Java layer.
1892N/A */
1892N/Avoid
1892N/ASetJavaCommandLineProp(char *classname, char *jarfile,
1892N/A int argc, char **argv)
1892N/A{
1892N/A
1892N/A int i = 0;
1892N/A size_t len = 0;
1892N/A char* javaCommand = NULL;
1892N/A char* dashDstr = "-Dsun.java.command=";
1892N/A
1892N/A if (classname == NULL && jarfile == NULL) {
1892N/A /* unexpected, one of these should be set. just return without
1892N/A * setting the property
1892N/A */
1892N/A return;
1892N/A }
1892N/A
1892N/A /* if the class name is not set, then use the jarfile name */
1892N/A if (classname == NULL) {
1892N/A classname = jarfile;
1892N/A }
1892N/A
1892N/A /* determine the amount of memory to allocate assuming
1892N/A * the individual components will be space separated
1892N/A */
1892N/A len = strlen(classname);
1892N/A for (i = 0; i < argc; i++) {
1892N/A len += strlen(argv[i]) + 1;
1892N/A }
1892N/A
1892N/A /* allocate the memory */
1892N/A javaCommand = (char*) JLI_MemAlloc(len + strlen(dashDstr) + 1);
1892N/A
1892N/A /* build the -D string */
1892N/A *javaCommand = '\0';
1892N/A strcat(javaCommand, dashDstr);
1892N/A strcat(javaCommand, classname);
1892N/A
1892N/A for (i = 0; i < argc; i++) {
1892N/A /* the components of the string are space separated. In
1892N/A * the case of embedded white space, the relationship of
1892N/A * the white space separated components to their true
1892N/A * positional arguments will be ambiguous. This issue may
1892N/A * be addressed in a future release.
1892N/A */
1892N/A strcat(javaCommand, " ");
1892N/A strcat(javaCommand, argv[i]);
1892N/A }
1892N/A
1892N/A AddOption(javaCommand, NULL);
1892N/A}
1892N/A
1892N/A/*
1892N/A * JVM would like to know if it's created by a standard Sun launcher, or by
1892N/A * user native application, the following property indicates the former.
1892N/A */
1892N/Avoid SetJavaLauncherProp() {
1892N/A AddOption("-Dsun.java.launcher=" LAUNCHER_TYPE, NULL);
1892N/A}
1892N/A
1892N/A/*
1892N/A * Prints the version information from the java.version and other properties.
1892N/A */
1892N/Astatic void
1892N/APrintJavaVersion(JNIEnv *env)
1892N/A{
1892N/A jclass ver;
1892N/A jmethodID print;
1892N/A
1892N/A NULL_CHECK(ver = (*env)->FindClass(env, "sun/misc/Version"));
1892N/A NULL_CHECK(print = (*env)->GetStaticMethodID(env, ver, "print", "()V"));
1892N/A
1892N/A (*env)->CallStaticVoidMethod(env, ver, print);
1892N/A}
1892N/A
1892N/A/*
1892N/A * Prints default usage message.
1892N/A */
1892N/Astatic void
1892N/APrintUsage(void)
1892N/A{
1892N/A#ifndef GAMMA
1892N/A int i;
1892N/A#endif
1892N/A
1892N/A fprintf(stdout,
1892N/A "Usage: %s [-options] class [args...]\n"
1892N/A " (to execute a class)\n"
1892N/A " or %s [-options] -jar jarfile [args...]\n"
1892N/A " (to execute a jar file)\n"
1892N/A "\n"
1892N/A "where options include:\n",
1892N/A progname,
1892N/A progname);
1892N/A
1892N/A#ifndef GAMMA
1892N/A PrintMachineDependentOptions();
1892N/A
1892N/A if ((knownVMs[0].flag == VM_KNOWN) ||
1892N/A (knownVMs[0].flag == VM_IF_SERVER_CLASS)) {
1892N/A fprintf(stdout, " %s\t to select the \"%s\" VM\n",
1892N/A knownVMs[0].name, knownVMs[0].name+1);
1892N/A }
1892N/A for (i=1; i<knownVMsCount; i++) {
1892N/A if (knownVMs[i].flag == VM_KNOWN)
1892N/A fprintf(stdout, " %s\t to select the \"%s\" VM\n",
1892N/A knownVMs[i].name, knownVMs[i].name+1);
1892N/A }
1892N/A for (i=1; i<knownVMsCount; i++) {
1892N/A if (knownVMs[i].flag == VM_ALIASED_TO)
1892N/A fprintf(stdout, " %s\t is a synonym for "
1892N/A "the \"%s\" VM [deprecated]\n",
1892N/A knownVMs[i].name, knownVMs[i].alias+1);
1892N/A }
1892N/A /* The first known VM is the default */
1892N/A {
1892N/A const char* defaultVM = knownVMs[0].name+1;
1892N/A const char* punctuation = ".";
1892N/A const char* reason = "";
1892N/A if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) &&
1892N/A (ServerClassMachine() == JNI_TRUE)) {
1892N/A defaultVM = knownVMs[0].server_class+1;
1892N/A punctuation = ", ";
1892N/A reason = "because you are running on a server-class machine.\n";
1892N/A }
1892N/A fprintf(stdout, " The default VM is %s%s\n",
1892N/A defaultVM, punctuation);
1892N/A fprintf(stdout, " %s\n",
1892N/A reason);
1892N/A }
1892N/A#endif /* ifndef GAMMA */
1892N/A
1892N/A fprintf(stdout,
1892N/A" -cp <class search path of directories and zip/jar files>\n"
1892N/A" -classpath <class search path of directories and zip/jar files>\n"
1892N/A" A %c separated list of directories, JAR archives,\n"
1892N/A" and ZIP archives to search for class files.\n"
1892N/A" -D<name>=<value>\n"
1892N/A" set a system property\n"
1892N/A" -verbose[:class|gc|jni]\n"
1892N/A" enable verbose output\n"
1892N/A" -version print product version and exit\n"
1892N/A" -version:<value>\n"
1892N/A" require the specified version to run\n"
1892N/A" -showversion print product version and continue\n"
1892N/A" -jre-restrict-search | -jre-no-restrict-search\n"
1892N/A" include/exclude user private JREs in the version search\n"
1892N/A" -? -help print this help message\n"
1892N/A" -X print help on non-standard options\n"
1892N/A" -ea[:<packagename>...|:<classname>]\n"
1892N/A" -enableassertions[:<packagename>...|:<classname>]\n"
1892N/A" enable assertions\n"
1892N/A" -da[:<packagename>...|:<classname>]\n"
1892N/A" -disableassertions[:<packagename>...|:<classname>]\n"
1892N/A" disable assertions\n"
1892N/A" -esa | -enablesystemassertions\n"
1892N/A" enable system assertions\n"
1892N/A" -dsa | -disablesystemassertions\n"
1892N/A" disable system assertions\n"
1892N/A" -agentlib:<libname>[=<options>]\n"
1892N/A" load native agent library <libname>, e.g. -agentlib:hprof\n"
1892N/A" see also, -agentlib:jdwp=help and -agentlib:hprof=help\n"
1892N/A" -agentpath:<pathname>[=<options>]\n"
1892N/A" load native agent library by full pathname\n"
1892N/A" -javaagent:<jarpath>[=<options>]\n"
1892N/A" load Java programming language agent, see java.lang.instrument\n"
1892N/A" -splash:<imagepath>\n"
1892N/A" show splash screen with specified image\n"
1892N/A
1892N/A ,PATH_SEPARATOR);
1892N/A}
1892N/A
1892N/A/*
1892N/A * Print usage message for -X options.
1892N/A */
1892N/Astatic jint
1892N/APrintXUsage(const char *jvmpath)
1892N/A{
1892N/A /*
1892N/A A 32 bit cushion to prevent buffer overrun, noting that
1892N/A fopen(3C) may fail if the buffer exceeds MAXPATHLEN.
1892N/A */
1892N/A char path[MAXPATHLEN+32];
1892N/A char buf[128];
1892N/A size_t n;
1892N/A FILE *fp;
1892N/A static const char Xusage_txt[] = "/Xusage.txt";
1892N/A
1892N/A strcpy(path, jvmpath);
1892N/A /* Note the FILE_SEPARATOR is platform dependent */
1892N/A strcpy(strrchr(path, FILE_SEPARATOR), Xusage_txt);
1892N/A fp = fopen(path, "r");
1892N/A if (fp == 0) {
1892N/A fprintf(stderr, "Can't open %s\n", path);
1892N/A return 1;
1892N/A }
1892N/A while ((n = fread(buf, 1, sizeof(buf), fp)) != 0) {
1892N/A fwrite(buf, 1, n, stdout);
1892N/A }
1892N/A fclose(fp);
1892N/A return 0;
1892N/A}
1892N/A
1892N/A#ifndef GAMMA
1892N/A/*
1892N/A * Read the jvm.cfg file and fill the knownJVMs[] array.
1892N/A *
1892N/A * The functionality of the jvm.cfg file is subject to change without
1892N/A * notice and the mechanism will be removed in the future.
1892N/A *
1892N/A * The lexical structure of the jvm.cfg file is as follows:
1892N/A *
1892N/A * jvmcfg := { vmLine }
1892N/A * vmLine := knownLine
1892N/A * | aliasLine
1892N/A * | warnLine
1892N/A * | ignoreLine
1892N/A * | errorLine
1892N/A * | predicateLine
1892N/A * | commentLine
1892N/A * knownLine := flag "KNOWN" EOL
1892N/A * warnLine := flag "WARN" EOL
1892N/A * ignoreLine := flag "IGNORE" EOL
1892N/A * errorLine := flag "ERROR" EOL
1892N/A * aliasLine := flag "ALIASED_TO" flag EOL
1892N/A * predicateLine := flag "IF_SERVER_CLASS" flag EOL
1892N/A * commentLine := "#" text EOL
1892N/A * flag := "-" identifier
1892N/A *
1892N/A * The semantics are that when someone specifies a flag on the command line:
1892N/A * - if the flag appears on a knownLine, then the identifier is used as
1892N/A * the name of the directory holding the JVM library (the name of the JVM).
1892N/A * - if the flag appears as the first flag on an aliasLine, the identifier
1892N/A * of the second flag is used as the name of the JVM.
1892N/A * - if the flag appears on a warnLine, the identifier is used as the
1892N/A * name of the JVM, but a warning is generated.
1892N/A * - if the flag appears on an ignoreLine, the identifier is recognized as the
1892N/A * name of a JVM, but the identifier is ignored and the default vm used
1892N/A * - if the flag appears on an errorLine, an error is generated.
1892N/A * - if the flag appears as the first flag on a predicateLine, and
1892N/A * the machine on which you are running passes the predicate indicated,
1892N/A * then the identifier of the second flag is used as the name of the JVM,
1892N/A * otherwise the identifier of the first flag is used as the name of the JVM.
1892N/A * If no flag is given on the command line, the first vmLine of the jvm.cfg
1892N/A * file determines the name of the JVM.
1892N/A * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
1892N/A * since they only make sense if someone hasn't specified the name of the
1892N/A * JVM on the command line.
1892N/A *
1892N/A * The intent of the jvm.cfg file is to allow several JVM libraries to
1892N/A * be installed in different subdirectories of a single JRE installation,
1892N/A * for space-savings and convenience in testing.
1892N/A * The intent is explicitly not to provide a full aliasing or predicate
1892N/A * mechanism.
1892N/A */
1892N/Ajint
1892N/AReadKnownVMs(const char *jrepath, char * arch, jboolean speculative)
1892N/A{
1892N/A FILE *jvmCfg;
1892N/A char jvmCfgName[MAXPATHLEN+20];
1892N/A char line[MAXPATHLEN+20];
1892N/A int cnt = 0;
1892N/A int lineno = 0;
1892N/A jlong start, end;
1892N/A int vmType;
1892N/A char *tmpPtr;
1892N/A char *altVMName = NULL;
1892N/A char *serverClassVMName = NULL;
1892N/A static char *whiteSpace = " \t";
1892N/A if (_launcher_debug) {
1892N/A start = CounterGet();
1892N/A }
1892N/A
1892N/A strcpy(jvmCfgName, jrepath);
1892N/A strcat(jvmCfgName, FILESEP "lib" FILESEP);
1892N/A strcat(jvmCfgName, arch);
1892N/A strcat(jvmCfgName, FILESEP "jvm.cfg");
1892N/A
1892N/A jvmCfg = fopen(jvmCfgName, "r");
1892N/A if (jvmCfg == NULL) {
1892N/A if (!speculative) {
1892N/A ReportErrorMessage2("Error: could not open `%s'", jvmCfgName,
1892N/A JNI_TRUE);
1892N/A exit(1);
1892N/A } else {
1892N/A return -1;
1892N/A }
1892N/A }
1892N/A while (fgets(line, sizeof(line), jvmCfg) != NULL) {
1892N/A vmType = VM_UNKNOWN;
1892N/A lineno++;
1892N/A if (line[0] == '#')
1892N/A continue;
1892N/A if (line[0] != '-') {
1892N/A fprintf(stderr, "Warning: no leading - on line %d of `%s'\n",
1892N/A lineno, jvmCfgName);
1892N/A }
1892N/A if (cnt >= knownVMsLimit) {
1892N/A GrowKnownVMs(cnt);
1892N/A }
1892N/A line[strlen(line)-1] = '\0'; /* remove trailing newline */
1892N/A tmpPtr = line + strcspn(line, whiteSpace);
1892N/A if (*tmpPtr == 0) {
1892N/A fprintf(stderr, "Warning: missing VM type on line %d of `%s'\n",
1892N/A lineno, jvmCfgName);
1892N/A } else {
1892N/A /* Null-terminate this string for JLI_StringDup below */
1892N/A *tmpPtr++ = 0;
1892N/A tmpPtr += strspn(tmpPtr, whiteSpace);
1892N/A if (*tmpPtr == 0) {
1892N/A fprintf(stderr, "Warning: missing VM type on line %d of `%s'\n",
1892N/A lineno, jvmCfgName);
1892N/A } else {
1892N/A if (!strncmp(tmpPtr, "KNOWN", strlen("KNOWN"))) {
1892N/A vmType = VM_KNOWN;
1892N/A } else if (!strncmp(tmpPtr, "ALIASED_TO", strlen("ALIASED_TO"))) {
1892N/A tmpPtr += strcspn(tmpPtr, whiteSpace);
1892N/A if (*tmpPtr != 0) {
1892N/A tmpPtr += strspn(tmpPtr, whiteSpace);
1892N/A }
1892N/A if (*tmpPtr == 0) {
1892N/A fprintf(stderr, "Warning: missing VM alias on line %d of `%s'\n",
1892N/A lineno, jvmCfgName);
1892N/A } else {
1892N/A /* Null terminate altVMName */
1892N/A altVMName = tmpPtr;
1892N/A tmpPtr += strcspn(tmpPtr, whiteSpace);
1892N/A *tmpPtr = 0;
1892N/A vmType = VM_ALIASED_TO;
1892N/A }
1892N/A } else if (!strncmp(tmpPtr, "WARN", strlen("WARN"))) {
1892N/A vmType = VM_WARN;
1892N/A } else if (!strncmp(tmpPtr, "IGNORE", strlen("IGNORE"))) {
1892N/A vmType = VM_IGNORE;
1892N/A } else if (!strncmp(tmpPtr, "ERROR", strlen("ERROR"))) {
1892N/A vmType = VM_ERROR;
1892N/A } else if (!strncmp(tmpPtr,
1892N/A "IF_SERVER_CLASS",
1892N/A strlen("IF_SERVER_CLASS"))) {
1892N/A tmpPtr += strcspn(tmpPtr, whiteSpace);
1892N/A if (*tmpPtr != 0) {
1892N/A tmpPtr += strspn(tmpPtr, whiteSpace);
1892N/A }
1892N/A if (*tmpPtr == 0) {
1892N/A fprintf(stderr, "Warning: missing server class VM on line %d of `%s'\n",
1892N/A lineno, jvmCfgName);
1892N/A } else {
1892N/A /* Null terminate server class VM name */
1892N/A serverClassVMName = tmpPtr;
1892N/A tmpPtr += strcspn(tmpPtr, whiteSpace);
1892N/A *tmpPtr = 0;
1892N/A vmType = VM_IF_SERVER_CLASS;
1892N/A }
1892N/A } else {
1892N/A fprintf(stderr, "Warning: unknown VM type on line %d of `%s'\n",
1892N/A lineno, &jvmCfgName[0]);
1892N/A vmType = VM_KNOWN;
1892N/A }
1892N/A }
1892N/A }
1892N/A
1892N/A if (_launcher_debug)
1892N/A printf("jvm.cfg[%d] = ->%s<-\n", cnt, line);
1892N/A if (vmType != VM_UNKNOWN) {
1892N/A knownVMs[cnt].name = JLI_StringDup(line);
1892N/A knownVMs[cnt].flag = vmType;
1892N/A switch (vmType) {
1892N/A default:
1892N/A break;
1892N/A case VM_ALIASED_TO:
1892N/A knownVMs[cnt].alias = JLI_StringDup(altVMName);
1892N/A if (_launcher_debug) {
1892N/A printf(" name: %s vmType: %s alias: %s\n",
1892N/A knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias);
1892N/A }
1892N/A break;
1892N/A case VM_IF_SERVER_CLASS:
1892N/A knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName);
1892N/A if (_launcher_debug) {
1892N/A printf(" name: %s vmType: %s server_class: %s\n",
1892N/A knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class);
1892N/A }
1892N/A break;
1892N/A }
1892N/A cnt++;
1892N/A }
1892N/A }
1892N/A fclose(jvmCfg);
1892N/A knownVMsCount = cnt;
1892N/A
1892N/A if (_launcher_debug) {
1892N/A end = CounterGet();
1892N/A printf("%ld micro seconds to parse jvm.cfg\n",
1892N/A (long)(jint)Counter2Micros(end-start));
1892N/A }
1892N/A
1892N/A return cnt;
1892N/A}
1892N/A
1892N/A
1892N/Astatic void
1892N/AGrowKnownVMs(int minimum)
1892N/A{
1892N/A struct vmdesc* newKnownVMs;
1892N/A int newMax;
1892N/A
1892N/A newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit));
1892N/A if (newMax <= minimum) {
1892N/A newMax = minimum;
1892N/A }
1892N/A newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc));
1892N/A if (knownVMs != NULL) {
1892N/A memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc));
1892N/A }
1892N/A JLI_MemFree(knownVMs);
1892N/A knownVMs = newKnownVMs;
1892N/A knownVMsLimit = newMax;
1892N/A}
1892N/A
1892N/A
1892N/A/* Returns index of VM or -1 if not found */
1892N/Astatic int
1892N/AKnownVMIndex(const char* name)
1892N/A{
1892N/A int i;
1892N/A if (strncmp(name, "-J", 2) == 0) name += 2;
1892N/A for (i = 0; i < knownVMsCount; i++) {
1892N/A if (!strcmp(name, knownVMs[i].name)) {
1892N/A return i;
1892N/A }
1892N/A }
1892N/A return -1;
1892N/A}
1892N/A
1892N/Astatic void
1892N/AFreeKnownVMs()
1892N/A{
1892N/A int i;
1892N/A for (i = 0; i < knownVMsCount; i++) {
1892N/A JLI_MemFree(knownVMs[i].name);
1892N/A knownVMs[i].name = NULL;
1892N/A }
1892N/A JLI_MemFree(knownVMs);
1892N/A}
1892N/A
1892N/A
1892N/A/*
1892N/A * Displays the splash screen according to the jar file name
1892N/A * and image file names stored in environment variables
1892N/A */
1892N/Astatic void
1892N/AShowSplashScreen()
1892N/A{
1892N/A const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
1892N/A const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY);
1892N/A int data_size;
1892N/A void *image_data;
1892N/A if (jar_name) {
1892N/A image_data = JLI_JarUnpackFile(jar_name, file_name, &data_size);
1892N/A if (image_data) {
1892N/A DoSplashInit();
1892N/A DoSplashLoadMemory(image_data, data_size);
1892N/A JLI_MemFree(image_data);
1892N/A }
1892N/A } else if (file_name) {
1892N/A DoSplashInit();
1892N/A DoSplashLoadFile(file_name);
1892N/A } else {
1892N/A return;
1892N/A }
1892N/A DoSplashSetFileJarName(file_name, jar_name);
1892N/A}
1892N/A
1892N/A#endif /* ifndef GAMMA */