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