jdk/src/java.base/share/native/libjli/java.c
author rchamyal
Thu, 24 Mar 2016 14:06:32 +0530
changeset 36907 c3d8383e3efb
parent 36511 9d0388c6b336
child 38753 9d4f778eda39
permissions -rw-r--r--
8145173: HiDPI splash screen support on Windows Reviewed-by: serb, alexsch, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28771
2885fb2e1002 8068033: JNI exception pending in jdk/src/share/bin/java.c
ksrini
parents: 28107
diff changeset
     2
 * Copyright (c) 1995, 2015, 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 */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    72
static char     *listModules = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
static const char *_program_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static const char *_launcher_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
static jboolean _is_java_args = JNI_FALSE;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    77
static jboolean _have_classpath = JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static const char *_fVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
static jboolean _wc_enabled = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static jint _ergo_policy = DEFAULT_POLICY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * Entries for splash screen environment variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * putenv is performed in SelectVersion. We need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * them in memory until UnsetEnv, so they are made static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * global instead of auto local.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
static char* splash_file_entry = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static char* splash_jar_entry = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * List of VM options to be specified when the VM is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
static JavaVMOption *options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
static int numOptions, maxOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Prototypes for functions internal to launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
static void SetClassPath(const char *s);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   101
static void SetModulePath(const char *s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   102
static void SetUpgradeModulePath(const char *s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   103
static void SetMainModule(const char *s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   104
static void SetAddModulesProp(const char *mods);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   105
static void SetLimitModulesProp(const char *mods);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   106
static void SetAddReadsProp(const jint n, const char *s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   107
static void SetAddExportsProp(const jint n, const char *s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   108
static void SetPatchProp(const jint n, const char *s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
static void SelectVersion(int argc, char **argv, char **main_class);
25816
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   110
static void SetJvmEnvironment(int argc, char **argv);
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   111
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
   112
                               int *pmode, char **pwhat,
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   113
                               int *pret, const char *jrepath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                              InvocationFunctions *ifn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static jstring NewPlatformString(JNIEnv *env, char *s);
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   117
static jclass LoadMainClass(JNIEnv *env, int mode, char *name);
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   118
static jclass GetApplicationClass(JNIEnv *env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static jboolean AddApplicationOptions(int cpathc, const char **cpathv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static void SetApplicationClassPath(const char**);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
static void PrintJavaVersion(JNIEnv *env, jboolean extraLF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
static void PrintUsage(JNIEnv* env, jboolean doXUsage);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   126
static void ShowSettings(JNIEnv* env, char *optString);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   127
static void ListModules(JNIEnv* env, char *optString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
static void SetPaths(int argc, char **argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
static void DumpState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
static jboolean RemovableOption(char *option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
/* Maximum supported entries from jvm.cfg. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#define INIT_MAX_KNOWN_VMS      10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/* Values for vmdesc.flag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
enum vmdesc_flag {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    VM_UNKNOWN = -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    VM_KNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    VM_ALIASED_TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    VM_WARN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    VM_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    VM_IF_SERVER_CLASS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    VM_IGNORE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
struct vmdesc {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    int flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    char *alias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    char *server_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
static struct vmdesc *knownVMs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
static int knownVMsCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
static int knownVMsLimit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
31476
d1e837c96aba 8130315: Fix wrong prototype of GrowKnownVMs() in java.c
simonis
parents: 29742
diff changeset
   158
static void GrowKnownVMs(int minimum);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
static int  KnownVMIndex(const char* name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
static void FreeKnownVMs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
static jboolean IsWildCardEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   163
#define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   164
    do { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   165
        if (AC_arg_count < 1) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   166
            JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   167
            printUsage = JNI_TRUE; \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   168
            *pret = 1; \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   169
            return JNI_TRUE; \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   170
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   171
    } while (JNI_FALSE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * Running Java code in primordial thread caused many problems. We will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * create a new thread to invoke JVM. See 6316197 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   177
static jlong threadStackSize    = 0;  /* stack size of the new thread */
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   178
static jlong maxHeapSize        = 0;  /* max heap size */
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   179
static jlong initialHeapSize    = 0;  /* inital heap size */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
/*
28102
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   182
 * A minimum -Xss stack size suitable for all platforms.
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   183
 */
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   184
#ifndef STACK_SIZE_MINIMUM
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   185
#define STACK_SIZE_MINIMUM (32 * KB)
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   186
#endif
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   187
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   188
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * Entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
JLI_Launch(int argc, char ** argv,              /* main argc, argc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int jargc, const char** jargv,          /* java args */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        int appclassc, const char** appclassv,  /* app classpath */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        const char* fullversion,                /* full version defined */
33987
24ecd3c83f33 8129601: [launcher] test VersionCheck.java fails with new version string
ksrini
parents: 29742
diff changeset
   196
        const char* dotversion,                 /* UNUSED dot version defined */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        const char* pname,                      /* program name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        const char* lname,                      /* launcher name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        jboolean javaargs,                      /* JAVA_ARGS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        jboolean cpwildcard,                    /* classpath wildcard*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        jboolean javaw,                         /* windows-only javaw */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        jint ergo                               /* ergonomics class policy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   205
    int mode = LM_UNKNOWN;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   206
    char *what = NULL;
2
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];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
   213
    char jvmcfg[MAXPATHLEN];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    _fVersion = fullversion;
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();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   224
    if (JLI_IsTraceLauncher()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   225
        int i;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   226
        printf("Command line args:\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   227
        for (i = 0; i < argc ; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   228
            printf("argv[%d] = %s\n", i, argv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   229
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   230
        AddOption("-Dsun.java.launcher.diag=true", NULL);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   231
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /*
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   234
     * SelectVersion() has several responsibilities:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   236
     *  1) Disallow specification of another JRE.  With 1.9, another
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   237
     *     version of the JRE cannot be invoked.
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   238
     *  2) Allow for a JRE version to invoke JDK 1.9 or later.  Since
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   239
     *     all mJRE directives have been stripped from the request but
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   240
     *     the pre 1.9 JRE [ 1.6 thru 1.8 ], it is as if 1.9+ has been
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   241
     *     invoked from the command line.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    SelectVersion(argc, argv, &main_class);
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   244
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    CreateExecutionEnvironment(&argc, &argv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                               jrepath, sizeof(jrepath),
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
   247
                               jvmpath, sizeof(jvmpath),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
   248
                               jvmcfg,  sizeof(jvmcfg));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
25816
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   250
    if (!IsJavaArgs()) {
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   251
        SetJvmEnvironment(argc,argv);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   252
    }
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    ifn.CreateJavaVM = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    ifn.GetDefaultJavaVMInitArgs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        start = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (!LoadJavaVM(jvmpath, &ifn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return(6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        end   = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
             (long)(jint)Counter2Micros(end-start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    ++argv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    --argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (IsJavaArgs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        /* Preprocess wrapper arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        TranslateApplicationArgs(jargc, jargv, &argc, &argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (!AddApplicationOptions(appclassc, appclassv)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        /* Set default CLASSPATH */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   283
        char* cpath = getenv("CLASSPATH");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   284
        if (cpath != NULL) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   285
            SetClassPath(cpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   289
    /* 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
   290
     * ParseArguments is false, the program should exit.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   292
    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
   293
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /* 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
   298
    if (mode == LM_JAR) {
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   299
        SetClassPath(what);     /* Override class path */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /* 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
   303
    SetJavaCommandLineProp(what, argc, argv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /* Set the -Dsun.java.launcher pseudo property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    SetJavaLauncherProp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /* set the -Dsun.java.launcher.* platform properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    SetJavaLauncherPlatformProps();
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   310
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   311
    return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   313
/*
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   314
 * 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
   315
 * the application's main method exits.  This will invoke the
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   316
 * uncaught exception handler machinery if main threw an
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   317
 * exception.  An uncaught exception handler cannot change the
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   318
 * launcher's return code except by calling System.exit.
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   319
 *
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   320
 * 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
   321
 * This will actually create a trivial new Java waiter thread
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   322
 * named "DestroyJavaVM", but this will be seen as a different
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   323
 * 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
   324
 * the same C thread.  This allows mainThread.join() and
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   325
 * mainThread.isAlive() to work as expected.
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   326
 */
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   327
#define LEAVE() \
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   328
    do { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   329
        if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   330
            JLI_ReportErrorMessage(JVM_ERROR2); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   331
            ret = 1; \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   332
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   333
        if (JNI_TRUE) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   334
            (*vm)->DestroyJavaVM(vm); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   335
            return ret; \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   336
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   337
    } while (JNI_FALSE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   339
#define CHECK_EXCEPTION_NULL_LEAVE(CENL_exception) \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   340
    do { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   341
        if ((*env)->ExceptionOccurred(env)) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   342
            JLI_ReportExceptionDescription(env); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   343
            LEAVE(); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   344
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   345
        if ((CENL_exception) == NULL) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   346
            JLI_ReportErrorMessage(JNI_ERROR); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   347
            LEAVE(); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   348
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   349
    } while (JNI_FALSE)
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   350
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   351
#define CHECK_EXCEPTION_LEAVE(CEL_return_value) \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   352
    do { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   353
        if ((*env)->ExceptionOccurred(env)) { \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   354
            JLI_ReportExceptionDescription(env); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   355
            ret = (CEL_return_value); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   356
            LEAVE(); \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   357
        } \
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   358
    } while (JNI_FALSE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
   360
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
int JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
JavaMain(void * _args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    JavaMainArgs *args = (JavaMainArgs *)_args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    int argc = args->argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    char **argv = args->argv;
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   367
    int mode = args->mode;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   368
    char *what = args->what;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    InvocationFunctions ifn = args->ifn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    JavaVM *vm = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    JNIEnv *env = 0;
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   373
    jclass mainClass = NULL;
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   374
    jclass appClass = NULL; // actual application class being launched
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    jmethodID mainID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    jobjectArray mainArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    int ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    jlong start, end;
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   379
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
   380
    RegisterThread();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
   381
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /* Initialize the virtual machine */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    start = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    if (!InitializeJVM(&vm, &env, &ifn)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
   385
        JLI_ReportErrorMessage(JVM_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
11363
09b0c9731145 7123582: (launcher) display the -version and -XshowSettings
ksrini
parents: 9035
diff changeset
   389
    if (showSettings != NULL) {
09b0c9731145 7123582: (launcher) display the -version and -XshowSettings
ksrini
parents: 9035
diff changeset
   390
        ShowSettings(env, showSettings);
09b0c9731145 7123582: (launcher) display the -version and -XshowSettings
ksrini
parents: 9035
diff changeset
   391
        CHECK_EXCEPTION_LEAVE(1);
09b0c9731145 7123582: (launcher) display the -version and -XshowSettings
ksrini
parents: 9035
diff changeset
   392
    }
09b0c9731145 7123582: (launcher) display the -version and -XshowSettings
ksrini
parents: 9035
diff changeset
   393
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   394
    if (listModules != NULL) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   395
        ListModules(env, listModules);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   396
        CHECK_EXCEPTION_LEAVE(1);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   397
        LEAVE();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   398
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   399
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    if (printVersion || showVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        PrintJavaVersion(env, showVersion);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   402
        CHECK_EXCEPTION_LEAVE(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (printVersion) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   404
            LEAVE();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /* 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
   409
    if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        PrintUsage(env, printXUsage);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   411
        CHECK_EXCEPTION_LEAVE(1);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   412
        LEAVE();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    FreeKnownVMs();  /* after last possible PrintUsage() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        end = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
               (long)(jint)Counter2Micros(end-start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   423
    /* At this stage, argc/argv have the application's arguments */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    if (JLI_IsTraceLauncher()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int i;
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   426
        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
   427
        printf("App's argc is %d\n", argc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        for (i=0; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            printf("    argv[%2d] = '%s'\n", i, argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    ret = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Get the application's main class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * See bugid 5030265.  The Main-Class name has already been parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * from the manifest, but not parsed properly for UTF-8 support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Hence the code here ignores the value previously extracted and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * uses the pre-existing code to reextract the value.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * possibly an end of release cycle expedient.  However, it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * also been discovered that passing some character sets through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * the environment has "strange" behavior on some variants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Windows.  Hence, maybe the manifest parsing code local to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * launcher should never be enhanced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Hence, future work should either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *     1)   Correct the local parsing code and verify that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *          Main-Class attribute gets properly passed through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *          all environments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *     2)   Remove the vestages of maintaining main_class through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *          the environment (and remove these comments).
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   454
     *
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   455
     * This method also correctly handles launching existing JavaFX
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   456
     * applications that may or may not have a Main-Class manifest entry.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   458
    mainClass = LoadMainClass(env, mode, what);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   459
    CHECK_EXCEPTION_NULL_LEAVE(mainClass);
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   460
    /*
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   461
     * In some cases when launching an application that needs a helper, e.g., a
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   462
     * JavaFX application with no main method, the mainClass will not be the
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   463
     * applications own main class but rather a helper class. To keep things
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   464
     * consistent in the UI we need to track and report the application main class.
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   465
     */
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   466
    appClass = GetApplicationClass(env);
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14518
diff changeset
   467
    NULL_CHECK_RETURN_VALUE(appClass, -1);
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   468
    /*
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   469
     * PostJVMInit uses the class name as the application name for GUI purposes,
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   470
     * for example, on OSX this sets the application name in the menu bar for
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   471
     * both SWT and JavaFX. So we'll pass the actual application class here
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   472
     * instead of mainClass as that may be a launcher or helper class instead
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   473
     * of the application class.
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   474
     */
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   475
    PostJVMInit(env, appClass, vm);
28771
2885fb2e1002 8068033: JNI exception pending in jdk/src/share/bin/java.c
ksrini
parents: 28107
diff changeset
   476
    CHECK_EXCEPTION_LEAVE(1);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   477
    /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   478
     * 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
   479
     * that the main method's signature is correct, therefore further checking
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   480
     * 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
   481
     * stacks are not in the application stack trace.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   482
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                       "([Ljava/lang/String;)V");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   485
    CHECK_EXCEPTION_NULL_LEAVE(mainID);
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   486
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   487
    /* Build platform specific argument array */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
   488
    mainArgs = CreateApplicationArgs(env, argv, argc);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   489
    CHECK_EXCEPTION_NULL_LEAVE(mainArgs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /* Invoke main method. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
   493
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * The launcher's exit code (in the absence of calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * System.exit) will be non-zero if main threw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   499
    LEAVE();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
 * Checks the command line options to find which JVM type was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
 * specified.  If no command line option was given for the JVM type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
 * the default type is used.  The environment variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
 * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
 * checked as ways of specifying which JVM type to invoke.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    int i, argi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    int argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    char **newArgv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    int newArgvIdx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    int isVMType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    int jvmidx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    char *jvmtype = getenv("JDK_ALTERNATE_VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    argc = *pargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /* To make things simpler we always copy the argv array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /* The program name is always present */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    newArgv[newArgvIdx++] = (*argv)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    for (argi = 1; argi < argc; argi++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        char *arg = (*argv)[argi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        isVMType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (IsJavaArgs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            if (arg[0] != '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                newArgv[newArgvIdx++] = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (JLI_StrCmp(arg, "-classpath") == 0 ||
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   538
                JLI_StrCmp(arg, "-cp") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   539
                JLI_StrCmp(arg, "-modulepath") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   540
                JLI_StrCmp(arg, "-mp") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   541
                JLI_StrCmp(arg, "-upgrademodulepath") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   542
                JLI_StrCmp(arg, "-addmods") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   543
                JLI_StrCmp(arg, "-limitmods") == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                newArgv[newArgvIdx++] = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                argi++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                if (argi < argc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    newArgv[newArgvIdx++] = (*argv)[argi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (arg[0] != '-') break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        /* Did the user pass an explicit VM type? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        i = KnownVMIndex(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            isVMType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            *pargc = *pargc - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /* Did the user specify an "alternate" VM? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        else if (JLI_StrCCmp(arg, "-XXaltjvm=") == 0 || JLI_StrCCmp(arg, "-J-XXaltjvm=") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            isVMType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            jvmtype = arg+((arg[1]=='X')? 10 : 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            jvmidx = -1;
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 (!isVMType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            newArgv[newArgvIdx++] = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Finish copying the arguments if we aborted the above loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * NOTE that if we aborted via "break" then we did NOT copy the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * last argument above, and in addition argi will be less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * argc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    while (argi < argc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        newArgv[newArgvIdx++] = (*argv)[argi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        argi++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /* argv is null-terminated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    newArgv[newArgvIdx] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /* Copy back argv */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    *argv = newArgv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    *pargc = newArgvIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /* use the default VM type if not specified (no alias processing) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    if (jvmtype == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
      char* result = knownVMs[0].name+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
      /* Use a different VM type if we are on a server class machine? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
      if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
          (ServerClassMachine() == JNI_TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        result = knownVMs[0].server_class+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
      JLI_TraceLauncher("Default VM: %s\n", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
      return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /* if using an alternate VM, no alias processing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    if (jvmidx < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
      return jvmtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /* Resolve aliases first */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
      int loopCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
      while (knownVMs[jvmidx].flag == VM_ALIASED_TO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (loopCount > knownVMsCount) {
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_ERROR1);
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
            /* break; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (nextIdx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
          if (!speculative) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
   626
            JLI_ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            return "ERROR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        jvmidx = nextIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        jvmtype = knownVMs[jvmidx].name+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        loopCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    switch (knownVMs[jvmidx].flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    case VM_WARN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (!speculative) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
   641
            JLI_ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /* fall through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    case VM_IGNORE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        jvmtype = knownVMs[jvmidx=0].name + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        /* fall through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    case VM_KNOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    case VM_ERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        if (!speculative) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
   651
            JLI_ReportErrorMessage(CFG_ERROR3, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            return "ERROR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    return jvmtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
25816
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   661
/*
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   662
 * static void SetJvmEnvironment(int argc, char **argv);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   663
 *   Is called just before the JVM is loaded.  We can set env variables
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   664
 *   that are consumed by the JVM.  This function is non-destructive,
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   665
 *   leaving the arg list intact.  The first use is for the JVM flag
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   666
 *   -XX:NativeMemoryTracking=value.
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   667
 */
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   668
static void
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   669
SetJvmEnvironment(int argc, char **argv) {
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   670
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   671
    static const char*  NMT_Env_Name    = "NMT_LEVEL_";
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   672
    int i;
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   673
    for (i = 0; i < argc; i++) {
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   674
        char *arg = argv[i];
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   675
        /*
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   676
         * Since this must be a VM flag we stop processing once we see
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   677
         * an argument the launcher would not have processed beyond (such
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   678
         * as -version or -h), or an argument that indicates the following
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   679
         * arguments are for the application (i.e. the main class name, or
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   680
         * the -jar argument).
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   681
         */
29373
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   682
        if (i > 0) {
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   683
            char *prev = argv[i - 1];
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   684
            // skip non-dash arg preceded by class path specifiers
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   685
            if (*arg != '-' &&
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   686
                    ((JLI_StrCmp(prev, "-cp") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   687
                    || JLI_StrCmp(prev, "-classpath") == 0))) {
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   688
                continue;
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   689
            }
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   690
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   691
            if (*arg != '-'
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   692
                    || JLI_StrCmp(arg, "-version") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   693
                    || JLI_StrCmp(arg, "-fullversion") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   694
                    || JLI_StrCmp(arg, "-help") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   695
                    || JLI_StrCmp(arg, "-?") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   696
                    || JLI_StrCmp(arg, "-jar") == 0
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   697
                    || JLI_StrCmp(arg, "-X") == 0) {
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   698
                return;
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   699
            }
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 28771
diff changeset
   700
        }
25816
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   701
        /*
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   702
         * The following case checks for "-XX:NativeMemoryTracking=value".
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   703
         * If value is non null, an environmental variable set to this value
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   704
         * will be created to be used by the JVM.
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   705
         * The argument is passed to the JVM, which will check validity.
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   706
         * The JVM is responsible for removing the env variable.
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   707
         */
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   708
        if (JLI_StrCCmp(arg, "-XX:NativeMemoryTracking=") == 0) {
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   709
            int retval;
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   710
            // get what follows this parameter, include "="
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   711
            size_t pnlen = JLI_StrLen("-XX:NativeMemoryTracking=");
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   712
            if (JLI_StrLen(arg) > pnlen) {
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   713
                char* value = arg + pnlen;
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   714
                size_t pbuflen = pnlen + JLI_StrLen(value) + 10; // 10 max pid digits
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   715
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   716
                /*
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   717
                 * ensures that malloc successful
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   718
                 * DONT JLI_MemFree() pbuf.  JLI_PutEnv() uses system call
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   719
                 *   that could store the address.
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   720
                 */
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   721
                char * pbuf = (char*)JLI_MemAlloc(pbuflen);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   722
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   723
                JLI_Snprintf(pbuf, pbuflen, "%s%d=%s", NMT_Env_Name, JLI_GetPid(), value);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   724
                retval = JLI_PutEnv(pbuf);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   725
                if (JLI_IsTraceLauncher()) {
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   726
                    char* envName;
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   727
                    char* envBuf;
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   728
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   729
                    // ensures that malloc successful
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   730
                    envName = (char*)JLI_MemAlloc(pbuflen);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   731
                    JLI_Snprintf(envName, pbuflen, "%s%d", NMT_Env_Name, JLI_GetPid());
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   732
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   733
                    printf("TRACER_MARKER: NativeMemoryTracking: env var is %s\n",envName);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   734
                    printf("TRACER_MARKER: NativeMemoryTracking: putenv arg %s\n",pbuf);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   735
                    envBuf = getenv(envName);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   736
                    printf("TRACER_MARKER: NativeMemoryTracking: got value %s\n",envBuf);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   737
                    free(envName);
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   738
                }
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   739
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   740
            }
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   741
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   742
        }
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   743
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   744
    }
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   745
}
2c05592cf0f2 8042469: Launcher changes for native memory tracking scalability enhancement
ksrini
parents: 25552
diff changeset
   746
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
/* copied from HotSpot function "atomll()" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
static int
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   749
parse_size(const char *s, jlong *result) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
  jlong n = 0;
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 29373
diff changeset
   751
  int args_read = sscanf(s, JLONG_FORMAT_SPECIFIER, &n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
  if (args_read != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
  while (*s != '\0' && *s >= '0' && *s <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    s++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
  // 4705540: illegal if more characters are found after the first non-digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
  if (JLI_StrLen(s) > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
  switch (*s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    case 'T': case 't':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      *result = n * GB * KB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    case 'G': case 'g':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      *result = n * GB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    case 'M': case 'm':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
      *result = n * MB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    case 'K': case 'k':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
      *result = n * KB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    case '\0':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      *result = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
      /* Create JVM with default stack and let VM handle malformed -Xss string*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
      return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
/*
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27938
diff changeset
   785
 * Adds a new VM option with the given name and value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
AddOption(char *str, void *info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * Expand options array if needed to accommodate at least one more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * VM option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    if (numOptions >= maxOptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (options == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            maxOptions = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            JavaVMOption *tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            maxOptions *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            JLI_MemFree(options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            options = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    options[numOptions].optionString = str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    options[numOptions++].extraInfo = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    if (JLI_StrCCmp(str, "-Xss") == 0) {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   811
        jlong tmp;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   812
        if (parse_size(str + 4, &tmp)) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   813
            threadStackSize = tmp;
28102
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   814
            /*
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   815
             * Make sure the thread stack size is big enough that we won't get a stack
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   816
             * overflow before the JVM startup code can check to make sure the stack
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   817
             * is big enough.
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   818
             */
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 29373
diff changeset
   819
            if (threadStackSize < (jlong)STACK_SIZE_MINIMUM) {
28102
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   820
                threadStackSize = STACK_SIZE_MINIMUM;
0efebd8c99e2 6762191: Setting stack size to 16K causes segmentation fault
cjplummer
parents: 25859
diff changeset
   821
            }
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   822
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   823
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   824
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   825
    if (JLI_StrCCmp(str, "-Xmx") == 0) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   826
        jlong tmp;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   827
        if (parse_size(str + 4, &tmp)) {
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   828
            maxHeapSize = tmp;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   829
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   830
    }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   831
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   832
    if (JLI_StrCCmp(str, "-Xms") == 0) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   833
        jlong tmp;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   834
        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
   835
           initialHeapSize = tmp;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
   836
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
SetClassPath(const char *s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    char *def;
3054
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   844
    const char *orig = s;
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   845
    static const char format[] = "-Djava.class.path=%s";
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   846
    /*
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   847
     * usually we should not get a null pointer, but there are cases where
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   848
     * we might just get one, in which case we simply ignore it, and let the
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   849
     * caller deal with it
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   850
     */
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   851
    if (s == NULL)
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12047
diff changeset
   852
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    s = JLI_WildcardExpandClasspath(s);
24504
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
   854
    if (sizeof(format) - 2 + JLI_StrLen(s) < JLI_StrLen(s))
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
   855
        // s is became corrupted after expanding wildcards
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
   856
        return;
3054
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   857
    def = JLI_MemAlloc(sizeof(format)
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   858
                       - 2 /* strlen("%s") */
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   859
                       + JLI_StrLen(s));
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   860
    sprintf(def, format, s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    AddOption(def, NULL);
3054
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   862
    if (s != orig)
ddb6acba8b6f 6851653: (launcher) Make every java process 20 bytes smaller
martin
parents: 2624
diff changeset
   863
        JLI_MemFree((char *) s);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   864
    _have_classpath = JNI_TRUE;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   865
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   866
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   867
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   868
SetModulePath(const char *s)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   869
{
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   870
    char *def;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   871
    const char *orig = s;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   872
    static const char format[] = "-Djdk.module.path=%s";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   873
    if (s == NULL)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   874
        return;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   875
    s = JLI_WildcardExpandClasspath(s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   876
    def = JLI_MemAlloc(sizeof(format)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   877
                       - 2 /* strlen("%s") */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   878
                       + JLI_StrLen(s));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   879
    sprintf(def, format, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   880
    AddOption(def, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   881
    if (s != orig)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   882
        JLI_MemFree((char *) s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   883
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   884
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   885
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   886
SetUpgradeModulePath(const char *s)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   887
{
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   888
    char *def;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   889
    const char *orig = s;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   890
    static const char format[] = "-Djdk.upgrade.module.path=%s";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   891
    if (s == NULL)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   892
        return;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   893
    s = JLI_WildcardExpandClasspath(s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   894
    def = JLI_MemAlloc(sizeof(format)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   895
                       - 2 /* strlen("%s") */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   896
                       + JLI_StrLen(s));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   897
    sprintf(def, format, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   898
    AddOption(def, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   899
    if (s != orig)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   900
        JLI_MemFree((char *) s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   901
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   902
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   903
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   904
SetMainModule(const char *s)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   905
{
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   906
    static const char format[] = "-Djdk.module.main=%s";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   907
    char* slash = JLI_StrChr(s, '/');
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   908
    size_t s_len, def_len;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   909
    char *def;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   910
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   911
    /* value may be <module> or <module>/<mainclass> */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   912
    if (slash == NULL) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   913
        s_len = JLI_StrLen(s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   914
    } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   915
        s_len = (size_t) (slash - s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   916
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   917
    def_len = sizeof(format)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   918
               - 2 /* strlen("%s") */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   919
               + s_len;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   920
    def = JLI_MemAlloc(def_len);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   921
    JLI_Snprintf(def, def_len, format, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   922
    AddOption(def, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   923
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   924
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   925
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   926
SetAddModulesProp(const char *mods) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   927
    size_t buflen = JLI_StrLen(mods) + 40;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   928
    char *prop = (char *)JLI_MemAlloc(buflen);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   929
    JLI_Snprintf(prop, buflen, "-Djdk.launcher.addmods=%s", mods);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   930
    AddOption(prop, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   931
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   932
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   933
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   934
SetLimitModulesProp(const char *mods) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   935
    size_t buflen = JLI_StrLen(mods) + 40;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   936
    char *prop = (char *)JLI_MemAlloc(buflen);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   937
    JLI_Snprintf(prop, buflen, "-Djdk.launcher.limitmods=%s", mods);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   938
    AddOption(prop, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   939
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   940
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   941
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   942
SetAddReadsProp(const jint n, const char *s) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   943
    size_t buflen = JLI_StrLen(s) + 40;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   944
    char *prop = (char *)JLI_MemAlloc(buflen);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   945
    JLI_Snprintf(prop, buflen, "-Djdk.launcher.addreads.%d=%s", n, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   946
    AddOption(prop, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   947
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   948
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   949
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   950
SetAddExportsProp(const jint n, const char *s) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   951
    size_t buflen = JLI_StrLen(s) + 40;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   952
    char *prop = (char *)JLI_MemAlloc(buflen);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   953
    JLI_Snprintf(prop, buflen, "-Djdk.launcher.addexports.%d=%s", n, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   954
    AddOption(prop, NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   955
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   956
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   957
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   958
SetPatchProp(const jint n, const char *s) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   959
    size_t buflen = JLI_StrLen(s) + 40;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   960
    char *prop = (char *)JLI_MemAlloc(buflen);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   961
    JLI_Snprintf(prop, buflen, "-Djdk.launcher.patch.%d=%s", n, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   962
    AddOption(prop, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
 * The SelectVersion() routine ensures that an appropriate version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
 * the JRE is running.  The specification for the appropriate version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
 * is obtained from either the manifest of a jar file (preferred) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
 * from command line options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
 * The routine also parses splash screen command line options and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
 * passes on their values in private environment variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
SelectVersion(int argc, char **argv, char **main_class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    char    *arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    char    *operand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    char    *version = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    char    *jre = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    int     jarflag = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    int     headlessflag = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    int     restrict_search = -1;               /* -1 implies not known */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    manifest_info info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    char    env_entry[MAXNAMELEN + 24] = ENV_ENTRY "=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    char    *splash_file_name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    char    *splash_jar_name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    char    *env_in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    int     res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * If the version has already been selected, set *main_class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * with the value passed through the environment (if any) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * simply return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   995
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   996
    /*
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   997
     * This environmental variable can be set by mJRE capable JREs
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   998
     * [ 1.5 thru 1.8 ].  All other aspects of mJRE processing have been
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
   999
     * stripped by those JREs.  This environmental variable allows 1.9+
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1000
     * JREs to be started by these mJRE capable JREs.
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1001
     * Note that mJRE directives in the jar manifest file would have been
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1002
     * ignored for a JRE started by another JRE...
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1003
     * .. skipped for JRE 1.5 and beyond.
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1004
     * .. not even checked for pre 1.5.
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1005
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    if ((env_in = getenv(ENV_ENTRY)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (*env_in != '\0')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            *main_class = JLI_StringDup(env_in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * Scan through the arguments for options relevant to multiple JRE
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1014
     * support.  Multiple JRE support existed in JRE versions 1.5 thru 1.8.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1016
     * This capability is no longer available with JRE versions 1.9 and later.
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1017
     * These command line options are reported as errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    argc--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    argv++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    while ((arg = *argv) != 0 && *arg == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        if (JLI_StrCCmp(arg, "-version:") == 0) {
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1023
            JLI_ReportErrorMessage(SPC_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        } else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) {
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1025
            JLI_ReportErrorMessage(SPC_ERROR2);
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1026
        } else if (JLI_StrCmp(arg, "-jre-no-restrict-search") == 0) {
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1027
            JLI_ReportErrorMessage(SPC_ERROR2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            if (JLI_StrCmp(arg, "-jar") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                jarflag = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            /* deal with "unfortunate" classpath syntax */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            if ((JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
              (argc >= 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                argc--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                argv++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                arg = *argv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
             * Checking for headless toolkit option in the some way as AWT does:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
             * "true" means true and any other value means false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (JLI_StrCmp(arg, "-Djava.awt.headless=true") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                headlessflag = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            } else if (JLI_StrCCmp(arg, "-Djava.awt.headless=") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                headlessflag = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                splash_file_name = arg+8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        argc--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        argv++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    if (argc <= 0) {    /* No operand? Possibly legit with -[full]version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        operand = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        argc--;
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1058
        operand = *argv++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * If there is a jar file, read the manifest. If the jarfile can't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * read, the manifest can't be read from the jar file, or the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * is corrupt, issue the appropriate error messages and exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * Even if there isn't a jar file, construct a manifest_info structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * containing the command line information.  It's a convenient way to carry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * this data around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    if (jarflag && operand) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        if ((res = JLI_ParseManifest(operand, &info)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            if (res == -1)
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1073
                JLI_ReportErrorMessage(JAR_ERROR2, operand);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            else
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1075
                JLI_ReportErrorMessage(JAR_ERROR3, operand);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
         * Command line splash screen option should have precedence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         * over the manifest, so the manifest data is used only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         * splash_file_name has not been initialized above during command
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
         * line parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            splash_file_name = info.splashscreen_image_file_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            splash_jar_name = operand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        info.manifest_version = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        info.main_class = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        info.jre_version = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        info.jre_restrict_search = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * Passing on splash screen info in environment variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    if (splash_file_name && !headlessflag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        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
  1101
        JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        JLI_StrCat(splash_file_entry, splash_file_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        putenv(splash_file_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    if (splash_jar_name && !headlessflag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        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
  1107
        JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        JLI_StrCat(splash_jar_entry, splash_jar_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        putenv(splash_jar_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * "Valid" returns (other than unrecoverable errors) follow.  Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * main_class as a side-effect of this routine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    if (info.main_class != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        *main_class = JLI_StringDup(info.main_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    if (info.jre_version == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        JLI_FreeManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
 * Parses command line arguments.  Returns JNI_FALSE if launcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
 * 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
  1130
 * to be started to process given options.  *pret (the launcher
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
 * process return value) is set to 0 for a normal exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
static jboolean
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1134
ParseArguments(int *pargc, char ***pargv,
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1135
               int *pmode, char **pwhat,
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1136
               int *pret, const char *jrepath)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    int argc = *pargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    char **argv = *pargv;
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1140
    int mode = LM_UNKNOWN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    char *arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    *pret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    while ((arg = *argv) != 0 && *arg == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        argv++; --argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            ARG_CHECK (argc, ARG_ERROR1, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            SetClassPath(*argv);
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1150
            mode = LM_CLASS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            argv++; --argc;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1152
        } else if (JLI_StrCmp(arg, "-modulepath") == 0 || JLI_StrCmp(arg, "-mp") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1153
            ARG_CHECK (argc, ARG_ERROR4, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1154
            SetModulePath(*argv);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1155
            argv++; --argc;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1156
        } else if (JLI_StrCmp(arg, "-upgrademodulepath") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1157
            ARG_CHECK (argc, ARG_ERROR4, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1158
            SetUpgradeModulePath(*argv);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1159
            argv++; --argc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        } else if (JLI_StrCmp(arg, "-jar") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            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
  1162
            mode = LM_JAR;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1163
        } else if (JLI_StrCmp(arg, "-m") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1164
            ARG_CHECK (argc, ARG_ERROR5, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1165
            SetMainModule(*argv);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1166
            mode = LM_MODULE;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1167
        } else if (JLI_StrCmp(arg, "-addmods") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1168
            ARG_CHECK (argc, ARG_ERROR6, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1169
            SetAddModulesProp(*argv);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1170
            argv++; --argc;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1171
        } else if (JLI_StrCmp(arg, "-limitmods") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1172
            ARG_CHECK (argc, ARG_ERROR6, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1173
            SetLimitModulesProp(*argv);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1174
            argv++; --argc;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1175
        } else if (JLI_StrCmp(arg, "-listmods") == 0 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1176
                   JLI_StrCCmp(arg, "-listmods:") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1177
            listModules = arg;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1178
            return JNI_TRUE;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1179
        } else if (JLI_StrCCmp(arg, "-XaddReads:") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1180
            static jint n;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1181
            char *value = arg + 11;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1182
            SetAddReadsProp(n++, value);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1183
        } else if (JLI_StrCCmp(arg, "-XaddExports:") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1184
            static jint n;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1185
            char *value = arg + 13;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1186
            SetAddExportsProp(n++, value);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1187
        } else if (JLI_StrCCmp(arg, "-Xpatch:") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1188
            static jint n;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1189
            char *value = arg + 8;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1190
            SetPatchProp(n++, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        } else if (JLI_StrCmp(arg, "-help") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                   JLI_StrCmp(arg, "-h") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                   JLI_StrCmp(arg, "-?") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            printUsage = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        } else if (JLI_StrCmp(arg, "-version") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            printVersion = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        } else if (JLI_StrCmp(arg, "-showversion") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            showVersion = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        } else if (JLI_StrCmp(arg, "-X") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            printXUsage = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
/*
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1205
 * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1206
 * 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
  1207
 */
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1208
        } else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1209
                   JLI_StrCCmp(arg, "-XshowSettings:") == 0) {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1210
            showSettings = arg;
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
  1211
        } else if (JLI_StrCmp(arg, "-Xdiag") == 0) {
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
  1212
            AddOption("-Dsun.java.launcher.diag=true", NULL);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1213
            AddOption("-Djdk.launcher.traceResolver=true", NULL);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1214
        } else if (JLI_StrCmp(arg, "-Xdiag:resolver") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1215
            AddOption("-Djdk.launcher.traceResolver=true", NULL);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1216
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
 * The following case provide backward compatibility with old-style
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
 * command line options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        } else if (JLI_StrCmp(arg, "-fullversion") == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1221
            JLI_ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        } else if (JLI_StrCmp(arg, "-verbosegc") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            AddOption("-verbose:gc", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        } else if (JLI_StrCmp(arg, "-t") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            AddOption("-Xt", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        } else if (JLI_StrCmp(arg, "-tm") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            AddOption("-Xtm", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        } else if (JLI_StrCmp(arg, "-debug") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            AddOption("-Xdebug", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        } else if (JLI_StrCmp(arg, "-noclassgc") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            AddOption("-Xnoclassgc", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        } else if (JLI_StrCmp(arg, "-Xfuture") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            AddOption("-Xverify:all", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        } else if (JLI_StrCmp(arg, "-verify") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            AddOption("-Xverify:all", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        } else if (JLI_StrCmp(arg, "-verifyremote") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            AddOption("-Xverify:remote", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        } else if (JLI_StrCmp(arg, "-noverify") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            AddOption("-Xverify:none", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        } else if (JLI_StrCCmp(arg, "-ss") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                   JLI_StrCCmp(arg, "-oss") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                   JLI_StrCCmp(arg, "-ms") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                   JLI_StrCCmp(arg, "-mx") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            sprintf(tmp, "-X%s", arg + 1); /* skip '-' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            AddOption(tmp, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        } else if (JLI_StrCmp(arg, "-checksource") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                   JLI_StrCmp(arg, "-cs") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                   JLI_StrCmp(arg, "-noasyncgc") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            /* No longer supported */
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1252
            JLI_ReportErrorMessage(ARG_WARN, arg);
27938
7f7f8bf64dd7 8058407: Remove Multiple JRE support in the Java launcher
ksrini
parents: 25859
diff changeset
  1253
        } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            ; /* Ignore machine independent options already handled */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  1255
        } else if (ProcessPlatformOption(arg)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  1256
            ; /* Processing of platform dependent options */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  1257
        } else if (RemovableOption(arg)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            ; /* Do not pass option to vm. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        } else {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1260
            /* java.class.path set on the command line */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1261
            if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1262
                _have_classpath = JNI_TRUE;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1263
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            AddOption(arg, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    if (--argc >= 0) {
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1269
        *pwhat = *argv++;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1270
    }
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1271
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1272
    if (*pwhat == NULL) {
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1273
        *pret = 1;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1274
    } else if (mode == LM_UNKNOWN) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1275
        /* default to LM_CLASS if -m, -jar and -cp options are
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1276
         * not specified */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1277
        if (!_have_classpath) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1278
            SetClassPath(".");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1279
        }
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1280
        mode = LM_CLASS;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1281
    }
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1282
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1283
    if (argc >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        *pargc = argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        *pargv = argv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    }
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1287
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1288
    *pmode = mode;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
 * Initializes the Java Virtual Machine. Also frees options array when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
 * finished.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    JavaVMInitArgs args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    jint r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    memset(&args, 0, sizeof(args));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    args.version  = JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    args.nOptions = numOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    args.options  = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    args.ignoreUnrecognized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        printf("JavaVM args:\n    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        printf("version 0x%08lx, ", (long)args.version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        printf("ignoreUnrecognized is %s, ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
               args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        printf("nOptions is %ld\n", (long)args.nOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        for (i = 0; i < numOptions; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            printf("    option[%2d] = '%s'\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                   i, args.options[i].optionString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    r = ifn->CreateJavaVM(pvm, (void **)penv, &args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    JLI_MemFree(options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    return r == JNI_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1326
static jclass helperClass = NULL;
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1327
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
  1328
jclass
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
  1329
GetLauncherHelperClass(JNIEnv *env)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
  1330
{
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1331
    if (helperClass == NULL) {
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1332
        NULL_CHECK0(helperClass = FindBootStrapClass(env,
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1333
                "sun/launcher/LauncherHelper"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    }
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1335
    return helperClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1338
static jmethodID makePlatformStringMID = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
 * Returns a new Java string object for the specified platform string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
static jstring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
NewPlatformString(JNIEnv *env, char *s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    int len = (int)JLI_StrLen(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    jbyteArray ary;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1347
    jclass cls = GetLauncherHelperClass(env);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1348
    NULL_CHECK0(cls);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    if (s == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    ary = (*env)->NewByteArray(env, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    if (ary != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        jstring str = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        if (!(*env)->ExceptionOccurred(env)) {
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1357
            if (makePlatformStringMID == NULL) {
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1358
                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
  1359
                        cls, "makePlatformString", "(Z[B)Ljava/lang/String;"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            }
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1361
            str = (*env)->CallStaticObjectMethod(env, cls,
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1362
                    makePlatformStringMID, USE_STDERR, ary);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            (*env)->DeleteLocalRef(env, ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
 * Returns a new array of Java string objects for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
 * array of platform strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
 */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
  1374
jobjectArray
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
NewPlatformStringArray(JNIEnv *env, char **strv, int strc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    jarray cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    jarray ary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1381
    NULL_CHECK0(cls = FindBootStrapClass(env, "java/lang/String"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    for (i = 0; i < strc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        jstring str = NewPlatformString(env, *strv++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        NULL_CHECK0(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        (*env)->SetObjectArrayElement(env, ary, i, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        (*env)->DeleteLocalRef(env, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    return ary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
/*
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1393
 * 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
  1394
 * call it for more details refer to the java implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
static jclass
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1397
LoadMainClass(JNIEnv *env, int mode, char *name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
{
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1399
    jmethodID mid;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1400
    jstring str;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1401
    jobject result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    jlong start, end;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1403
    jclass cls = GetLauncherHelperClass(env);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1404
    NULL_CHECK0(cls);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1405
    if (JLI_IsTraceLauncher()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        start = CounterGet();
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1407
    }
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1408
    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
  1409
                "checkAndLoadMain",
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1410
                "(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
  1411
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1412
    NULL_CHECK0(str = NewPlatformString(env, name));
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1413
    NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid,
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1414
                                                        USE_STDERR, mode, str));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        end   = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        printf("%ld micro seconds to load main class\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
               (long)(jint)Counter2Micros(end-start));
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12550
diff changeset
  1420
        printf("----%s----\n", JLDEBUG_ENV_ENTRY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1423
    return (jclass)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1426
static jclass
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1427
GetApplicationClass(JNIEnv *env)
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1428
{
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1429
    jmethodID mid;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1430
    jclass cls = GetLauncherHelperClass(env);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1431
    NULL_CHECK0(cls);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1432
    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1433
                "getApplicationClass",
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1434
                "()Ljava/lang/Class;"));
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1435
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1436
    return (*env)->CallStaticObjectMethod(env, cls, mid);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1437
}
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
  1438
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
 * For tools, convert command line args thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
 *   javac -cp foo:foo/"*" -J-ms32m ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
 *   java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
 * Takes 4 parameters, and returns the populated arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    int argc = *pargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    char **argv = *pargv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    int nargc = argc + jargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    *pargc = nargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    *pargv = nargv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /* Copy the VM arguments (i.e. prefixed with -J) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    for (i = 0; i < jargc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        const char *arg = jargv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        if (arg[0] == '-' && arg[1] == 'J') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            *nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    for (i = 0; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        char *arg = argv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        if (arg[0] == '-' && arg[1] == 'J') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            if (arg[2] == '\0') {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1470
                JLI_ReportErrorMessage(ARG_ERROR3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            *nargv++ = arg + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    /* Copy the rest of the arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    for (i = 0; i < jargc ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        const char *arg = jargv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        if (arg[0] != '-' || arg[1] != 'J') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            *nargv++ = (arg == NULL) ? NULL : JLI_StringDup(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    for (i = 0; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        char *arg = argv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        if (arg[0] == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            if (arg[1] == 'J')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            if (IsWildCardEnabled() && arg[1] == 'c'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                && (JLI_StrCmp(arg, "-cp") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                    JLI_StrCmp(arg, "-classpath") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                && i < argc - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                *nargv++ = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        *nargv++ = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    *nargv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
 * For our tools, we try to add 3 VM options:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
 *      -Denv.class.path=<envcp>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
 *      -Dapplication.home=<apphome>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
 *      -Djava.class.path=<appcp>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
 * <envcp>   is the user's setting of CLASSPATH -- for instance the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
 *           tells javac where to find binary classes through this environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
 *           variable.  Notice that users will be able to compile against our
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
 *           tools classes (sun.tools.javac.Main) only if they explicitly add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
 *           tools.jar to CLASSPATH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
 * <apphome> is the directory where the application is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
 * <appcp>   is the classpath to where our apps' classfiles are.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
AddApplicationOptions(int cpathc, const char **cpathv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    char *envcp, *appcp, *apphome;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    char home[MAXPATHLEN]; /* application home */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    char separator[] = { PATH_SEPARATOR, '\0' };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    int size, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        const char *s = getenv("CLASSPATH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        if (s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            s = (char *) JLI_WildcardExpandClasspath(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            /* 40 for -Denv.class.path= */
24504
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
  1530
            if (JLI_StrLen(s) + 40 > JLI_StrLen(s)) { // Safeguard from overflow
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
  1531
                envcp = (char *)JLI_MemAlloc(JLI_StrLen(s) + 40);
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
  1532
                sprintf(envcp, "-Denv.class.path=%s", s);
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
  1533
                AddOption(envcp, NULL);
25a78d39aaa9 8037398: integer overflow in jdk/src/share/bin/java.c
kizune
parents: 22962
diff changeset
  1534
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    if (!GetApplicationHome(home, sizeof(home))) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1539
        JLI_ReportErrorMessage(CFG_ERROR5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    /* 40 for '-Dapplication.home=' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    apphome = (char *)JLI_MemAlloc(JLI_StrLen(home) + 40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    sprintf(apphome, "-Dapplication.home=%s", home);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    AddOption(apphome, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    /* How big is the application's classpath? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    size = 40;                                 /* 40: "-Djava.class.path=" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    for (i = 0; i < cpathc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    appcp = (char *)JLI_MemAlloc(size + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    JLI_StrCpy(appcp, "-Djava.class.path=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    for (i = 0; i < cpathc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        JLI_StrCat(appcp, home);                        /* c:\program files\myapp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        JLI_StrCat(appcp, cpathv[i]);           /* \lib\myapp.jar         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        JLI_StrCat(appcp, separator);           /* ;                      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    appcp[JLI_StrLen(appcp)-1] = '\0';  /* remove trailing path separator */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    AddOption(appcp, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
 * inject the -Dsun.java.command pseudo property into the args structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
 * this pseudo property is used in the HotSpot VM to expose the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
 * Java class name and arguments to the main method to the VM. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
 * HotSpot VM uses this pseudo property to store the Java class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
 * (or jar file name) and the arguments to the class's main method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
 * to the instrumentation memory region. The sun.java.command pseudo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
 * property is not exported by HotSpot to the Java layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
void
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1575
SetJavaCommandLineProp(char *what, int argc, char **argv)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    size_t len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    char* javaCommand = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    char* dashDstr = "-Dsun.java.command=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1583
    if (what == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        /* unexpected, one of these should be set. just return without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
         * setting the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    /* determine the amount of memory to allocate assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * the individual components will be space separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     */
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1593
    len = JLI_StrLen(what);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    for (i = 0; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        len += JLI_StrLen(argv[i]) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    /* allocate the memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    javaCommand = (char*) JLI_MemAlloc(len + JLI_StrLen(dashDstr) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    /* build the -D string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    *javaCommand = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    JLI_StrCat(javaCommand, dashDstr);
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1604
    JLI_StrCat(javaCommand, what);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    for (i = 0; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        /* the components of the string are space separated. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
         * the case of embedded white space, the relationship of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
         * the white space separated components to their true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         * positional arguments will be ambiguous. This issue may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
         * be addressed in a future release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        JLI_StrCat(javaCommand, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        JLI_StrCat(javaCommand, argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    AddOption(javaCommand, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
 * JVM would like to know if it's created by a standard Sun launcher, or by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
 * user native application, the following property indicates the former.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
 */
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1624
void
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  1625
SetJavaLauncherProp() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
  AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
 * Prints the version information from the java.version and other properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
PrintJavaVersion(JNIEnv *env, jboolean extraLF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    jclass ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    jmethodID print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
36225
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34000
diff changeset
  1638
    NULL_CHECK(ver = FindBootStrapClass(env, "java/lang/VersionProps"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    NULL_CHECK(print = (*env)->GetStaticMethodID(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                                                 ver,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                                                 (extraLF == JNI_TRUE) ? "println" : "print",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                                                 "()V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                                                 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
              );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    (*env)->CallStaticVoidMethod(env, ver, print);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
/*
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1650
 * 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
  1651
 */
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1652
static void
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1653
ShowSettings(JNIEnv *env, char *optString)
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1654
{
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1655
    jmethodID showSettingsID;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1656
    jstring joptString;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1657
    jclass cls = GetLauncherHelperClass(env);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1658
    NULL_CHECK(cls);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1659
    NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
  1660
            "showSettings", "(ZLjava/lang/String;JJJZ)V"));
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1661
    NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString));
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1662
    (*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
  1663
                                 USE_STDERR,
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1664
                                 joptString,
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
  1665
                                 (jlong)initialHeapSize,
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
  1666
                                 (jlong)maxHeapSize,
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1667
                                 (jlong)threadStackSize,
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1668
                                 ServerClassMachine());
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1669
}
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1670
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1671
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1672
 * List modules supported by the runtime
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1673
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1674
static void
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1675
ListModules(JNIEnv *env, char *optString)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1676
{
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1677
    jmethodID listModulesID;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1678
    jstring joptString;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1679
    jclass cls = GetLauncherHelperClass(env);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1680
    NULL_CHECK(cls);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1681
    NULL_CHECK(listModulesID = (*env)->GetStaticMethodID(env, cls,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1682
            "listModules", "(ZLjava/lang/String;)V"));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1683
    NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString));
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1684
    (*env)->CallStaticVoidMethod(env, cls, listModulesID,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1685
                                 USE_STDERR,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1686
                                 joptString);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1687
}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1688
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 7028
diff changeset
  1689
/*
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1690
 * Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
PrintUsage(JNIEnv* env, jboolean doXUsage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
  jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
  jstring jprogname, vm1, vm2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
  int i;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1698
  jclass cls = GetLauncherHelperClass(env);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1699
  NULL_CHECK(cls);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
  if (doXUsage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                                        "printXUsageMessage", "(Z)V"));
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
  1703
    (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, USE_STDERR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                                        "initHelpMessage", "(Ljava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    NULL_CHECK(vmSelect = (*env)->GetStaticMethodID(env, cls, "appendVmSelectMessage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                                        "(Ljava/lang/String;Ljava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    NULL_CHECK(vmSynonym = (*env)->GetStaticMethodID(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                                        "appendVmSynonymMessage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                                        "(Ljava/lang/String;Ljava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    NULL_CHECK(vmErgo = (*env)->GetStaticMethodID(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                                        "appendVmErgoMessage", "(ZLjava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
    NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                                        "printHelpMessage", "(Z)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1720
    NULL_CHECK(jprogname = (*env)->NewStringUTF(env, _program_name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    /* Initialize the usage message with the usual preamble */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    (*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname);
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1724
    CHECK_EXCEPTION_RETURN();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
    /* Assemble the other variant part of the usage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    if ((knownVMs[0].flag == VM_KNOWN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        (knownVMs[0].flag == VM_IF_SERVER_CLASS)) {
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1730
      NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[0].name));
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1731
      NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[0].name+1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
      (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1733
      CHECK_EXCEPTION_RETURN();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    for (i=1; i<knownVMsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
      if (knownVMs[i].flag == VM_KNOWN) {
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1737
        NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name));
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1738
        NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[i].name+1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1740
        CHECK_EXCEPTION_RETURN();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    for (i=1; i<knownVMsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
      if (knownVMs[i].flag == VM_ALIASED_TO) {
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1745
        NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, knownVMs[i].name));
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1746
        NULL_CHECK(vm2 =  (*env)->NewStringUTF(env, knownVMs[i].alias+1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        (*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2);
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1748
        CHECK_EXCEPTION_RETURN();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    /* The first known VM is the default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
      jboolean isServerClassMachine = ServerClassMachine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
      const char* defaultVM  =  knownVMs[0].name+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
      if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && isServerClassMachine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        defaultVM = knownVMs[0].server_class+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1761
      NULL_CHECK(vm1 =  (*env)->NewStringUTF(env, defaultVM));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
      (*env)->CallStaticVoidMethod(env, cls, vmErgo, isServerClassMachine,  vm1);
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 21606
diff changeset
  1763
      CHECK_EXCEPTION_RETURN();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
    /* 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
  1767
    (*env)->CallStaticVoidMethod(env, cls, printHelp, USE_STDERR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
 * Read the jvm.cfg file and fill the knownJVMs[] array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
 * The functionality of the jvm.cfg file is subject to change without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
 * notice and the mechanism will be removed in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
 * The lexical structure of the jvm.cfg file is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
 *     jvmcfg         :=  { vmLine }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
 *     vmLine         :=  knownLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
 *                    |   aliasLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
 *                    |   warnLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
 *                    |   ignoreLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
 *                    |   errorLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
 *                    |   predicateLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
 *                    |   commentLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
 *     knownLine      :=  flag  "KNOWN"                  EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
 *     warnLine       :=  flag  "WARN"                   EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
 *     ignoreLine     :=  flag  "IGNORE"                 EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
 *     errorLine      :=  flag  "ERROR"                  EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
 *     aliasLine      :=  flag  "ALIASED_TO"       flag  EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
 *     predicateLine  :=  flag  "IF_SERVER_CLASS"  flag  EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
 *     commentLine    :=  "#" text                       EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
 *     flag           :=  "-" identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
 * The semantics are that when someone specifies a flag on the command line:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
 * - if the flag appears on a knownLine, then the identifier is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
 *   the name of the directory holding the JVM library (the name of the JVM).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
 * - if the flag appears as the first flag on an aliasLine, the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
 *   of the second flag is used as the name of the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
 * - if the flag appears on a warnLine, the identifier is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
 *   name of the JVM, but a warning is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
 * - if the flag appears on an ignoreLine, the identifier is recognized as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
 *   name of a JVM, but the identifier is ignored and the default vm used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
 * - if the flag appears on an errorLine, an error is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
 * - if the flag appears as the first flag on a predicateLine, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
 *   the machine on which you are running passes the predicate indicated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
 *   then the identifier of the second flag is used as the name of the JVM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
 *   otherwise the identifier of the first flag is used as the name of the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
 * If no flag is given on the command line, the first vmLine of the jvm.cfg
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
 * file determines the name of the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
 * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
 * since they only make sense if someone hasn't specified the name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
 * JVM on the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
 * The intent of the jvm.cfg file is to allow several JVM libraries to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
 * be installed in different subdirectories of a single JRE installation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
 * for space-savings and convenience in testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
 * The intent is explicitly not to provide a full aliasing or predicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
 * mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
jint
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  1824
ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
    FILE *jvmCfg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    char line[MAXPATHLEN+20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
    int cnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
    int lineno = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    jlong start, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
    int vmType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    char *tmpPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    char *altVMName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    char *serverClassVMName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
    static char *whiteSpace = " \t";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        start = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    jvmCfg = fopen(jvmCfgName, "r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
    if (jvmCfg == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
      if (!speculative) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1843
        JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    while (fgets(line, sizeof(line), jvmCfg) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        vmType = VM_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        lineno++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        if (line[0] == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
        if (line[0] != '-') {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1855
            JLI_ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        if (cnt >= knownVMsLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            GrowKnownVMs(cnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        tmpPtr = line + JLI_StrCSpn(line, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        if (*tmpPtr == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1863
            JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            /* Null-terminate this string for JLI_StringDup below */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            *tmpPtr++ = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
            if (*tmpPtr == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1869
                JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                if (!JLI_StrCCmp(tmpPtr, "KNOWN")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                    vmType = VM_KNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                } else if (!JLI_StrCCmp(tmpPtr, "ALIASED_TO")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                    tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                    if (*tmpPtr != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                        tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                    if (*tmpPtr == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1879
                        JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                        /* Null terminate altVMName */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                        altVMName = tmpPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                        tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                        *tmpPtr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                        vmType = VM_ALIASED_TO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                } else if (!JLI_StrCCmp(tmpPtr, "WARN")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                    vmType = VM_WARN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                } else if (!JLI_StrCCmp(tmpPtr, "IGNORE")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    vmType = VM_IGNORE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                } else if (!JLI_StrCCmp(tmpPtr, "ERROR")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                    vmType = VM_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                } else if (!JLI_StrCCmp(tmpPtr, "IF_SERVER_CLASS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                    tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                    if (*tmpPtr != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                        tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                    if (*tmpPtr == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1899
                        JLI_ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                        /* Null terminate server class VM name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                        serverClassVMName = tmpPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                        tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                        *tmpPtr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                        vmType = VM_IF_SERVER_CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                } else {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  1908
                    JLI_ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                    vmType = VM_KNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        JLI_TraceLauncher("jvm.cfg[%d] = ->%s<-\n", cnt, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        if (vmType != VM_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            knownVMs[cnt].name = JLI_StringDup(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            knownVMs[cnt].flag = vmType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            switch (vmType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            case VM_ALIASED_TO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                knownVMs[cnt].alias = JLI_StringDup(altVMName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                JLI_TraceLauncher("    name: %s  vmType: %s  alias: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                   knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            case VM_IF_SERVER_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                JLI_TraceLauncher("    name: %s  vmType: %s  server_class: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                    knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            cnt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
    fclose(jvmCfg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    knownVMsCount = cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        end   = CounterGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        printf("%ld micro seconds to parse jvm.cfg\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
               (long)(jint)Counter2Micros(end-start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
    return cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
GrowKnownVMs(int minimum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    struct vmdesc* newKnownVMs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    int newMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    if (newMax <= minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
        newMax = minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
    if (knownVMs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    JLI_MemFree(knownVMs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    knownVMs = newKnownVMs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    knownVMsLimit = newMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
/* Returns index of VM or -1 if not found */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
KnownVMIndex(const char* name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    if (JLI_StrCCmp(name, "-J") == 0) name += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    for (i = 0; i < knownVMsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        if (!JLI_StrCmp(name, knownVMs[i].name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
FreeKnownVMs()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    for (i = 0; i < knownVMsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        JLI_MemFree(knownVMs[i].name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        knownVMs[i].name = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
    JLI_MemFree(knownVMs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
 * Displays the splash screen according to the jar file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
 * and image file names stored in environment variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
 */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  1997
void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
ShowSplashScreen()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
    const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
    int data_size;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2003
    void *image_data = NULL;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2004
    float scale_factor = 1;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2005
    char *scaled_splash_name = NULL;
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2006
    jboolean isImageScaled = JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2007
    size_t maxScaledImgNameLength = 0;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2008
    if (file_name == NULL){
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2009
        return;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2010
    }
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2011
    maxScaledImgNameLength = DoSplashGetScaledImgNameMaxPstfixLen(file_name);
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2012
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2013
    scaled_splash_name = JLI_MemAlloc(
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2014
                            maxScaledImgNameLength * sizeof(char));
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2015
    isImageScaled = DoSplashGetScaledImageName(jar_name, file_name,
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2016
                            &scale_factor,
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2017
                            scaled_splash_name, maxScaledImgNameLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    if (jar_name) {
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2019
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2020
        if (isImageScaled) {
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2021
            image_data = JLI_JarUnpackFile(
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2022
                    jar_name, scaled_splash_name, &data_size);
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2023
        }
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2024
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2025
        if (!image_data) {
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2026
            scale_factor = 1;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2027
            image_data = JLI_JarUnpackFile(
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2028
                            jar_name, file_name, &data_size);
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2029
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        if (image_data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            DoSplashInit();
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2032
            DoSplashSetScaleFactor(scale_factor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            DoSplashLoadMemory(image_data, data_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            JLI_MemFree(image_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        }
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2036
    } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        DoSplashInit();
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2038
        if (isImageScaled) {
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2039
            DoSplashSetScaleFactor(scale_factor);
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2040
            DoSplashLoadFile(scaled_splash_name);
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2041
        } else {
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2042
            DoSplashLoadFile(file_name);
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2043
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
    }
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 36511
diff changeset
  2045
    JLI_MemFree(scaled_splash_name);
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24504
diff changeset
  2046
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
    DoSplashSetFileJarName(file_name, jar_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * Done with all command line processing and potential re-execs so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * clean up the environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    (void)UnsetEnv(ENV_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
    (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    JLI_MemFree(splash_jar_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
    JLI_MemFree(splash_file_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
GetFullVersion()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    return _fVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
GetProgramName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    return _program_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
GetLauncherName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    return _launcher_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
GetErgoPolicy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    return _ergo_policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
IsJavaArgs()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    return _is_java_args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
IsWildCardEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
    return _wc_enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  2098
int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  2099
ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11520
diff changeset
  2100
                    int argc, char **argv,
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  2101
                    int mode, char *what, int ret)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * If user doesn't specify stack size, check if VM has a preference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * return its default stack size through the init args structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    if (threadStackSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
      struct JDK1_1InitArgs args1_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
      memset((void*)&args1_1, 0, sizeof(args1_1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
      args1_1.version = JNI_VERSION_1_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
      ifn->GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
      if (args1_1.javaStackSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
         threadStackSize = args1_1.javaStackSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    { /* Create a new thread to create JVM and invoke main method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
      JavaMainArgs args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
      int rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
      args.argc = argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
      args.argv = argv;
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  2125
      args.mode = mode;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
  2126
      args.what = what;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
      args.ifn = *ifn;
21606
1984e107a4b3 8027755: Anti-delta incorrect push for 8025198
dholmes
parents: 21605
diff changeset
  2128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
      rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
      /* If the caller has deemed there is an error we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
       * simply return that, otherwise we return the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
       * the callee
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
      return (ret != 0) ? ret : rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
DumpState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    if (!JLI_IsTraceLauncher()) return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    printf("Launcher state:\n");
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 32222
diff changeset
  2143
    printf("\tFirst application arg index: %d\n", JLI_GetAppArgIndex());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
    printf("\tprogram name:%s\n", GetProgramName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    printf("\tlauncher name:%s\n", GetLauncherName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
    printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
    printf("\tfullversion:%s\n", GetFullVersion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
    printf("\tergo_policy:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
    switch(GetErgoPolicy()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        case NEVER_SERVER_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            printf("NEVER_ACT_AS_A_SERVER_CLASS_MACHINE\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        case ALWAYS_SERVER_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            printf("ALWAYS_ACT_AS_A_SERVER_CLASS_MACHINE\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            printf("DEFAULT_ERGONOMICS_POLICY\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
 * Return JNI_TRUE for an option string that has no effect but should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
 * _not_ be passed on to the vm; return JNI_FALSE otherwise.  On
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
 * 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
  2167
 *    -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
  2168
 *    (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
  2169
 *    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
  2170
 *    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
  2171
 *    were erroneously passed to the vm.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
RemovableOption(char * option)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
   * Unconditionally remove both -d32 and -d64 options since only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
   * the last such options has an effect; e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
   * java -d32 -d64 -d32 -version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
   * is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
   * java -d32 -version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
  if( (JLI_StrCCmp(option, "-d32")  == 0 ) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
      (JLI_StrCCmp(option, "-d64")  == 0 ) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
 * A utility procedure to always print to stderr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
void
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 399
diff changeset
  2195
JLI_ReportMessage(const char* fmt, ...)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
}