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