Thu, 02 Dec 2010 05:45:54 -0800
6981484: Update development launcher
Summary: Add new development launcher called hotspot(.exe)
Reviewed-by: coleenp
sla@2327 | 1 | /* |
sla@2327 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
sla@2327 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sla@2327 | 4 | * |
sla@2327 | 5 | * This code is free software; you can redistribute it and/or modify it |
sla@2327 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sla@2327 | 7 | * published by the Free Software Foundation. |
sla@2327 | 8 | * |
sla@2327 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sla@2327 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sla@2327 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sla@2327 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sla@2327 | 13 | * accompanied this code). |
sla@2327 | 14 | * |
sla@2327 | 15 | * You should have received a copy of the GNU General Public License version |
sla@2327 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sla@2327 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sla@2327 | 18 | * |
sla@2327 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sla@2327 | 20 | * or visit www.oracle.com if you need additional information or have any |
sla@2327 | 21 | * questions. |
sla@2327 | 22 | * |
sla@2327 | 23 | */ |
sla@2327 | 24 | |
sla@2327 | 25 | /* |
sla@2327 | 26 | * Gamma (Hotspot internal engineering test) launcher based on 6.0u22 JDK, |
sla@2327 | 27 | * search "GAMMA" for gamma specific changes. |
sla@2327 | 28 | * |
sla@2327 | 29 | * GAMMA: gamma launcher is much simpler than regular java launcher in that |
sla@2327 | 30 | * JVM is either statically linked in or it is installed in the |
sla@2327 | 31 | * same directory where the launcher exists, so we don't have to |
sla@2327 | 32 | * worry about choosing the right JVM based on command line flag, jar |
sla@2327 | 33 | * file and/or ergonomics. Intead of removing unused logic from source |
sla@2327 | 34 | * they are commented out with #ifndef GAMMA, hopefully it'll be easier |
sla@2327 | 35 | * to maintain this file in sync with regular JDK launcher. |
sla@2327 | 36 | */ |
sla@2327 | 37 | |
sla@2327 | 38 | /* |
sla@2327 | 39 | * Shared source for 'java' command line tool. |
sla@2327 | 40 | * |
sla@2327 | 41 | * If JAVA_ARGS is defined, then acts as a launcher for applications. For |
sla@2327 | 42 | * instance, the JDK command line tools such as javac and javadoc (see |
sla@2327 | 43 | * makefiles for more details) are built with this program. Any arguments |
sla@2327 | 44 | * prefixed with '-J' will be passed directly to the 'java' command. |
sla@2327 | 45 | */ |
sla@2327 | 46 | |
sla@2327 | 47 | #ifdef GAMMA |
sla@2327 | 48 | # ifdef JAVA_ARGS |
sla@2327 | 49 | # error Do NOT define JAVA_ARGS when building gamma launcher |
sla@2327 | 50 | # endif |
sla@2327 | 51 | # if !defined(LINK_INTO_AOUT) && !defined(LINK_INTO_LIBJVM) |
sla@2327 | 52 | # error Either LINK_INTO_AOUT or LINK_INTO_LIBJVM must be defined |
sla@2327 | 53 | # endif |
sla@2327 | 54 | #endif |
sla@2327 | 55 | |
sla@2327 | 56 | /* |
sla@2327 | 57 | * One job of the launcher is to remove command line options which the |
sla@2327 | 58 | * vm does not understand and will not process. These options include |
sla@2327 | 59 | * options which select which style of vm is run (e.g. -client and |
sla@2327 | 60 | * -server) as well as options which select the data model to use. |
sla@2327 | 61 | * Additionally, for tools which invoke an underlying vm "-J-foo" |
sla@2327 | 62 | * options are turned into "-foo" options to the vm. This option |
sla@2327 | 63 | * filtering is handled in a number of places in the launcher, some of |
sla@2327 | 64 | * it in machine-dependent code. In this file, the function |
sla@2327 | 65 | * CheckJVMType removes vm style options and TranslateApplicationArgs |
sla@2327 | 66 | * removes "-J" prefixes. On unix platforms, the |
sla@2327 | 67 | * CreateExecutionEnvironment function from the unix java_md.c file |
sla@2327 | 68 | * processes and removes -d<n> options. However, in case |
sla@2327 | 69 | * CreateExecutionEnvironment does not need to exec because |
sla@2327 | 70 | * LD_LIBRARY_PATH is set acceptably and the data model does not need |
sla@2327 | 71 | * to be changed, ParseArguments will screen out the redundant -d<n> |
sla@2327 | 72 | * options and prevent them from being passed to the vm; this is done |
sla@2327 | 73 | * by using the machine-dependent call |
sla@2327 | 74 | * RemovableMachineDependentOption. |
sla@2327 | 75 | */ |
sla@2327 | 76 | |
sla@2327 | 77 | #include <stdio.h> |
sla@2327 | 78 | #include <stdlib.h> |
sla@2327 | 79 | #include <string.h> |
sla@2327 | 80 | |
sla@2327 | 81 | #include <jni.h> |
sla@2327 | 82 | #include <jvm.h> |
sla@2327 | 83 | #include "java.h" |
sla@2327 | 84 | #ifndef GAMMA |
sla@2327 | 85 | #include "manifest_info.h" |
sla@2327 | 86 | #include "version_comp.h" |
sla@2327 | 87 | #include "splashscreen.h" |
sla@2327 | 88 | #endif |
sla@2327 | 89 | #include "wildcard.h" |
sla@2327 | 90 | |
sla@2327 | 91 | #ifndef FULL_VERSION |
sla@2327 | 92 | #define FULL_VERSION JDK_MAJOR_VERSION "." JDK_MINOR_VERSION |
sla@2327 | 93 | #endif |
sla@2327 | 94 | |
sla@2327 | 95 | /* |
sla@2327 | 96 | * The following environment variable is used to influence the behavior |
sla@2327 | 97 | * of the jre exec'd through the SelectVersion routine. The command line |
sla@2327 | 98 | * options which specify the version are not passed to the exec'd version, |
sla@2327 | 99 | * because that jre may be an older version which wouldn't recognize them. |
sla@2327 | 100 | * This environment variable is known to this (and later) version and serves |
sla@2327 | 101 | * to suppress the version selection code. This is not only for efficiency, |
sla@2327 | 102 | * but also for correctness, since any command line options have been |
sla@2327 | 103 | * removed which would cause any value found in the manifest to be used. |
sla@2327 | 104 | * This would be incorrect because the command line options are defined |
sla@2327 | 105 | * to take precedence. |
sla@2327 | 106 | * |
sla@2327 | 107 | * The value associated with this environment variable is the MainClass |
sla@2327 | 108 | * name from within the executable jar file (if any). This is strictly a |
sla@2327 | 109 | * performance enhancement to avoid re-reading the jar file manifest. |
sla@2327 | 110 | * |
sla@2327 | 111 | * A NOTE TO DEVELOPERS: For performance reasons it is important that |
sla@2327 | 112 | * the program image remain relatively small until after SelectVersion |
sla@2327 | 113 | * CreateExecutionEnvironment have finished their possibly recursive |
sla@2327 | 114 | * processing. Watch everything, but resist all temptations to use Java |
sla@2327 | 115 | * interfaces. |
sla@2327 | 116 | */ |
sla@2327 | 117 | #define ENV_ENTRY "_JAVA_VERSION_SET" |
sla@2327 | 118 | |
sla@2327 | 119 | #ifndef GAMMA |
sla@2327 | 120 | #define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE" |
sla@2327 | 121 | #define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR" |
sla@2327 | 122 | #endif |
sla@2327 | 123 | |
sla@2327 | 124 | static jboolean printVersion = JNI_FALSE; /* print and exit */ |
sla@2327 | 125 | static jboolean showVersion = JNI_FALSE; /* print but continue */ |
sla@2327 | 126 | static char *progname; |
sla@2327 | 127 | jboolean _launcher_debug = JNI_FALSE; |
sla@2327 | 128 | |
sla@2327 | 129 | #ifndef GAMMA |
sla@2327 | 130 | /* |
sla@2327 | 131 | * Entries for splash screen environment variables. |
sla@2327 | 132 | * putenv is performed in SelectVersion. We need |
sla@2327 | 133 | * them in memory until UnsetEnv, so they are made static |
sla@2327 | 134 | * global instead of auto local. |
sla@2327 | 135 | */ |
sla@2327 | 136 | static char* splash_file_entry = NULL; |
sla@2327 | 137 | static char* splash_jar_entry = NULL; |
sla@2327 | 138 | #endif |
sla@2327 | 139 | |
sla@2327 | 140 | /* |
sla@2327 | 141 | * List of VM options to be specified when the VM is created. |
sla@2327 | 142 | */ |
sla@2327 | 143 | static JavaVMOption *options; |
sla@2327 | 144 | static int numOptions, maxOptions; |
sla@2327 | 145 | |
sla@2327 | 146 | /* |
sla@2327 | 147 | * Prototypes for functions internal to launcher. |
sla@2327 | 148 | */ |
sla@2327 | 149 | static void SetClassPath(const char *s); |
sla@2327 | 150 | static void SelectVersion(int argc, char **argv, char **main_class); |
sla@2327 | 151 | static jboolean ParseArguments(int *pargc, char ***pargv, char **pjarfile, |
sla@2327 | 152 | char **pclassname, int *pret, const char *jvmpath); |
sla@2327 | 153 | static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv, |
sla@2327 | 154 | InvocationFunctions *ifn); |
sla@2327 | 155 | static jstring NewPlatformString(JNIEnv *env, char *s); |
sla@2327 | 156 | static jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); |
sla@2327 | 157 | static jclass LoadClass(JNIEnv *env, char *name); |
sla@2327 | 158 | static jstring GetMainClassName(JNIEnv *env, char *jarname); |
sla@2327 | 159 | static void SetJavaCommandLineProp(char* classname, char* jarfile, int argc, char** argv); |
sla@2327 | 160 | static void SetJavaLauncherProp(void); |
sla@2327 | 161 | |
sla@2327 | 162 | #ifdef JAVA_ARGS |
sla@2327 | 163 | static void TranslateApplicationArgs(int *pargc, char ***pargv); |
sla@2327 | 164 | static jboolean AddApplicationOptions(void); |
sla@2327 | 165 | #endif |
sla@2327 | 166 | |
sla@2327 | 167 | static void PrintJavaVersion(JNIEnv *env); |
sla@2327 | 168 | static void PrintUsage(void); |
sla@2327 | 169 | static jint PrintXUsage(const char *jvmpath); |
sla@2327 | 170 | |
sla@2327 | 171 | static void SetPaths(int argc, char **argv); |
sla@2327 | 172 | |
sla@2327 | 173 | #ifndef GAMMA |
sla@2327 | 174 | |
sla@2327 | 175 | /* Maximum supported entries from jvm.cfg. */ |
sla@2327 | 176 | #define INIT_MAX_KNOWN_VMS 10 |
sla@2327 | 177 | /* Values for vmdesc.flag */ |
sla@2327 | 178 | #define VM_UNKNOWN -1 |
sla@2327 | 179 | #define VM_KNOWN 0 |
sla@2327 | 180 | #define VM_ALIASED_TO 1 |
sla@2327 | 181 | #define VM_WARN 2 |
sla@2327 | 182 | #define VM_ERROR 3 |
sla@2327 | 183 | #define VM_IF_SERVER_CLASS 4 |
sla@2327 | 184 | #define VM_IGNORE 5 |
sla@2327 | 185 | struct vmdesc { |
sla@2327 | 186 | char *name; |
sla@2327 | 187 | int flag; |
sla@2327 | 188 | char *alias; |
sla@2327 | 189 | char *server_class; |
sla@2327 | 190 | }; |
sla@2327 | 191 | static struct vmdesc *knownVMs = NULL; |
sla@2327 | 192 | static int knownVMsCount = 0; |
sla@2327 | 193 | static int knownVMsLimit = 0; |
sla@2327 | 194 | |
sla@2327 | 195 | static void GrowKnownVMs(); |
sla@2327 | 196 | static int KnownVMIndex(const char* name); |
sla@2327 | 197 | static void FreeKnownVMs(); |
sla@2327 | 198 | static void ShowSplashScreen(); |
sla@2327 | 199 | |
sla@2327 | 200 | #endif /* ifndef GAMMA */ |
sla@2327 | 201 | |
sla@2327 | 202 | jboolean ServerClassMachine(); |
sla@2327 | 203 | |
sla@2327 | 204 | /* flag which if set suppresses error messages from the launcher */ |
sla@2327 | 205 | static int noExitErrorMessage = 0; |
sla@2327 | 206 | |
sla@2327 | 207 | /* |
sla@2327 | 208 | * Running Java code in primordial thread caused many problems. We will |
sla@2327 | 209 | * create a new thread to invoke JVM. See 6316197 for more information. |
sla@2327 | 210 | */ |
sla@2327 | 211 | static jlong threadStackSize = 0; /* stack size of the new thread */ |
sla@2327 | 212 | |
sla@2327 | 213 | int JNICALL JavaMain(void * args); /* entry point */ |
sla@2327 | 214 | |
sla@2327 | 215 | struct JavaMainArgs { |
sla@2327 | 216 | int argc; |
sla@2327 | 217 | char ** argv; |
sla@2327 | 218 | char * jarfile; |
sla@2327 | 219 | char * classname; |
sla@2327 | 220 | InvocationFunctions ifn; |
sla@2327 | 221 | }; |
sla@2327 | 222 | |
sla@2327 | 223 | /* |
sla@2327 | 224 | * Entry point. |
sla@2327 | 225 | */ |
sla@2327 | 226 | int |
sla@2327 | 227 | main(int argc, char ** argv) |
sla@2327 | 228 | { |
sla@2327 | 229 | char *jarfile = 0; |
sla@2327 | 230 | char *classname = 0; |
sla@2327 | 231 | char *s = 0; |
sla@2327 | 232 | char *main_class = NULL; |
sla@2327 | 233 | int ret; |
sla@2327 | 234 | InvocationFunctions ifn; |
sla@2327 | 235 | jlong start, end; |
sla@2327 | 236 | char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN]; |
sla@2327 | 237 | char ** original_argv = argv; |
sla@2327 | 238 | |
sla@2327 | 239 | if (getenv("_JAVA_LAUNCHER_DEBUG") != 0) { |
sla@2327 | 240 | _launcher_debug = JNI_TRUE; |
sla@2327 | 241 | printf("----_JAVA_LAUNCHER_DEBUG----\n"); |
sla@2327 | 242 | } |
sla@2327 | 243 | |
sla@2327 | 244 | #ifndef GAMMA |
sla@2327 | 245 | /* |
sla@2327 | 246 | * Make sure the specified version of the JRE is running. |
sla@2327 | 247 | * |
sla@2327 | 248 | * There are three things to note about the SelectVersion() routine: |
sla@2327 | 249 | * 1) If the version running isn't correct, this routine doesn't |
sla@2327 | 250 | * return (either the correct version has been exec'd or an error |
sla@2327 | 251 | * was issued). |
sla@2327 | 252 | * 2) Argc and Argv in this scope are *not* altered by this routine. |
sla@2327 | 253 | * It is the responsibility of subsequent code to ignore the |
sla@2327 | 254 | * arguments handled by this routine. |
sla@2327 | 255 | * 3) As a side-effect, the variable "main_class" is guaranteed to |
sla@2327 | 256 | * be set (if it should ever be set). This isn't exactly the |
sla@2327 | 257 | * poster child for structured programming, but it is a small |
sla@2327 | 258 | * price to pay for not processing a jar file operand twice. |
sla@2327 | 259 | * (Note: This side effect has been disabled. See comment on |
sla@2327 | 260 | * bugid 5030265 below.) |
sla@2327 | 261 | */ |
sla@2327 | 262 | SelectVersion(argc, argv, &main_class); |
sla@2327 | 263 | #endif /* ifndef GAMMA */ |
sla@2327 | 264 | |
sla@2327 | 265 | /* copy original argv */ |
sla@2327 | 266 | { |
sla@2327 | 267 | int i; |
sla@2327 | 268 | original_argv = (char**)JLI_MemAlloc(sizeof(char*)*(argc+1)); |
sla@2327 | 269 | for(i = 0; i < argc+1; i++) |
sla@2327 | 270 | original_argv[i] = argv[i]; |
sla@2327 | 271 | } |
sla@2327 | 272 | |
sla@2327 | 273 | CreateExecutionEnvironment(&argc, &argv, |
sla@2327 | 274 | jrepath, sizeof(jrepath), |
sla@2327 | 275 | jvmpath, sizeof(jvmpath), |
sla@2327 | 276 | original_argv); |
sla@2327 | 277 | |
sla@2327 | 278 | ifn.CreateJavaVM = 0; |
sla@2327 | 279 | ifn.GetDefaultJavaVMInitArgs = 0; |
sla@2327 | 280 | |
sla@2327 | 281 | if (_launcher_debug) |
sla@2327 | 282 | start = CounterGet(); |
sla@2327 | 283 | if (!LoadJavaVM(jvmpath, &ifn)) { |
sla@2327 | 284 | exit(6); |
sla@2327 | 285 | } |
sla@2327 | 286 | if (_launcher_debug) { |
sla@2327 | 287 | end = CounterGet(); |
sla@2327 | 288 | printf("%ld micro seconds to LoadJavaVM\n", |
sla@2327 | 289 | (long)(jint)Counter2Micros(end-start)); |
sla@2327 | 290 | } |
sla@2327 | 291 | |
sla@2327 | 292 | #ifdef JAVA_ARGS /* javac, jar and friends. */ |
sla@2327 | 293 | progname = "java"; |
sla@2327 | 294 | #else /* java, oldjava, javaw and friends */ |
sla@2327 | 295 | #ifdef PROGNAME |
sla@2327 | 296 | progname = PROGNAME; |
sla@2327 | 297 | #else |
sla@2327 | 298 | progname = *argv; |
sla@2327 | 299 | if ((s = strrchr(progname, FILE_SEPARATOR)) != 0) { |
sla@2327 | 300 | progname = s + 1; |
sla@2327 | 301 | } |
sla@2327 | 302 | #endif /* PROGNAME */ |
sla@2327 | 303 | #endif /* JAVA_ARGS */ |
sla@2327 | 304 | ++argv; |
sla@2327 | 305 | --argc; |
sla@2327 | 306 | |
sla@2327 | 307 | #ifdef JAVA_ARGS |
sla@2327 | 308 | /* Preprocess wrapper arguments */ |
sla@2327 | 309 | TranslateApplicationArgs(&argc, &argv); |
sla@2327 | 310 | if (!AddApplicationOptions()) { |
sla@2327 | 311 | exit(1); |
sla@2327 | 312 | } |
sla@2327 | 313 | #endif |
sla@2327 | 314 | |
sla@2327 | 315 | /* Set default CLASSPATH */ |
sla@2327 | 316 | if ((s = getenv("CLASSPATH")) == 0) { |
sla@2327 | 317 | s = "."; |
sla@2327 | 318 | } |
sla@2327 | 319 | #ifndef JAVA_ARGS |
sla@2327 | 320 | SetClassPath(s); |
sla@2327 | 321 | #endif |
sla@2327 | 322 | |
sla@2327 | 323 | /* |
sla@2327 | 324 | * Parse command line options; if the return value of |
sla@2327 | 325 | * ParseArguments is false, the program should exit. |
sla@2327 | 326 | */ |
sla@2327 | 327 | if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret, jvmpath)) { |
sla@2327 | 328 | exit(ret); |
sla@2327 | 329 | } |
sla@2327 | 330 | |
sla@2327 | 331 | /* Override class path if -jar flag was specified */ |
sla@2327 | 332 | if (jarfile != 0) { |
sla@2327 | 333 | SetClassPath(jarfile); |
sla@2327 | 334 | } |
sla@2327 | 335 | |
sla@2327 | 336 | /* set the -Dsun.java.command pseudo property */ |
sla@2327 | 337 | SetJavaCommandLineProp(classname, jarfile, argc, argv); |
sla@2327 | 338 | |
sla@2327 | 339 | /* Set the -Dsun.java.launcher pseudo property */ |
sla@2327 | 340 | SetJavaLauncherProp(); |
sla@2327 | 341 | |
sla@2327 | 342 | /* set the -Dsun.java.launcher.* platform properties */ |
sla@2327 | 343 | SetJavaLauncherPlatformProps(); |
sla@2327 | 344 | |
sla@2327 | 345 | #ifndef GAMMA |
sla@2327 | 346 | /* Show the splash screen if needed */ |
sla@2327 | 347 | ShowSplashScreen(); |
sla@2327 | 348 | #endif |
sla@2327 | 349 | |
sla@2327 | 350 | /* |
sla@2327 | 351 | * Done with all command line processing and potential re-execs so |
sla@2327 | 352 | * clean up the environment. |
sla@2327 | 353 | */ |
sla@2327 | 354 | (void)UnsetEnv(ENV_ENTRY); |
sla@2327 | 355 | #ifndef GAMMA |
sla@2327 | 356 | (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY); |
sla@2327 | 357 | (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY); |
sla@2327 | 358 | |
sla@2327 | 359 | JLI_MemFree(splash_jar_entry); |
sla@2327 | 360 | JLI_MemFree(splash_file_entry); |
sla@2327 | 361 | #endif |
sla@2327 | 362 | |
sla@2327 | 363 | /* |
sla@2327 | 364 | * If user doesn't specify stack size, check if VM has a preference. |
sla@2327 | 365 | * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will |
sla@2327 | 366 | * return its default stack size through the init args structure. |
sla@2327 | 367 | */ |
sla@2327 | 368 | if (threadStackSize == 0) { |
sla@2327 | 369 | struct JDK1_1InitArgs args1_1; |
sla@2327 | 370 | memset((void*)&args1_1, 0, sizeof(args1_1)); |
sla@2327 | 371 | args1_1.version = JNI_VERSION_1_1; |
sla@2327 | 372 | ifn.GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */ |
sla@2327 | 373 | if (args1_1.javaStackSize > 0) { |
sla@2327 | 374 | threadStackSize = args1_1.javaStackSize; |
sla@2327 | 375 | } |
sla@2327 | 376 | } |
sla@2327 | 377 | |
sla@2327 | 378 | { /* Create a new thread to create JVM and invoke main method */ |
sla@2327 | 379 | struct JavaMainArgs args; |
sla@2327 | 380 | |
sla@2327 | 381 | args.argc = argc; |
sla@2327 | 382 | args.argv = argv; |
sla@2327 | 383 | args.jarfile = jarfile; |
sla@2327 | 384 | args.classname = classname; |
sla@2327 | 385 | args.ifn = ifn; |
sla@2327 | 386 | |
sla@2327 | 387 | return ContinueInNewThread(JavaMain, threadStackSize, (void*)&args); |
sla@2327 | 388 | } |
sla@2327 | 389 | } |
sla@2327 | 390 | |
sla@2327 | 391 | int JNICALL |
sla@2327 | 392 | JavaMain(void * _args) |
sla@2327 | 393 | { |
sla@2327 | 394 | struct JavaMainArgs *args = (struct JavaMainArgs *)_args; |
sla@2327 | 395 | int argc = args->argc; |
sla@2327 | 396 | char **argv = args->argv; |
sla@2327 | 397 | char *jarfile = args->jarfile; |
sla@2327 | 398 | char *classname = args->classname; |
sla@2327 | 399 | InvocationFunctions ifn = args->ifn; |
sla@2327 | 400 | |
sla@2327 | 401 | JavaVM *vm = 0; |
sla@2327 | 402 | JNIEnv *env = 0; |
sla@2327 | 403 | jstring mainClassName; |
sla@2327 | 404 | jclass mainClass; |
sla@2327 | 405 | jmethodID mainID; |
sla@2327 | 406 | jobjectArray mainArgs; |
sla@2327 | 407 | int ret = 0; |
sla@2327 | 408 | jlong start, end; |
sla@2327 | 409 | |
sla@2327 | 410 | /* |
sla@2327 | 411 | * Error message to print or display; by default the message will |
sla@2327 | 412 | * only be displayed in a window. |
sla@2327 | 413 | */ |
sla@2327 | 414 | char * message = "Fatal exception occurred. Program will exit."; |
sla@2327 | 415 | jboolean messageDest = JNI_FALSE; |
sla@2327 | 416 | |
sla@2327 | 417 | /* Initialize the virtual machine */ |
sla@2327 | 418 | |
sla@2327 | 419 | if (_launcher_debug) |
sla@2327 | 420 | start = CounterGet(); |
sla@2327 | 421 | if (!InitializeJVM(&vm, &env, &ifn)) { |
sla@2327 | 422 | ReportErrorMessage("Could not create the Java virtual machine.", |
sla@2327 | 423 | JNI_TRUE); |
sla@2327 | 424 | exit(1); |
sla@2327 | 425 | } |
sla@2327 | 426 | |
sla@2327 | 427 | if (printVersion || showVersion) { |
sla@2327 | 428 | PrintJavaVersion(env); |
sla@2327 | 429 | if ((*env)->ExceptionOccurred(env)) { |
sla@2327 | 430 | ReportExceptionDescription(env); |
sla@2327 | 431 | goto leave; |
sla@2327 | 432 | } |
sla@2327 | 433 | if (printVersion) { |
sla@2327 | 434 | ret = 0; |
sla@2327 | 435 | message = NULL; |
sla@2327 | 436 | goto leave; |
sla@2327 | 437 | } |
sla@2327 | 438 | if (showVersion) { |
sla@2327 | 439 | fprintf(stderr, "\n"); |
sla@2327 | 440 | } |
sla@2327 | 441 | } |
sla@2327 | 442 | |
sla@2327 | 443 | /* If the user specified neither a class name nor a JAR file */ |
sla@2327 | 444 | if (jarfile == 0 && classname == 0) { |
sla@2327 | 445 | PrintUsage(); |
sla@2327 | 446 | message = NULL; |
sla@2327 | 447 | goto leave; |
sla@2327 | 448 | } |
sla@2327 | 449 | |
sla@2327 | 450 | #ifndef GAMMA |
sla@2327 | 451 | FreeKnownVMs(); /* after last possible PrintUsage() */ |
sla@2327 | 452 | #endif |
sla@2327 | 453 | |
sla@2327 | 454 | if (_launcher_debug) { |
sla@2327 | 455 | end = CounterGet(); |
sla@2327 | 456 | printf("%ld micro seconds to InitializeJVM\n", |
sla@2327 | 457 | (long)(jint)Counter2Micros(end-start)); |
sla@2327 | 458 | } |
sla@2327 | 459 | |
sla@2327 | 460 | /* At this stage, argc/argv have the applications' arguments */ |
sla@2327 | 461 | if (_launcher_debug) { |
sla@2327 | 462 | int i = 0; |
sla@2327 | 463 | printf("Main-Class is '%s'\n", classname ? classname : ""); |
sla@2327 | 464 | printf("Apps' argc is %d\n", argc); |
sla@2327 | 465 | for (; i < argc; i++) { |
sla@2327 | 466 | printf(" argv[%2d] = '%s'\n", i, argv[i]); |
sla@2327 | 467 | } |
sla@2327 | 468 | } |
sla@2327 | 469 | |
sla@2327 | 470 | ret = 1; |
sla@2327 | 471 | |
sla@2327 | 472 | /* |
sla@2327 | 473 | * Get the application's main class. |
sla@2327 | 474 | * |
sla@2327 | 475 | * See bugid 5030265. The Main-Class name has already been parsed |
sla@2327 | 476 | * from the manifest, but not parsed properly for UTF-8 support. |
sla@2327 | 477 | * Hence the code here ignores the value previously extracted and |
sla@2327 | 478 | * uses the pre-existing code to reextract the value. This is |
sla@2327 | 479 | * possibly an end of release cycle expedient. However, it has |
sla@2327 | 480 | * also been discovered that passing some character sets through |
sla@2327 | 481 | * the environment has "strange" behavior on some variants of |
sla@2327 | 482 | * Windows. Hence, maybe the manifest parsing code local to the |
sla@2327 | 483 | * launcher should never be enhanced. |
sla@2327 | 484 | * |
sla@2327 | 485 | * Hence, future work should either: |
sla@2327 | 486 | * 1) Correct the local parsing code and verify that the |
sla@2327 | 487 | * Main-Class attribute gets properly passed through |
sla@2327 | 488 | * all environments, |
sla@2327 | 489 | * 2) Remove the vestages of maintaining main_class through |
sla@2327 | 490 | * the environment (and remove these comments). |
sla@2327 | 491 | */ |
sla@2327 | 492 | if (jarfile != 0) { |
sla@2327 | 493 | mainClassName = GetMainClassName(env, jarfile); |
sla@2327 | 494 | if ((*env)->ExceptionOccurred(env)) { |
sla@2327 | 495 | ReportExceptionDescription(env); |
sla@2327 | 496 | goto leave; |
sla@2327 | 497 | } |
sla@2327 | 498 | if (mainClassName == NULL) { |
sla@2327 | 499 | const char * format = "Failed to load Main-Class manifest " |
sla@2327 | 500 | "attribute from\n%s"; |
sla@2327 | 501 | message = (char*)JLI_MemAlloc((strlen(format) + strlen(jarfile)) * |
sla@2327 | 502 | sizeof(char)); |
sla@2327 | 503 | sprintf(message, format, jarfile); |
sla@2327 | 504 | messageDest = JNI_TRUE; |
sla@2327 | 505 | goto leave; |
sla@2327 | 506 | } |
sla@2327 | 507 | classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0); |
sla@2327 | 508 | if (classname == NULL) { |
sla@2327 | 509 | ReportExceptionDescription(env); |
sla@2327 | 510 | goto leave; |
sla@2327 | 511 | } |
sla@2327 | 512 | mainClass = LoadClass(env, classname); |
sla@2327 | 513 | if(mainClass == NULL) { /* exception occured */ |
sla@2327 | 514 | const char * format = "Could not find the main class: %s. Program will exit."; |
sla@2327 | 515 | ReportExceptionDescription(env); |
sla@2327 | 516 | message = (char *)JLI_MemAlloc((strlen(format) + |
sla@2327 | 517 | strlen(classname)) * sizeof(char) ); |
sla@2327 | 518 | messageDest = JNI_TRUE; |
sla@2327 | 519 | sprintf(message, format, classname); |
sla@2327 | 520 | goto leave; |
sla@2327 | 521 | } |
sla@2327 | 522 | (*env)->ReleaseStringUTFChars(env, mainClassName, classname); |
sla@2327 | 523 | } else { |
sla@2327 | 524 | mainClassName = NewPlatformString(env, classname); |
sla@2327 | 525 | if (mainClassName == NULL) { |
sla@2327 | 526 | const char * format = "Failed to load Main Class: %s"; |
sla@2327 | 527 | message = (char *)JLI_MemAlloc((strlen(format) + strlen(classname)) * |
sla@2327 | 528 | sizeof(char) ); |
sla@2327 | 529 | sprintf(message, format, classname); |
sla@2327 | 530 | messageDest = JNI_TRUE; |
sla@2327 | 531 | goto leave; |
sla@2327 | 532 | } |
sla@2327 | 533 | classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0); |
sla@2327 | 534 | if (classname == NULL) { |
sla@2327 | 535 | ReportExceptionDescription(env); |
sla@2327 | 536 | goto leave; |
sla@2327 | 537 | } |
sla@2327 | 538 | mainClass = LoadClass(env, classname); |
sla@2327 | 539 | if(mainClass == NULL) { /* exception occured */ |
sla@2327 | 540 | const char * format = "Could not find the main class: %s. Program will exit."; |
sla@2327 | 541 | ReportExceptionDescription(env); |
sla@2327 | 542 | message = (char *)JLI_MemAlloc((strlen(format) + |
sla@2327 | 543 | strlen(classname)) * sizeof(char) ); |
sla@2327 | 544 | messageDest = JNI_TRUE; |
sla@2327 | 545 | sprintf(message, format, classname); |
sla@2327 | 546 | goto leave; |
sla@2327 | 547 | } |
sla@2327 | 548 | (*env)->ReleaseStringUTFChars(env, mainClassName, classname); |
sla@2327 | 549 | } |
sla@2327 | 550 | |
sla@2327 | 551 | /* Get the application's main method */ |
sla@2327 | 552 | mainID = (*env)->GetStaticMethodID(env, mainClass, "main", |
sla@2327 | 553 | "([Ljava/lang/String;)V"); |
sla@2327 | 554 | if (mainID == NULL) { |
sla@2327 | 555 | if ((*env)->ExceptionOccurred(env)) { |
sla@2327 | 556 | ReportExceptionDescription(env); |
sla@2327 | 557 | } else { |
sla@2327 | 558 | message = "No main method found in specified class."; |
sla@2327 | 559 | messageDest = JNI_TRUE; |
sla@2327 | 560 | } |
sla@2327 | 561 | goto leave; |
sla@2327 | 562 | } |
sla@2327 | 563 | |
sla@2327 | 564 | { /* Make sure the main method is public */ |
sla@2327 | 565 | jint mods; |
sla@2327 | 566 | jmethodID mid; |
sla@2327 | 567 | jobject obj = (*env)->ToReflectedMethod(env, mainClass, |
sla@2327 | 568 | mainID, JNI_TRUE); |
sla@2327 | 569 | |
sla@2327 | 570 | if( obj == NULL) { /* exception occurred */ |
sla@2327 | 571 | ReportExceptionDescription(env); |
sla@2327 | 572 | goto leave; |
sla@2327 | 573 | } |
sla@2327 | 574 | |
sla@2327 | 575 | mid = |
sla@2327 | 576 | (*env)->GetMethodID(env, |
sla@2327 | 577 | (*env)->GetObjectClass(env, obj), |
sla@2327 | 578 | "getModifiers", "()I"); |
sla@2327 | 579 | if ((*env)->ExceptionOccurred(env)) { |
sla@2327 | 580 | ReportExceptionDescription(env); |
sla@2327 | 581 | goto leave; |
sla@2327 | 582 | } |
sla@2327 | 583 | |
sla@2327 | 584 | mods = (*env)->CallIntMethod(env, obj, mid); |
sla@2327 | 585 | if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */ |
sla@2327 | 586 | message = "Main method not public."; |
sla@2327 | 587 | messageDest = JNI_TRUE; |
sla@2327 | 588 | goto leave; |
sla@2327 | 589 | } |
sla@2327 | 590 | } |
sla@2327 | 591 | |
sla@2327 | 592 | /* Build argument array */ |
sla@2327 | 593 | mainArgs = NewPlatformStringArray(env, argv, argc); |
sla@2327 | 594 | if (mainArgs == NULL) { |
sla@2327 | 595 | ReportExceptionDescription(env); |
sla@2327 | 596 | goto leave; |
sla@2327 | 597 | } |
sla@2327 | 598 | |
sla@2327 | 599 | /* Invoke main method. */ |
sla@2327 | 600 | (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); |
sla@2327 | 601 | |
sla@2327 | 602 | /* |
sla@2327 | 603 | * The launcher's exit code (in the absence of calls to |
sla@2327 | 604 | * System.exit) will be non-zero if main threw an exception. |
sla@2327 | 605 | */ |
sla@2327 | 606 | ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1; |
sla@2327 | 607 | |
sla@2327 | 608 | /* |
sla@2327 | 609 | * Detach the main thread so that it appears to have ended when |
sla@2327 | 610 | * the application's main method exits. This will invoke the |
sla@2327 | 611 | * uncaught exception handler machinery if main threw an |
sla@2327 | 612 | * exception. An uncaught exception handler cannot change the |
sla@2327 | 613 | * launcher's return code except by calling System.exit. |
sla@2327 | 614 | */ |
sla@2327 | 615 | if ((*vm)->DetachCurrentThread(vm) != 0) { |
sla@2327 | 616 | message = "Could not detach main thread."; |
sla@2327 | 617 | messageDest = JNI_TRUE; |
sla@2327 | 618 | ret = 1; |
sla@2327 | 619 | goto leave; |
sla@2327 | 620 | } |
sla@2327 | 621 | |
sla@2327 | 622 | message = NULL; |
sla@2327 | 623 | |
sla@2327 | 624 | leave: |
sla@2327 | 625 | /* |
sla@2327 | 626 | * Wait for all non-daemon threads to end, then destroy the VM. |
sla@2327 | 627 | * This will actually create a trivial new Java waiter thread |
sla@2327 | 628 | * named "DestroyJavaVM", but this will be seen as a different |
sla@2327 | 629 | * thread from the one that executed main, even though they are |
sla@2327 | 630 | * the same C thread. This allows mainThread.join() and |
sla@2327 | 631 | * mainThread.isAlive() to work as expected. |
sla@2327 | 632 | */ |
sla@2327 | 633 | (*vm)->DestroyJavaVM(vm); |
sla@2327 | 634 | |
sla@2327 | 635 | if(message != NULL && !noExitErrorMessage) |
sla@2327 | 636 | ReportErrorMessage(message, messageDest); |
sla@2327 | 637 | return ret; |
sla@2327 | 638 | } |
sla@2327 | 639 | |
sla@2327 | 640 | #ifndef GAMMA |
sla@2327 | 641 | /* |
sla@2327 | 642 | * Checks the command line options to find which JVM type was |
sla@2327 | 643 | * specified. If no command line option was given for the JVM type, |
sla@2327 | 644 | * the default type is used. The environment variable |
sla@2327 | 645 | * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also |
sla@2327 | 646 | * checked as ways of specifying which JVM type to invoke. |
sla@2327 | 647 | */ |
sla@2327 | 648 | char * |
sla@2327 | 649 | CheckJvmType(int *pargc, char ***argv, jboolean speculative) { |
sla@2327 | 650 | int i, argi; |
sla@2327 | 651 | int argc; |
sla@2327 | 652 | char **newArgv; |
sla@2327 | 653 | int newArgvIdx = 0; |
sla@2327 | 654 | int isVMType; |
sla@2327 | 655 | int jvmidx = -1; |
sla@2327 | 656 | char *jvmtype = getenv("JDK_ALTERNATE_VM"); |
sla@2327 | 657 | |
sla@2327 | 658 | argc = *pargc; |
sla@2327 | 659 | |
sla@2327 | 660 | /* To make things simpler we always copy the argv array */ |
sla@2327 | 661 | newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *)); |
sla@2327 | 662 | |
sla@2327 | 663 | /* The program name is always present */ |
sla@2327 | 664 | newArgv[newArgvIdx++] = (*argv)[0]; |
sla@2327 | 665 | |
sla@2327 | 666 | for (argi = 1; argi < argc; argi++) { |
sla@2327 | 667 | char *arg = (*argv)[argi]; |
sla@2327 | 668 | isVMType = 0; |
sla@2327 | 669 | |
sla@2327 | 670 | #ifdef JAVA_ARGS |
sla@2327 | 671 | if (arg[0] != '-') { |
sla@2327 | 672 | newArgv[newArgvIdx++] = arg; |
sla@2327 | 673 | continue; |
sla@2327 | 674 | } |
sla@2327 | 675 | #else |
sla@2327 | 676 | if (strcmp(arg, "-classpath") == 0 || |
sla@2327 | 677 | strcmp(arg, "-cp") == 0) { |
sla@2327 | 678 | newArgv[newArgvIdx++] = arg; |
sla@2327 | 679 | argi++; |
sla@2327 | 680 | if (argi < argc) { |
sla@2327 | 681 | newArgv[newArgvIdx++] = (*argv)[argi]; |
sla@2327 | 682 | } |
sla@2327 | 683 | continue; |
sla@2327 | 684 | } |
sla@2327 | 685 | if (arg[0] != '-') break; |
sla@2327 | 686 | #endif |
sla@2327 | 687 | |
sla@2327 | 688 | /* Did the user pass an explicit VM type? */ |
sla@2327 | 689 | i = KnownVMIndex(arg); |
sla@2327 | 690 | if (i >= 0) { |
sla@2327 | 691 | jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */ |
sla@2327 | 692 | isVMType = 1; |
sla@2327 | 693 | *pargc = *pargc - 1; |
sla@2327 | 694 | } |
sla@2327 | 695 | |
sla@2327 | 696 | /* Did the user specify an "alternate" VM? */ |
sla@2327 | 697 | else if (strncmp(arg, "-XXaltjvm=", 10) == 0 || strncmp(arg, "-J-XXaltjvm=", 12) == 0) { |
sla@2327 | 698 | isVMType = 1; |
sla@2327 | 699 | jvmtype = arg+((arg[1]=='X')? 10 : 12); |
sla@2327 | 700 | jvmidx = -1; |
sla@2327 | 701 | } |
sla@2327 | 702 | |
sla@2327 | 703 | if (!isVMType) { |
sla@2327 | 704 | newArgv[newArgvIdx++] = arg; |
sla@2327 | 705 | } |
sla@2327 | 706 | } |
sla@2327 | 707 | |
sla@2327 | 708 | /* |
sla@2327 | 709 | * Finish copying the arguments if we aborted the above loop. |
sla@2327 | 710 | * NOTE that if we aborted via "break" then we did NOT copy the |
sla@2327 | 711 | * last argument above, and in addition argi will be less than |
sla@2327 | 712 | * argc. |
sla@2327 | 713 | */ |
sla@2327 | 714 | while (argi < argc) { |
sla@2327 | 715 | newArgv[newArgvIdx++] = (*argv)[argi]; |
sla@2327 | 716 | argi++; |
sla@2327 | 717 | } |
sla@2327 | 718 | |
sla@2327 | 719 | /* argv is null-terminated */ |
sla@2327 | 720 | newArgv[newArgvIdx] = 0; |
sla@2327 | 721 | |
sla@2327 | 722 | /* Copy back argv */ |
sla@2327 | 723 | *argv = newArgv; |
sla@2327 | 724 | *pargc = newArgvIdx; |
sla@2327 | 725 | |
sla@2327 | 726 | /* use the default VM type if not specified (no alias processing) */ |
sla@2327 | 727 | if (jvmtype == NULL) { |
sla@2327 | 728 | char* result = knownVMs[0].name+1; |
sla@2327 | 729 | /* Use a different VM type if we are on a server class machine? */ |
sla@2327 | 730 | if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && |
sla@2327 | 731 | (ServerClassMachine() == JNI_TRUE)) { |
sla@2327 | 732 | result = knownVMs[0].server_class+1; |
sla@2327 | 733 | } |
sla@2327 | 734 | if (_launcher_debug) { |
sla@2327 | 735 | printf("Default VM: %s\n", result); |
sla@2327 | 736 | } |
sla@2327 | 737 | return result; |
sla@2327 | 738 | } |
sla@2327 | 739 | |
sla@2327 | 740 | /* if using an alternate VM, no alias processing */ |
sla@2327 | 741 | if (jvmidx < 0) |
sla@2327 | 742 | return jvmtype; |
sla@2327 | 743 | |
sla@2327 | 744 | /* Resolve aliases first */ |
sla@2327 | 745 | { |
sla@2327 | 746 | int loopCount = 0; |
sla@2327 | 747 | while (knownVMs[jvmidx].flag == VM_ALIASED_TO) { |
sla@2327 | 748 | int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias); |
sla@2327 | 749 | |
sla@2327 | 750 | if (loopCount > knownVMsCount) { |
sla@2327 | 751 | if (!speculative) { |
sla@2327 | 752 | ReportErrorMessage("Error: Corrupt jvm.cfg file; cycle in alias list.", |
sla@2327 | 753 | JNI_TRUE); |
sla@2327 | 754 | exit(1); |
sla@2327 | 755 | } else { |
sla@2327 | 756 | return "ERROR"; |
sla@2327 | 757 | /* break; */ |
sla@2327 | 758 | } |
sla@2327 | 759 | } |
sla@2327 | 760 | |
sla@2327 | 761 | if (nextIdx < 0) { |
sla@2327 | 762 | if (!speculative) { |
sla@2327 | 763 | ReportErrorMessage2("Error: Unable to resolve VM alias %s", |
sla@2327 | 764 | knownVMs[jvmidx].alias, JNI_TRUE); |
sla@2327 | 765 | exit(1); |
sla@2327 | 766 | } else { |
sla@2327 | 767 | return "ERROR"; |
sla@2327 | 768 | } |
sla@2327 | 769 | } |
sla@2327 | 770 | jvmidx = nextIdx; |
sla@2327 | 771 | jvmtype = knownVMs[jvmidx].name+1; |
sla@2327 | 772 | loopCount++; |
sla@2327 | 773 | } |
sla@2327 | 774 | } |
sla@2327 | 775 | |
sla@2327 | 776 | switch (knownVMs[jvmidx].flag) { |
sla@2327 | 777 | case VM_WARN: |
sla@2327 | 778 | if (!speculative) { |
sla@2327 | 779 | fprintf(stderr, "Warning: %s VM not supported; %s VM will be used\n", |
sla@2327 | 780 | jvmtype, knownVMs[0].name + 1); |
sla@2327 | 781 | } |
sla@2327 | 782 | /* fall through */ |
sla@2327 | 783 | case VM_IGNORE: |
sla@2327 | 784 | jvmtype = knownVMs[jvmidx=0].name + 1; |
sla@2327 | 785 | /* fall through */ |
sla@2327 | 786 | case VM_KNOWN: |
sla@2327 | 787 | break; |
sla@2327 | 788 | case VM_ERROR: |
sla@2327 | 789 | if (!speculative) { |
sla@2327 | 790 | ReportErrorMessage2("Error: %s VM not supported", jvmtype, JNI_TRUE); |
sla@2327 | 791 | exit(1); |
sla@2327 | 792 | } else { |
sla@2327 | 793 | return "ERROR"; |
sla@2327 | 794 | } |
sla@2327 | 795 | } |
sla@2327 | 796 | |
sla@2327 | 797 | return jvmtype; |
sla@2327 | 798 | } |
sla@2327 | 799 | #endif /* ifndef GAMMA */ |
sla@2327 | 800 | |
sla@2327 | 801 | # define KB (1024UL) |
sla@2327 | 802 | # define MB (1024UL * KB) |
sla@2327 | 803 | # define GB (1024UL * MB) |
sla@2327 | 804 | |
sla@2327 | 805 | /* copied from HotSpot function "atomll()" */ |
sla@2327 | 806 | static int |
sla@2327 | 807 | parse_stack_size(const char *s, jlong *result) { |
sla@2327 | 808 | jlong n = 0; |
sla@2327 | 809 | int args_read = sscanf(s, jlong_format_specifier(), &n); |
sla@2327 | 810 | if (args_read != 1) { |
sla@2327 | 811 | return 0; |
sla@2327 | 812 | } |
sla@2327 | 813 | while (*s != '\0' && *s >= '0' && *s <= '9') { |
sla@2327 | 814 | s++; |
sla@2327 | 815 | } |
sla@2327 | 816 | // 4705540: illegal if more characters are found after the first non-digit |
sla@2327 | 817 | if (strlen(s) > 1) { |
sla@2327 | 818 | return 0; |
sla@2327 | 819 | } |
sla@2327 | 820 | switch (*s) { |
sla@2327 | 821 | case 'T': case 't': |
sla@2327 | 822 | *result = n * GB * KB; |
sla@2327 | 823 | return 1; |
sla@2327 | 824 | case 'G': case 'g': |
sla@2327 | 825 | *result = n * GB; |
sla@2327 | 826 | return 1; |
sla@2327 | 827 | case 'M': case 'm': |
sla@2327 | 828 | *result = n * MB; |
sla@2327 | 829 | return 1; |
sla@2327 | 830 | case 'K': case 'k': |
sla@2327 | 831 | *result = n * KB; |
sla@2327 | 832 | return 1; |
sla@2327 | 833 | case '\0': |
sla@2327 | 834 | *result = n; |
sla@2327 | 835 | return 1; |
sla@2327 | 836 | default: |
sla@2327 | 837 | /* Create JVM with default stack and let VM handle malformed -Xss string*/ |
sla@2327 | 838 | return 0; |
sla@2327 | 839 | } |
sla@2327 | 840 | } |
sla@2327 | 841 | |
sla@2327 | 842 | /* |
sla@2327 | 843 | * Adds a new VM option with the given given name and value. |
sla@2327 | 844 | */ |
sla@2327 | 845 | void |
sla@2327 | 846 | AddOption(char *str, void *info) |
sla@2327 | 847 | { |
sla@2327 | 848 | /* |
sla@2327 | 849 | * Expand options array if needed to accommodate at least one more |
sla@2327 | 850 | * VM option. |
sla@2327 | 851 | */ |
sla@2327 | 852 | if (numOptions >= maxOptions) { |
sla@2327 | 853 | if (options == 0) { |
sla@2327 | 854 | maxOptions = 4; |
sla@2327 | 855 | options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption)); |
sla@2327 | 856 | } else { |
sla@2327 | 857 | JavaVMOption *tmp; |
sla@2327 | 858 | maxOptions *= 2; |
sla@2327 | 859 | tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption)); |
sla@2327 | 860 | memcpy(tmp, options, numOptions * sizeof(JavaVMOption)); |
sla@2327 | 861 | JLI_MemFree(options); |
sla@2327 | 862 | options = tmp; |
sla@2327 | 863 | } |
sla@2327 | 864 | } |
sla@2327 | 865 | options[numOptions].optionString = str; |
sla@2327 | 866 | options[numOptions++].extraInfo = info; |
sla@2327 | 867 | |
sla@2327 | 868 | if (strncmp(str, "-Xss", 4) == 0) { |
sla@2327 | 869 | jlong tmp; |
sla@2327 | 870 | if (parse_stack_size(str + 4, &tmp)) { |
sla@2327 | 871 | threadStackSize = tmp; |
sla@2327 | 872 | } |
sla@2327 | 873 | } |
sla@2327 | 874 | } |
sla@2327 | 875 | |
sla@2327 | 876 | static void |
sla@2327 | 877 | SetClassPath(const char *s) |
sla@2327 | 878 | { |
sla@2327 | 879 | char *def; |
sla@2327 | 880 | s = JLI_WildcardExpandClasspath(s); |
sla@2327 | 881 | def = JLI_MemAlloc(strlen(s) + 40); |
sla@2327 | 882 | sprintf(def, "-Djava.class.path=%s", s); |
sla@2327 | 883 | AddOption(def, NULL); |
sla@2327 | 884 | } |
sla@2327 | 885 | |
sla@2327 | 886 | #ifndef GAMMA |
sla@2327 | 887 | /* |
sla@2327 | 888 | * The SelectVersion() routine ensures that an appropriate version of |
sla@2327 | 889 | * the JRE is running. The specification for the appropriate version |
sla@2327 | 890 | * is obtained from either the manifest of a jar file (preferred) or |
sla@2327 | 891 | * from command line options. |
sla@2327 | 892 | * The routine also parses splash screen command line options and |
sla@2327 | 893 | * passes on their values in private environment variables. |
sla@2327 | 894 | */ |
sla@2327 | 895 | static void |
sla@2327 | 896 | SelectVersion(int argc, char **argv, char **main_class) |
sla@2327 | 897 | { |
sla@2327 | 898 | char *arg; |
sla@2327 | 899 | char **new_argv; |
sla@2327 | 900 | char **new_argp; |
sla@2327 | 901 | char *operand; |
sla@2327 | 902 | char *version = NULL; |
sla@2327 | 903 | char *jre = NULL; |
sla@2327 | 904 | int jarflag = 0; |
sla@2327 | 905 | int headlessflag = 0; |
sla@2327 | 906 | int restrict_search = -1; /* -1 implies not known */ |
sla@2327 | 907 | manifest_info info; |
sla@2327 | 908 | char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "="; |
sla@2327 | 909 | char *splash_file_name = NULL; |
sla@2327 | 910 | char *splash_jar_name = NULL; |
sla@2327 | 911 | char *env_in; |
sla@2327 | 912 | int res; |
sla@2327 | 913 | |
sla@2327 | 914 | /* |
sla@2327 | 915 | * If the version has already been selected, set *main_class |
sla@2327 | 916 | * with the value passed through the environment (if any) and |
sla@2327 | 917 | * simply return. |
sla@2327 | 918 | */ |
sla@2327 | 919 | if ((env_in = getenv(ENV_ENTRY)) != NULL) { |
sla@2327 | 920 | if (*env_in != '\0') |
sla@2327 | 921 | *main_class = JLI_StringDup(env_in); |
sla@2327 | 922 | return; |
sla@2327 | 923 | } |
sla@2327 | 924 | |
sla@2327 | 925 | /* |
sla@2327 | 926 | * Scan through the arguments for options relevant to multiple JRE |
sla@2327 | 927 | * support. For reference, the command line syntax is defined as: |
sla@2327 | 928 | * |
sla@2327 | 929 | * SYNOPSIS |
sla@2327 | 930 | * java [options] class [argument...] |
sla@2327 | 931 | * |
sla@2327 | 932 | * java [options] -jar file.jar [argument...] |
sla@2327 | 933 | * |
sla@2327 | 934 | * As the scan is performed, make a copy of the argument list with |
sla@2327 | 935 | * the version specification options (new to 1.5) removed, so that |
sla@2327 | 936 | * a version less than 1.5 can be exec'd. |
sla@2327 | 937 | * |
sla@2327 | 938 | * Note that due to the syntax of the native Windows interface |
sla@2327 | 939 | * CreateProcess(), processing similar to the following exists in |
sla@2327 | 940 | * the Windows platform specific routine ExecJRE (in java_md.c). |
sla@2327 | 941 | * Changes here should be reproduced there. |
sla@2327 | 942 | */ |
sla@2327 | 943 | new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*)); |
sla@2327 | 944 | new_argv[0] = argv[0]; |
sla@2327 | 945 | new_argp = &new_argv[1]; |
sla@2327 | 946 | argc--; |
sla@2327 | 947 | argv++; |
sla@2327 | 948 | while ((arg = *argv) != 0 && *arg == '-') { |
sla@2327 | 949 | if (strncmp(arg, "-version:", 9) == 0) { |
sla@2327 | 950 | version = arg + 9; |
sla@2327 | 951 | } else if (strcmp(arg, "-jre-restrict-search") == 0) { |
sla@2327 | 952 | restrict_search = 1; |
sla@2327 | 953 | } else if (strcmp(arg, "-no-jre-restrict-search") == 0) { |
sla@2327 | 954 | restrict_search = 0; |
sla@2327 | 955 | } else { |
sla@2327 | 956 | if (strcmp(arg, "-jar") == 0) |
sla@2327 | 957 | jarflag = 1; |
sla@2327 | 958 | /* deal with "unfortunate" classpath syntax */ |
sla@2327 | 959 | if ((strcmp(arg, "-classpath") == 0 || strcmp(arg, "-cp") == 0) && |
sla@2327 | 960 | (argc >= 2)) { |
sla@2327 | 961 | *new_argp++ = arg; |
sla@2327 | 962 | argc--; |
sla@2327 | 963 | argv++; |
sla@2327 | 964 | arg = *argv; |
sla@2327 | 965 | } |
sla@2327 | 966 | |
sla@2327 | 967 | /* |
sla@2327 | 968 | * Checking for headless toolkit option in the some way as AWT does: |
sla@2327 | 969 | * "true" means true and any other value means false |
sla@2327 | 970 | */ |
sla@2327 | 971 | if (strcmp(arg, "-Djava.awt.headless=true") == 0) { |
sla@2327 | 972 | headlessflag = 1; |
sla@2327 | 973 | } else if (strncmp(arg, "-Djava.awt.headless=", 20) == 0) { |
sla@2327 | 974 | headlessflag = 0; |
sla@2327 | 975 | } else if (strncmp(arg, "-splash:", 8) == 0) { |
sla@2327 | 976 | splash_file_name = arg+8; |
sla@2327 | 977 | } |
sla@2327 | 978 | *new_argp++ = arg; |
sla@2327 | 979 | } |
sla@2327 | 980 | argc--; |
sla@2327 | 981 | argv++; |
sla@2327 | 982 | } |
sla@2327 | 983 | if (argc <= 0) { /* No operand? Possibly legit with -[full]version */ |
sla@2327 | 984 | operand = NULL; |
sla@2327 | 985 | } else { |
sla@2327 | 986 | argc--; |
sla@2327 | 987 | *new_argp++ = operand = *argv++; |
sla@2327 | 988 | } |
sla@2327 | 989 | while (argc-- > 0) /* Copy over [argument...] */ |
sla@2327 | 990 | *new_argp++ = *argv++; |
sla@2327 | 991 | *new_argp = NULL; |
sla@2327 | 992 | |
sla@2327 | 993 | /* |
sla@2327 | 994 | * If there is a jar file, read the manifest. If the jarfile can't be |
sla@2327 | 995 | * read, the manifest can't be read from the jar file, or the manifest |
sla@2327 | 996 | * is corrupt, issue the appropriate error messages and exit. |
sla@2327 | 997 | * |
sla@2327 | 998 | * Even if there isn't a jar file, construct a manifest_info structure |
sla@2327 | 999 | * containing the command line information. It's a convenient way to carry |
sla@2327 | 1000 | * this data around. |
sla@2327 | 1001 | */ |
sla@2327 | 1002 | if (jarflag && operand) { |
sla@2327 | 1003 | if ((res = JLI_ParseManifest(operand, &info)) != 0) { |
sla@2327 | 1004 | if (res == -1) |
sla@2327 | 1005 | ReportErrorMessage2("Unable to access jarfile %s", |
sla@2327 | 1006 | operand, JNI_TRUE); |
sla@2327 | 1007 | else |
sla@2327 | 1008 | ReportErrorMessage2("Invalid or corrupt jarfile %s", |
sla@2327 | 1009 | operand, JNI_TRUE); |
sla@2327 | 1010 | exit(1); |
sla@2327 | 1011 | } |
sla@2327 | 1012 | |
sla@2327 | 1013 | /* |
sla@2327 | 1014 | * Command line splash screen option should have precedence |
sla@2327 | 1015 | * over the manifest, so the manifest data is used only if |
sla@2327 | 1016 | * splash_file_name has not been initialized above during command |
sla@2327 | 1017 | * line parsing |
sla@2327 | 1018 | */ |
sla@2327 | 1019 | if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) { |
sla@2327 | 1020 | splash_file_name = info.splashscreen_image_file_name; |
sla@2327 | 1021 | splash_jar_name = operand; |
sla@2327 | 1022 | } |
sla@2327 | 1023 | } else { |
sla@2327 | 1024 | info.manifest_version = NULL; |
sla@2327 | 1025 | info.main_class = NULL; |
sla@2327 | 1026 | info.jre_version = NULL; |
sla@2327 | 1027 | info.jre_restrict_search = 0; |
sla@2327 | 1028 | } |
sla@2327 | 1029 | |
sla@2327 | 1030 | /* |
sla@2327 | 1031 | * Passing on splash screen info in environment variables |
sla@2327 | 1032 | */ |
sla@2327 | 1033 | if (splash_file_name && !headlessflag) { |
sla@2327 | 1034 | char* splash_file_entry = JLI_MemAlloc(strlen(SPLASH_FILE_ENV_ENTRY "=")+strlen(splash_file_name)+1); |
sla@2327 | 1035 | strcpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "="); |
sla@2327 | 1036 | strcat(splash_file_entry, splash_file_name); |
sla@2327 | 1037 | putenv(splash_file_entry); |
sla@2327 | 1038 | } |
sla@2327 | 1039 | if (splash_jar_name && !headlessflag) { |
sla@2327 | 1040 | char* splash_jar_entry = JLI_MemAlloc(strlen(SPLASH_JAR_ENV_ENTRY "=")+strlen(splash_jar_name)+1); |
sla@2327 | 1041 | strcpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "="); |
sla@2327 | 1042 | strcat(splash_jar_entry, splash_jar_name); |
sla@2327 | 1043 | putenv(splash_jar_entry); |
sla@2327 | 1044 | } |
sla@2327 | 1045 | |
sla@2327 | 1046 | /* |
sla@2327 | 1047 | * The JRE-Version and JRE-Restrict-Search values (if any) from the |
sla@2327 | 1048 | * manifest are overwritten by any specified on the command line. |
sla@2327 | 1049 | */ |
sla@2327 | 1050 | if (version != NULL) |
sla@2327 | 1051 | info.jre_version = version; |
sla@2327 | 1052 | if (restrict_search != -1) |
sla@2327 | 1053 | info.jre_restrict_search = restrict_search; |
sla@2327 | 1054 | |
sla@2327 | 1055 | /* |
sla@2327 | 1056 | * "Valid" returns (other than unrecoverable errors) follow. Set |
sla@2327 | 1057 | * main_class as a side-effect of this routine. |
sla@2327 | 1058 | */ |
sla@2327 | 1059 | if (info.main_class != NULL) |
sla@2327 | 1060 | *main_class = JLI_StringDup(info.main_class); |
sla@2327 | 1061 | |
sla@2327 | 1062 | /* |
sla@2327 | 1063 | * If no version selection information is found either on the command |
sla@2327 | 1064 | * line or in the manifest, simply return. |
sla@2327 | 1065 | */ |
sla@2327 | 1066 | if (info.jre_version == NULL) { |
sla@2327 | 1067 | JLI_FreeManifest(); |
sla@2327 | 1068 | JLI_MemFree(new_argv); |
sla@2327 | 1069 | return; |
sla@2327 | 1070 | } |
sla@2327 | 1071 | |
sla@2327 | 1072 | /* |
sla@2327 | 1073 | * Check for correct syntax of the version specification (JSR 56). |
sla@2327 | 1074 | */ |
sla@2327 | 1075 | if (!JLI_ValidVersionString(info.jre_version)) { |
sla@2327 | 1076 | ReportErrorMessage2("Syntax error in version specification \"%s\"", |
sla@2327 | 1077 | info.jre_version, JNI_TRUE); |
sla@2327 | 1078 | exit(1); |
sla@2327 | 1079 | } |
sla@2327 | 1080 | |
sla@2327 | 1081 | /* |
sla@2327 | 1082 | * Find the appropriate JVM on the system. Just to be as forgiving as |
sla@2327 | 1083 | * possible, if the standard algorithms don't locate an appropriate |
sla@2327 | 1084 | * jre, check to see if the one running will satisfy the requirements. |
sla@2327 | 1085 | * This can happen on systems which haven't been set-up for multiple |
sla@2327 | 1086 | * JRE support. |
sla@2327 | 1087 | */ |
sla@2327 | 1088 | jre = LocateJRE(&info); |
sla@2327 | 1089 | if (_launcher_debug) |
sla@2327 | 1090 | printf("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n", |
sla@2327 | 1091 | (info.jre_version?info.jre_version:"null"), |
sla@2327 | 1092 | (info.jre_restrict_search?"true":"false"), (jre?jre:"null")); |
sla@2327 | 1093 | if (jre == NULL) { |
sla@2327 | 1094 | if (JLI_AcceptableRelease(FULL_VERSION, info.jre_version)) { |
sla@2327 | 1095 | JLI_FreeManifest(); |
sla@2327 | 1096 | JLI_MemFree(new_argv); |
sla@2327 | 1097 | return; |
sla@2327 | 1098 | } else { |
sla@2327 | 1099 | ReportErrorMessage2( |
sla@2327 | 1100 | "Unable to locate JRE meeting specification \"%s\"", |
sla@2327 | 1101 | info.jre_version, JNI_TRUE); |
sla@2327 | 1102 | exit(1); |
sla@2327 | 1103 | } |
sla@2327 | 1104 | } |
sla@2327 | 1105 | |
sla@2327 | 1106 | /* |
sla@2327 | 1107 | * If I'm not the chosen one, exec the chosen one. Returning from |
sla@2327 | 1108 | * ExecJRE indicates that I am indeed the chosen one. |
sla@2327 | 1109 | * |
sla@2327 | 1110 | * The private environment variable _JAVA_VERSION_SET is used to |
sla@2327 | 1111 | * prevent the chosen one from re-reading the manifest file and |
sla@2327 | 1112 | * using the values found within to override the (potential) command |
sla@2327 | 1113 | * line flags stripped from argv (because the target may not |
sla@2327 | 1114 | * understand them). Passing the MainClass value is an optimization |
sla@2327 | 1115 | * to avoid locating, expanding and parsing the manifest extra |
sla@2327 | 1116 | * times. |
sla@2327 | 1117 | */ |
sla@2327 | 1118 | if (info.main_class != NULL) { |
sla@2327 | 1119 | if (strlen(info.main_class) <= MAXNAMELEN) { |
sla@2327 | 1120 | (void)strcat(env_entry, info.main_class); |
sla@2327 | 1121 | } else { |
sla@2327 | 1122 | ReportErrorMessage("Error: main-class: attribute exceeds system limits\n", JNI_TRUE); |
sla@2327 | 1123 | exit(1); |
sla@2327 | 1124 | } |
sla@2327 | 1125 | } |
sla@2327 | 1126 | (void)putenv(env_entry); |
sla@2327 | 1127 | ExecJRE(jre, new_argv); |
sla@2327 | 1128 | JLI_FreeManifest(); |
sla@2327 | 1129 | JLI_MemFree(new_argv); |
sla@2327 | 1130 | return; |
sla@2327 | 1131 | } |
sla@2327 | 1132 | #endif /* ifndef GAMMA */ |
sla@2327 | 1133 | |
sla@2327 | 1134 | /* |
sla@2327 | 1135 | * Parses command line arguments. Returns JNI_FALSE if launcher |
sla@2327 | 1136 | * should exit without starting vm (e.g. certain version and usage |
sla@2327 | 1137 | * options); returns JNI_TRUE if vm needs to be started to process |
sla@2327 | 1138 | * given options. *pret (the launcher process return value) is set to |
sla@2327 | 1139 | * 0 for a normal exit. |
sla@2327 | 1140 | */ |
sla@2327 | 1141 | static jboolean |
sla@2327 | 1142 | ParseArguments(int *pargc, char ***pargv, char **pjarfile, |
sla@2327 | 1143 | char **pclassname, int *pret, const char *jvmpath) |
sla@2327 | 1144 | { |
sla@2327 | 1145 | int argc = *pargc; |
sla@2327 | 1146 | char **argv = *pargv; |
sla@2327 | 1147 | jboolean jarflag = JNI_FALSE; |
sla@2327 | 1148 | char *arg; |
sla@2327 | 1149 | |
sla@2327 | 1150 | *pret = 1; |
sla@2327 | 1151 | while ((arg = *argv) != 0 && *arg == '-') { |
sla@2327 | 1152 | argv++; --argc; |
sla@2327 | 1153 | if (strcmp(arg, "-classpath") == 0 || strcmp(arg, "-cp") == 0) { |
sla@2327 | 1154 | if (argc < 1) { |
sla@2327 | 1155 | ReportErrorMessage2("%s requires class path specification", |
sla@2327 | 1156 | arg, JNI_TRUE); |
sla@2327 | 1157 | PrintUsage(); |
sla@2327 | 1158 | return JNI_FALSE; |
sla@2327 | 1159 | } |
sla@2327 | 1160 | SetClassPath(*argv); |
sla@2327 | 1161 | argv++; --argc; |
sla@2327 | 1162 | } else if (strcmp(arg, "-jar") == 0) { |
sla@2327 | 1163 | jarflag = JNI_TRUE; |
sla@2327 | 1164 | } else if (strcmp(arg, "-help") == 0 || |
sla@2327 | 1165 | strcmp(arg, "-h") == 0 || |
sla@2327 | 1166 | strcmp(arg, "-?") == 0) { |
sla@2327 | 1167 | PrintUsage(); |
sla@2327 | 1168 | *pret = 0; |
sla@2327 | 1169 | return JNI_FALSE; |
sla@2327 | 1170 | } else if (strcmp(arg, "-version") == 0) { |
sla@2327 | 1171 | printVersion = JNI_TRUE; |
sla@2327 | 1172 | return JNI_TRUE; |
sla@2327 | 1173 | } else if (strcmp(arg, "-showversion") == 0) { |
sla@2327 | 1174 | showVersion = JNI_TRUE; |
sla@2327 | 1175 | } else if (strcmp(arg, "-X") == 0) { |
sla@2327 | 1176 | *pret = PrintXUsage(jvmpath); |
sla@2327 | 1177 | return JNI_FALSE; |
sla@2327 | 1178 | /* |
sla@2327 | 1179 | * The following case provide backward compatibility with old-style |
sla@2327 | 1180 | * command line options. |
sla@2327 | 1181 | */ |
sla@2327 | 1182 | } else if (strcmp(arg, "-fullversion") == 0) { |
sla@2327 | 1183 | fprintf(stderr, "%s full version \"%s\"\n", progname, |
sla@2327 | 1184 | FULL_VERSION); |
sla@2327 | 1185 | *pret = 0; |
sla@2327 | 1186 | return JNI_FALSE; |
sla@2327 | 1187 | } else if (strcmp(arg, "-verbosegc") == 0) { |
sla@2327 | 1188 | AddOption("-verbose:gc", NULL); |
sla@2327 | 1189 | } else if (strcmp(arg, "-t") == 0) { |
sla@2327 | 1190 | AddOption("-Xt", NULL); |
sla@2327 | 1191 | } else if (strcmp(arg, "-tm") == 0) { |
sla@2327 | 1192 | AddOption("-Xtm", NULL); |
sla@2327 | 1193 | } else if (strcmp(arg, "-debug") == 0) { |
sla@2327 | 1194 | AddOption("-Xdebug", NULL); |
sla@2327 | 1195 | } else if (strcmp(arg, "-noclassgc") == 0) { |
sla@2327 | 1196 | AddOption("-Xnoclassgc", NULL); |
sla@2327 | 1197 | } else if (strcmp(arg, "-Xfuture") == 0) { |
sla@2327 | 1198 | AddOption("-Xverify:all", NULL); |
sla@2327 | 1199 | } else if (strcmp(arg, "-verify") == 0) { |
sla@2327 | 1200 | AddOption("-Xverify:all", NULL); |
sla@2327 | 1201 | } else if (strcmp(arg, "-verifyremote") == 0) { |
sla@2327 | 1202 | AddOption("-Xverify:remote", NULL); |
sla@2327 | 1203 | } else if (strcmp(arg, "-noverify") == 0) { |
sla@2327 | 1204 | AddOption("-Xverify:none", NULL); |
sla@2327 | 1205 | } else if (strcmp(arg, "-XXsuppressExitMessage") == 0) { |
sla@2327 | 1206 | noExitErrorMessage = 1; |
sla@2327 | 1207 | } else if (strncmp(arg, "-prof", 5) == 0) { |
sla@2327 | 1208 | char *p = arg + 5; |
sla@2327 | 1209 | char *tmp = JLI_MemAlloc(strlen(arg) + 50); |
sla@2327 | 1210 | if (*p) { |
sla@2327 | 1211 | sprintf(tmp, "-Xrunhprof:cpu=old,file=%s", p + 1); |
sla@2327 | 1212 | } else { |
sla@2327 | 1213 | sprintf(tmp, "-Xrunhprof:cpu=old,file=java.prof"); |
sla@2327 | 1214 | } |
sla@2327 | 1215 | AddOption(tmp, NULL); |
sla@2327 | 1216 | } else if (strncmp(arg, "-ss", 3) == 0 || |
sla@2327 | 1217 | strncmp(arg, "-oss", 4) == 0 || |
sla@2327 | 1218 | strncmp(arg, "-ms", 3) == 0 || |
sla@2327 | 1219 | strncmp(arg, "-mx", 3) == 0) { |
sla@2327 | 1220 | char *tmp = JLI_MemAlloc(strlen(arg) + 6); |
sla@2327 | 1221 | sprintf(tmp, "-X%s", arg + 1); /* skip '-' */ |
sla@2327 | 1222 | AddOption(tmp, NULL); |
sla@2327 | 1223 | } else if (strcmp(arg, "-checksource") == 0 || |
sla@2327 | 1224 | strcmp(arg, "-cs") == 0 || |
sla@2327 | 1225 | strcmp(arg, "-noasyncgc") == 0) { |
sla@2327 | 1226 | /* No longer supported */ |
sla@2327 | 1227 | fprintf(stderr, |
sla@2327 | 1228 | "Warning: %s option is no longer supported.\n", |
sla@2327 | 1229 | arg); |
sla@2327 | 1230 | } else if (strncmp(arg, "-version:", 9) == 0 || |
sla@2327 | 1231 | strcmp(arg, "-no-jre-restrict-search") == 0 || |
sla@2327 | 1232 | strcmp(arg, "-jre-restrict-search") == 0 || |
sla@2327 | 1233 | strncmp(arg, "-splash:", 8) == 0) { |
sla@2327 | 1234 | ; /* Ignore machine independent options already handled */ |
sla@2327 | 1235 | } else if (RemovableMachineDependentOption(arg) ) { |
sla@2327 | 1236 | ; /* Do not pass option to vm. */ |
sla@2327 | 1237 | } |
sla@2327 | 1238 | else { |
sla@2327 | 1239 | AddOption(arg, NULL); |
sla@2327 | 1240 | } |
sla@2327 | 1241 | } |
sla@2327 | 1242 | |
sla@2327 | 1243 | if (--argc >= 0) { |
sla@2327 | 1244 | if (jarflag) { |
sla@2327 | 1245 | *pjarfile = *argv++; |
sla@2327 | 1246 | *pclassname = 0; |
sla@2327 | 1247 | } else { |
sla@2327 | 1248 | *pjarfile = 0; |
sla@2327 | 1249 | *pclassname = *argv++; |
sla@2327 | 1250 | } |
sla@2327 | 1251 | *pargc = argc; |
sla@2327 | 1252 | *pargv = argv; |
sla@2327 | 1253 | } |
sla@2327 | 1254 | |
sla@2327 | 1255 | return JNI_TRUE; |
sla@2327 | 1256 | } |
sla@2327 | 1257 | |
sla@2327 | 1258 | /* |
sla@2327 | 1259 | * Initializes the Java Virtual Machine. Also frees options array when |
sla@2327 | 1260 | * finished. |
sla@2327 | 1261 | */ |
sla@2327 | 1262 | static jboolean |
sla@2327 | 1263 | InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn) |
sla@2327 | 1264 | { |
sla@2327 | 1265 | JavaVMInitArgs args; |
sla@2327 | 1266 | jint r; |
sla@2327 | 1267 | |
sla@2327 | 1268 | memset(&args, 0, sizeof(args)); |
sla@2327 | 1269 | args.version = JNI_VERSION_1_2; |
sla@2327 | 1270 | args.nOptions = numOptions; |
sla@2327 | 1271 | args.options = options; |
sla@2327 | 1272 | args.ignoreUnrecognized = JNI_FALSE; |
sla@2327 | 1273 | |
sla@2327 | 1274 | if (_launcher_debug) { |
sla@2327 | 1275 | int i = 0; |
sla@2327 | 1276 | printf("JavaVM args:\n "); |
sla@2327 | 1277 | printf("version 0x%08lx, ", (long)args.version); |
sla@2327 | 1278 | printf("ignoreUnrecognized is %s, ", |
sla@2327 | 1279 | args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE"); |
sla@2327 | 1280 | printf("nOptions is %ld\n", (long)args.nOptions); |
sla@2327 | 1281 | for (i = 0; i < numOptions; i++) |
sla@2327 | 1282 | printf(" option[%2d] = '%s'\n", |
sla@2327 | 1283 | i, args.options[i].optionString); |
sla@2327 | 1284 | } |
sla@2327 | 1285 | |
sla@2327 | 1286 | r = ifn->CreateJavaVM(pvm, (void **)penv, &args); |
sla@2327 | 1287 | JLI_MemFree(options); |
sla@2327 | 1288 | return r == JNI_OK; |
sla@2327 | 1289 | } |
sla@2327 | 1290 | |
sla@2327 | 1291 | |
sla@2327 | 1292 | #define NULL_CHECK0(e) if ((e) == 0) return 0 |
sla@2327 | 1293 | #define NULL_CHECK(e) if ((e) == 0) return |
sla@2327 | 1294 | |
sla@2327 | 1295 | static jstring platformEncoding = NULL; |
sla@2327 | 1296 | static jstring getPlatformEncoding(JNIEnv *env) { |
sla@2327 | 1297 | if (platformEncoding == NULL) { |
sla@2327 | 1298 | jstring propname = (*env)->NewStringUTF(env, "sun.jnu.encoding"); |
sla@2327 | 1299 | if (propname) { |
sla@2327 | 1300 | jclass cls; |
sla@2327 | 1301 | jmethodID mid; |
sla@2327 | 1302 | NULL_CHECK0 (cls = (*env)->FindClass(env, "java/lang/System")); |
sla@2327 | 1303 | NULL_CHECK0 (mid = (*env)->GetStaticMethodID( |
sla@2327 | 1304 | env, cls, |
sla@2327 | 1305 | "getProperty", |
sla@2327 | 1306 | "(Ljava/lang/String;)Ljava/lang/String;")); |
sla@2327 | 1307 | platformEncoding = (*env)->CallStaticObjectMethod ( |
sla@2327 | 1308 | env, cls, mid, propname); |
sla@2327 | 1309 | } |
sla@2327 | 1310 | } |
sla@2327 | 1311 | return platformEncoding; |
sla@2327 | 1312 | } |
sla@2327 | 1313 | |
sla@2327 | 1314 | static jboolean isEncodingSupported(JNIEnv *env, jstring enc) { |
sla@2327 | 1315 | jclass cls; |
sla@2327 | 1316 | jmethodID mid; |
sla@2327 | 1317 | NULL_CHECK0 (cls = (*env)->FindClass(env, "java/nio/charset/Charset")); |
sla@2327 | 1318 | NULL_CHECK0 (mid = (*env)->GetStaticMethodID( |
sla@2327 | 1319 | env, cls, |
sla@2327 | 1320 | "isSupported", |
sla@2327 | 1321 | "(Ljava/lang/String;)Z")); |
sla@2327 | 1322 | return (*env)->CallStaticBooleanMethod(env, cls, mid, enc); |
sla@2327 | 1323 | } |
sla@2327 | 1324 | |
sla@2327 | 1325 | /* |
sla@2327 | 1326 | * Returns a new Java string object for the specified platform string. |
sla@2327 | 1327 | */ |
sla@2327 | 1328 | static jstring |
sla@2327 | 1329 | NewPlatformString(JNIEnv *env, char *s) |
sla@2327 | 1330 | { |
sla@2327 | 1331 | int len = (int)strlen(s); |
sla@2327 | 1332 | jclass cls; |
sla@2327 | 1333 | jmethodID mid; |
sla@2327 | 1334 | jbyteArray ary; |
sla@2327 | 1335 | jstring enc; |
sla@2327 | 1336 | |
sla@2327 | 1337 | if (s == NULL) |
sla@2327 | 1338 | return 0; |
sla@2327 | 1339 | enc = getPlatformEncoding(env); |
sla@2327 | 1340 | |
sla@2327 | 1341 | ary = (*env)->NewByteArray(env, len); |
sla@2327 | 1342 | if (ary != 0) { |
sla@2327 | 1343 | jstring str = 0; |
sla@2327 | 1344 | (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s); |
sla@2327 | 1345 | if (!(*env)->ExceptionOccurred(env)) { |
sla@2327 | 1346 | if (isEncodingSupported(env, enc) == JNI_TRUE) { |
sla@2327 | 1347 | NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String")); |
sla@2327 | 1348 | NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>", |
sla@2327 | 1349 | "([BLjava/lang/String;)V")); |
sla@2327 | 1350 | str = (*env)->NewObject(env, cls, mid, ary, enc); |
sla@2327 | 1351 | } else { |
sla@2327 | 1352 | /*If the encoding specified in sun.jnu.encoding is not |
sla@2327 | 1353 | endorsed by "Charset.isSupported" we have to fall back |
sla@2327 | 1354 | to use String(byte[]) explicitly here without specifying |
sla@2327 | 1355 | the encoding name, in which the StringCoding class will |
sla@2327 | 1356 | pickup the iso-8859-1 as the fallback converter for us. |
sla@2327 | 1357 | */ |
sla@2327 | 1358 | NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String")); |
sla@2327 | 1359 | NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>", |
sla@2327 | 1360 | "([B)V")); |
sla@2327 | 1361 | str = (*env)->NewObject(env, cls, mid, ary); |
sla@2327 | 1362 | } |
sla@2327 | 1363 | (*env)->DeleteLocalRef(env, ary); |
sla@2327 | 1364 | return str; |
sla@2327 | 1365 | } |
sla@2327 | 1366 | } |
sla@2327 | 1367 | return 0; |
sla@2327 | 1368 | } |
sla@2327 | 1369 | |
sla@2327 | 1370 | /* |
sla@2327 | 1371 | * Returns a new array of Java string objects for the specified |
sla@2327 | 1372 | * array of platform strings. |
sla@2327 | 1373 | */ |
sla@2327 | 1374 | static jobjectArray |
sla@2327 | 1375 | NewPlatformStringArray(JNIEnv *env, char **strv, int strc) |
sla@2327 | 1376 | { |
sla@2327 | 1377 | jarray cls; |
sla@2327 | 1378 | jarray ary; |
sla@2327 | 1379 | int i; |
sla@2327 | 1380 | |
sla@2327 | 1381 | NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String")); |
sla@2327 | 1382 | NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0)); |
sla@2327 | 1383 | for (i = 0; i < strc; i++) { |
sla@2327 | 1384 | jstring str = NewPlatformString(env, *strv++); |
sla@2327 | 1385 | NULL_CHECK0(str); |
sla@2327 | 1386 | (*env)->SetObjectArrayElement(env, ary, i, str); |
sla@2327 | 1387 | (*env)->DeleteLocalRef(env, str); |
sla@2327 | 1388 | } |
sla@2327 | 1389 | return ary; |
sla@2327 | 1390 | } |
sla@2327 | 1391 | |
sla@2327 | 1392 | /* |
sla@2327 | 1393 | * Loads a class, convert the '.' to '/'. |
sla@2327 | 1394 | */ |
sla@2327 | 1395 | static jclass |
sla@2327 | 1396 | LoadClass(JNIEnv *env, char *name) |
sla@2327 | 1397 | { |
sla@2327 | 1398 | char *buf = JLI_MemAlloc(strlen(name) + 1); |
sla@2327 | 1399 | char *s = buf, *t = name, c; |
sla@2327 | 1400 | jclass cls; |
sla@2327 | 1401 | jlong start, end; |
sla@2327 | 1402 | |
sla@2327 | 1403 | if (_launcher_debug) |
sla@2327 | 1404 | start = CounterGet(); |
sla@2327 | 1405 | |
sla@2327 | 1406 | do { |
sla@2327 | 1407 | c = *t++; |
sla@2327 | 1408 | *s++ = (c == '.') ? '/' : c; |
sla@2327 | 1409 | } while (c != '\0'); |
sla@2327 | 1410 | cls = (*env)->FindClass(env, buf); |
sla@2327 | 1411 | JLI_MemFree(buf); |
sla@2327 | 1412 | |
sla@2327 | 1413 | if (_launcher_debug) { |
sla@2327 | 1414 | end = CounterGet(); |
sla@2327 | 1415 | printf("%ld micro seconds to load main class\n", |
sla@2327 | 1416 | (long)(jint)Counter2Micros(end-start)); |
sla@2327 | 1417 | printf("----_JAVA_LAUNCHER_DEBUG----\n"); |
sla@2327 | 1418 | } |
sla@2327 | 1419 | |
sla@2327 | 1420 | return cls; |
sla@2327 | 1421 | } |
sla@2327 | 1422 | |
sla@2327 | 1423 | |
sla@2327 | 1424 | /* |
sla@2327 | 1425 | * Returns the main class name for the specified jar file. |
sla@2327 | 1426 | */ |
sla@2327 | 1427 | static jstring |
sla@2327 | 1428 | GetMainClassName(JNIEnv *env, char *jarname) |
sla@2327 | 1429 | { |
sla@2327 | 1430 | #define MAIN_CLASS "Main-Class" |
sla@2327 | 1431 | jclass cls; |
sla@2327 | 1432 | jmethodID mid; |
sla@2327 | 1433 | jobject jar, man, attr; |
sla@2327 | 1434 | jstring str, result = 0; |
sla@2327 | 1435 | |
sla@2327 | 1436 | NULL_CHECK0(cls = (*env)->FindClass(env, "java/util/jar/JarFile")); |
sla@2327 | 1437 | NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>", |
sla@2327 | 1438 | "(Ljava/lang/String;)V")); |
sla@2327 | 1439 | NULL_CHECK0(str = NewPlatformString(env, jarname)); |
sla@2327 | 1440 | NULL_CHECK0(jar = (*env)->NewObject(env, cls, mid, str)); |
sla@2327 | 1441 | NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "getManifest", |
sla@2327 | 1442 | "()Ljava/util/jar/Manifest;")); |
sla@2327 | 1443 | man = (*env)->CallObjectMethod(env, jar, mid); |
sla@2327 | 1444 | if (man != 0) { |
sla@2327 | 1445 | NULL_CHECK0(mid = (*env)->GetMethodID(env, |
sla@2327 | 1446 | (*env)->GetObjectClass(env, man), |
sla@2327 | 1447 | "getMainAttributes", |
sla@2327 | 1448 | "()Ljava/util/jar/Attributes;")); |
sla@2327 | 1449 | attr = (*env)->CallObjectMethod(env, man, mid); |
sla@2327 | 1450 | if (attr != 0) { |
sla@2327 | 1451 | NULL_CHECK0(mid = (*env)->GetMethodID(env, |
sla@2327 | 1452 | (*env)->GetObjectClass(env, attr), |
sla@2327 | 1453 | "getValue", |
sla@2327 | 1454 | "(Ljava/lang/String;)Ljava/lang/String;")); |
sla@2327 | 1455 | NULL_CHECK0(str = NewPlatformString(env, MAIN_CLASS)); |
sla@2327 | 1456 | result = (*env)->CallObjectMethod(env, attr, mid, str); |
sla@2327 | 1457 | } |
sla@2327 | 1458 | } |
sla@2327 | 1459 | return result; |
sla@2327 | 1460 | } |
sla@2327 | 1461 | |
sla@2327 | 1462 | #ifdef JAVA_ARGS |
sla@2327 | 1463 | static char *java_args[] = JAVA_ARGS; |
sla@2327 | 1464 | static char *app_classpath[] = APP_CLASSPATH; |
sla@2327 | 1465 | |
sla@2327 | 1466 | /* |
sla@2327 | 1467 | * For tools, convert command line args thus: |
sla@2327 | 1468 | * javac -cp foo:foo/"*" -J-ms32m ... |
sla@2327 | 1469 | * java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ... |
sla@2327 | 1470 | */ |
sla@2327 | 1471 | static void |
sla@2327 | 1472 | TranslateApplicationArgs(int *pargc, char ***pargv) |
sla@2327 | 1473 | { |
sla@2327 | 1474 | const int NUM_ARGS = (sizeof(java_args) / sizeof(char *)); |
sla@2327 | 1475 | int argc = *pargc; |
sla@2327 | 1476 | char **argv = *pargv; |
sla@2327 | 1477 | int nargc = argc + NUM_ARGS; |
sla@2327 | 1478 | char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *)); |
sla@2327 | 1479 | int i; |
sla@2327 | 1480 | |
sla@2327 | 1481 | *pargc = nargc; |
sla@2327 | 1482 | *pargv = nargv; |
sla@2327 | 1483 | |
sla@2327 | 1484 | /* Copy the VM arguments (i.e. prefixed with -J) */ |
sla@2327 | 1485 | for (i = 0; i < NUM_ARGS; i++) { |
sla@2327 | 1486 | char *arg = java_args[i]; |
sla@2327 | 1487 | if (arg[0] == '-' && arg[1] == 'J') { |
sla@2327 | 1488 | *nargv++ = arg + 2; |
sla@2327 | 1489 | } |
sla@2327 | 1490 | } |
sla@2327 | 1491 | |
sla@2327 | 1492 | for (i = 0; i < argc; i++) { |
sla@2327 | 1493 | char *arg = argv[i]; |
sla@2327 | 1494 | if (arg[0] == '-' && arg[1] == 'J') { |
sla@2327 | 1495 | if (arg[2] == '\0') { |
sla@2327 | 1496 | ReportErrorMessage("Error: the -J option should not be " |
sla@2327 | 1497 | "followed by a space.", JNI_TRUE); |
sla@2327 | 1498 | exit(1); |
sla@2327 | 1499 | } |
sla@2327 | 1500 | *nargv++ = arg + 2; |
sla@2327 | 1501 | } |
sla@2327 | 1502 | } |
sla@2327 | 1503 | |
sla@2327 | 1504 | /* Copy the rest of the arguments */ |
sla@2327 | 1505 | for (i = 0; i < NUM_ARGS; i++) { |
sla@2327 | 1506 | char *arg = java_args[i]; |
sla@2327 | 1507 | if (arg[0] != '-' || arg[1] != 'J') { |
sla@2327 | 1508 | *nargv++ = arg; |
sla@2327 | 1509 | } |
sla@2327 | 1510 | } |
sla@2327 | 1511 | for (i = 0; i < argc; i++) { |
sla@2327 | 1512 | char *arg = argv[i]; |
sla@2327 | 1513 | if (arg[0] == '-') { |
sla@2327 | 1514 | if (arg[1] == 'J') |
sla@2327 | 1515 | continue; |
sla@2327 | 1516 | #ifdef EXPAND_CLASSPATH_WILDCARDS |
sla@2327 | 1517 | if (arg[1] == 'c' |
sla@2327 | 1518 | && (strcmp(arg, "-cp") == 0 || |
sla@2327 | 1519 | strcmp(arg, "-classpath") == 0) |
sla@2327 | 1520 | && i < argc - 1) { |
sla@2327 | 1521 | *nargv++ = arg; |
sla@2327 | 1522 | *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]); |
sla@2327 | 1523 | i++; |
sla@2327 | 1524 | continue; |
sla@2327 | 1525 | } |
sla@2327 | 1526 | #endif |
sla@2327 | 1527 | } |
sla@2327 | 1528 | *nargv++ = arg; |
sla@2327 | 1529 | } |
sla@2327 | 1530 | *nargv = 0; |
sla@2327 | 1531 | } |
sla@2327 | 1532 | |
sla@2327 | 1533 | /* |
sla@2327 | 1534 | * For our tools, we try to add 3 VM options: |
sla@2327 | 1535 | * -Denv.class.path=<envcp> |
sla@2327 | 1536 | * -Dapplication.home=<apphome> |
sla@2327 | 1537 | * -Djava.class.path=<appcp> |
sla@2327 | 1538 | * <envcp> is the user's setting of CLASSPATH -- for instance the user |
sla@2327 | 1539 | * tells javac where to find binary classes through this environment |
sla@2327 | 1540 | * variable. Notice that users will be able to compile against our |
sla@2327 | 1541 | * tools classes (sun.tools.javac.Main) only if they explicitly add |
sla@2327 | 1542 | * tools.jar to CLASSPATH. |
sla@2327 | 1543 | * <apphome> is the directory where the application is installed. |
sla@2327 | 1544 | * <appcp> is the classpath to where our apps' classfiles are. |
sla@2327 | 1545 | */ |
sla@2327 | 1546 | static jboolean |
sla@2327 | 1547 | AddApplicationOptions() |
sla@2327 | 1548 | { |
sla@2327 | 1549 | const int NUM_APP_CLASSPATH = (sizeof(app_classpath) / sizeof(char *)); |
sla@2327 | 1550 | char *envcp, *appcp, *apphome; |
sla@2327 | 1551 | char home[MAXPATHLEN]; /* application home */ |
sla@2327 | 1552 | char separator[] = { PATH_SEPARATOR, '\0' }; |
sla@2327 | 1553 | int size, i; |
sla@2327 | 1554 | int strlenHome; |
sla@2327 | 1555 | |
sla@2327 | 1556 | { |
sla@2327 | 1557 | const char *s = getenv("CLASSPATH"); |
sla@2327 | 1558 | if (s) { |
sla@2327 | 1559 | s = (char *) JLI_WildcardExpandClasspath(s); |
sla@2327 | 1560 | /* 40 for -Denv.class.path= */ |
sla@2327 | 1561 | envcp = (char *)JLI_MemAlloc(strlen(s) + 40); |
sla@2327 | 1562 | sprintf(envcp, "-Denv.class.path=%s", s); |
sla@2327 | 1563 | AddOption(envcp, NULL); |
sla@2327 | 1564 | } |
sla@2327 | 1565 | } |
sla@2327 | 1566 | |
sla@2327 | 1567 | if (!GetApplicationHome(home, sizeof(home))) { |
sla@2327 | 1568 | ReportErrorMessage("Can't determine application home", JNI_TRUE); |
sla@2327 | 1569 | return JNI_FALSE; |
sla@2327 | 1570 | } |
sla@2327 | 1571 | |
sla@2327 | 1572 | /* 40 for '-Dapplication.home=' */ |
sla@2327 | 1573 | apphome = (char *)JLI_MemAlloc(strlen(home) + 40); |
sla@2327 | 1574 | sprintf(apphome, "-Dapplication.home=%s", home); |
sla@2327 | 1575 | AddOption(apphome, NULL); |
sla@2327 | 1576 | |
sla@2327 | 1577 | /* How big is the application's classpath? */ |
sla@2327 | 1578 | size = 40; /* 40: "-Djava.class.path=" */ |
sla@2327 | 1579 | strlenHome = (int)strlen(home); |
sla@2327 | 1580 | for (i = 0; i < NUM_APP_CLASSPATH; i++) { |
sla@2327 | 1581 | size += strlenHome + (int)strlen(app_classpath[i]) + 1; /* 1: separator */ |
sla@2327 | 1582 | } |
sla@2327 | 1583 | appcp = (char *)JLI_MemAlloc(size + 1); |
sla@2327 | 1584 | strcpy(appcp, "-Djava.class.path="); |
sla@2327 | 1585 | for (i = 0; i < NUM_APP_CLASSPATH; i++) { |
sla@2327 | 1586 | strcat(appcp, home); /* c:\program files\myapp */ |
sla@2327 | 1587 | strcat(appcp, app_classpath[i]); /* \lib\myapp.jar */ |
sla@2327 | 1588 | strcat(appcp, separator); /* ; */ |
sla@2327 | 1589 | } |
sla@2327 | 1590 | appcp[strlen(appcp)-1] = '\0'; /* remove trailing path separator */ |
sla@2327 | 1591 | AddOption(appcp, NULL); |
sla@2327 | 1592 | return JNI_TRUE; |
sla@2327 | 1593 | } |
sla@2327 | 1594 | #endif /* JAVA_ARGS */ |
sla@2327 | 1595 | |
sla@2327 | 1596 | /* |
sla@2327 | 1597 | * inject the -Dsun.java.command pseudo property into the args structure |
sla@2327 | 1598 | * this pseudo property is used in the HotSpot VM to expose the |
sla@2327 | 1599 | * Java class name and arguments to the main method to the VM. The |
sla@2327 | 1600 | * HotSpot VM uses this pseudo property to store the Java class name |
sla@2327 | 1601 | * (or jar file name) and the arguments to the class's main method |
sla@2327 | 1602 | * to the instrumentation memory region. The sun.java.command pseudo |
sla@2327 | 1603 | * property is not exported by HotSpot to the Java layer. |
sla@2327 | 1604 | */ |
sla@2327 | 1605 | void |
sla@2327 | 1606 | SetJavaCommandLineProp(char *classname, char *jarfile, |
sla@2327 | 1607 | int argc, char **argv) |
sla@2327 | 1608 | { |
sla@2327 | 1609 | |
sla@2327 | 1610 | int i = 0; |
sla@2327 | 1611 | size_t len = 0; |
sla@2327 | 1612 | char* javaCommand = NULL; |
sla@2327 | 1613 | char* dashDstr = "-Dsun.java.command="; |
sla@2327 | 1614 | |
sla@2327 | 1615 | if (classname == NULL && jarfile == NULL) { |
sla@2327 | 1616 | /* unexpected, one of these should be set. just return without |
sla@2327 | 1617 | * setting the property |
sla@2327 | 1618 | */ |
sla@2327 | 1619 | return; |
sla@2327 | 1620 | } |
sla@2327 | 1621 | |
sla@2327 | 1622 | /* if the class name is not set, then use the jarfile name */ |
sla@2327 | 1623 | if (classname == NULL) { |
sla@2327 | 1624 | classname = jarfile; |
sla@2327 | 1625 | } |
sla@2327 | 1626 | |
sla@2327 | 1627 | /* determine the amount of memory to allocate assuming |
sla@2327 | 1628 | * the individual components will be space separated |
sla@2327 | 1629 | */ |
sla@2327 | 1630 | len = strlen(classname); |
sla@2327 | 1631 | for (i = 0; i < argc; i++) { |
sla@2327 | 1632 | len += strlen(argv[i]) + 1; |
sla@2327 | 1633 | } |
sla@2327 | 1634 | |
sla@2327 | 1635 | /* allocate the memory */ |
sla@2327 | 1636 | javaCommand = (char*) JLI_MemAlloc(len + strlen(dashDstr) + 1); |
sla@2327 | 1637 | |
sla@2327 | 1638 | /* build the -D string */ |
sla@2327 | 1639 | *javaCommand = '\0'; |
sla@2327 | 1640 | strcat(javaCommand, dashDstr); |
sla@2327 | 1641 | strcat(javaCommand, classname); |
sla@2327 | 1642 | |
sla@2327 | 1643 | for (i = 0; i < argc; i++) { |
sla@2327 | 1644 | /* the components of the string are space separated. In |
sla@2327 | 1645 | * the case of embedded white space, the relationship of |
sla@2327 | 1646 | * the white space separated components to their true |
sla@2327 | 1647 | * positional arguments will be ambiguous. This issue may |
sla@2327 | 1648 | * be addressed in a future release. |
sla@2327 | 1649 | */ |
sla@2327 | 1650 | strcat(javaCommand, " "); |
sla@2327 | 1651 | strcat(javaCommand, argv[i]); |
sla@2327 | 1652 | } |
sla@2327 | 1653 | |
sla@2327 | 1654 | AddOption(javaCommand, NULL); |
sla@2327 | 1655 | } |
sla@2327 | 1656 | |
sla@2327 | 1657 | /* |
sla@2327 | 1658 | * JVM would like to know if it's created by a standard Sun launcher, or by |
sla@2327 | 1659 | * user native application, the following property indicates the former. |
sla@2327 | 1660 | */ |
sla@2327 | 1661 | void SetJavaLauncherProp() { |
sla@2327 | 1662 | AddOption("-Dsun.java.launcher=" LAUNCHER_TYPE, NULL); |
sla@2327 | 1663 | } |
sla@2327 | 1664 | |
sla@2327 | 1665 | /* |
sla@2327 | 1666 | * Prints the version information from the java.version and other properties. |
sla@2327 | 1667 | */ |
sla@2327 | 1668 | static void |
sla@2327 | 1669 | PrintJavaVersion(JNIEnv *env) |
sla@2327 | 1670 | { |
sla@2327 | 1671 | jclass ver; |
sla@2327 | 1672 | jmethodID print; |
sla@2327 | 1673 | |
sla@2327 | 1674 | NULL_CHECK(ver = (*env)->FindClass(env, "sun/misc/Version")); |
sla@2327 | 1675 | NULL_CHECK(print = (*env)->GetStaticMethodID(env, ver, "print", "()V")); |
sla@2327 | 1676 | |
sla@2327 | 1677 | (*env)->CallStaticVoidMethod(env, ver, print); |
sla@2327 | 1678 | } |
sla@2327 | 1679 | |
sla@2327 | 1680 | /* |
sla@2327 | 1681 | * Prints default usage message. |
sla@2327 | 1682 | */ |
sla@2327 | 1683 | static void |
sla@2327 | 1684 | PrintUsage(void) |
sla@2327 | 1685 | { |
sla@2327 | 1686 | #ifndef GAMMA |
sla@2327 | 1687 | int i; |
sla@2327 | 1688 | #endif |
sla@2327 | 1689 | |
sla@2327 | 1690 | fprintf(stdout, |
sla@2327 | 1691 | "Usage: %s [-options] class [args...]\n" |
sla@2327 | 1692 | " (to execute a class)\n" |
sla@2327 | 1693 | " or %s [-options] -jar jarfile [args...]\n" |
sla@2327 | 1694 | " (to execute a jar file)\n" |
sla@2327 | 1695 | "\n" |
sla@2327 | 1696 | "where options include:\n", |
sla@2327 | 1697 | progname, |
sla@2327 | 1698 | progname); |
sla@2327 | 1699 | |
sla@2327 | 1700 | #ifndef GAMMA |
sla@2327 | 1701 | PrintMachineDependentOptions(); |
sla@2327 | 1702 | |
sla@2327 | 1703 | if ((knownVMs[0].flag == VM_KNOWN) || |
sla@2327 | 1704 | (knownVMs[0].flag == VM_IF_SERVER_CLASS)) { |
sla@2327 | 1705 | fprintf(stdout, " %s\t to select the \"%s\" VM\n", |
sla@2327 | 1706 | knownVMs[0].name, knownVMs[0].name+1); |
sla@2327 | 1707 | } |
sla@2327 | 1708 | for (i=1; i<knownVMsCount; i++) { |
sla@2327 | 1709 | if (knownVMs[i].flag == VM_KNOWN) |
sla@2327 | 1710 | fprintf(stdout, " %s\t to select the \"%s\" VM\n", |
sla@2327 | 1711 | knownVMs[i].name, knownVMs[i].name+1); |
sla@2327 | 1712 | } |
sla@2327 | 1713 | for (i=1; i<knownVMsCount; i++) { |
sla@2327 | 1714 | if (knownVMs[i].flag == VM_ALIASED_TO) |
sla@2327 | 1715 | fprintf(stdout, " %s\t is a synonym for " |
sla@2327 | 1716 | "the \"%s\" VM [deprecated]\n", |
sla@2327 | 1717 | knownVMs[i].name, knownVMs[i].alias+1); |
sla@2327 | 1718 | } |
sla@2327 | 1719 | /* The first known VM is the default */ |
sla@2327 | 1720 | { |
sla@2327 | 1721 | const char* defaultVM = knownVMs[0].name+1; |
sla@2327 | 1722 | const char* punctuation = "."; |
sla@2327 | 1723 | const char* reason = ""; |
sla@2327 | 1724 | if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && |
sla@2327 | 1725 | (ServerClassMachine() == JNI_TRUE)) { |
sla@2327 | 1726 | defaultVM = knownVMs[0].server_class+1; |
sla@2327 | 1727 | punctuation = ", "; |
sla@2327 | 1728 | reason = "because you are running on a server-class machine.\n"; |
sla@2327 | 1729 | } |
sla@2327 | 1730 | fprintf(stdout, " The default VM is %s%s\n", |
sla@2327 | 1731 | defaultVM, punctuation); |
sla@2327 | 1732 | fprintf(stdout, " %s\n", |
sla@2327 | 1733 | reason); |
sla@2327 | 1734 | } |
sla@2327 | 1735 | #endif /* ifndef GAMMA */ |
sla@2327 | 1736 | |
sla@2327 | 1737 | fprintf(stdout, |
sla@2327 | 1738 | " -cp <class search path of directories and zip/jar files>\n" |
sla@2327 | 1739 | " -classpath <class search path of directories and zip/jar files>\n" |
sla@2327 | 1740 | " A %c separated list of directories, JAR archives,\n" |
sla@2327 | 1741 | " and ZIP archives to search for class files.\n" |
sla@2327 | 1742 | " -D<name>=<value>\n" |
sla@2327 | 1743 | " set a system property\n" |
sla@2327 | 1744 | " -verbose[:class|gc|jni]\n" |
sla@2327 | 1745 | " enable verbose output\n" |
sla@2327 | 1746 | " -version print product version and exit\n" |
sla@2327 | 1747 | " -version:<value>\n" |
sla@2327 | 1748 | " require the specified version to run\n" |
sla@2327 | 1749 | " -showversion print product version and continue\n" |
sla@2327 | 1750 | " -jre-restrict-search | -jre-no-restrict-search\n" |
sla@2327 | 1751 | " include/exclude user private JREs in the version search\n" |
sla@2327 | 1752 | " -? -help print this help message\n" |
sla@2327 | 1753 | " -X print help on non-standard options\n" |
sla@2327 | 1754 | " -ea[:<packagename>...|:<classname>]\n" |
sla@2327 | 1755 | " -enableassertions[:<packagename>...|:<classname>]\n" |
sla@2327 | 1756 | " enable assertions\n" |
sla@2327 | 1757 | " -da[:<packagename>...|:<classname>]\n" |
sla@2327 | 1758 | " -disableassertions[:<packagename>...|:<classname>]\n" |
sla@2327 | 1759 | " disable assertions\n" |
sla@2327 | 1760 | " -esa | -enablesystemassertions\n" |
sla@2327 | 1761 | " enable system assertions\n" |
sla@2327 | 1762 | " -dsa | -disablesystemassertions\n" |
sla@2327 | 1763 | " disable system assertions\n" |
sla@2327 | 1764 | " -agentlib:<libname>[=<options>]\n" |
sla@2327 | 1765 | " load native agent library <libname>, e.g. -agentlib:hprof\n" |
sla@2327 | 1766 | " see also, -agentlib:jdwp=help and -agentlib:hprof=help\n" |
sla@2327 | 1767 | " -agentpath:<pathname>[=<options>]\n" |
sla@2327 | 1768 | " load native agent library by full pathname\n" |
sla@2327 | 1769 | " -javaagent:<jarpath>[=<options>]\n" |
sla@2327 | 1770 | " load Java programming language agent, see java.lang.instrument\n" |
sla@2327 | 1771 | " -splash:<imagepath>\n" |
sla@2327 | 1772 | " show splash screen with specified image\n" |
sla@2327 | 1773 | |
sla@2327 | 1774 | ,PATH_SEPARATOR); |
sla@2327 | 1775 | } |
sla@2327 | 1776 | |
sla@2327 | 1777 | /* |
sla@2327 | 1778 | * Print usage message for -X options. |
sla@2327 | 1779 | */ |
sla@2327 | 1780 | static jint |
sla@2327 | 1781 | PrintXUsage(const char *jvmpath) |
sla@2327 | 1782 | { |
sla@2327 | 1783 | /* |
sla@2327 | 1784 | A 32 bit cushion to prevent buffer overrun, noting that |
sla@2327 | 1785 | fopen(3C) may fail if the buffer exceeds MAXPATHLEN. |
sla@2327 | 1786 | */ |
sla@2327 | 1787 | char path[MAXPATHLEN+32]; |
sla@2327 | 1788 | char buf[128]; |
sla@2327 | 1789 | size_t n; |
sla@2327 | 1790 | FILE *fp; |
sla@2327 | 1791 | static const char Xusage_txt[] = "/Xusage.txt"; |
sla@2327 | 1792 | |
sla@2327 | 1793 | strcpy(path, jvmpath); |
sla@2327 | 1794 | /* Note the FILE_SEPARATOR is platform dependent */ |
sla@2327 | 1795 | strcpy(strrchr(path, FILE_SEPARATOR), Xusage_txt); |
sla@2327 | 1796 | fp = fopen(path, "r"); |
sla@2327 | 1797 | if (fp == 0) { |
sla@2327 | 1798 | fprintf(stderr, "Can't open %s\n", path); |
sla@2327 | 1799 | return 1; |
sla@2327 | 1800 | } |
sla@2327 | 1801 | while ((n = fread(buf, 1, sizeof(buf), fp)) != 0) { |
sla@2327 | 1802 | fwrite(buf, 1, n, stdout); |
sla@2327 | 1803 | } |
sla@2327 | 1804 | fclose(fp); |
sla@2327 | 1805 | return 0; |
sla@2327 | 1806 | } |
sla@2327 | 1807 | |
sla@2327 | 1808 | #ifndef GAMMA |
sla@2327 | 1809 | /* |
sla@2327 | 1810 | * Read the jvm.cfg file and fill the knownJVMs[] array. |
sla@2327 | 1811 | * |
sla@2327 | 1812 | * The functionality of the jvm.cfg file is subject to change without |
sla@2327 | 1813 | * notice and the mechanism will be removed in the future. |
sla@2327 | 1814 | * |
sla@2327 | 1815 | * The lexical structure of the jvm.cfg file is as follows: |
sla@2327 | 1816 | * |
sla@2327 | 1817 | * jvmcfg := { vmLine } |
sla@2327 | 1818 | * vmLine := knownLine |
sla@2327 | 1819 | * | aliasLine |
sla@2327 | 1820 | * | warnLine |
sla@2327 | 1821 | * | ignoreLine |
sla@2327 | 1822 | * | errorLine |
sla@2327 | 1823 | * | predicateLine |
sla@2327 | 1824 | * | commentLine |
sla@2327 | 1825 | * knownLine := flag "KNOWN" EOL |
sla@2327 | 1826 | * warnLine := flag "WARN" EOL |
sla@2327 | 1827 | * ignoreLine := flag "IGNORE" EOL |
sla@2327 | 1828 | * errorLine := flag "ERROR" EOL |
sla@2327 | 1829 | * aliasLine := flag "ALIASED_TO" flag EOL |
sla@2327 | 1830 | * predicateLine := flag "IF_SERVER_CLASS" flag EOL |
sla@2327 | 1831 | * commentLine := "#" text EOL |
sla@2327 | 1832 | * flag := "-" identifier |
sla@2327 | 1833 | * |
sla@2327 | 1834 | * The semantics are that when someone specifies a flag on the command line: |
sla@2327 | 1835 | * - if the flag appears on a knownLine, then the identifier is used as |
sla@2327 | 1836 | * the name of the directory holding the JVM library (the name of the JVM). |
sla@2327 | 1837 | * - if the flag appears as the first flag on an aliasLine, the identifier |
sla@2327 | 1838 | * of the second flag is used as the name of the JVM. |
sla@2327 | 1839 | * - if the flag appears on a warnLine, the identifier is used as the |
sla@2327 | 1840 | * name of the JVM, but a warning is generated. |
sla@2327 | 1841 | * - if the flag appears on an ignoreLine, the identifier is recognized as the |
sla@2327 | 1842 | * name of a JVM, but the identifier is ignored and the default vm used |
sla@2327 | 1843 | * - if the flag appears on an errorLine, an error is generated. |
sla@2327 | 1844 | * - if the flag appears as the first flag on a predicateLine, and |
sla@2327 | 1845 | * the machine on which you are running passes the predicate indicated, |
sla@2327 | 1846 | * then the identifier of the second flag is used as the name of the JVM, |
sla@2327 | 1847 | * otherwise the identifier of the first flag is used as the name of the JVM. |
sla@2327 | 1848 | * If no flag is given on the command line, the first vmLine of the jvm.cfg |
sla@2327 | 1849 | * file determines the name of the JVM. |
sla@2327 | 1850 | * PredicateLines are only interpreted on first vmLine of a jvm.cfg file, |
sla@2327 | 1851 | * since they only make sense if someone hasn't specified the name of the |
sla@2327 | 1852 | * JVM on the command line. |
sla@2327 | 1853 | * |
sla@2327 | 1854 | * The intent of the jvm.cfg file is to allow several JVM libraries to |
sla@2327 | 1855 | * be installed in different subdirectories of a single JRE installation, |
sla@2327 | 1856 | * for space-savings and convenience in testing. |
sla@2327 | 1857 | * The intent is explicitly not to provide a full aliasing or predicate |
sla@2327 | 1858 | * mechanism. |
sla@2327 | 1859 | */ |
sla@2327 | 1860 | jint |
sla@2327 | 1861 | ReadKnownVMs(const char *jrepath, char * arch, jboolean speculative) |
sla@2327 | 1862 | { |
sla@2327 | 1863 | FILE *jvmCfg; |
sla@2327 | 1864 | char jvmCfgName[MAXPATHLEN+20]; |
sla@2327 | 1865 | char line[MAXPATHLEN+20]; |
sla@2327 | 1866 | int cnt = 0; |
sla@2327 | 1867 | int lineno = 0; |
sla@2327 | 1868 | jlong start, end; |
sla@2327 | 1869 | int vmType; |
sla@2327 | 1870 | char *tmpPtr; |
sla@2327 | 1871 | char *altVMName = NULL; |
sla@2327 | 1872 | char *serverClassVMName = NULL; |
sla@2327 | 1873 | static char *whiteSpace = " \t"; |
sla@2327 | 1874 | if (_launcher_debug) { |
sla@2327 | 1875 | start = CounterGet(); |
sla@2327 | 1876 | } |
sla@2327 | 1877 | |
sla@2327 | 1878 | strcpy(jvmCfgName, jrepath); |
sla@2327 | 1879 | strcat(jvmCfgName, FILESEP "lib" FILESEP); |
sla@2327 | 1880 | strcat(jvmCfgName, arch); |
sla@2327 | 1881 | strcat(jvmCfgName, FILESEP "jvm.cfg"); |
sla@2327 | 1882 | |
sla@2327 | 1883 | jvmCfg = fopen(jvmCfgName, "r"); |
sla@2327 | 1884 | if (jvmCfg == NULL) { |
sla@2327 | 1885 | if (!speculative) { |
sla@2327 | 1886 | ReportErrorMessage2("Error: could not open `%s'", jvmCfgName, |
sla@2327 | 1887 | JNI_TRUE); |
sla@2327 | 1888 | exit(1); |
sla@2327 | 1889 | } else { |
sla@2327 | 1890 | return -1; |
sla@2327 | 1891 | } |
sla@2327 | 1892 | } |
sla@2327 | 1893 | while (fgets(line, sizeof(line), jvmCfg) != NULL) { |
sla@2327 | 1894 | vmType = VM_UNKNOWN; |
sla@2327 | 1895 | lineno++; |
sla@2327 | 1896 | if (line[0] == '#') |
sla@2327 | 1897 | continue; |
sla@2327 | 1898 | if (line[0] != '-') { |
sla@2327 | 1899 | fprintf(stderr, "Warning: no leading - on line %d of `%s'\n", |
sla@2327 | 1900 | lineno, jvmCfgName); |
sla@2327 | 1901 | } |
sla@2327 | 1902 | if (cnt >= knownVMsLimit) { |
sla@2327 | 1903 | GrowKnownVMs(cnt); |
sla@2327 | 1904 | } |
sla@2327 | 1905 | line[strlen(line)-1] = '\0'; /* remove trailing newline */ |
sla@2327 | 1906 | tmpPtr = line + strcspn(line, whiteSpace); |
sla@2327 | 1907 | if (*tmpPtr == 0) { |
sla@2327 | 1908 | fprintf(stderr, "Warning: missing VM type on line %d of `%s'\n", |
sla@2327 | 1909 | lineno, jvmCfgName); |
sla@2327 | 1910 | } else { |
sla@2327 | 1911 | /* Null-terminate this string for JLI_StringDup below */ |
sla@2327 | 1912 | *tmpPtr++ = 0; |
sla@2327 | 1913 | tmpPtr += strspn(tmpPtr, whiteSpace); |
sla@2327 | 1914 | if (*tmpPtr == 0) { |
sla@2327 | 1915 | fprintf(stderr, "Warning: missing VM type on line %d of `%s'\n", |
sla@2327 | 1916 | lineno, jvmCfgName); |
sla@2327 | 1917 | } else { |
sla@2327 | 1918 | if (!strncmp(tmpPtr, "KNOWN", strlen("KNOWN"))) { |
sla@2327 | 1919 | vmType = VM_KNOWN; |
sla@2327 | 1920 | } else if (!strncmp(tmpPtr, "ALIASED_TO", strlen("ALIASED_TO"))) { |
sla@2327 | 1921 | tmpPtr += strcspn(tmpPtr, whiteSpace); |
sla@2327 | 1922 | if (*tmpPtr != 0) { |
sla@2327 | 1923 | tmpPtr += strspn(tmpPtr, whiteSpace); |
sla@2327 | 1924 | } |
sla@2327 | 1925 | if (*tmpPtr == 0) { |
sla@2327 | 1926 | fprintf(stderr, "Warning: missing VM alias on line %d of `%s'\n", |
sla@2327 | 1927 | lineno, jvmCfgName); |
sla@2327 | 1928 | } else { |
sla@2327 | 1929 | /* Null terminate altVMName */ |
sla@2327 | 1930 | altVMName = tmpPtr; |
sla@2327 | 1931 | tmpPtr += strcspn(tmpPtr, whiteSpace); |
sla@2327 | 1932 | *tmpPtr = 0; |
sla@2327 | 1933 | vmType = VM_ALIASED_TO; |
sla@2327 | 1934 | } |
sla@2327 | 1935 | } else if (!strncmp(tmpPtr, "WARN", strlen("WARN"))) { |
sla@2327 | 1936 | vmType = VM_WARN; |
sla@2327 | 1937 | } else if (!strncmp(tmpPtr, "IGNORE", strlen("IGNORE"))) { |
sla@2327 | 1938 | vmType = VM_IGNORE; |
sla@2327 | 1939 | } else if (!strncmp(tmpPtr, "ERROR", strlen("ERROR"))) { |
sla@2327 | 1940 | vmType = VM_ERROR; |
sla@2327 | 1941 | } else if (!strncmp(tmpPtr, |
sla@2327 | 1942 | "IF_SERVER_CLASS", |
sla@2327 | 1943 | strlen("IF_SERVER_CLASS"))) { |
sla@2327 | 1944 | tmpPtr += strcspn(tmpPtr, whiteSpace); |
sla@2327 | 1945 | if (*tmpPtr != 0) { |
sla@2327 | 1946 | tmpPtr += strspn(tmpPtr, whiteSpace); |
sla@2327 | 1947 | } |
sla@2327 | 1948 | if (*tmpPtr == 0) { |
sla@2327 | 1949 | fprintf(stderr, "Warning: missing server class VM on line %d of `%s'\n", |
sla@2327 | 1950 | lineno, jvmCfgName); |
sla@2327 | 1951 | } else { |
sla@2327 | 1952 | /* Null terminate server class VM name */ |
sla@2327 | 1953 | serverClassVMName = tmpPtr; |
sla@2327 | 1954 | tmpPtr += strcspn(tmpPtr, whiteSpace); |
sla@2327 | 1955 | *tmpPtr = 0; |
sla@2327 | 1956 | vmType = VM_IF_SERVER_CLASS; |
sla@2327 | 1957 | } |
sla@2327 | 1958 | } else { |
sla@2327 | 1959 | fprintf(stderr, "Warning: unknown VM type on line %d of `%s'\n", |
sla@2327 | 1960 | lineno, &jvmCfgName[0]); |
sla@2327 | 1961 | vmType = VM_KNOWN; |
sla@2327 | 1962 | } |
sla@2327 | 1963 | } |
sla@2327 | 1964 | } |
sla@2327 | 1965 | |
sla@2327 | 1966 | if (_launcher_debug) |
sla@2327 | 1967 | printf("jvm.cfg[%d] = ->%s<-\n", cnt, line); |
sla@2327 | 1968 | if (vmType != VM_UNKNOWN) { |
sla@2327 | 1969 | knownVMs[cnt].name = JLI_StringDup(line); |
sla@2327 | 1970 | knownVMs[cnt].flag = vmType; |
sla@2327 | 1971 | switch (vmType) { |
sla@2327 | 1972 | default: |
sla@2327 | 1973 | break; |
sla@2327 | 1974 | case VM_ALIASED_TO: |
sla@2327 | 1975 | knownVMs[cnt].alias = JLI_StringDup(altVMName); |
sla@2327 | 1976 | if (_launcher_debug) { |
sla@2327 | 1977 | printf(" name: %s vmType: %s alias: %s\n", |
sla@2327 | 1978 | knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias); |
sla@2327 | 1979 | } |
sla@2327 | 1980 | break; |
sla@2327 | 1981 | case VM_IF_SERVER_CLASS: |
sla@2327 | 1982 | knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName); |
sla@2327 | 1983 | if (_launcher_debug) { |
sla@2327 | 1984 | printf(" name: %s vmType: %s server_class: %s\n", |
sla@2327 | 1985 | knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class); |
sla@2327 | 1986 | } |
sla@2327 | 1987 | break; |
sla@2327 | 1988 | } |
sla@2327 | 1989 | cnt++; |
sla@2327 | 1990 | } |
sla@2327 | 1991 | } |
sla@2327 | 1992 | fclose(jvmCfg); |
sla@2327 | 1993 | knownVMsCount = cnt; |
sla@2327 | 1994 | |
sla@2327 | 1995 | if (_launcher_debug) { |
sla@2327 | 1996 | end = CounterGet(); |
sla@2327 | 1997 | printf("%ld micro seconds to parse jvm.cfg\n", |
sla@2327 | 1998 | (long)(jint)Counter2Micros(end-start)); |
sla@2327 | 1999 | } |
sla@2327 | 2000 | |
sla@2327 | 2001 | return cnt; |
sla@2327 | 2002 | } |
sla@2327 | 2003 | |
sla@2327 | 2004 | |
sla@2327 | 2005 | static void |
sla@2327 | 2006 | GrowKnownVMs(int minimum) |
sla@2327 | 2007 | { |
sla@2327 | 2008 | struct vmdesc* newKnownVMs; |
sla@2327 | 2009 | int newMax; |
sla@2327 | 2010 | |
sla@2327 | 2011 | newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit)); |
sla@2327 | 2012 | if (newMax <= minimum) { |
sla@2327 | 2013 | newMax = minimum; |
sla@2327 | 2014 | } |
sla@2327 | 2015 | newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc)); |
sla@2327 | 2016 | if (knownVMs != NULL) { |
sla@2327 | 2017 | memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc)); |
sla@2327 | 2018 | } |
sla@2327 | 2019 | JLI_MemFree(knownVMs); |
sla@2327 | 2020 | knownVMs = newKnownVMs; |
sla@2327 | 2021 | knownVMsLimit = newMax; |
sla@2327 | 2022 | } |
sla@2327 | 2023 | |
sla@2327 | 2024 | |
sla@2327 | 2025 | /* Returns index of VM or -1 if not found */ |
sla@2327 | 2026 | static int |
sla@2327 | 2027 | KnownVMIndex(const char* name) |
sla@2327 | 2028 | { |
sla@2327 | 2029 | int i; |
sla@2327 | 2030 | if (strncmp(name, "-J", 2) == 0) name += 2; |
sla@2327 | 2031 | for (i = 0; i < knownVMsCount; i++) { |
sla@2327 | 2032 | if (!strcmp(name, knownVMs[i].name)) { |
sla@2327 | 2033 | return i; |
sla@2327 | 2034 | } |
sla@2327 | 2035 | } |
sla@2327 | 2036 | return -1; |
sla@2327 | 2037 | } |
sla@2327 | 2038 | |
sla@2327 | 2039 | static void |
sla@2327 | 2040 | FreeKnownVMs() |
sla@2327 | 2041 | { |
sla@2327 | 2042 | int i; |
sla@2327 | 2043 | for (i = 0; i < knownVMsCount; i++) { |
sla@2327 | 2044 | JLI_MemFree(knownVMs[i].name); |
sla@2327 | 2045 | knownVMs[i].name = NULL; |
sla@2327 | 2046 | } |
sla@2327 | 2047 | JLI_MemFree(knownVMs); |
sla@2327 | 2048 | } |
sla@2327 | 2049 | |
sla@2327 | 2050 | |
sla@2327 | 2051 | /* |
sla@2327 | 2052 | * Displays the splash screen according to the jar file name |
sla@2327 | 2053 | * and image file names stored in environment variables |
sla@2327 | 2054 | */ |
sla@2327 | 2055 | static void |
sla@2327 | 2056 | ShowSplashScreen() |
sla@2327 | 2057 | { |
sla@2327 | 2058 | const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY); |
sla@2327 | 2059 | const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY); |
sla@2327 | 2060 | int data_size; |
sla@2327 | 2061 | void *image_data; |
sla@2327 | 2062 | if (jar_name) { |
sla@2327 | 2063 | image_data = JLI_JarUnpackFile(jar_name, file_name, &data_size); |
sla@2327 | 2064 | if (image_data) { |
sla@2327 | 2065 | DoSplashInit(); |
sla@2327 | 2066 | DoSplashLoadMemory(image_data, data_size); |
sla@2327 | 2067 | JLI_MemFree(image_data); |
sla@2327 | 2068 | } |
sla@2327 | 2069 | } else if (file_name) { |
sla@2327 | 2070 | DoSplashInit(); |
sla@2327 | 2071 | DoSplashLoadFile(file_name); |
sla@2327 | 2072 | } else { |
sla@2327 | 2073 | return; |
sla@2327 | 2074 | } |
sla@2327 | 2075 | DoSplashSetFileJarName(file_name, jar_name); |
sla@2327 | 2076 | } |
sla@2327 | 2077 | |
sla@2327 | 2078 | #endif /* ifndef GAMMA */ |