src/java.base/windows/native/libjli/java_md.c
author mbaesken
Mon, 28 Jan 2019 16:42:23 +0100
changeset 53656 645ba889ee5f
parent 49440 396ea30afbd5
child 53941 f9302cf718c9
permissions -rw-r--r--
8217093: Support extended-length paths in parse_manifest.c on windows Reviewed-by: chegar, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53656
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
     2
 * Copyright (c) 1997, 2019, 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
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <io.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <process.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sys/stat.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <wtypes.h>
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
    36
#include <commctrl.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "java.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define JVM_DLL "jvm.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define JAVA_DLL "java.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
53656
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
    44
#define ELP_PREFIX L"\\\\?\\"
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Prototypes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                           char *jvmpath, jint jvmpathsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static jboolean GetJREPath(char *path, jint pathsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
41558
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
    53
#ifdef USE_REGISTRY_LOOKUP
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
    54
jboolean GetPublicJREHome(char *buf, jint bufsize);
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
    55
#endif
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
    56
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    57
/* We supports warmup for UI stack that is performed in parallel
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    58
 * to VM initialization.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    59
 * This helps to improve startup of UI application as warmup phase
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    60
 * might be long due to initialization of OS or hardware resources.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    61
 * It is not CPU bound and therefore it does not interfere with VM init.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    62
 * Obviously such warmup only has sense for UI apps and therefore it needs
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    63
 * to be explicitly requested by passing -Dsun.awt.warmup=true property
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    64
 * (this is always the case for plugin/javaws).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    65
 *
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    66
 * Implementation launches new thread after VM starts and use it to perform
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    67
 * warmup code (platform dependent).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    68
 * This thread is later reused as AWT toolkit thread as graphics toolkit
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    69
 * often assume that they are used from the same thread they were launched on.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    70
 *
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    71
 * At the moment we only support warmup for D3D. It only possible on windows
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    72
 * and only if other flags do not prohibit this (e.g. OpenGL support requested).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    73
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    74
#undef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    75
#ifndef JAVA_ARGS /* turn off AWT preloading for javac, jar, etc */
7256
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    76
    /* CR6999872: fastdebug crashes if awt library is loaded before JVM is
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    77
     * initialized*/
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    78
    #if !defined(DEBUG)
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    79
        #define ENABLE_AWT_PRELOAD
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    80
    #endif
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    81
#endif
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    82
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    83
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    84
/* "AWT was preloaded" flag;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    85
 * turned on by AWTPreload().
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    86
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    87
int awtPreloaded = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    88
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    89
/* Calls a function with the name specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    90
 * the function must be int(*fn)(void).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    91
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    92
int AWTPreload(const char *funcName);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    93
/* stops AWT preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    94
void AWTPreloadStop();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    95
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    96
/* D3D preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    97
/* -1: not initialized; 0: OFF, 1: ON */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    98
int awtPreloadD3D = -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    99
/* command line parameter to swith D3D preloading on */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   100
#define PARAM_PRELOAD_D3D "-Dsun.awt.warmup"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   101
/* D3D/OpenGL management parameters */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   102
#define PARAM_NODDRAW "-Dsun.java2d.noddraw"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   103
#define PARAM_D3D "-Dsun.java2d.d3d"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   104
#define PARAM_OPENGL "-Dsun.java2d.opengl"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   105
/* funtion in awt.dll (src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   106
#define D3D_PRELOAD_FUNC "preloadD3D"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   107
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   108
/* Extracts value of a parameter with the specified name
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   109
 * from command line argument (returns pointer in the argument).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   110
 * Returns NULL if the argument does not contains the parameter.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   111
 * e.g.:
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   112
 * GetParamValue("theParam", "theParam=value") returns pointer to "value".
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   113
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   114
const char * GetParamValue(const char *paramName, const char *arg) {
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 28984
diff changeset
   115
    size_t nameLen = JLI_StrLen(paramName);
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   116
    if (JLI_StrNCmp(paramName, arg, nameLen) == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   117
        /* arg[nameLen] is valid (may contain final NULL) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   118
        if (arg[nameLen] == '=') {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   119
            return arg + nameLen + 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   120
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   121
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   122
    return NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   123
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   124
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   125
/* Checks if commandline argument contains property specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   126
 * and analyze it as boolean property (true/false).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   127
 * Returns -1 if the argument does not contain the parameter;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   128
 * Returns 1 if the argument contains the parameter and its value is "true";
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   129
 * Returns 0 if the argument contains the parameter and its value is "false".
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   130
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   131
int GetBoolParamValue(const char *paramName, const char *arg) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   132
    const char * paramValue = GetParamValue(paramName, arg);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   133
    if (paramValue != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   134
        if (JLI_StrCaseCmp(paramValue, "true") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   135
            return 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   136
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   137
        if (JLI_StrCaseCmp(paramValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   138
            return 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   139
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   140
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   141
    return -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   142
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   143
#endif /* ENABLE_AWT_PRELOAD */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   144
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
static jboolean _isjavaw = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
IsJavaw()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    return _isjavaw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
void
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   159
CreateExecutionEnvironment(int *pargc, char ***pargv,
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   160
                           char *jrepath, jint so_jrepath,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   161
                           char *jvmpath, jint so_jvmpath,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   162
                           char *jvmcfg,  jint so_jvmcfg) {
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   163
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   164
    char *jvmtype;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    int i = 0;
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   166
    char** argv = *pargv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /* Find out where the JRE is that we will be using. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (!GetJREPath(jrepath, so_jrepath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   170
        JLI_ReportErrorMessage(JRE_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
42753
40f61533b93d 8066474: Remove the lib/ directory from Linux and Solaris images
erikj
parents: 41558
diff changeset
   174
    JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%sjvm.cfg",
40f61533b93d 8066474: Remove the lib/ directory from Linux and Solaris images
erikj
parents: 41558
diff changeset
   175
        jrepath, FILESEP, FILESEP);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   176
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /* Find the specified JVM type */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   178
    if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   179
        JLI_ReportErrorMessage(CFG_ERROR7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   182
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   183
    jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   184
    if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   185
        JLI_ReportErrorMessage(CFG_ERROR9);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   186
        exit(4);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   187
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    jvmpath[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   191
        JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        exit(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /* If we got here, jvmpath has been correctly initialized. */
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   195
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   196
    /* Check if we need preload AWT */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   197
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   198
    argv = *pargv;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   199
    for (i = 0; i < *pargc ; i++) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   200
        /* Tests the "turn on" parameter only if not set yet. */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   201
        if (awtPreloadD3D < 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   202
            if (GetBoolParamValue(PARAM_PRELOAD_D3D, argv[i]) == 1) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   203
                awtPreloadD3D = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   204
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   205
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   206
        /* Test parameters which can disable preloading if not already disabled. */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   207
        if (awtPreloadD3D != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   208
            if (GetBoolParamValue(PARAM_NODDRAW, argv[i]) == 1
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   209
                || GetBoolParamValue(PARAM_D3D, argv[i]) == 0
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   210
                || GetBoolParamValue(PARAM_OPENGL, argv[i]) == 1)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   211
            {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   212
                awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   213
                /* no need to test the rest of the parameters */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   214
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   215
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   216
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   217
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   218
#endif /* ENABLE_AWT_PRELOAD */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   221
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   222
static jboolean
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   223
LoadMSVCRT()
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   224
{
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   225
    // Only do this once
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   226
    static int loaded = 0;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   227
    char crtpath[MAXPATHLEN];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   228
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   229
    if (!loaded) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   230
        /*
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   231
         * The Microsoft C Runtime Library needs to be loaded first.  A copy is
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   232
         * assumed to be present in the "JRE path" directory.  If it is not found
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   233
         * there (or "JRE path" fails to resolve), skip the explicit load and let
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   234
         * nature take its course, which is likely to be a failure to execute.
28984
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   235
         * The makefiles will provide the correct lib contained in quotes in the
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   236
         * macro MSVCR_DLL_NAME.
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   237
         */
28984
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   238
#ifdef MSVCR_DLL_NAME
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   239
        if (GetJREPath(crtpath, MAXPATHLEN)) {
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   240
            if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +
28984
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   241
                    JLI_StrLen(MSVCR_DLL_NAME) >= MAXPATHLEN) {
6535
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   242
                JLI_ReportErrorMessage(JRE_ERROR11);
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   243
                return JNI_FALSE;
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   244
            }
28984
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   245
            (void)JLI_StrCat(crtpath, "\\bin\\" MSVCR_DLL_NAME);   /* Add crt dll */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   246
            JLI_TraceLauncher("CRT path is %s\n", crtpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   247
            if (_access(crtpath, 0) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   248
                if (LoadLibrary(crtpath) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   249
                    JLI_ReportErrorMessage(DLL_ERROR4, crtpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   250
                    return JNI_FALSE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   251
                }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   252
            }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   253
        }
28984
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   254
#endif /* MSVCR_DLL_NAME */
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   255
#ifdef MSVCP_DLL_NAME
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   256
        if (GetJREPath(crtpath, MAXPATHLEN)) {
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   257
            if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   258
                    JLI_StrLen(MSVCP_DLL_NAME) >= MAXPATHLEN) {
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   259
                JLI_ReportErrorMessage(JRE_ERROR11);
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   260
                return JNI_FALSE;
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   261
            }
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   262
            (void)JLI_StrCat(crtpath, "\\bin\\" MSVCP_DLL_NAME);   /* Add prt dll */
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   263
            JLI_TraceLauncher("PRT path is %s\n", crtpath);
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   264
            if (_access(crtpath, 0) == 0) {
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   265
                if (LoadLibrary(crtpath) == 0) {
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   266
                    JLI_ReportErrorMessage(DLL_ERROR4, crtpath);
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   267
                    return JNI_FALSE;
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   268
                }
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   269
            }
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   270
        }
12031ba2dc38 8042707: Source changes needed to build JDK 9 with Visual Studio 2013 (VS2013)
erikj
parents: 27938
diff changeset
   271
#endif /* MSVCP_DLL_NAME */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   272
        loaded = 1;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   273
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   274
    return JNI_TRUE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   275
}
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   276
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   277
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * Find path to JRE based on .exe's location or registry settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
GetJREPath(char *path, jint pathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    char javadll[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    if (GetApplicationHome(path, pathsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        /* Is JRE co-located with the application? */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   289
        JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (stat(javadll, &s) == 0) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   291
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   292
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
31690
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30914
diff changeset
   294
        /* ensure storage for path + \jre + NULL */
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30914
diff changeset
   295
        if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30914
diff changeset
   296
            JLI_TraceLauncher("Insufficient space to store JRE path\n");
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30914
diff changeset
   297
            return JNI_FALSE;
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30914
diff changeset
   298
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        /* Does this app ship a private JRE in <apphome>\jre directory? */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   300
        JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (stat(javadll, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            JLI_StrCat(path, "\\jre");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   303
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   304
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   308
    /* Try getting path to JRE from path to JLI.DLL */
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   309
    if (GetApplicationHomeFromDll(path, pathsize)) {
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   310
        JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   311
        if (stat(javadll, &s) == 0) {
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   312
            JLI_TraceLauncher("JRE path is %s\n", path);
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   313
            return JNI_TRUE;
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   314
        }
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   315
    }
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   316
41558
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   317
#ifdef USE_REGISTRY_LOOKUP
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   318
    /* Lookup public JRE using Windows registry. */
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   319
    if (GetPublicJREHome(path, pathsize)) {
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   320
        JLI_TraceLauncher("JRE path is %s\n", path);
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   321
        return JNI_TRUE;
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   322
    }
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   323
#endif
750de2810ded 8168093: Need a way for the launcher to query the JRE location using Windows registry.
asemenyuk
parents: 40945
diff changeset
   324
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   325
    JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * Given a JRE location and a JVM type, construct what the name the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 * JVM shared library will be.  Return true, if such a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * exists, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
           char *jvmpath, jint jvmpathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   340
        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    } else {
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   342
        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL,
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   343
                     jrepath, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (stat(jvmpath, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 * Load a jvm from "jvmpath" and initialize the invocation functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    HINSTANCE handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * The Microsoft C Runtime Library needs to be loaded first.  A copy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * assumed to be present in the "JRE path" directory.  If it is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * there (or "JRE path" fails to resolve), skip the explicit load and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * nature take its course, which is likely to be a failure to execute.
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 1331
diff changeset
   367
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   369
    LoadMSVCRT();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /* Load the Java VM DLL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    if ((handle = LoadLibrary(jvmpath)) == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   373
        JLI_ReportErrorMessage(DLL_ERROR4, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /* Now get the function addresses */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    ifn->CreateJavaVM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        (void *)GetProcAddress(handle, "JNI_CreateJavaVM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    ifn->GetDefaultJavaVMInitArgs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        (void *)GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    if (ifn->CreateJavaVM == 0 || ifn->GetDefaultJavaVMInitArgs == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   383
        JLI_ReportErrorMessage(JNI_ERROR1, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
/*
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   391
 * Removes the trailing file name and one sub-folder from a path.
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   392
 * If buf is "c:\foo\bin\javac", then put "c:\foo" into buf.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
jboolean
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   395
TruncatePath(char *buf)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    *JLI_StrRChr(buf, '\\') = '\0'; /* remove .exe file name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if ((cp = JLI_StrRChr(buf, '\\')) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        /* This happens if the application is in a drive root, and
40945
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   401
         * there is no bin directory. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
40945
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   405
    *cp = '\0'; /* remove the bin\ part */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
/*
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   410
 * Retrieves the path to the JRE home by locating the executable file
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   411
 * of the current process and then truncating the path to the executable
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   412
 */
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   413
jboolean
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   414
GetApplicationHome(char *buf, jint bufsize)
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   415
{
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   416
    GetModuleFileName(NULL, buf, bufsize);
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   417
    return TruncatePath(buf);
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   418
}
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   419
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   420
/*
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   421
 * Retrieves the path to the JRE home by locating JLI.DLL and
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   422
 * then truncating the path to JLI.DLL
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   423
 */
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   424
jboolean
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   425
GetApplicationHomeFromDll(char *buf, jint bufsize)
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   426
{
40945
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   427
    HMODULE module;
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   428
    DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   429
                  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   430
40945
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   431
    if (GetModuleHandleEx(flags, (LPCSTR)&GetJREPath, &module) != 0) {
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   432
        if (GetModuleFileName(module, buf, bufsize) != 0) {
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   433
            return TruncatePath(buf);
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   434
        }
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   435
    }
f241705723ea 8165524: Better detect JRE that Linux JLI will be using
ksrini
parents: 39761
diff changeset
   436
    return JNI_FALSE;
34960
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   437
}
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   438
75262319b048 8145409: Better detect JRE that JLI will be using
dcherepanov
parents: 31690
diff changeset
   439
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
 * Support for doing cheap, accurate interval timing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
static jboolean counterAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
static jboolean counterInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
static LARGE_INTEGER counterFrequency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
jlong CounterGet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    LARGE_INTEGER count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    if (!counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        counterAvailable = QueryPerformanceFrequency(&counterFrequency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        counterInitialized = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    if (!counterAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    QueryPerformanceCounter(&count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    return (jlong)(count.QuadPart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
jlong Counter2Micros(jlong counts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    if (!counterAvailable || !counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    return (counts * 1000 * 1000)/counterFrequency.QuadPart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
}
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   468
/*
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   469
 * windows snprintf does not guarantee a null terminator in the buffer,
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   470
 * if the computed size is equal to or greater than the buffer size,
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   471
 * as well as error conditions. This function guarantees a null terminator
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   472
 * under all these conditions. An unreasonable buffer or size will return
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   473
 * an error value. Under all other conditions this function will return the
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   474
 * size of the bytes actually written minus the null terminator, similar
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   475
 * to ansi snprintf api. Thus when calling this function the caller must
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   476
 * ensure storage for the null terminator.
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   477
 */
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   478
int
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   479
JLI_Snprintf(char* buffer, size_t size, const char* format, ...) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   480
    int rc;
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   481
    va_list vl;
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   482
    if (size == 0 || buffer == NULL)
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   483
        return -1;
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   484
    buffer[0] = '\0';
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   485
    va_start(vl, format);
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   486
    rc = vsnprintf(buffer, size, format, vl);
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   487
    va_end(vl);
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   488
    /* force a null terminator, if something is amiss */
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   489
    if (rc < 0) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   490
        /* apply ansi semantics */
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   491
        buffer[size - 1] = '\0';
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 28984
diff changeset
   492
        return (int)size;
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   493
    } else if (rc == size) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   494
        /* force a null terminator */
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   495
        buffer[size - 1] = '\0';
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   496
    }
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   497
    return rc;
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   498
}
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   499
53656
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   500
/* On Windows, if _open fails, retry again with CreateFileW and
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   501
 *  "\\?\" prefix ( extended-length paths) - this allows to open paths with larger file names;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   502
 * otherwise we run into the MAX_PATH limitation */
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   503
int JLI_Open(const char* name, int flags) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   504
    int fd = _open(name, flags);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   505
    if (fd == -1 && errno == ENOENT) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   506
        wchar_t* wname = NULL;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   507
        wchar_t* wfullname = NULL;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   508
        wchar_t* wfullname_w_prefix = NULL;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   509
        size_t wnamelen, wfullnamelen, elplen;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   510
        HANDLE h;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   511
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   512
        wnamelen = strlen(name) + 1;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   513
        wname = (wchar_t*) malloc(wnamelen*sizeof(wchar_t));
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   514
        if (wname == NULL) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   515
            goto end;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   516
        }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   517
        if (mbstowcs(wname, name, wnamelen - 1) == -1) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   518
            goto end;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   519
        }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   520
        wname[wnamelen - 1] = L'\0';
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   521
        wfullname = _wfullpath(wfullname, wname, 0);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   522
        if (wfullname == NULL) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   523
            goto end;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   524
        }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   525
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   526
        wfullnamelen = wcslen(wfullname);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   527
        if (wfullnamelen > 247) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   528
            elplen = wcslen(ELP_PREFIX);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   529
            wfullname_w_prefix = (wchar_t*) malloc((elplen+wfullnamelen+1)*sizeof(wchar_t));
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   530
            wcscpy(wfullname_w_prefix, ELP_PREFIX);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   531
            wcscpy(wfullname_w_prefix+elplen, wfullname);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   532
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   533
            h = CreateFileW(wfullname_w_prefix, GENERIC_READ, FILE_SHARE_READ, NULL,
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   534
                            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   535
            if (h == INVALID_HANDLE_VALUE) {
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   536
                goto end;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   537
            }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   538
            /* associates fd with handle */
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   539
            fd = _open_osfhandle((intptr_t)h, _O_RDONLY);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   540
        }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   541
end:
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   542
        free(wname);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   543
        free(wfullname);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   544
        free(wfullname_w_prefix);
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   545
    }
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   546
    return fd;
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   547
}
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   548
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   549
645ba889ee5f 8217093: Support extended-length paths in parse_manifest.c on windows
mbaesken
parents: 49440
diff changeset
   550
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   551
JNIEXPORT void JNICALL
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   552
JLI_ReportErrorMessage(const char* fmt, ...) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    va_start(vl,fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        int n = _vscprintf(fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        message = (char *)JLI_MemAlloc(n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        _vsnprintf(message, n, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        message[n]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
/*
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   576
 * Just like JLI_ReportErrorMessage, except that it concatenates the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * error message if any, its upto the calling routine to correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * format the separation of the messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 */
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   580
JNIEXPORT void JNICALL
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   581
JLI_ReportErrorMessageSys(const char *fmt, ...)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    int save_errno = errno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    DWORD       errval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    jboolean freeit = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    char  *errtext = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (errtext == NULL || n == 0) {                /* Paranoia check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            errtext = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            freeit = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (n > 2) {                                /* Drop final CR, LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                if (errtext[n - 1] == '\n') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                if (errtext[n - 1] == '\r') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                errtext[n] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    } else {   /* C runtime error that has no corresponding DOS error code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        errtext = strerror(save_errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        int mlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        int len = mlen =  _vscprintf(fmt, vl) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (freeit) {
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 6535
diff changeset
   617
           mlen += (int)JLI_StrLen(errtext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        message = (char *)JLI_MemAlloc(mlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        _vsnprintf(message, len, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        message[len]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
           JLI_StrCat(message, errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
           fprintf(stderr, "%s", errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        (void)LocalFree((HLOCAL)errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   644
JNIEXPORT void JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   645
JLI_ReportExceptionDescription(JNIEnv * env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
       /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        * This code should be replaced by code which opens a window with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        * the exception detail message, for now atleast put a dialog up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
               (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
 * Wrapper for platform dependent unsetenv function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
UnsetEnv(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    int ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    buf = JLI_StrCat(JLI_StrCpy(buf, name), "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    ret = _putenv(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    JLI_MemFree(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    return (ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
/* --- Splash Screen shared library support --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
static const char* SPLASHSCREEN_SO = "\\bin\\splashscreen.dll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
static HMODULE hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
void* SplashProcAddress(const char* name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    char libraryPath[MAXPATHLEN]; /* some extra space for JLI_StrCat'ing SPLASHSCREEN_SO */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    if (!GetJREPath(libraryPath, MAXPATHLEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    if (JLI_StrLen(libraryPath)+JLI_StrLen(SPLASHSCREEN_SO) >= MAXPATHLEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    JLI_StrCat(libraryPath, SPLASHSCREEN_SO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    if (!hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        hSplashLib = LoadLibrary(libraryPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        return GetProcAddress(hSplashLib, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
void SplashFreeLibrary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        FreeLibrary(hSplashLib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
 * Block current thread and continue execution in a new thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    int rslt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    unsigned thread_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
#define STACK_SIZE_PARAM_IS_A_RESERVATION  (0x10000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * supported on older version of Windows. Try first with the flag; and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * if that fails try again without the flag. See MSDN document or HotSpot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * source (os_win32.cpp) for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    HANDLE thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                             STACK_SIZE_PARAM_IS_A_RESERVATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    if (thread_handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
      thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   740
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   741
    /* AWT preloading (AFTER main thread start) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   742
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   743
    /* D3D preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   744
    if (awtPreloadD3D != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   745
        char *envValue;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   746
        /* D3D routines checks env.var J2D_D3D if no appropriate
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   747
         * command line params was specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   748
         */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   749
        envValue = getenv("J2D_D3D");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   750
        if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   751
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   752
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   753
        /* Test that AWT preloading isn't disabled by J2D_D3D_PRELOAD env.var */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   754
        envValue = getenv("J2D_D3D_PRELOAD");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   755
        if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   756
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   757
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   758
        if (awtPreloadD3D < 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   759
            /* If awtPreloadD3D is still undefined (-1), test
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   760
             * if it is turned on by J2D_D3D_PRELOAD env.var.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   761
             * By default it's turned OFF.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   762
             */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   763
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   764
            if (envValue != NULL && JLI_StrCaseCmp(envValue, "true") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   765
                awtPreloadD3D = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   766
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   767
         }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   768
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   769
    if (awtPreloadD3D) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   770
        AWTPreload(D3D_PRELOAD_FUNC);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   771
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   772
#endif /* ENABLE_AWT_PRELOAD */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   773
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    if (thread_handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
      WaitForSingleObject(thread_handle, INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      GetExitCodeThread(thread_handle, &rslt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
      CloseHandle(thread_handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
      rslt = continuation(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   781
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   782
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   783
    if (awtPreloaded) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   784
        AWTPreloadStop();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   785
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   786
#endif /* ENABLE_AWT_PRELOAD */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   787
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    return rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   791
/* Unix only, empty on windows. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
void SetJavaLauncherPlatformProps() {}
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   793
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   794
/*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   795
 * The implementation for finding classes from the bootstrap
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   796
 * class loader, refer to java.h
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   797
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   798
static FindClassFromBootLoader_t *findBootClass = NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   799
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   800
jclass FindBootStrapClass(JNIEnv *env, const char *classname)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   801
{
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   802
   HMODULE hJvm;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   803
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   804
   if (findBootClass == NULL) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   805
       hJvm = GetModuleHandle(JVM_DLL);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   806
       if (hJvm == NULL) return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   807
       /* need to use the demangled entry point */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   808
       findBootClass = (FindClassFromBootLoader_t *)GetProcAddress(hJvm,
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 3111
diff changeset
   809
            "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   810
       if (findBootClass == NULL) {
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 3111
diff changeset
   811
          JLI_ReportErrorMessage(DLL_ERROR4, "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   812
          return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   813
       }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   814
   }
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 3111
diff changeset
   815
   return findBootClass(env, classname);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   816
}
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
   817
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   818
void
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   819
InitLauncher(boolean javaw)
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   820
{
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   821
    INITCOMMONCONTROLSEX icx;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   822
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   823
    /*
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   824
     * Required for javaw mode MessageBox output as well as for
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   825
     * HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   826
     * flag field is sufficient to perform the basic UI initialization.
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   827
     */
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   828
    memset(&icx, 0, sizeof(INITCOMMONCONTROLSEX));
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   829
    icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   830
    InitCommonControlsEx(&icx);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   831
    _isjavaw = javaw;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   832
    JLI_SetTraceLauncher();
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
   833
}
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   834
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   835
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   836
/* ============================== */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   837
/* AWT preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   838
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   839
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   840
typedef int FnPreloadStart(void);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   841
typedef void FnPreloadStop(void);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   842
static FnPreloadStop *fnPreloadStop = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   843
static HMODULE hPreloadAwt = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   844
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   845
/*
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   846
 * Starts AWT preloading
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   847
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   848
int AWTPreload(const char *funcName)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   849
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   850
    int result = -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   851
    /* load AWT library once (if several preload function should be called) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   852
    if (hPreloadAwt == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   853
        /* awt.dll is not loaded yet */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   854
        char libraryPath[MAXPATHLEN];
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 28984
diff changeset
   855
        size_t jrePathLen = 0;
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   856
        HMODULE hJava = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   857
        HMODULE hVerify = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   858
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   859
        while (1) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   860
            /* awt.dll depends on jvm.dll & java.dll;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   861
             * jvm.dll is already loaded, so we need only java.dll;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   862
             * java.dll depends on MSVCRT lib & verify.dll.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   863
             */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   864
            if (!GetJREPath(libraryPath, MAXPATHLEN)) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   865
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   866
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   867
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   868
            /* save path length */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   869
            jrePathLen = JLI_StrLen(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   870
25538
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   871
            if (jrePathLen + JLI_StrLen("\\bin\\verify.dll") >= MAXPATHLEN) {
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   872
              /* jre path is too long, the library path will not fit there;
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   873
               * report and abort preloading
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   874
               */
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   875
              JLI_ReportErrorMessage(JRE_ERROR11);
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   876
              break;
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   877
            }
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
   878
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   879
            /* load msvcrt 1st */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   880
            LoadMSVCRT();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   881
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   882
            /* load verify.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   883
            JLI_StrCat(libraryPath, "\\bin\\verify.dll");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   884
            hVerify = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   885
            if (hVerify == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   886
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   887
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   888
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   889
            /* restore jrePath */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   890
            libraryPath[jrePathLen] = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   891
            /* load java.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   892
            JLI_StrCat(libraryPath, "\\bin\\" JAVA_DLL);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   893
            hJava = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   894
            if (hJava == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   895
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   896
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   897
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   898
            /* restore jrePath */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   899
            libraryPath[jrePathLen] = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   900
            /* load awt.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   901
            JLI_StrCat(libraryPath, "\\bin\\awt.dll");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   902
            hPreloadAwt = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   903
            if (hPreloadAwt == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   904
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   905
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   906
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   907
            /* get "preloadStop" func ptr */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   908
            fnPreloadStop = (FnPreloadStop *)GetProcAddress(hPreloadAwt, "preloadStop");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   909
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   910
            break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   911
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   912
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   913
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   914
    if (hPreloadAwt != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   915
        FnPreloadStart *fnInit = (FnPreloadStart *)GetProcAddress(hPreloadAwt, funcName);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   916
        if (fnInit != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   917
            /* don't forget to stop preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   918
            awtPreloaded = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   919
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   920
            result = fnInit();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   921
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   922
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   923
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   924
    return result;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   925
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   926
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   927
/*
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   928
 * Terminates AWT preloading
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   929
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   930
void AWTPreloadStop() {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   931
    if (fnPreloadStop != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   932
        fnPreloadStop();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   933
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   934
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   935
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   936
#endif /* ENABLE_AWT_PRELOAD */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   937
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   938
int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   939
JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   940
        int argc, char **argv,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   941
        int mode, char *what, int ret)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   942
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   943
    ShowSplashScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   944
    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   945
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   946
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   947
void
30467
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   948
PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   949
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   950
    // stubbed out for windows and *nixes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   951
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   952
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   953
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   954
RegisterThread()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   955
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   956
    // stubbed out for windows and *nixes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   957
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   958
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   959
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   960
 * on windows, we return a false to indicate this option is not applicable
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   961
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   962
jboolean
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   963
ProcessPlatformOption(const char *arg)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   964
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   965
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   966
}
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   967
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   968
/*
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   969
 * At this point we have the arguments to the application, and we need to
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   970
 * check with original stdargs in order to compare which of these truly
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   971
 * needs expansion. cmdtoargs will specify this if it finds a bare
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   972
 * (unquoted) argument containing a glob character(s) ie. * or ?
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   973
 */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   974
jobjectArray
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   975
CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   976
{
29742
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 28984
diff changeset
   977
    int i, j, idx;
b73f38796859 8074840: Resolve disabled warnings for libjli and libjli_static
mikael
parents: 28984
diff changeset
   978
    size_t tlen;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   979
    jobjectArray outArray, inArray;
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
   980
    char *arg, **nargv;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   981
    jboolean needs_expansion = JNI_FALSE;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   982
    jmethodID mid;
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
   983
    int stdargc;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   984
    StdArg *stdargs;
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
   985
    int *appArgIdx;
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
   986
    int isTool;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   987
    jclass cls = GetLauncherHelperClass(env);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   988
    NULL_CHECK0(cls);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   989
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   990
    if (argc == 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   991
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   992
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   993
    // the holy grail we need to compare with.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   994
    stdargs = JLI_GetStdArgs();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   995
    stdargc = JLI_GetStdArgc();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   996
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   997
    // sanity check, this should never happen
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   998
    if (argc > stdargc) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
   999
        JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1000
        JLI_TraceLauncher("passing arguments as-is.\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1001
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1002
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1003
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1004
    // sanity check, match the args we have, to the holy grail
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1005
    idx = JLI_GetAppArgIndex();
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1006
    isTool = (idx == 0);
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1007
    if (isTool) { idx++; } // skip tool name
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1008
    JLI_TraceLauncher("AppArgIndex: %d points to %s\n", idx, stdargs[idx].arg);
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1009
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1010
    appArgIdx = calloc(argc, sizeof(int));
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1011
    for (i = idx, j = 0; i < stdargc; i++) {
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1012
        if (isTool) { // filter -J used by tools to pass JVM options
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1013
            arg = stdargs[i].arg;
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1014
            if (arg[0] == '-' && arg[1] == 'J') {
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1015
                continue;
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1016
            }
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1017
        }
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1018
        appArgIdx[j++] = i;
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1019
    }
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1020
    // sanity check, ensure same number of arguments for application
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1021
    if (j != argc) {
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1022
        JLI_TraceLauncher("Warning: app args count doesn't match, %d %d\n", j, argc);
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1023
        JLI_TraceLauncher("passing arguments as-is.\n");
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1024
        JLI_MemFree(appArgIdx);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1025
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1026
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1027
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1028
    // make a copy of the args which will be expanded in java if required.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1029
    nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1030
    for (i = 0; i < argc; i++) {
39761
4e61ba4a71b4 8161951: 8132379 introduced non ANSI C coding
simonis
parents: 39640
diff changeset
  1031
        jboolean arg_expand;
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1032
        j = appArgIdx[i];
39761
4e61ba4a71b4 8161951: 8132379 introduced non ANSI C coding
simonis
parents: 39640
diff changeset
  1033
        arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0)
4e61ba4a71b4 8161951: 8132379 introduced non ANSI C coding
simonis
parents: 39640
diff changeset
  1034
            ? stdargs[j].has_wildcard
4e61ba4a71b4 8161951: 8132379 introduced non ANSI C coding
simonis
parents: 39640
diff changeset
  1035
            : JNI_FALSE;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1036
        if (needs_expansion == JNI_FALSE)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1037
            needs_expansion = arg_expand;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1038
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1039
        // indicator char + String + NULL terminator, the java method will strip
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1040
        // out the first character, the indicator character, so no matter what
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1041
        // we add the indicator
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1042
        tlen = 1 + JLI_StrLen(strv[i]) + 1;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1043
        nargv[i] = (char *) JLI_MemAlloc(tlen);
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1044
        if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1045
                         strv[i]) < 0) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1046
            return NULL;
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1047
        }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1048
        JLI_TraceLauncher("%s\n", nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1049
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1050
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1051
    if (!needs_expansion) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1052
        // clean up any allocated memory and return back the old arguments
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1053
        for (i = 0 ; i < argc ; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1054
            JLI_MemFree(nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1055
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1056
        JLI_MemFree(nargv);
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1057
        JLI_MemFree(appArgIdx);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1058
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1059
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1060
    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1061
                                                "expandArgs",
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1062
                                                "([Ljava/lang/String;)[Ljava/lang/String;"));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1063
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1064
    // expand the arguments that require expansion, the java method will strip
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1065
    // out the indicator character.
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 22066
diff changeset
  1066
    NULL_CHECK0(inArray = NewPlatformStringArray(env, nargv, argc));
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1067
    outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1068
    for (i = 0; i < argc; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1069
        JLI_MemFree(nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1070
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1071
    JLI_MemFree(nargv);
39640
6f1a839ff43d 8132379: -J options can cause crash or "Warning: app args parsing error passing arguments as-is"
henryjen
parents: 34960
diff changeset
  1072
    JLI_MemFree(appArgIdx);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1073
    return outArray;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1074
}