1892N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1892N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1892N/A * This code is free software; you can redistribute it and/or modify it 1892N/A * under the terms of the GNU General Public License version 2 only, as 1892N/A * published by the Free Software Foundation. 1892N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1892N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1892N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1892N/A * version 2 for more details (a copy is included in the LICENSE file that 1892N/A * You should have received a copy of the GNU General Public License version 1892N/A * 2 along with this work; if not, write to the Free Software Foundation, 1892N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1892N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1892N/A * If a processor / os combination has the ability to run binaries of 1892N/A * two data models and cohabitation of jre/jdk bits with both data 1892N/A * models is supported, then DUAL_MODE is defined. When DUAL_MODE is 1892N/A * defined, the architecture names for the narrow and wide version of 1892N/A * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME. Currently 1892N/A#
error "The macro LIBARCHNAME was not defined on the compile line" 1892N/A#
error "The macro LIBARCH32NAME was not defined on the compile line" 1892N/A#
error "The macro LIBARCH64NAME was not defined on the compile line" 1892N/A/* pointer to environment */ 1892N/A * A collection of useful strings. One should think of these as #define 1892N/A * entries, but actual strings can be more efficient (with many compilers). 1892N/A * Flowchart of launcher execs and options processing on unix 1892N/A * The selection of the proper vm shared library to open depends on 1892N/A * several classes of command line options, including vm "flavor" 1892N/A * options (-client, -server) and the data model options, -d32 and 1892N/A * -d64, as well as a version specification which may have come from 1892N/A * the command line or from the manifest of an executable jar file. 1892N/A * The vm selection options are not passed to the running 1892N/A * virtual machine; they must be screened out by the launcher. 1892N/A * The version specification (if any) is processed first by the 1892N/A * platform independent routine SelectVersion. This may result in 1892N/A * the exec of the specified launcher version. 1892N/A * Typically, the launcher execs at least once to ensure a suitable 1892N/A * LD_LIBRARY_PATH is in effect for the process. The first exec 1892N/A * screens out all the data model options; leaving the choice of data 1892N/A * model implicit in the binary selected to run. However, in case no 1892N/A * exec is done, the data model options are screened out before the vm 1892N/A * incoming argv ------------------------------ 1892N/A * (removes -client, -server, etc.) | 1892N/A * CreateExecutionEnvironment 1892N/A * determines desired data model, 1892N/A * -------------------------------------------- 1892N/A * exec child 1 incoming argv ----------------- 1892N/A * (removes -client, -server, etc.) | 1892N/A * | CreateExecutionEnvironment 1892N/A * | (verifies desired data model 1892N/A * | is running and acceptable 1892N/A * (Prepare to pass args to vm) 1892N/A * processes version options, 1892N/A * creates argument list for vm, 1892N/A * First, determine if we are running the desired data model. If we 1892N/A * are running the desired data model, all the error messages 1892N/A * associated with calling GetJREPath, ReadKnownVMs, etc. should be 1892N/A * output. However, if we are not running the desired data model, 1892N/A * some of the errors should be suppressed since it is more 1892N/A * informative to issue an error message based on whether or not the 1892N/A /* Compute the name of the executable */ 1892N/A /* Set the LD_LIBRARY_PATH environment variable, check data model 1892N/A flags, and exec process, if needed */ 1892N/A 32 bit vm; LP64 => 64 bit vm */ 1892N/A asked for? Current model is 1892N/A * Starting in 1.5, all unix platforms accept the -d32 and -d64 1892N/A * options. On platforms where only one data-model is supported 1892N/A * (e.g. ia-64 Linux), using the flag for the other data model is 1892N/A * an error and will terminate the program. 1892N/A {
/* open new scope to declare local variables */ 1892N/A /* scan for data model arguments and remove from argument list; 1892N/A last occurrence determines desired data model */ 1892N/A /* copy rest of args [i .. argc) */ 1892N/A * newargv has all proper arguments here 1892N/A /* If the data model is not changing, it is an error if the 1892N/A /* Find out where the JRE is that we will be using. */ 1892N/A /* Find the specified JVM type */ 1892N/A }
else {
/* do the same speculatively or exit */ 1892N/A /* Find out where the JRE is that we will be using. */ 1892N/A * Read in jvm.cfg for target data model and process vm 1892N/A /* exec child can do error checking on the existence of the path */ 1892N/A * We will set the LD_LIBRARY_PATH as follows: 1892N/A * o $JVMPATH (directory portion only) 1892N/A * o $JRE/../lib/$LIBARCHNAME 1892N/A * followed by the user's previous effective LD_LIBRARY_PATH, if 1892N/A * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH 1892N/A * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if 1892N/A * data-model specific variables are not set. 1892N/A * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH 1892N/A * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH 1892N/A * The vm uses LD_LIBRARY_PATH to set the java.library.path system 1892N/A * property. To shield the vm from the complication of multiple 1892N/A * LD_LIBRARY_PATH variables, if the appropriate data model 1892N/A * specific variable is set, we will act as if LD_LIBRARY_PATH had 1892N/A * the value of the data model specific variant and the data model 1892N/A * specific variant will be unset. Note that the variable for the 1892N/A * *wanted* data model must be used (if it is set), not simply the 1892N/A * current running data model. 1892N/A * If dmpath is NULL, the relevant data model specific variable is 1892N/A * not set and normal LD_LIBRARY_PATH should be used. 1892N/A * If not on Solaris, assume only a single LD_LIBRARY_PATH 1892N/A * On linux, if a binary is running as sgid or suid, glibc sets 1892N/A * LD_LIBRARY_PATH to the empty string for security purposes. (In 1892N/A * contrast, on Solaris the LD_LIBRARY_PATH variable for a 1892N/A * privileged binary does not lose its settings; but the dynamic 1892N/A * linker does apply more scrutiny to the path.) The launcher uses 1892N/A * the value of LD_LIBRARY_PATH to prevent an exec loop. 1892N/A * Therefore, if we are running sgid or suid, this function's 1892N/A * setting of LD_LIBRARY_PATH will be ineffective and we should 1892N/A * return from the function now. Getting the right libraries to 1892N/A * be found must be handled through other mechanisms. 2796N/A * On BSD, if a binary is running as sgid or suid, libc sets 2796N/A * LD_LIBRARY_PATH to the empty string for security purposes. (In 2796N/A * contrast, on Solaris the LD_LIBRARY_PATH variable for a 2796N/A * privileged binary does not lose its settings; but the dynamic 2796N/A * linker does apply more scrutiny to the path.) The launcher uses 2796N/A * the value of LD_LIBRARY_PATH to prevent an exec loop. 2796N/A * Therefore, if we are running sgid or suid, this function's 2796N/A * setting of LD_LIBRARY_PATH will be ineffective and we should 2796N/A * return from the function now. Getting the right libraries to 2796N/A * be found must be handled through other mechanisms. 1892N/A /* runpath contains current effective LD_LIBRARY_PATH setting */ 1892N/A * Create desired LD_LIBRARY_PATH value for target data model. 1892N/A /* remove the name of the .so from the JVM path */ 1892N/A /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */ 1892N/A * Check to make sure that the prefix of the current path is the 1892N/A * desired environment variable setting. 1892N/A * Place the desired environment setting onto the prefix of 1892N/A * LD_LIBRARY_PATH. Note that this prevents any possible infinite 1892N/A * loop of execv() because we test for the prefix, above. 1892N/A exit(
1);
/* problem allocating memory; LD_LIBRARY_PATH not set 1892N/A * Unix systems document that they look at LD_LIBRARY_PATH only 1892N/A * once at startup, so we have to re-exec the current executable 1892N/A * to get the changed environment variable to have an effect. 1892N/A * If dmpath is not NULL, remove the data model specific string 1892N/A * in the environment for the exec'ed child. 1892N/A * If the data model is being changed, the path to the 1892N/A * executable must be updated accordingly; the executable name 1892N/A * and directory the executable resides in are separate. In the 1892N/A * case of 32 => 64, the new bits are assumed to reside in, e.g. 1892N/A * the bits are assumed to be in "olddir/../execname". For example, 1892N/A * for Solaris SPARC and Linux amd64, respectively. 1892N/A "(Solaris SPARC 64-bit components must be installed after 32-bit components.)\n" );
1892N/A * gamma launcher is simpler in that it doesn't handle VM flavors, data 1892N/A * model, LD_LIBRARY_PATH, etc. Assuming everything is set-up correctly 1892N/A * all we need to do here is to return correct path names. See also 1892N/A * GetJVMPath() and GetApplicationHome(). 1892N/A * On Solaris VM choosing is done by the launcher (java.c). 1892N/A * For gamma launcher, JVM is either built-in or in the same directory. 1892N/A * Either way we return "<exe_path>/libjvm.so" where <exe_path> is the 1892N/A * directory where gamma launcher is located. 1892N/A /* this case shouldn't happen */ 1892N/A * Find path to JRE based on .exe's location or registry settings. 3129N/A /* Is the JRE universal, i.e. no arch dir? */ 1892N/A /* Is JRE co-located with the application? */ 1892N/A /* Does the app ship a private JRE in <apphome>/jre directory? */ 1892N/A /* JVM is directly linked with gamma launcher; no dlopen() */ 1892N/A * Check for running a server vm (compiled with -xarch=v8plus) 1892N/A * on a stock v8 processor. In this case, the machine type in 1892N/A * the elf header would not be included the architecture list 1892N/A * provided by the isalist command, which is turn is gotten from 1892N/A * sysinfo. This case cannot occur on 64-bit hardware and thus 1892N/A * does not have to be checked for in binaries with an LP64 data 1892N/A char buf[
257];
/* recommended buffer size from sysinfo man 1934N/A /* gamma launcher uses JAVA_HOME environment variable to find JDK/JRE */ 1892N/A * Return true if the named program exists 1892N/A * Find a command in a directory, returning the path. 1892N/A * Find a path for the executable 1892N/A /* relative path element */ 1892N/A/* Store the name of the executable once computed */ 1892N/A * Compute the name of the executable 1892N/A * In order to re-exec securely we need the absolute path of the 1892N/A * executable. On Solaris getexecname(3c) may not return an absolute 1892N/A * path so we use dladdr to get the filename of the executable and 1892N/A * then use realpath to derive an absolute path. From Solaris 9 1892N/A * onwards the filename returned in DL_info structure from dladdr is 1892N/A * an absolute pathname so technically realpath isn't required. 1892N/A * As a fallback, and for platforms other than Solaris and Linux, 1892N/A * we use FindExecName to compute the executable name. 1892N/A#
else /* !__sun && !__linux */ 1892N/A * Return the name of the executable. Used in java_md.c to find the JRE area. 1892N/A * Return JNI_TRUE for an option string that has no effect but should 1892N/A * _not_ be passed on to the vm; return JNI_FALSE otherwise. On 1892N/A * Solaris SPARC, this screening needs to be done if: 1892N/A * 1) LD_LIBRARY_PATH does _not_ need to be reset and 1892N/A * 2) -d32 or -d64 is passed to a binary with a matching data model 1892N/A * (the exec in SetLibraryPath removes -d<n> options and points the 1892N/A * exec to the proper binary). When this exec is not done, these options 1892N/A * would end up getting passed onto the vm. 1892N/A * Unconditionally remove both -d32 and -d64 options since only 1892N/A * the last such options has an effect; e.g. 1892N/A * java -d32 -d64 -d32 -version 1892N/A " -d32 use a 32-bit data model if available\n" 1892N/A " -d64 use a 64-bit data model if available\n");
1892N/A * The following methods (down to ServerClassMachine()) answer 1892N/A * the question about whether a machine is a "server-class" 1892N/A * machine. A server-class machine is loosely defined as one 1892N/A * with 2 or more processors and 2 gigabytes or more physical 1892N/A * memory. The definition of a processor is a physical package, 1892N/A * not a hyperthreaded chip masquerading as a multi-processor. 1892N/A * The definition of memory is also somewhat fuzzy, since x86 1892N/A * machines seem not to report all the memory in their DIMMs, we 1892N/A * think because of memory mapping of graphics cards, etc. 1892N/A * This code is somewhat more confused with #ifdef's than we'd 1892N/A * like because this file is used by both Solaris and Linux 1892N/A * platforms, and so needs to be parameterized for SPARC and 1892N/A * i586 hardware. The other Linux platforms (amd64 and ia64) 1892N/A * don't even ask this question, because they only come with 1892N/A/* Compute physical memory by asking the OS */ 1892N/A/* Methods for solaris-sparc: these are easy. */ 1892N/A/* Ask the OS how many processors there are. */ 1892N/A/* The solaris-sparc version of the "server-class" predicate. */ 1892N/A /* How big is a server class machine? */ 1892N/A /* Is this a server class machine? */ 1892N/A#
endif /* __sun && __sparc */ 1892N/A * A utility method for asking the CPU about itself. 1892N/A * There's a corresponding version of linux-i586 1892N/A * because the compilers are different. 1892N/A /* rbx is a callee-saved register */ 1892N/A /* rdx and rcx are 3rd and 4th argument registers */ 1892N/A /* EBX is a callee-saved register */ 1892N/A /* Need ESI for storing through arguments */ 1892N/A asm(
" movl 8(%ebp), %eax \n" 1892N/A * A utility method for asking the CPU about itself. 1892N/A * There's a corresponding version of solaris-i586 1892N/A * because the compilers are different. 1892N/A "%rax",
"%rbx",
"%rcx",
"%rdx",
"memory" 1892N/A /* ebx is callee-save, so push it */ 1892N/A#
endif /* __linux__ && i586 */ 1892N/A * Routines shared by solaris-i586 and linux-i586. 1892N/A/* Determine if hyperthreading is supported */ 1892N/A /* Bits 11 through 8 is family processor id */ 1892N/A /* Bits 23 through 20 is extended family processor id */ 1892N/A /* Pentium 4 family processor id */ 1892N/A /* Bit 28 indicates Hyper-Threading Technology support */ 1892N/A /* Yes, this is supposed to be [0], [2], [1] */ 1892N/A/* Determine how many logical processors there are per CPU */ 1892N/A * After CPUID with EAX==1, register EBX bits 23 through 16 1892N/A * indicate the number of logical processors per package 1892N/A/* Compute the number of physical processors, not logical processors */ 1892N/A /* How big is a server class machine? */ 1892N/A * We seem not to get our full complement of memory. 1892N/A * We allow some part (1/8?) of the memory to be "missing", 1892N/A * based on the sizes of DIMMs, and maybe graphics cards. 1892N/A /* Is this a server class machine? */ 1892N/A/* The definition of a server-class machine for linux-i586 */ 1892N/A /* How big is a server class machine? */ 1892N/A * We seem not to get our full complement of memory. 1892N/A * We allow some part (1/8?) of the memory to be "missing", 1892N/A * based on the sizes of DIMMs, and maybe graphics cards. 1892N/A /* Is this a server class machine? */ 1892N/A#
endif /* __linux__ && i586 */ 2796N/A/* The definition of a server-class machine for bsd-i586 */ 2796N/A /* How big is a server class machine? */ 2796N/A * We seem not to get our full complement of memory. 2796N/A * We allow some part (1/8?) of the memory to be "missing", 2796N/A * based on the sizes of DIMMs, and maybe graphics cards. 2796N/A /* Is this a server class machine? */ 2796N/A#
endif /* _ALLBSD_SOURCE && i586 */ 1892N/A/* Dispatch to the platform-specific definition of "server-class" */ 1892N/A printf(
"ServerClassMachine: returns default value of %s\n",
1892N/A * Since using the file system as a registry is a bit risky, perform 1892N/A * additional sanity checks on the identified directory to validate 1892N/A * Return 0 if the tests fail; otherwise return non-zero (true). 1892N/A * Note that checking for anything more than the existence of an 1892N/A * executable object at bin/java relative to the path being checked 1892N/A * will break the regression tests. 1892N/A return (0);
/* Silently reject "impossibly" long paths */ 1892N/A * Determine if there is an acceptable JRE in the directory dirname. 1892N/A * Upon locating the "best" one, return a fully qualified path to 1892N/A * it. "Best" is defined as the most advanced JRE meeting the 1892N/A * constraints contained in the manifest_info. If no JRE in this 1892N/A * directory meets the constraints, return NULL. 1892N/A * Note that we don't check for errors in reading the directory 1892N/A * (which would be done by checking errno). This is because it 1892N/A * doesn't matter if we get an error reading the directory, or 1892N/A * we just don't find anything interesting in the directory. We 1892N/A * just return NULL in either case. 1892N/A * The historical names of j2sdk and j2re were changed to jdk and 1892N/A * jre respecively as part of the 1.5 rebranding effort. Since the 1892N/A * former names are legacy on Linux, they must be recognized for 1892N/A * all time. Fortunately, this is a minor cost. 1892N/A * This is the global entry point. It examines the host for the optimal 1892N/A * JRE to be used by scanning a set of directories. The set of directories 1892N/A * is platform dependent and can be overridden by the environment 1892N/A * variable JAVA_VERSION_PATH. 1892N/A * This routine itself simply determines the set of appropriate 1892N/A * directories before passing control onto ProcessDir(). 1892N/A * Start by getting JAVA_VERSION_PATH 1892N/A * Step through each directory on the path. Terminate the scan with 1892N/A * the first directory with an acceptable JRE. 1892N/A * Given a path to a jre to execute, this routine checks if this process 1892N/A * is indeed that jre. If not, it exec's that jre. 1892N/A * We want to actually check the paths rather than just the version string 1892N/A * built into the executable, so that given version specification (and 1892N/A * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless 1892N/A * of the version of the arbitrary launcher we start with. 1892N/A * Resolve the real path to the directory containing the selected JRE. 1892N/A * Resolve the real path to the currently running launcher. 1892N/A * If the path to the selected JRE directory is a match to the initial 1892N/A * portion of the path to the currently executing JRE, we have a winner! 1892N/A return;
/* I am the droid you were looking for */ 1892N/A * If this isn't the selected version, exec the selected version. 1892N/A#
else /* java, oldjava, javaw and friends */ 1892N/A * This should never happen (because of the selection code in SelectJRE), 1892N/A * but check for "impossibly" long path names just because buffer overruns 1892N/A * Construct the path and exec it. 1892N/A * "Borrowed" from Solaris 10 where the unsetenv() function is being added 1892N/A * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As 1892N/A * such, in the fullness of time this will appear in libc on all relevant 1892N/A * time, this stub can be removed. 1892N/A * This implementation removes the environment locking for multithreaded 1892N/A * applications. (We don't have access to these mutexes within libc and 1892N/A * the launcher isn't multithreaded.) Note that what remains is platform 1892N/A * independent, because it only relies on attributes that a POSIX environment 1892N/A * Returns 0 on success, -1 on failure. 1892N/A * Also removed was the setting of errno. The only value of errno set 1892N/A * was EINVAL ("Invalid Argument"). 1892N/A * s1(environ) is name=value 1892N/A * s2(name) is name(not the form of name=value). 1892N/A * if names match, return value of 1, else return 0 1892N/A * Delete entry from environ. 1892N/A * Do not free() memory! Other threads may be using it. 1892N/A /* name not found but still a success */ 1892N/A/* --- End of "borrowed" code --- */ 1892N/A * Wrapper for unsetenv() function. 1892N/A/* --- Splash Screen shared library support --- */ 1892N/A * Block current thread and continue execution in a new thread 1892N/A * Continue execution in current thread if for some reason (e.g. out of 1892N/A * later in continuation as JNI_CreateJavaVM needs to create quite a 1892N/A * few new threads, anyway, just give it a try.. 1892N/A /* See above. Continue in current thread if thr_create() failed */ 1892N/A/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */