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