Mercurial > hg > graal-jvmci-8
annotate src/os/posix/launcher/java_md.c @ 2027:aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
Summary: Updates to Visual Studio project creation and development launcher
Reviewed-by: stefank, coleenp
author | sla |
---|---|
date | Wed, 15 Dec 2010 07:11:31 -0800 |
parents | cb2d0a362639 |
children | e58d06a8037e |
rev | line source |
---|---|
1985 | 1 /* |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. | |
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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 | |
26 #include "java.h" | |
27 #include <dirent.h> | |
28 #include <dlfcn.h> | |
29 #include <fcntl.h> | |
30 #include <inttypes.h> | |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
31 #include <stdint.h> |
1985 | 32 #include <stdio.h> |
33 #include <string.h> | |
34 #include <stdlib.h> | |
35 #include <limits.h> | |
36 #include <sys/stat.h> | |
37 #include <unistd.h> | |
38 #include <sys/types.h> | |
39 | |
40 #ifndef GAMMA | |
41 #include "manifest_info.h" | |
42 #include "version_comp.h" | |
43 #endif | |
44 | |
45 #ifdef __linux__ | |
46 #include <pthread.h> | |
47 #else | |
48 #include <thread.h> | |
49 #endif | |
50 | |
51 #define JVM_DLL "libjvm.so" | |
52 #define JAVA_DLL "libjava.so" | |
53 | |
54 #ifndef GAMMA /* launcher.make defines ARCH */ | |
55 /* | |
56 * If a processor / os combination has the ability to run binaries of | |
57 * two data models and cohabitation of jre/jdk bits with both data | |
58 * models is supported, then DUAL_MODE is defined. When DUAL_MODE is | |
59 * defined, the architecture names for the narrow and wide version of | |
60 * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME. Currently | |
61 * only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE; linux | |
62 * i586/amd64 could be defined as DUAL_MODE but that is not the | |
63 * current policy. | |
64 */ | |
65 | |
66 #ifndef LIBARCHNAME | |
67 # error "The macro LIBARCHNAME was not defined on the compile line" | |
68 #endif | |
69 | |
70 #ifdef __sun | |
71 # define DUAL_MODE | |
72 # ifndef LIBARCH32NAME | |
73 # error "The macro LIBARCH32NAME was not defined on the compile line" | |
74 # endif | |
75 # ifndef LIBARCH64NAME | |
76 # error "The macro LIBARCH64NAME was not defined on the compile line" | |
77 # endif | |
78 # include <sys/systeminfo.h> | |
79 # include <sys/elf.h> | |
80 # include <stdio.h> | |
81 #endif | |
82 | |
83 #endif /* ifndef GAMMA */ | |
84 | |
85 /* pointer to environment */ | |
86 extern char **environ; | |
87 | |
88 #ifndef GAMMA | |
89 /* | |
90 * A collection of useful strings. One should think of these as #define | |
91 * entries, but actual strings can be more efficient (with many compilers). | |
92 */ | |
93 #ifdef __linux__ | |
94 static const char *system_dir = "/usr/java"; | |
95 static const char *user_dir = "/java"; | |
96 #else /* Solaris */ | |
97 static const char *system_dir = "/usr/jdk"; | |
98 static const char *user_dir = "/jdk"; | |
99 #endif | |
100 | |
101 #endif /* ifndef GAMMA */ | |
102 | |
103 /* | |
104 * Flowchart of launcher execs and options processing on unix | |
105 * | |
106 * The selection of the proper vm shared library to open depends on | |
107 * several classes of command line options, including vm "flavor" | |
108 * options (-client, -server) and the data model options, -d32 and | |
109 * -d64, as well as a version specification which may have come from | |
110 * the command line or from the manifest of an executable jar file. | |
111 * The vm selection options are not passed to the running | |
112 * virtual machine; they must be screened out by the launcher. | |
113 * | |
114 * The version specification (if any) is processed first by the | |
115 * platform independent routine SelectVersion. This may result in | |
116 * the exec of the specified launcher version. | |
117 * | |
118 * Typically, the launcher execs at least once to ensure a suitable | |
119 * LD_LIBRARY_PATH is in effect for the process. The first exec | |
120 * screens out all the data model options; leaving the choice of data | |
121 * model implicit in the binary selected to run. However, in case no | |
122 * exec is done, the data model options are screened out before the vm | |
123 * is invoked. | |
124 * | |
125 * incoming argv ------------------------------ | |
126 * | | | |
127 * \|/ | | |
128 * CheckJVMType | | |
129 * (removes -client, -server, etc.) | | |
130 * \|/ | |
131 * CreateExecutionEnvironment | |
132 * (removes -d32 and -d64, | |
133 * determines desired data model, | |
134 * sets up LD_LIBRARY_PATH, | |
135 * and exec's) | |
136 * | | |
137 * -------------------------------------------- | |
138 * | | |
139 * \|/ | |
140 * exec child 1 incoming argv ----------------- | |
141 * | | | |
142 * \|/ | | |
143 * CheckJVMType | | |
144 * (removes -client, -server, etc.) | | |
145 * | \|/ | |
146 * | CreateExecutionEnvironment | |
147 * | (verifies desired data model | |
148 * | is running and acceptable | |
149 * | LD_LIBRARY_PATH; | |
150 * | no-op in child) | |
151 * | | |
152 * \|/ | |
153 * TranslateDashJArgs... | |
154 * (Prepare to pass args to vm) | |
155 * | | |
156 * | | |
157 * | | |
158 * \|/ | |
159 * ParseArguments | |
160 * (ignores -d32 and -d64, | |
161 * processes version options, | |
162 * creates argument list for vm, | |
163 * etc.) | |
164 * | |
165 */ | |
166 | |
167 static char *SetExecname(char **argv); | |
168 static char * GetExecname(); | |
169 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype, | |
170 char *jvmpath, jint jvmpathsize, char * arch); | |
171 static jboolean GetJREPath(char *path, jint pathsize, char * arch, jboolean speculative); | |
172 | |
173 #ifndef GAMMA | |
174 const char * | |
175 GetArch() | |
176 { | |
177 return LIBARCHNAME; | |
178 } | |
179 #endif /* ifndef GAMMA */ | |
180 | |
181 void | |
182 CreateExecutionEnvironment(int *_argcp, | |
183 char ***_argvp, | |
184 char jrepath[], | |
185 jint so_jrepath, | |
186 char jvmpath[], | |
187 jint so_jvmpath, | |
188 char **original_argv) { | |
189 /* | |
190 * First, determine if we are running the desired data model. If we | |
191 * are running the desired data model, all the error messages | |
192 * associated with calling GetJREPath, ReadKnownVMs, etc. should be | |
193 * output. However, if we are not running the desired data model, | |
194 * some of the errors should be suppressed since it is more | |
195 * informative to issue an error message based on whether or not the | |
196 * os/processor combination has dual mode capabilities. | |
197 */ | |
198 | |
199 char *execname = NULL; | |
200 int original_argc = *_argcp; | |
201 jboolean jvmpathExists; | |
202 | |
203 /* Compute the name of the executable */ | |
204 execname = SetExecname(*_argvp); | |
205 | |
206 #ifndef GAMMA | |
207 /* Set the LD_LIBRARY_PATH environment variable, check data model | |
208 flags, and exec process, if needed */ | |
209 { | |
210 char *arch = (char *)GetArch(); /* like sparc or sparcv9 */ | |
211 char * jvmtype = NULL; | |
212 int argc = *_argcp; | |
213 char **argv = original_argv; | |
214 | |
215 char *runpath = NULL; /* existing effective LD_LIBRARY_PATH | |
216 setting */ | |
217 | |
218 int running = /* What data model is being ILP32 => | |
219 32 bit vm; LP64 => 64 bit vm */ | |
220 #ifdef _LP64 | |
221 64; | |
222 #else | |
223 32; | |
224 #endif | |
225 | |
226 int wanted = running; /* What data mode is being | |
227 asked for? Current model is | |
228 fine unless another model | |
229 is asked for */ | |
230 | |
231 char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */ | |
232 char* newpath = NULL; /* path on new LD_LIBRARY_PATH */ | |
233 char* lastslash = NULL; | |
234 | |
235 char** newenvp = NULL; /* current environment */ | |
236 | |
237 char** newargv = NULL; | |
238 int newargc = 0; | |
239 #ifdef __sun | |
240 char* dmpath = NULL; /* data model specific LD_LIBRARY_PATH, | |
241 Solaris only */ | |
242 #endif | |
243 | |
244 /* | |
245 * Starting in 1.5, all unix platforms accept the -d32 and -d64 | |
246 * options. On platforms where only one data-model is supported | |
247 * (e.g. ia-64 Linux), using the flag for the other data model is | |
248 * an error and will terminate the program. | |
249 */ | |
250 | |
251 { /* open new scope to declare local variables */ | |
252 int i; | |
253 | |
254 newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(*newargv)); | |
255 newargv[newargc++] = argv[0]; | |
256 | |
257 /* scan for data model arguments and remove from argument list; | |
258 last occurrence determines desired data model */ | |
259 for (i=1; i < argc; i++) { | |
260 | |
261 if (strcmp(argv[i], "-J-d64") == 0 || strcmp(argv[i], "-d64") == 0) { | |
262 wanted = 64; | |
263 continue; | |
264 } | |
265 if (strcmp(argv[i], "-J-d32") == 0 || strcmp(argv[i], "-d32") == 0) { | |
266 wanted = 32; | |
267 continue; | |
268 } | |
269 newargv[newargc++] = argv[i]; | |
270 | |
271 #ifdef JAVA_ARGS | |
272 if (argv[i][0] != '-') | |
273 continue; | |
274 #else | |
275 if (strcmp(argv[i], "-classpath") == 0 || strcmp(argv[i], "-cp") == 0) { | |
276 i++; | |
277 if (i >= argc) break; | |
278 newargv[newargc++] = argv[i]; | |
279 continue; | |
280 } | |
281 if (argv[i][0] != '-') { i++; break; } | |
282 #endif | |
283 } | |
284 | |
285 /* copy rest of args [i .. argc) */ | |
286 while (i < argc) { | |
287 newargv[newargc++] = argv[i++]; | |
288 } | |
289 newargv[newargc] = NULL; | |
290 | |
291 /* | |
292 * newargv has all proper arguments here | |
293 */ | |
294 | |
295 argc = newargc; | |
296 argv = newargv; | |
297 } | |
298 | |
299 /* If the data model is not changing, it is an error if the | |
300 jvmpath does not exist */ | |
301 if (wanted == running) { | |
302 /* Find out where the JRE is that we will be using. */ | |
303 if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { | |
304 fprintf(stderr, "Error: could not find Java 2 Runtime Environment.\n"); | |
305 exit(2); | |
306 } | |
307 | |
308 /* Find the specified JVM type */ | |
309 if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) { | |
310 fprintf(stderr, "Error: no known VMs. (check for corrupt jvm.cfg file)\n"); | |
311 exit(1); | |
312 } | |
313 | |
314 jvmpath[0] = '\0'; | |
315 jvmtype = CheckJvmType(_argcp, _argvp, JNI_FALSE); | |
316 | |
317 if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) { | |
318 fprintf(stderr, "Error: no `%s' JVM at `%s'.\n", jvmtype, jvmpath); | |
319 exit(4); | |
320 } | |
321 } else { /* do the same speculatively or exit */ | |
322 #ifdef DUAL_MODE | |
323 if (running != wanted) { | |
324 /* Find out where the JRE is that we will be using. */ | |
325 if (!GetJREPath(jrepath, so_jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME), JNI_TRUE)) { | |
326 goto EndDataModelSpeculate; | |
327 } | |
328 | |
329 /* | |
330 * Read in jvm.cfg for target data model and process vm | |
331 * selection options. | |
332 */ | |
333 if (ReadKnownVMs(jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME), JNI_TRUE) < 1) { | |
334 goto EndDataModelSpeculate; | |
335 } | |
336 jvmpath[0] = '\0'; | |
337 jvmtype = CheckJvmType(_argcp, _argvp, JNI_TRUE); | |
338 /* exec child can do error checking on the existence of the path */ | |
339 jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, | |
340 ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME)); | |
341 | |
342 } | |
343 EndDataModelSpeculate: /* give up and let other code report error message */ | |
344 ; | |
345 #else | |
346 fprintf(stderr, "Running a %d-bit JVM is not supported on this platform.\n", wanted); | |
347 exit(1); | |
348 #endif | |
349 } | |
350 | |
351 /* | |
352 * We will set the LD_LIBRARY_PATH as follows: | |
353 * | |
354 * o $JVMPATH (directory portion only) | |
355 * o $JRE/lib/$LIBARCHNAME | |
356 * o $JRE/../lib/$LIBARCHNAME | |
357 * | |
358 * followed by the user's previous effective LD_LIBRARY_PATH, if | |
359 * any. | |
360 */ | |
361 | |
362 #ifdef __sun | |
363 /* | |
364 * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH | |
365 * variables: | |
366 * | |
367 * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if | |
368 * data-model specific variables are not set. | |
369 * | |
370 * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH | |
371 * for 64-bit binaries. | |
372 * | |
373 * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH | |
374 * for 32-bit binaries. | |
375 * | |
376 * The vm uses LD_LIBRARY_PATH to set the java.library.path system | |
377 * property. To shield the vm from the complication of multiple | |
378 * LD_LIBRARY_PATH variables, if the appropriate data model | |
379 * specific variable is set, we will act as if LD_LIBRARY_PATH had | |
380 * the value of the data model specific variant and the data model | |
381 * specific variant will be unset. Note that the variable for the | |
382 * *wanted* data model must be used (if it is set), not simply the | |
383 * current running data model. | |
384 */ | |
385 | |
386 switch(wanted) { | |
387 case 0: | |
388 if(running == 32) { | |
389 dmpath = getenv("LD_LIBRARY_PATH_32"); | |
390 wanted = 32; | |
391 } | |
392 else { | |
393 dmpath = getenv("LD_LIBRARY_PATH_64"); | |
394 wanted = 64; | |
395 } | |
396 break; | |
397 | |
398 case 32: | |
399 dmpath = getenv("LD_LIBRARY_PATH_32"); | |
400 break; | |
401 | |
402 case 64: | |
403 dmpath = getenv("LD_LIBRARY_PATH_64"); | |
404 break; | |
405 | |
406 default: | |
407 fprintf(stderr, "Improper value at line %d.", __LINE__); | |
408 exit(1); /* unknown value in wanted */ | |
409 break; | |
410 } | |
411 | |
412 /* | |
413 * If dmpath is NULL, the relevant data model specific variable is | |
414 * not set and normal LD_LIBRARY_PATH should be used. | |
415 */ | |
416 if( dmpath == NULL) { | |
417 runpath = getenv("LD_LIBRARY_PATH"); | |
418 } | |
419 else { | |
420 runpath = dmpath; | |
421 } | |
422 #else | |
423 /* | |
424 * If not on Solaris, assume only a single LD_LIBRARY_PATH | |
425 * variable. | |
426 */ | |
427 runpath = getenv("LD_LIBRARY_PATH"); | |
428 #endif /* __sun */ | |
429 | |
430 #ifdef __linux | |
431 /* | |
432 * On linux, if a binary is running as sgid or suid, glibc sets | |
433 * LD_LIBRARY_PATH to the empty string for security purposes. (In | |
434 * contrast, on Solaris the LD_LIBRARY_PATH variable for a | |
435 * privileged binary does not lose its settings; but the dynamic | |
436 * linker does apply more scrutiny to the path.) The launcher uses | |
437 * the value of LD_LIBRARY_PATH to prevent an exec loop. | |
438 * Therefore, if we are running sgid or suid, this function's | |
439 * setting of LD_LIBRARY_PATH will be ineffective and we should | |
440 * return from the function now. Getting the right libraries to | |
441 * be found must be handled through other mechanisms. | |
442 */ | |
443 if((getgid() != getegid()) || (getuid() != geteuid()) ) { | |
444 return; | |
445 } | |
446 #endif | |
447 | |
448 /* runpath contains current effective LD_LIBRARY_PATH setting */ | |
449 | |
450 jvmpath = JLI_StringDup(jvmpath); | |
451 new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) + | |
452 2*strlen(jrepath) + 2*strlen(arch) + | |
453 strlen(jvmpath) + 52); | |
454 newpath = new_runpath + strlen("LD_LIBRARY_PATH="); | |
455 | |
456 | |
457 /* | |
458 * Create desired LD_LIBRARY_PATH value for target data model. | |
459 */ | |
460 { | |
461 /* remove the name of the .so from the JVM path */ | |
462 lastslash = strrchr(jvmpath, '/'); | |
463 if (lastslash) | |
464 *lastslash = '\0'; | |
465 | |
466 | |
467 /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */ | |
468 | |
469 sprintf(new_runpath, "LD_LIBRARY_PATH=" | |
470 "%s:" | |
471 "%s/lib/%s:" | |
472 "%s/../lib/%s", | |
473 jvmpath, | |
474 #ifdef DUAL_MODE | |
475 jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME), | |
476 jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME) | |
477 #else | |
478 jrepath, arch, | |
479 jrepath, arch | |
480 #endif | |
481 ); | |
482 | |
483 | |
484 /* | |
485 * Check to make sure that the prefix of the current path is the | |
486 * desired environment variable setting. | |
487 */ | |
488 if (runpath != NULL && | |
489 strncmp(newpath, runpath, strlen(newpath))==0 && | |
490 (runpath[strlen(newpath)] == 0 || runpath[strlen(newpath)] == ':') && | |
491 (running == wanted) /* data model does not have to be changed */ | |
492 #ifdef __sun | |
493 && (dmpath == NULL) /* data model specific variables not set */ | |
494 #endif | |
495 ) { | |
496 | |
497 return; | |
498 | |
499 } | |
500 } | |
501 | |
502 /* | |
503 * Place the desired environment setting onto the prefix of | |
504 * LD_LIBRARY_PATH. Note that this prevents any possible infinite | |
505 * loop of execv() because we test for the prefix, above. | |
506 */ | |
507 if (runpath != 0) { | |
508 strcat(new_runpath, ":"); | |
509 strcat(new_runpath, runpath); | |
510 } | |
511 | |
512 if( putenv(new_runpath) != 0) { | |
513 exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set | |
514 properly */ | |
515 } | |
516 | |
517 /* | |
518 * Unix systems document that they look at LD_LIBRARY_PATH only | |
519 * once at startup, so we have to re-exec the current executable | |
520 * to get the changed environment variable to have an effect. | |
521 */ | |
522 | |
523 #ifdef __sun | |
524 /* | |
525 * If dmpath is not NULL, remove the data model specific string | |
526 * in the environment for the exec'ed child. | |
527 */ | |
528 | |
529 if( dmpath != NULL) | |
530 (void)UnsetEnv((wanted==32)?"LD_LIBRARY_PATH_32":"LD_LIBRARY_PATH_64"); | |
531 #endif | |
532 | |
533 newenvp = environ; | |
534 | |
535 { | |
536 char *newexec = execname; | |
537 #ifdef DUAL_MODE | |
538 /* | |
539 * If the data model is being changed, the path to the | |
540 * executable must be updated accordingly; the executable name | |
541 * and directory the executable resides in are separate. In the | |
542 * case of 32 => 64, the new bits are assumed to reside in, e.g. | |
543 * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32, | |
544 * the bits are assumed to be in "olddir/../execname". For example, | |
545 * | |
546 * olddir/sparcv9/execname | |
547 * olddir/amd64/execname | |
548 * | |
549 * for Solaris SPARC and Linux amd64, respectively. | |
550 */ | |
551 | |
552 if (running != wanted) { | |
553 char *oldexec = strcpy(JLI_MemAlloc(strlen(execname) + 1), execname); | |
554 char *olddir = oldexec; | |
555 char *oldbase = strrchr(oldexec, '/'); | |
556 | |
557 | |
558 newexec = JLI_MemAlloc(strlen(execname) + 20); | |
559 *oldbase++ = 0; | |
560 sprintf(newexec, "%s/%s/%s", olddir, | |
561 ((wanted==64) ? LIBARCH64NAME : ".."), oldbase); | |
562 argv[0] = newexec; | |
563 } | |
564 #endif | |
565 | |
566 (void)fflush(stdout); | |
567 (void)fflush(stderr); | |
568 execve(newexec, argv, newenvp); | |
569 perror("execve()"); | |
570 | |
571 fprintf(stderr, "Error trying to exec %s.\n", newexec); | |
572 fprintf(stderr, "Check if file exists and permissions are set correctly.\n"); | |
573 | |
574 #ifdef DUAL_MODE | |
575 if (running != wanted) { | |
576 fprintf(stderr, "Failed to start a %d-bit JVM process from a %d-bit JVM.\n", | |
577 wanted, running); | |
578 # ifdef __sun | |
579 | |
580 # ifdef __sparc | |
581 fprintf(stderr, "Verify all necessary J2SE components have been installed.\n" ); | |
582 fprintf(stderr, | |
583 "(Solaris SPARC 64-bit components must be installed after 32-bit components.)\n" ); | |
584 # else | |
585 fprintf(stderr, "Either 64-bit processes are not supported by this platform\n"); | |
586 fprintf(stderr, "or the 64-bit components have not been installed.\n"); | |
587 # endif | |
588 } | |
589 # endif | |
590 #endif | |
591 | |
592 } | |
593 | |
594 exit(1); | |
595 } | |
596 | |
597 #else /* ifndef GAMMA */ | |
598 | |
599 /* | |
600 * gamma launcher is simpler in that it doesn't handle VM flavors, data | |
601 * model, LD_LIBRARY_PATH, etc. Assuming everything is set-up correctly | |
602 * all we need to do here is to return correct path names. See also | |
603 * GetJVMPath() and GetApplicationHome(). | |
604 */ | |
605 | |
606 { char *arch = (char *) ARCH; /* like sparc or sparcv9 */ | |
607 char *p; | |
608 | |
609 if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { | |
610 fprintf(stderr, "Error: could not find Java 2 Runtime Environment.\n"); | |
611 exit(2); | |
612 } | |
613 | |
614 if (!GetJVMPath(jrepath, NULL, jvmpath, so_jvmpath, arch )) { | |
615 fprintf(stderr, "Error: no JVM at `%s'.\n", jvmpath); | |
616 exit(4); | |
617 } | |
618 } | |
619 | |
620 #endif /* ifndef GAMMA */ | |
621 } | |
622 | |
623 | |
624 /* | |
625 * On Solaris VM choosing is done by the launcher (java.c). | |
626 */ | |
627 static jboolean | |
628 GetJVMPath(const char *jrepath, const char *jvmtype, | |
629 char *jvmpath, jint jvmpathsize, char * arch) | |
630 { | |
631 struct stat s; | |
632 | |
633 #ifndef GAMMA | |
634 if (strchr(jvmtype, '/')) { | |
635 sprintf(jvmpath, "%s/" JVM_DLL, jvmtype); | |
636 } else { | |
637 sprintf(jvmpath, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype); | |
638 } | |
639 #else | |
640 /* | |
641 * For gamma launcher, JVM is either built-in or in the same directory. | |
642 * Either way we return "<exe_path>/libjvm.so" where <exe_path> is the | |
643 * directory where gamma launcher is located. | |
644 */ | |
645 | |
646 char *p; | |
647 | |
648 snprintf(jvmpath, jvmpathsize, "%s", GetExecname()); | |
649 p = strrchr(jvmpath, '/'); | |
650 if (p) { | |
651 /* replace executable name with libjvm.so */ | |
652 snprintf(p + 1, jvmpathsize - (p + 1 - jvmpath), "%s", JVM_DLL); | |
653 } else { | |
654 /* this case shouldn't happen */ | |
655 snprintf(jvmpath, jvmpathsize, "%s", JVM_DLL); | |
656 } | |
657 #endif /* ifndef GAMMA */ | |
658 | |
659 if (_launcher_debug) | |
660 printf("Does `%s' exist ... ", jvmpath); | |
661 | |
662 if (stat(jvmpath, &s) == 0) { | |
663 if (_launcher_debug) | |
664 printf("yes.\n"); | |
665 return JNI_TRUE; | |
666 } else { | |
667 if (_launcher_debug) | |
668 printf("no.\n"); | |
669 return JNI_FALSE; | |
670 } | |
671 } | |
672 | |
673 /* | |
674 * Find path to JRE based on .exe's location or registry settings. | |
675 */ | |
676 static jboolean | |
677 GetJREPath(char *path, jint pathsize, char * arch, jboolean speculative) | |
678 { | |
679 char libjava[MAXPATHLEN]; | |
680 | |
681 if (GetApplicationHome(path, pathsize)) { | |
682 /* Is JRE co-located with the application? */ | |
683 sprintf(libjava, "%s/lib/%s/" JAVA_DLL, path, arch); | |
684 if (access(libjava, F_OK) == 0) { | |
685 goto found; | |
686 } | |
687 | |
688 /* Does the app ship a private JRE in <apphome>/jre directory? */ | |
689 sprintf(libjava, "%s/jre/lib/%s/" JAVA_DLL, path, arch); | |
690 if (access(libjava, F_OK) == 0) { | |
691 strcat(path, "/jre"); | |
692 goto found; | |
693 } | |
694 } | |
695 | |
696 if (!speculative) | |
697 fprintf(stderr, "Error: could not find " JAVA_DLL "\n"); | |
698 return JNI_FALSE; | |
699 | |
700 found: | |
701 if (_launcher_debug) | |
702 printf("JRE path is %s\n", path); | |
703 return JNI_TRUE; | |
704 } | |
705 | |
706 jboolean | |
707 LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) | |
708 { | |
709 #ifdef GAMMA | |
710 /* JVM is directly linked with gamma launcher; no dlopen() */ | |
711 ifn->CreateJavaVM = JNI_CreateJavaVM; | |
712 ifn->GetDefaultJavaVMInitArgs = JNI_GetDefaultJavaVMInitArgs; | |
713 return JNI_TRUE; | |
714 #else | |
715 Dl_info dlinfo; | |
716 void *libjvm; | |
717 | |
718 if (_launcher_debug) { | |
719 printf("JVM path is %s\n", jvmpath); | |
720 } | |
721 | |
722 libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL); | |
723 if (libjvm == NULL) { | |
724 #if defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */ | |
725 FILE * fp; | |
726 Elf32_Ehdr elf_head; | |
727 int count; | |
728 int location; | |
729 | |
730 fp = fopen(jvmpath, "r"); | |
731 if(fp == NULL) | |
732 goto error; | |
733 | |
734 /* read in elf header */ | |
735 count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp); | |
736 fclose(fp); | |
737 if(count < 1) | |
738 goto error; | |
739 | |
740 /* | |
741 * Check for running a server vm (compiled with -xarch=v8plus) | |
742 * on a stock v8 processor. In this case, the machine type in | |
743 * the elf header would not be included the architecture list | |
744 * provided by the isalist command, which is turn is gotten from | |
745 * sysinfo. This case cannot occur on 64-bit hardware and thus | |
746 * does not have to be checked for in binaries with an LP64 data | |
747 * model. | |
748 */ | |
749 if(elf_head.e_machine == EM_SPARC32PLUS) { | |
750 char buf[257]; /* recommended buffer size from sysinfo man | |
751 page */ | |
752 long length; | |
753 char* location; | |
754 | |
755 length = sysinfo(SI_ISALIST, buf, 257); | |
756 if(length > 0) { | |
757 location = strstr(buf, "sparcv8plus "); | |
758 if(location == NULL) { | |
759 fprintf(stderr, "SPARC V8 processor detected; Server compiler requires V9 or better.\n"); | |
760 fprintf(stderr, "Use Client compiler on V8 processors.\n"); | |
761 fprintf(stderr, "Could not create the Java virtual machine.\n"); | |
762 return JNI_FALSE; | |
763 } | |
764 } | |
765 } | |
766 #endif | |
767 fprintf(stderr, "dl failure on line %d", __LINE__); | |
768 goto error; | |
769 } | |
770 | |
771 ifn->CreateJavaVM = (CreateJavaVM_t) | |
772 dlsym(libjvm, "JNI_CreateJavaVM"); | |
773 if (ifn->CreateJavaVM == NULL) | |
774 goto error; | |
775 | |
776 ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t) | |
777 dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs"); | |
778 if (ifn->GetDefaultJavaVMInitArgs == NULL) | |
779 goto error; | |
780 | |
781 return JNI_TRUE; | |
782 | |
783 error: | |
784 fprintf(stderr, "Error: failed %s, because %s\n", jvmpath, dlerror()); | |
785 return JNI_FALSE; | |
786 #endif /* ifndef GAMMA */ | |
787 } | |
788 | |
789 /* | |
790 * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put | |
791 * "/foo" into buf. | |
792 */ | |
793 jboolean | |
794 GetApplicationHome(char *buf, jint bufsize) | |
795 { | |
796 #ifdef __linux__ | |
797 char *execname = GetExecname(); | |
798 if (execname) { | |
799 strncpy(buf, execname, bufsize-1); | |
800 buf[bufsize-1] = '\0'; | |
801 } else { | |
802 return JNI_FALSE; | |
803 } | |
804 #else | |
805 Dl_info dlinfo; | |
806 | |
807 dladdr((void *)GetApplicationHome, &dlinfo); | |
808 if (realpath(dlinfo.dli_fname, buf) == NULL) { | |
809 fprintf(stderr, "Error: realpath(`%s') failed.\n", dlinfo.dli_fname); | |
810 return JNI_FALSE; | |
811 } | |
812 #endif | |
813 | |
814 #ifdef GAMMA | |
815 { | |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
816 /* gamma launcher uses JAVA_HOME environment variable to find JDK/JRE */ |
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
817 char* java_home_var = getenv("JAVA_HOME"); |
1985 | 818 if (java_home_var == NULL) { |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
819 printf("JAVA_HOME must point to a valid JDK/JRE to run gamma\n"); |
1985 | 820 return JNI_FALSE; |
821 } | |
822 snprintf(buf, bufsize, "%s", java_home_var); | |
823 } | |
824 #else | |
825 if (strrchr(buf, '/') == 0) { | |
826 buf[0] = '\0'; | |
827 return JNI_FALSE; | |
828 } | |
829 *(strrchr(buf, '/')) = '\0'; /* executable file */ | |
830 if (strlen(buf) < 4 || strrchr(buf, '/') == 0) { | |
831 buf[0] = '\0'; | |
832 return JNI_FALSE; | |
833 } | |
834 if (strcmp("/bin", buf + strlen(buf) - 4) != 0) | |
835 *(strrchr(buf, '/')) = '\0'; /* sparcv9 or amd64 */ | |
836 if (strlen(buf) < 4 || strcmp("/bin", buf + strlen(buf) - 4) != 0) { | |
837 buf[0] = '\0'; | |
838 return JNI_FALSE; | |
839 } | |
840 *(strrchr(buf, '/')) = '\0'; /* bin */ | |
841 #endif /* ifndef GAMMA */ | |
842 | |
843 return JNI_TRUE; | |
844 } | |
845 | |
846 | |
847 /* | |
848 * Return true if the named program exists | |
849 */ | |
850 static int | |
851 ProgramExists(char *name) | |
852 { | |
853 struct stat sb; | |
854 if (stat(name, &sb) != 0) return 0; | |
855 if (S_ISDIR(sb.st_mode)) return 0; | |
856 return (sb.st_mode & S_IEXEC) != 0; | |
857 } | |
858 | |
859 | |
860 /* | |
861 * Find a command in a directory, returning the path. | |
862 */ | |
863 static char * | |
864 Resolve(char *indir, char *cmd) | |
865 { | |
866 char name[PATH_MAX + 2], *real; | |
867 | |
868 if ((strlen(indir) + strlen(cmd) + 1) > PATH_MAX) return 0; | |
869 sprintf(name, "%s%c%s", indir, FILE_SEPARATOR, cmd); | |
870 if (!ProgramExists(name)) return 0; | |
871 real = JLI_MemAlloc(PATH_MAX + 2); | |
872 if (!realpath(name, real)) | |
873 strcpy(real, name); | |
874 return real; | |
875 } | |
876 | |
877 | |
878 /* | |
879 * Find a path for the executable | |
880 */ | |
881 static char * | |
882 FindExecName(char *program) | |
883 { | |
884 char cwdbuf[PATH_MAX+2]; | |
885 char *path; | |
886 char *tmp_path; | |
887 char *f; | |
888 char *result = NULL; | |
889 | |
890 /* absolute path? */ | |
891 if (*program == FILE_SEPARATOR || | |
892 (FILE_SEPARATOR=='\\' && strrchr(program, ':'))) | |
893 return Resolve("", program+1); | |
894 | |
895 /* relative path? */ | |
896 if (strrchr(program, FILE_SEPARATOR) != 0) { | |
897 char buf[PATH_MAX+2]; | |
898 return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program); | |
899 } | |
900 | |
901 /* from search path? */ | |
902 path = getenv("PATH"); | |
903 if (!path || !*path) path = "."; | |
904 tmp_path = JLI_MemAlloc(strlen(path) + 2); | |
905 strcpy(tmp_path, path); | |
906 | |
907 for (f=tmp_path; *f && result==0; ) { | |
908 char *s = f; | |
909 while (*f && (*f != PATH_SEPARATOR)) ++f; | |
910 if (*f) *f++ = 0; | |
911 if (*s == FILE_SEPARATOR) | |
912 result = Resolve(s, program); | |
913 else { | |
914 /* relative path element */ | |
915 char dir[2*PATH_MAX]; | |
916 sprintf(dir, "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)), | |
917 FILE_SEPARATOR, s); | |
918 result = Resolve(dir, program); | |
919 } | |
920 if (result != 0) break; | |
921 } | |
922 | |
923 JLI_MemFree(tmp_path); | |
924 return result; | |
925 } | |
926 | |
927 | |
928 /* Store the name of the executable once computed */ | |
929 static char *execname = NULL; | |
930 | |
931 /* | |
932 * Compute the name of the executable | |
933 * | |
934 * In order to re-exec securely we need the absolute path of the | |
935 * executable. On Solaris getexecname(3c) may not return an absolute | |
936 * path so we use dladdr to get the filename of the executable and | |
937 * then use realpath to derive an absolute path. From Solaris 9 | |
938 * onwards the filename returned in DL_info structure from dladdr is | |
939 * an absolute pathname so technically realpath isn't required. | |
940 * On Linux we read the executable name from /proc/self/exe. | |
941 * As a fallback, and for platforms other than Solaris and Linux, | |
942 * we use FindExecName to compute the executable name. | |
943 */ | |
944 static char * | |
945 SetExecname(char **argv) | |
946 { | |
947 char* exec_path = NULL; | |
948 | |
949 if (execname != NULL) /* Already determined */ | |
950 return (execname); | |
951 | |
952 #if defined(__sun) | |
953 { | |
954 Dl_info dlinfo; | |
955 if (dladdr((void*)&SetExecname, &dlinfo)) { | |
956 char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1); | |
957 if (resolved != NULL) { | |
958 exec_path = realpath(dlinfo.dli_fname, resolved); | |
959 if (exec_path == NULL) { | |
960 JLI_MemFree(resolved); | |
961 } | |
962 } | |
963 } | |
964 } | |
965 #elif defined(__linux__) | |
966 { | |
967 const char* self = "/proc/self/exe"; | |
968 char buf[PATH_MAX+1]; | |
969 int len = readlink(self, buf, PATH_MAX); | |
970 if (len >= 0) { | |
971 buf[len] = '\0'; /* readlink doesn't nul terminate */ | |
972 exec_path = JLI_StringDup(buf); | |
973 } | |
974 } | |
975 #else /* !__sun && !__linux */ | |
976 { | |
977 /* Not implemented */ | |
978 } | |
979 #endif | |
980 | |
981 if (exec_path == NULL) { | |
982 exec_path = FindExecName(argv[0]); | |
983 } | |
984 execname = exec_path; | |
985 return exec_path; | |
986 } | |
987 | |
988 /* | |
989 * Return the name of the executable. Used in java_md.c to find the JRE area. | |
990 */ | |
991 static char * | |
992 GetExecname() { | |
993 return execname; | |
994 } | |
995 | |
996 void ReportErrorMessage(char * message, jboolean always) { | |
997 if (always) { | |
998 fprintf(stderr, "%s\n", message); | |
999 } | |
1000 } | |
1001 | |
1002 void ReportErrorMessage2(char * format, char * string, jboolean always) { | |
1003 if (always) { | |
1004 fprintf(stderr, format, string); | |
1005 fprintf(stderr, "\n"); | |
1006 } | |
1007 } | |
1008 | |
1009 void ReportExceptionDescription(JNIEnv * env) { | |
1010 (*env)->ExceptionDescribe(env); | |
1011 } | |
1012 | |
1013 /* | |
1014 * Return JNI_TRUE for an option string that has no effect but should | |
1015 * _not_ be passed on to the vm; return JNI_FALSE otherwise. On | |
1016 * Solaris SPARC, this screening needs to be done if: | |
1017 * 1) LD_LIBRARY_PATH does _not_ need to be reset and | |
1018 * 2) -d32 or -d64 is passed to a binary with a matching data model | |
1019 * (the exec in SetLibraryPath removes -d<n> options and points the | |
1020 * exec to the proper binary). When this exec is not done, these options | |
1021 * would end up getting passed onto the vm. | |
1022 */ | |
1023 jboolean RemovableMachineDependentOption(char * option) { | |
1024 /* | |
1025 * Unconditionally remove both -d32 and -d64 options since only | |
1026 * the last such options has an effect; e.g. | |
1027 * java -d32 -d64 -d32 -version | |
1028 * is equivalent to | |
1029 * java -d32 -version | |
1030 */ | |
1031 | |
1032 if( (strcmp(option, "-d32") == 0 ) || | |
1033 (strcmp(option, "-d64") == 0 )) | |
1034 return JNI_TRUE; | |
1035 else | |
1036 return JNI_FALSE; | |
1037 } | |
1038 | |
1039 void PrintMachineDependentOptions() { | |
1040 fprintf(stdout, | |
1041 " -d32 use a 32-bit data model if available\n" | |
1042 "\n" | |
1043 " -d64 use a 64-bit data model if available\n"); | |
1044 return; | |
1045 } | |
1046 | |
1047 #ifndef GAMMA | |
1048 /* | |
1049 * The following methods (down to ServerClassMachine()) answer | |
1050 * the question about whether a machine is a "server-class" | |
1051 * machine. A server-class machine is loosely defined as one | |
1052 * with 2 or more processors and 2 gigabytes or more physical | |
1053 * memory. The definition of a processor is a physical package, | |
1054 * not a hyperthreaded chip masquerading as a multi-processor. | |
1055 * The definition of memory is also somewhat fuzzy, since x86 | |
1056 * machines seem not to report all the memory in their DIMMs, we | |
1057 * think because of memory mapping of graphics cards, etc. | |
1058 * | |
1059 * This code is somewhat more confused with #ifdef's than we'd | |
1060 * like because this file is used by both Solaris and Linux | |
1061 * platforms, and so needs to be parameterized for SPARC and | |
1062 * i586 hardware. The other Linux platforms (amd64 and ia64) | |
1063 * don't even ask this question, because they only come with | |
1064 * server JVMs. */ | |
1065 | |
1066 # define KB (1024UL) | |
1067 # define MB (1024UL * KB) | |
1068 # define GB (1024UL * MB) | |
1069 | |
1070 /* Compute physical memory by asking the OS */ | |
1071 uint64_t | |
1072 physical_memory(void) { | |
1073 const uint64_t pages = (uint64_t) sysconf(_SC_PHYS_PAGES); | |
1074 const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE); | |
1075 const uint64_t result = pages * page_size; | |
1076 # define UINT64_FORMAT "%" PRIu64 | |
1077 | |
1078 if (_launcher_debug) { | |
1079 printf("pages: " UINT64_FORMAT | |
1080 " page_size: " UINT64_FORMAT | |
1081 " physical memory: " UINT64_FORMAT " (%.3fGB)\n", | |
1082 pages, page_size, result, result / (double) GB); | |
1083 } | |
1084 return result; | |
1085 } | |
1086 | |
1087 #if defined(__sun) && defined(__sparc) | |
1088 | |
1089 /* Methods for solaris-sparc: these are easy. */ | |
1090 | |
1091 /* Ask the OS how many processors there are. */ | |
1092 unsigned long | |
1093 physical_processors(void) { | |
1094 const unsigned long sys_processors = sysconf(_SC_NPROCESSORS_CONF); | |
1095 | |
1096 if (_launcher_debug) { | |
1097 printf("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors); | |
1098 } | |
1099 return sys_processors; | |
1100 } | |
1101 | |
1102 /* The solaris-sparc version of the "server-class" predicate. */ | |
1103 jboolean | |
1104 solaris_sparc_ServerClassMachine(void) { | |
1105 jboolean result = JNI_FALSE; | |
1106 /* How big is a server class machine? */ | |
1107 const unsigned long server_processors = 2UL; | |
1108 const uint64_t server_memory = 2UL * GB; | |
1109 const uint64_t actual_memory = physical_memory(); | |
1110 | |
1111 /* Is this a server class machine? */ | |
1112 if (actual_memory >= server_memory) { | |
1113 const unsigned long actual_processors = physical_processors(); | |
1114 if (actual_processors >= server_processors) { | |
1115 result = JNI_TRUE; | |
1116 } | |
1117 } | |
1118 if (_launcher_debug) { | |
1119 printf("solaris_" LIBARCHNAME "_ServerClassMachine: %s\n", | |
1120 (result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE")); | |
1121 } | |
1122 return result; | |
1123 } | |
1124 | |
1125 #endif /* __sun && __sparc */ | |
1126 | |
1127 #if defined(__sun) && defined(i586) | |
1128 | |
1129 /* | |
1130 * A utility method for asking the CPU about itself. | |
1131 * There's a corresponding version of linux-i586 | |
1132 * because the compilers are different. | |
1133 */ | |
1134 void | |
1135 get_cpuid(uint32_t arg, | |
1136 uint32_t* eaxp, | |
1137 uint32_t* ebxp, | |
1138 uint32_t* ecxp, | |
1139 uint32_t* edxp) { | |
1140 #ifdef _LP64 | |
1141 asm( | |
1142 /* rbx is a callee-saved register */ | |
1143 " movq %rbx, %r11 \n" | |
1144 /* rdx and rcx are 3rd and 4th argument registers */ | |
1145 " movq %rdx, %r10 \n" | |
1146 " movq %rcx, %r9 \n" | |
1147 " movl %edi, %eax \n" | |
1148 " cpuid \n" | |
1149 " movl %eax, (%rsi)\n" | |
1150 " movl %ebx, (%r10)\n" | |
1151 " movl %ecx, (%r9) \n" | |
1152 " movl %edx, (%r8) \n" | |
1153 /* Restore rbx */ | |
1154 " movq %r11, %rbx"); | |
1155 #else | |
1156 /* EBX is a callee-saved register */ | |
1157 asm(" pushl %ebx"); | |
1158 /* Need ESI for storing through arguments */ | |
1159 asm(" pushl %esi"); | |
1160 asm(" movl 8(%ebp), %eax \n" | |
1161 " cpuid \n" | |
1162 " movl 12(%ebp), %esi \n" | |
1163 " movl %eax, (%esi) \n" | |
1164 " movl 16(%ebp), %esi \n" | |
1165 " movl %ebx, (%esi) \n" | |
1166 " movl 20(%ebp), %esi \n" | |
1167 " movl %ecx, (%esi) \n" | |
1168 " movl 24(%ebp), %esi \n" | |
1169 " movl %edx, (%esi) "); | |
1170 /* Restore ESI and EBX */ | |
1171 asm(" popl %esi"); | |
1172 /* Restore EBX */ | |
1173 asm(" popl %ebx"); | |
1174 #endif | |
1175 } | |
1176 | |
1177 #endif /* __sun && i586 */ | |
1178 | |
1179 #if defined(__linux__) && defined(i586) | |
1180 | |
1181 /* | |
1182 * A utility method for asking the CPU about itself. | |
1183 * There's a corresponding version of solaris-i586 | |
1184 * because the compilers are different. | |
1185 */ | |
1186 void | |
1187 get_cpuid(uint32_t arg, | |
1188 uint32_t* eaxp, | |
1189 uint32_t* ebxp, | |
1190 uint32_t* ecxp, | |
1191 uint32_t* edxp) { | |
1192 #ifdef _LP64 | |
1193 __asm__ volatile (/* Instructions */ | |
1194 " movl %4, %%eax \n" | |
1195 " cpuid \n" | |
1196 " movl %%eax, (%0)\n" | |
1197 " movl %%ebx, (%1)\n" | |
1198 " movl %%ecx, (%2)\n" | |
1199 " movl %%edx, (%3)\n" | |
1200 : /* Outputs */ | |
1201 : /* Inputs */ | |
1202 "r" (eaxp), | |
1203 "r" (ebxp), | |
1204 "r" (ecxp), | |
1205 "r" (edxp), | |
1206 "r" (arg) | |
1207 : /* Clobbers */ | |
1208 "%rax", "%rbx", "%rcx", "%rdx", "memory" | |
1209 ); | |
1210 #else | |
1211 uint32_t value_of_eax = 0; | |
1212 uint32_t value_of_ebx = 0; | |
1213 uint32_t value_of_ecx = 0; | |
1214 uint32_t value_of_edx = 0; | |
1215 __asm__ volatile (/* Instructions */ | |
1216 /* ebx is callee-save, so push it */ | |
1217 " pushl %%ebx \n" | |
1218 " movl %4, %%eax \n" | |
1219 " cpuid \n" | |
1220 " movl %%eax, %0 \n" | |
1221 " movl %%ebx, %1 \n" | |
1222 " movl %%ecx, %2 \n" | |
1223 " movl %%edx, %3 \n" | |
1224 /* restore ebx */ | |
1225 " popl %%ebx \n" | |
1226 | |
1227 : /* Outputs */ | |
1228 "=m" (value_of_eax), | |
1229 "=m" (value_of_ebx), | |
1230 "=m" (value_of_ecx), | |
1231 "=m" (value_of_edx) | |
1232 : /* Inputs */ | |
1233 "m" (arg) | |
1234 : /* Clobbers */ | |
1235 "%eax", "%ecx", "%edx" | |
1236 ); | |
1237 *eaxp = value_of_eax; | |
1238 *ebxp = value_of_ebx; | |
1239 *ecxp = value_of_ecx; | |
1240 *edxp = value_of_edx; | |
1241 #endif | |
1242 } | |
1243 | |
1244 #endif /* __linux__ && i586 */ | |
1245 | |
1246 #ifdef i586 | |
1247 /* | |
1248 * Routines shared by solaris-i586 and linux-i586. | |
1249 */ | |
1250 | |
1251 enum HyperThreadingSupport_enum { | |
1252 hts_supported = 1, | |
1253 hts_too_soon_to_tell = 0, | |
1254 hts_not_supported = -1, | |
1255 hts_not_pentium4 = -2, | |
1256 hts_not_intel = -3 | |
1257 }; | |
1258 typedef enum HyperThreadingSupport_enum HyperThreadingSupport; | |
1259 | |
1260 /* Determine if hyperthreading is supported */ | |
1261 HyperThreadingSupport | |
1262 hyperthreading_support(void) { | |
1263 HyperThreadingSupport result = hts_too_soon_to_tell; | |
1264 /* Bits 11 through 8 is family processor id */ | |
1265 # define FAMILY_ID_SHIFT 8 | |
1266 # define FAMILY_ID_MASK 0xf | |
1267 /* Bits 23 through 20 is extended family processor id */ | |
1268 # define EXT_FAMILY_ID_SHIFT 20 | |
1269 # define EXT_FAMILY_ID_MASK 0xf | |
1270 /* Pentium 4 family processor id */ | |
1271 # define PENTIUM4_FAMILY_ID 0xf | |
1272 /* Bit 28 indicates Hyper-Threading Technology support */ | |
1273 # define HT_BIT_SHIFT 28 | |
1274 # define HT_BIT_MASK 1 | |
1275 uint32_t vendor_id[3] = { 0U, 0U, 0U }; | |
1276 uint32_t value_of_eax = 0U; | |
1277 uint32_t value_of_edx = 0U; | |
1278 uint32_t dummy = 0U; | |
1279 | |
1280 /* Yes, this is supposed to be [0], [2], [1] */ | |
1281 get_cpuid(0, &dummy, &vendor_id[0], &vendor_id[2], &vendor_id[1]); | |
1282 if (_launcher_debug) { | |
1283 printf("vendor: %c %c %c %c %c %c %c %c %c %c %c %c \n", | |
1284 ((vendor_id[0] >> 0) & 0xff), | |
1285 ((vendor_id[0] >> 8) & 0xff), | |
1286 ((vendor_id[0] >> 16) & 0xff), | |
1287 ((vendor_id[0] >> 24) & 0xff), | |
1288 ((vendor_id[1] >> 0) & 0xff), | |
1289 ((vendor_id[1] >> 8) & 0xff), | |
1290 ((vendor_id[1] >> 16) & 0xff), | |
1291 ((vendor_id[1] >> 24) & 0xff), | |
1292 ((vendor_id[2] >> 0) & 0xff), | |
1293 ((vendor_id[2] >> 8) & 0xff), | |
1294 ((vendor_id[2] >> 16) & 0xff), | |
1295 ((vendor_id[2] >> 24) & 0xff)); | |
1296 } | |
1297 get_cpuid(1, &value_of_eax, &dummy, &dummy, &value_of_edx); | |
1298 if (_launcher_debug) { | |
1299 printf("value_of_eax: 0x%x value_of_edx: 0x%x\n", | |
1300 value_of_eax, value_of_edx); | |
1301 } | |
1302 if ((((value_of_eax >> FAMILY_ID_SHIFT) & FAMILY_ID_MASK) == PENTIUM4_FAMILY_ID) || | |
1303 (((value_of_eax >> EXT_FAMILY_ID_SHIFT) & EXT_FAMILY_ID_MASK) != 0)) { | |
1304 if ((((vendor_id[0] >> 0) & 0xff) == 'G') && | |
1305 (((vendor_id[0] >> 8) & 0xff) == 'e') && | |
1306 (((vendor_id[0] >> 16) & 0xff) == 'n') && | |
1307 (((vendor_id[0] >> 24) & 0xff) == 'u') && | |
1308 (((vendor_id[1] >> 0) & 0xff) == 'i') && | |
1309 (((vendor_id[1] >> 8) & 0xff) == 'n') && | |
1310 (((vendor_id[1] >> 16) & 0xff) == 'e') && | |
1311 (((vendor_id[1] >> 24) & 0xff) == 'I') && | |
1312 (((vendor_id[2] >> 0) & 0xff) == 'n') && | |
1313 (((vendor_id[2] >> 8) & 0xff) == 't') && | |
1314 (((vendor_id[2] >> 16) & 0xff) == 'e') && | |
1315 (((vendor_id[2] >> 24) & 0xff) == 'l')) { | |
1316 if (((value_of_edx >> HT_BIT_SHIFT) & HT_BIT_MASK) == HT_BIT_MASK) { | |
1317 if (_launcher_debug) { | |
1318 printf("Hyperthreading supported\n"); | |
1319 } | |
1320 result = hts_supported; | |
1321 } else { | |
1322 if (_launcher_debug) { | |
1323 printf("Hyperthreading not supported\n"); | |
1324 } | |
1325 result = hts_not_supported; | |
1326 } | |
1327 } else { | |
1328 if (_launcher_debug) { | |
1329 printf("Not GenuineIntel\n"); | |
1330 } | |
1331 result = hts_not_intel; | |
1332 } | |
1333 } else { | |
1334 if (_launcher_debug) { | |
1335 printf("not Pentium 4 or extended\n"); | |
1336 } | |
1337 result = hts_not_pentium4; | |
1338 } | |
1339 return result; | |
1340 } | |
1341 | |
1342 /* Determine how many logical processors there are per CPU */ | |
1343 unsigned int | |
1344 logical_processors_per_package(void) { | |
1345 /* | |
1346 * After CPUID with EAX==1, register EBX bits 23 through 16 | |
1347 * indicate the number of logical processors per package | |
1348 */ | |
1349 # define NUM_LOGICAL_SHIFT 16 | |
1350 # define NUM_LOGICAL_MASK 0xff | |
1351 unsigned int result = 1U; | |
1352 const HyperThreadingSupport hyperthreading = hyperthreading_support(); | |
1353 | |
1354 if (hyperthreading == hts_supported) { | |
1355 uint32_t value_of_ebx = 0U; | |
1356 uint32_t dummy = 0U; | |
1357 | |
1358 get_cpuid(1, &dummy, &value_of_ebx, &dummy, &dummy); | |
1359 result = (value_of_ebx >> NUM_LOGICAL_SHIFT) & NUM_LOGICAL_MASK; | |
1360 if (_launcher_debug) { | |
1361 printf("logical processors per package: %u\n", result); | |
1362 } | |
1363 } | |
1364 return result; | |
1365 } | |
1366 | |
1367 /* Compute the number of physical processors, not logical processors */ | |
1368 unsigned long | |
1369 physical_processors(void) { | |
1370 const long sys_processors = sysconf(_SC_NPROCESSORS_CONF); | |
1371 unsigned long result = sys_processors; | |
1372 | |
1373 if (_launcher_debug) { | |
1374 printf("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors); | |
1375 } | |
1376 if (sys_processors > 1) { | |
1377 unsigned int logical_processors = logical_processors_per_package(); | |
1378 if (logical_processors > 1) { | |
1379 result = (unsigned long) sys_processors / logical_processors; | |
1380 } | |
1381 } | |
1382 if (_launcher_debug) { | |
1383 printf("physical processors: %lu\n", result); | |
1384 } | |
1385 return result; | |
1386 } | |
1387 | |
1388 #endif /* i586 */ | |
1389 | |
1390 #if defined(__sun) && defined(i586) | |
1391 | |
1392 /* The definition of a server-class machine for solaris-i586/amd64 */ | |
1393 jboolean | |
1394 solaris_i586_ServerClassMachine(void) { | |
1395 jboolean result = JNI_FALSE; | |
1396 /* How big is a server class machine? */ | |
1397 const unsigned long server_processors = 2UL; | |
1398 const uint64_t server_memory = 2UL * GB; | |
1399 /* | |
1400 * We seem not to get our full complement of memory. | |
1401 * We allow some part (1/8?) of the memory to be "missing", | |
1402 * based on the sizes of DIMMs, and maybe graphics cards. | |
1403 */ | |
1404 const uint64_t missing_memory = 256UL * MB; | |
1405 const uint64_t actual_memory = physical_memory(); | |
1406 | |
1407 /* Is this a server class machine? */ | |
1408 if (actual_memory >= (server_memory - missing_memory)) { | |
1409 const unsigned long actual_processors = physical_processors(); | |
1410 if (actual_processors >= server_processors) { | |
1411 result = JNI_TRUE; | |
1412 } | |
1413 } | |
1414 if (_launcher_debug) { | |
1415 printf("solaris_" LIBARCHNAME "_ServerClassMachine: %s\n", | |
1416 (result == JNI_TRUE ? "true" : "false")); | |
1417 } | |
1418 return result; | |
1419 } | |
1420 | |
1421 #endif /* __sun && i586 */ | |
1422 | |
1423 #if defined(__linux__) && defined(i586) | |
1424 | |
1425 /* The definition of a server-class machine for linux-i586 */ | |
1426 jboolean | |
1427 linux_i586_ServerClassMachine(void) { | |
1428 jboolean result = JNI_FALSE; | |
1429 /* How big is a server class machine? */ | |
1430 const unsigned long server_processors = 2UL; | |
1431 const uint64_t server_memory = 2UL * GB; | |
1432 /* | |
1433 * We seem not to get our full complement of memory. | |
1434 * We allow some part (1/8?) of the memory to be "missing", | |
1435 * based on the sizes of DIMMs, and maybe graphics cards. | |
1436 */ | |
1437 const uint64_t missing_memory = 256UL * MB; | |
1438 const uint64_t actual_memory = physical_memory(); | |
1439 | |
1440 /* Is this a server class machine? */ | |
1441 if (actual_memory >= (server_memory - missing_memory)) { | |
1442 const unsigned long actual_processors = physical_processors(); | |
1443 if (actual_processors >= server_processors) { | |
1444 result = JNI_TRUE; | |
1445 } | |
1446 } | |
1447 if (_launcher_debug) { | |
1448 printf("linux_" LIBARCHNAME "_ServerClassMachine: %s\n", | |
1449 (result == JNI_TRUE ? "true" : "false")); | |
1450 } | |
1451 return result; | |
1452 } | |
1453 | |
1454 #endif /* __linux__ && i586 */ | |
1455 | |
1456 /* Dispatch to the platform-specific definition of "server-class" */ | |
1457 jboolean | |
1458 ServerClassMachine(void) { | |
1459 jboolean result = JNI_FALSE; | |
1460 #if defined(NEVER_ACT_AS_SERVER_CLASS_MACHINE) | |
1461 result = JNI_FALSE; | |
1462 #elif defined(ALWAYS_ACT_AS_SERVER_CLASS_MACHINE) | |
1463 result = JNI_TRUE; | |
1464 #elif defined(__sun) && defined(__sparc) | |
1465 result = solaris_sparc_ServerClassMachine(); | |
1466 #elif defined(__sun) && defined(i586) | |
1467 result = solaris_i586_ServerClassMachine(); | |
1468 #elif defined(__linux__) && defined(i586) | |
1469 result = linux_i586_ServerClassMachine(); | |
1470 #else | |
1471 if (_launcher_debug) { | |
1472 printf("ServerClassMachine: returns default value of %s\n", | |
1473 (result == JNI_TRUE ? "true" : "false")); | |
1474 } | |
1475 #endif | |
1476 return result; | |
1477 } | |
1478 | |
1479 /* | |
1480 * Since using the file system as a registry is a bit risky, perform | |
1481 * additional sanity checks on the identified directory to validate | |
1482 * it as a valid jre/sdk. | |
1483 * | |
1484 * Return 0 if the tests fail; otherwise return non-zero (true). | |
1485 * | |
1486 * Note that checking for anything more than the existence of an | |
1487 * executable object at bin/java relative to the path being checked | |
1488 * will break the regression tests. | |
1489 */ | |
1490 static int | |
1491 CheckSanity(char *path, char *dir) | |
1492 { | |
1493 char buffer[PATH_MAX]; | |
1494 | |
1495 if (strlen(path) + strlen(dir) + 11 > PATH_MAX) | |
1496 return (0); /* Silently reject "impossibly" long paths */ | |
1497 | |
1498 (void)strcat(strcat(strcat(strcpy(buffer, path), "/"), dir), "/bin/java"); | |
1499 return ((access(buffer, X_OK) == 0) ? 1 : 0); | |
1500 } | |
1501 | |
1502 /* | |
1503 * Determine if there is an acceptable JRE in the directory dirname. | |
1504 * Upon locating the "best" one, return a fully qualified path to | |
1505 * it. "Best" is defined as the most advanced JRE meeting the | |
1506 * constraints contained in the manifest_info. If no JRE in this | |
1507 * directory meets the constraints, return NULL. | |
1508 * | |
1509 * Note that we don't check for errors in reading the directory | |
1510 * (which would be done by checking errno). This is because it | |
1511 * doesn't matter if we get an error reading the directory, or | |
1512 * we just don't find anything interesting in the directory. We | |
1513 * just return NULL in either case. | |
1514 * | |
1515 * The historical names of j2sdk and j2re were changed to jdk and | |
1516 * jre respecively as part of the 1.5 rebranding effort. Since the | |
1517 * former names are legacy on Linux, they must be recognized for | |
1518 * all time. Fortunately, this is a minor cost. | |
1519 */ | |
1520 static char | |
1521 *ProcessDir(manifest_info *info, char *dirname) | |
1522 { | |
1523 DIR *dirp; | |
1524 struct dirent *dp; | |
1525 char *best = NULL; | |
1526 int offset; | |
1527 int best_offset = 0; | |
1528 char *ret_str = NULL; | |
1529 char buffer[PATH_MAX]; | |
1530 | |
1531 if ((dirp = opendir(dirname)) == NULL) | |
1532 return (NULL); | |
1533 | |
1534 do { | |
1535 if ((dp = readdir(dirp)) != NULL) { | |
1536 offset = 0; | |
1537 if ((strncmp(dp->d_name, "jre", 3) == 0) || | |
1538 (strncmp(dp->d_name, "jdk", 3) == 0)) | |
1539 offset = 3; | |
1540 else if (strncmp(dp->d_name, "j2re", 4) == 0) | |
1541 offset = 4; | |
1542 else if (strncmp(dp->d_name, "j2sdk", 5) == 0) | |
1543 offset = 5; | |
1544 if (offset > 0) { | |
1545 if ((JLI_AcceptableRelease(dp->d_name + offset, | |
1546 info->jre_version)) && CheckSanity(dirname, dp->d_name)) | |
1547 if ((best == NULL) || (JLI_ExactVersionId( | |
1548 dp->d_name + offset, best + best_offset) > 0)) { | |
1549 if (best != NULL) | |
1550 JLI_MemFree(best); | |
1551 best = JLI_StringDup(dp->d_name); | |
1552 best_offset = offset; | |
1553 } | |
1554 } | |
1555 } | |
1556 } while (dp != NULL); | |
1557 (void) closedir(dirp); | |
1558 if (best == NULL) | |
1559 return (NULL); | |
1560 else { | |
1561 ret_str = JLI_MemAlloc(strlen(dirname) + strlen(best) + 2); | |
1562 ret_str = strcat(strcat(strcpy(ret_str, dirname), "/"), best); | |
1563 JLI_MemFree(best); | |
1564 return (ret_str); | |
1565 } | |
1566 } | |
1567 | |
1568 /* | |
1569 * This is the global entry point. It examines the host for the optimal | |
1570 * JRE to be used by scanning a set of directories. The set of directories | |
1571 * is platform dependent and can be overridden by the environment | |
1572 * variable JAVA_VERSION_PATH. | |
1573 * | |
1574 * This routine itself simply determines the set of appropriate | |
1575 * directories before passing control onto ProcessDir(). | |
1576 */ | |
1577 char* | |
1578 LocateJRE(manifest_info* info) | |
1579 { | |
1580 char *path; | |
1581 char *home; | |
1582 char *target = NULL; | |
1583 char *dp; | |
1584 char *cp; | |
1585 | |
1586 /* | |
1587 * Start by getting JAVA_VERSION_PATH | |
1588 */ | |
1589 if (info->jre_restrict_search) | |
1590 path = JLI_StringDup(system_dir); | |
1591 else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) | |
1592 path = JLI_StringDup(path); | |
1593 else | |
1594 if ((home = getenv("HOME")) != NULL) { | |
1595 path = (char *)JLI_MemAlloc(strlen(home) + strlen(system_dir) + | |
1596 strlen(user_dir) + 2); | |
1597 path = strcat(strcat(strcat(strcpy(path, home), | |
1598 user_dir), ":"), system_dir); | |
1599 } else | |
1600 path = JLI_StringDup(system_dir); | |
1601 | |
1602 /* | |
1603 * Step through each directory on the path. Terminate the scan with | |
1604 * the first directory with an acceptable JRE. | |
1605 */ | |
1606 cp = dp = path; | |
1607 while (dp != NULL) { | |
1608 cp = strchr(dp, (int)':'); | |
1609 if (cp != NULL) | |
1610 *cp = (char)NULL; | |
1611 if ((target = ProcessDir(info, dp)) != NULL) | |
1612 break; | |
1613 dp = cp; | |
1614 if (dp != NULL) | |
1615 dp++; | |
1616 } | |
1617 JLI_MemFree(path); | |
1618 return (target); | |
1619 } | |
1620 | |
1621 /* | |
1622 * Given a path to a jre to execute, this routine checks if this process | |
1623 * is indeed that jre. If not, it exec's that jre. | |
1624 * | |
1625 * We want to actually check the paths rather than just the version string | |
1626 * built into the executable, so that given version specification (and | |
1627 * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless | |
1628 * of the version of the arbitrary launcher we start with. | |
1629 */ | |
1630 void | |
1631 ExecJRE(char *jre, char **argv) | |
1632 { | |
1633 char wanted[PATH_MAX]; | |
1634 char *execname; | |
1635 char *progname; | |
1636 | |
1637 /* | |
1638 * Resolve the real path to the directory containing the selected JRE. | |
1639 */ | |
1640 if (realpath(jre, wanted) == NULL) { | |
1641 fprintf(stderr, "Unable to resolve %s\n", jre); | |
1642 exit(1); | |
1643 } | |
1644 | |
1645 /* | |
1646 * Resolve the real path to the currently running launcher. | |
1647 */ | |
1648 execname = SetExecname(argv); | |
1649 if (execname == NULL) { | |
1650 fprintf(stderr, "Unable to resolve current executable\n"); | |
1651 exit(1); | |
1652 } | |
1653 | |
1654 /* | |
1655 * If the path to the selected JRE directory is a match to the initial | |
1656 * portion of the path to the currently executing JRE, we have a winner! | |
1657 * If so, just return. | |
1658 */ | |
1659 if (strncmp(wanted, execname, strlen(wanted)) == 0) | |
1660 return; /* I am the droid you were looking for */ | |
1661 | |
1662 /* | |
1663 * If this isn't the selected version, exec the selected version. | |
1664 */ | |
1665 #ifdef JAVA_ARGS /* javac, jar and friends. */ | |
1666 progname = "java"; | |
1667 #else /* java, oldjava, javaw and friends */ | |
1668 #ifdef PROGNAME | |
1669 progname = PROGNAME; | |
1670 #else | |
1671 progname = *argv; | |
1672 if ((s = strrchr(progname, FILE_SEPARATOR)) != 0) { | |
1673 progname = s + 1; | |
1674 } | |
1675 #endif /* PROGNAME */ | |
1676 #endif /* JAVA_ARGS */ | |
1677 | |
1678 /* | |
1679 * This should never happen (because of the selection code in SelectJRE), | |
1680 * but check for "impossibly" long path names just because buffer overruns | |
1681 * can be so deadly. | |
1682 */ | |
1683 if (strlen(wanted) + strlen(progname) + 6 > PATH_MAX) { | |
1684 fprintf(stderr, "Path length exceeds maximum length (PATH_MAX)\n"); | |
1685 exit(1); | |
1686 } | |
1687 | |
1688 /* | |
1689 * Construct the path and exec it. | |
1690 */ | |
1691 (void)strcat(strcat(wanted, "/bin/"), progname); | |
1692 argv[0] = progname; | |
1693 if (_launcher_debug) { | |
1694 int i; | |
1695 printf("ReExec Command: %s (%s)\n", wanted, argv[0]); | |
1696 printf("ReExec Args:"); | |
1697 for (i = 1; argv[i] != NULL; i++) | |
1698 printf(" %s", argv[i]); | |
1699 printf("\n"); | |
1700 } | |
1701 (void)fflush(stdout); | |
1702 (void)fflush(stderr); | |
1703 execv(wanted, argv); | |
1704 perror("execv()"); | |
1705 fprintf(stderr, "Exec of %s failed\n", wanted); | |
1706 exit(1); | |
1707 } | |
1708 #endif /* ifndef GAMMA */ | |
1709 | |
1710 /* | |
1711 * "Borrowed" from Solaris 10 where the unsetenv() function is being added | |
1712 * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As | |
1713 * such, in the fullness of time this will appear in libc on all relevant | |
1714 * Solaris/Linux platforms and maybe even the Windows platform. At that | |
1715 * time, this stub can be removed. | |
1716 * | |
1717 * This implementation removes the environment locking for multithreaded | |
1718 * applications. (We don't have access to these mutexes within libc and | |
1719 * the launcher isn't multithreaded.) Note that what remains is platform | |
1720 * independent, because it only relies on attributes that a POSIX environment | |
1721 * defines. | |
1722 * | |
1723 * Returns 0 on success, -1 on failure. | |
1724 * | |
1725 * Also removed was the setting of errno. The only value of errno set | |
1726 * was EINVAL ("Invalid Argument"). | |
1727 */ | |
1728 | |
1729 /* | |
1730 * s1(environ) is name=value | |
1731 * s2(name) is name(not the form of name=value). | |
1732 * if names match, return value of 1, else return 0 | |
1733 */ | |
1734 static int | |
1735 match_noeq(const char *s1, const char *s2) | |
1736 { | |
1737 while (*s1 == *s2++) { | |
1738 if (*s1++ == '=') | |
1739 return (1); | |
1740 } | |
1741 if (*s1 == '=' && s2[-1] == '\0') | |
1742 return (1); | |
1743 return (0); | |
1744 } | |
1745 | |
1746 /* | |
1747 * added for SUSv3 standard | |
1748 * | |
1749 * Delete entry from environ. | |
1750 * Do not free() memory! Other threads may be using it. | |
1751 * Keep it around forever. | |
1752 */ | |
1753 static int | |
1754 borrowed_unsetenv(const char *name) | |
1755 { | |
1756 long idx; /* index into environ */ | |
1757 | |
1758 if (name == NULL || *name == '\0' || | |
1759 strchr(name, '=') != NULL) { | |
1760 return (-1); | |
1761 } | |
1762 | |
1763 for (idx = 0; environ[idx] != NULL; idx++) { | |
1764 if (match_noeq(environ[idx], name)) | |
1765 break; | |
1766 } | |
1767 if (environ[idx] == NULL) { | |
1768 /* name not found but still a success */ | |
1769 return (0); | |
1770 } | |
1771 /* squeeze up one entry */ | |
1772 do { | |
1773 environ[idx] = environ[idx+1]; | |
1774 } while (environ[++idx] != NULL); | |
1775 | |
1776 return (0); | |
1777 } | |
1778 /* --- End of "borrowed" code --- */ | |
1779 | |
1780 /* | |
1781 * Wrapper for unsetenv() function. | |
1782 */ | |
1783 int | |
1784 UnsetEnv(char *name) | |
1785 { | |
1786 return(borrowed_unsetenv(name)); | |
1787 } | |
1788 | |
1789 /* --- Splash Screen shared library support --- */ | |
1790 | |
1791 static const char* SPLASHSCREEN_SO = "libsplashscreen.so"; | |
1792 | |
1793 static void* hSplashLib = NULL; | |
1794 | |
1795 void* SplashProcAddress(const char* name) { | |
1796 if (!hSplashLib) { | |
1797 hSplashLib = dlopen(SPLASHSCREEN_SO, RTLD_LAZY | RTLD_GLOBAL); | |
1798 } | |
1799 if (hSplashLib) { | |
1800 void* sym = dlsym(hSplashLib, name); | |
1801 return sym; | |
1802 } else { | |
1803 return NULL; | |
1804 } | |
1805 } | |
1806 | |
1807 void SplashFreeLibrary() { | |
1808 if (hSplashLib) { | |
1809 dlclose(hSplashLib); | |
1810 hSplashLib = NULL; | |
1811 } | |
1812 } | |
1813 | |
1814 const char * | |
1815 jlong_format_specifier() { | |
1816 return "%lld"; | |
1817 } | |
1818 | |
1819 /* | |
1820 * Block current thread and continue execution in a new thread | |
1821 */ | |
1822 int | |
1823 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { | |
1824 int rslt; | |
1825 #ifdef __linux__ | |
1826 pthread_t tid; | |
1827 pthread_attr_t attr; | |
1828 pthread_attr_init(&attr); | |
1829 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); | |
1830 | |
1831 if (stack_size > 0) { | |
1832 pthread_attr_setstacksize(&attr, stack_size); | |
1833 } | |
1834 | |
1835 if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { | |
1836 void * tmp; | |
1837 pthread_join(tid, &tmp); | |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
1838 rslt = (int)(intptr_t)tmp; |
1985 | 1839 } else { |
1840 /* | |
1841 * Continue execution in current thread if for some reason (e.g. out of | |
1842 * memory/LWP) a new thread can't be created. This will likely fail | |
1843 * later in continuation as JNI_CreateJavaVM needs to create quite a | |
1844 * few new threads, anyway, just give it a try.. | |
1845 */ | |
1846 rslt = continuation(args); | |
1847 } | |
1848 | |
1849 pthread_attr_destroy(&attr); | |
1850 #else | |
1851 thread_t tid; | |
1852 long flags = 0; | |
1853 if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) { | |
1854 void * tmp; | |
1855 thr_join(tid, NULL, &tmp); | |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
1985
diff
changeset
|
1856 rslt = (int)(intptr_t)tmp; |
1985 | 1857 } else { |
1858 /* See above. Continue in current thread if thr_create() failed */ | |
1859 rslt = continuation(args); | |
1860 } | |
1861 #endif | |
1862 return rslt; | |
1863 } | |
1864 | |
1865 /* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */ | |
1866 #define MAX_PID_STR_SZ 20 | |
1867 | |
1868 void SetJavaLauncherPlatformProps() { | |
1869 /* Linux only */ | |
1870 #ifdef __linux__ | |
1871 const char *substr = "-Dsun.java.launcher.pid="; | |
1872 char *pid_prop_str = (char *)JLI_MemAlloc(strlen(substr) + MAX_PID_STR_SZ + 1); | |
1873 sprintf(pid_prop_str, "%s%d", substr, getpid()); | |
1874 AddOption(pid_prop_str, NULL); | |
1875 #endif | |
1876 } |