annotate src/os/solaris/launcher/java.c @ 605:98cb887364d3

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