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