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