jdk/src/java.base/share/native/launcher/main.c
author ksrini
Thu, 10 Nov 2016 15:19:47 -0800
changeset 41966 bac52fa6e617
parent 41814 a0333150713e
child 43325 033e4cced1dc
permissions -rw-r--r--
8169001: Remove launcher's built-in ergonomics Reviewed-by: dholmes, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41966
bac52fa6e617 8169001: Remove launcher's built-in ergonomics
ksrini
parents: 41814
diff changeset
     2
 * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5381
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5381
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5381
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5381
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5381
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * This file contains the main entry point into the launcher code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * this is the only file which will be repeatedly compiled by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * tools. The rest of the files will be linked in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "defines.h"
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
    34
#include "jli_util.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    36
#ifdef _MSC_VER
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 1776
diff changeset
    37
#if _MSC_VER > 1400 && _MSC_VER < 1600
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    38
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    39
/*
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    40
 * When building for Microsoft Windows, main has a dependency on msvcr??.dll.
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    41
 *
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 1776
diff changeset
    42
 * When using Visual Studio 2005 or 2008, that must be recorded in
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    43
 * the [java,javaw].exe.manifest file.
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    44
 *
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 1776
diff changeset
    45
 * As of VS2010 (ver=1600), the runtimes again no longer need manifests.
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 1776
diff changeset
    46
 *
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    47
 * Reference:
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    48
 *     C:/Program Files/Microsoft SDKs/Windows/v6.1/include/crtdefs.h
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    49
 */
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    50
#include <crtassem.h>
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    51
#ifdef _M_IX86
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    52
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    53
#pragma comment(linker,"/manifestdependency:\"type='win32' "            \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    54
        "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' "              \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    55
        "version='" _CRT_ASSEMBLY_VERSION "' "                          \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    56
        "processorArchitecture='x86' "                                  \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    57
        "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    58
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    59
#endif /* _M_IX86 */
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    60
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    61
//This may not be necessary yet for the Windows 64-bit build, but it
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    62
//will be when that build environment is updated.  Need to test to see
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    63
//if it is harmless:
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    64
#ifdef _M_AMD64
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    65
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    66
#pragma comment(linker,"/manifestdependency:\"type='win32' "            \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    67
        "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' "              \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    68
        "version='" _CRT_ASSEMBLY_VERSION "' "                          \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    69
        "processorArchitecture='amd64' "                                \
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    70
        "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    71
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    72
#endif  /* _M_AMD64 */
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 1776
diff changeset
    73
#endif  /* _MSC_VER > 1400 && _MSC_VER < 1600 */
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 715
diff changeset
    74
#endif  /* _MSC_VER */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#ifdef JAVAW
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
char **__initenv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
int WINAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
41814
a0333150713e 8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents: 36511
diff changeset
    86
    int margc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    char** margv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    const jboolean const_javaw = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    __initenv = _environ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
#else /* JAVAW */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
int
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
    94
main(int argc, char **argv)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
{
41814
a0333150713e 8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents: 36511
diff changeset
    96
    int margc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    char** margv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    const jboolean const_javaw = JNI_FALSE;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
    99
#endif /* JAVAW */
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   100
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   101
    JLI_InitArgProcessing(!HAS_JAVA_ARGS, const_disable_argfile);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   102
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   103
#ifdef _WIN32
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   104
    {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   105
        int i = 0;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   106
        if (getenv(JLDEBUG_ENV_ENTRY) != NULL) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   107
            printf("Windows original main args:\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   108
            for (i = 0 ; i < __argc ; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   109
                printf("wwwd_args[%d] = %s\n", i, __argv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   110
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   111
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   112
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   113
    JLI_CmdToArgs(GetCommandLine());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   114
    margc = JLI_GetStdArgc();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   115
    // add one more to mark the end
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   116
    margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *)));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   117
    {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   118
        int i = 0;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   119
        StdArg *stdargs = JLI_GetStdArgs();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   120
        for (i = 0 ; i < margc ; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   121
            margv[i] = stdargs[i].arg;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   122
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   123
        margv[i] = NULL;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   124
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   125
#else /* *NIXES */
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   126
    {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   127
        // accommodate the NULL at the end
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   128
        JLI_List args = JLI_List_new(argc + 1);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   129
        int i = 0;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   130
        for (i = 0; i < argc; i++) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   131
            JLI_List argsInFile = JLI_PreprocessArg(argv[i]);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   132
            if (NULL == argsInFile) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   133
                JLI_List_add(args, JLI_StringDup(argv[i]));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   134
            } else {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   135
                int cnt, idx;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   136
                cnt = argsInFile->size;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   137
                for (idx = 0; idx < cnt; idx++) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   138
                    JLI_List_add(args, argsInFile->elements[idx]);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   139
                }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   140
                // Shallow free, we reuse the string to avoid copy
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   141
                JLI_MemFree(argsInFile->elements);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   142
                JLI_MemFree(argsInFile);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   143
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   144
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   145
        margc = args->size;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   146
        // add the NULL pointer at argv[argc]
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   147
        JLI_List_add(args, NULL);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   148
        margv = args->elements;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents: 30822
diff changeset
   149
    }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   150
#endif /* WIN32 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return JLI_Launch(margc, margv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                   sizeof(const_jargs) / sizeof(char *), const_jargs,
41814
a0333150713e 8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents: 36511
diff changeset
   153
                   0, NULL,
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 30822
diff changeset
   154
                   VERSION_STRING,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                   DOT_VERSION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                   (const_progname != NULL) ? const_progname : *margv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                   (const_launcher != NULL) ? const_launcher : *margv,
30822
e26f66cc0f05 8080991: Compilation error with recent clang in java.base/share/native/launcher/main.c: error: comparison of array 'const_jargs' not equal to a null pointer is always true
ksrini
parents: 25859
diff changeset
   158
                   HAS_JAVA_ARGS,
41966
bac52fa6e617 8169001: Remove launcher's built-in ergonomics
ksrini
parents: 41814
diff changeset
   159
                   const_cpwildcard, const_javaw, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}