jdk/src/windows/bin/java_md.c
author kizune
Sat, 22 Mar 2014 02:21:11 +0400
changeset 25538 421c18d84c71
parent 22279 877c94f9476b
permissions -rw-r--r--
8037046: Validate libraries to be loaded Reviewed-by: ksrini, ahgross
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22066
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
     2
 * Copyright (c) 1997, 2013, 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
#include "version_comp.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define JVM_DLL "jvm.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define JAVA_DLL "java.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Prototypes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
static jboolean GetPublicJREHome(char *path, jint pathsize);
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
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    53
/* 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
    54
 * to VM initialization.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    55
 * 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
    56
 * 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
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * (this is always the case for plugin/javaws).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    61
 *
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    62
 * 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
    63
 * warmup code (platform dependent).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    64
 * 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
    65
 * 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
    66
 *
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    67
 * 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
    68
 * 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
    69
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    70
#undef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    71
#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
    72
    /* 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
    73
     * initialized*/
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    74
    #if !defined(DEBUG)
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    75
        #define ENABLE_AWT_PRELOAD
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7048
diff changeset
    76
    #endif
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    77
#endif
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    78
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    79
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    80
/* "AWT was preloaded" flag;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    81
 * turned on by AWTPreload().
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
int awtPreloaded = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    84
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    85
/* Calls a function with the name specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    86
 * the function must be int(*fn)(void).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    87
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    88
int AWTPreload(const char *funcName);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    89
/* stops AWT preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    90
void AWTPreloadStop();
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
/* D3D preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    93
/* -1: not initialized; 0: OFF, 1: ON */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    94
int awtPreloadD3D = -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    95
/* command line parameter to swith D3D preloading on */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    96
#define PARAM_PRELOAD_D3D "-Dsun.awt.warmup"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    97
/* D3D/OpenGL management parameters */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    98
#define PARAM_NODDRAW "-Dsun.java2d.noddraw"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
    99
#define PARAM_D3D "-Dsun.java2d.d3d"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   100
#define PARAM_OPENGL "-Dsun.java2d.opengl"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   101
/* 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
   102
#define D3D_PRELOAD_FUNC "preloadD3D"
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   103
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   104
/* Extracts value of a parameter with the specified name
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   105
 * from command line argument (returns pointer in the argument).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   106
 * 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
   107
 * e.g.:
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   108
 * GetParamValue("theParam", "theParam=value") returns pointer to "value".
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   109
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   110
const char * GetParamValue(const char *paramName, const char *arg) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   111
    int nameLen = JLI_StrLen(paramName);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   112
    if (JLI_StrNCmp(paramName, arg, nameLen) == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   113
        /* arg[nameLen] is valid (may contain final NULL) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   114
        if (arg[nameLen] == '=') {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   115
            return arg + nameLen + 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   116
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   117
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   118
    return NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   119
}
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
/* Checks if commandline argument contains property specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   122
 * and analyze it as boolean property (true/false).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   123
 * 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
   124
 * 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
   125
 * 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
   126
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   127
int GetBoolParamValue(const char *paramName, const char *arg) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   128
    const char * paramValue = GetParamValue(paramName, arg);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   129
    if (paramValue != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   130
        if (JLI_StrCaseCmp(paramValue, "true") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   131
            return 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   132
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   133
        if (JLI_StrCaseCmp(paramValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   134
            return 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   135
        }
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
    return -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   138
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   139
#endif /* ENABLE_AWT_PRELOAD */
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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
static jboolean _isjavaw = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
IsJavaw()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return _isjavaw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * Returns the arch path, to get the current arch use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * macro GetArch, nbits here is ignored for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
GetArchPath(int nbits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#ifdef _M_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    return "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#elif defined(_M_IA64)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    return "i386";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
void
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   171
CreateExecutionEnvironment(int *pargc, char ***pargv,
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   172
                           char *jrepath, jint so_jrepath,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   173
                           char *jvmpath, jint so_jvmpath,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   174
                           char *jvmcfg,  jint so_jvmcfg) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    char * jvmtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    int running = CURRENT_DATA_MODEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    int wanted = running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   181
    char** argv = *pargv;
22066
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   182
    for (i = 1; i < *pargc ; i++) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   183
        if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            wanted = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   187
        if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            wanted = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
22066
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   191
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   192
        if (IsJavaArgs() && argv[i][0] != '-')
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   193
            continue;
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   194
        if (argv[i][0] != '-')
f2133b498789 8029388: java.exe consumes argument intended for launched java class
ksrini
parents: 16091
diff changeset
   195
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (running != wanted) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   198
        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /* Find out where the JRE is that we will be using. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    if (!GetJREPath(jrepath, so_jrepath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   204
        JLI_ReportErrorMessage(JRE_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   208
    JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   209
        jrepath, FILESEP, FILESEP, (char*)GetArch(), FILESEP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   210
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /* Find the specified JVM type */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
   212
    if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   213
        JLI_ReportErrorMessage(CFG_ERROR7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   216
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   217
    jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   218
    if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   219
        JLI_ReportErrorMessage(CFG_ERROR9);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   220
        exit(4);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   221
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    jvmpath[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   225
        JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        exit(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /* 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
   229
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   230
    /* Check if we need preload AWT */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   231
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   232
    argv = *pargv;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   233
    for (i = 0; i < *pargc ; i++) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   234
        /* 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
   235
        if (awtPreloadD3D < 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   236
            if (GetBoolParamValue(PARAM_PRELOAD_D3D, argv[i]) == 1) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   237
                awtPreloadD3D = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   238
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   239
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   240
        /* 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
   241
        if (awtPreloadD3D != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   242
            if (GetBoolParamValue(PARAM_NODDRAW, argv[i]) == 1
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   243
                || GetBoolParamValue(PARAM_D3D, argv[i]) == 0
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   244
                || GetBoolParamValue(PARAM_OPENGL, argv[i]) == 1)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   245
            {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   246
                awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   247
                /* no need to test the rest of the parameters */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   248
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   249
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   250
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   251
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
   252
#endif /* ENABLE_AWT_PRELOAD */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   255
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   256
static jboolean
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   257
LoadMSVCRT()
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   258
{
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   259
    // Only do this once
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   260
    static int loaded = 0;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   261
    char crtpath[MAXPATHLEN];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   262
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   263
    if (!loaded) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   264
        /*
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   265
         * 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
   266
         * 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
   267
         * 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
   268
         * nature take its course, which is likely to be a failure to execute.
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   269
         * This is clearly completely specific to the exact compiler version
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   270
         * which isn't very nice, but its hardly the only place.
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   271
         * No attempt to look for compiler versions in between 2003 and 2010
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   272
         * as we aren't supporting building with those.
3111
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
#ifdef _MSC_VER
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   275
#if _MSC_VER < 1400
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   276
#define CRT_DLL "msvcr71.dll"
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   277
#endif
5381
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   278
#if _MSC_VER >= 1600
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   279
#define CRT_DLL "msvcr100.dll"
d6d64a42ff51 6931180: Migration to recent versions of MS Platform SDK
prr
parents: 3834
diff changeset
   280
#endif
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   281
#ifdef CRT_DLL
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   282
        if (GetJREPath(crtpath, MAXPATHLEN)) {
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   283
            if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   284
                    JLI_StrLen(CRT_DLL) >= MAXPATHLEN) {
6535
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   285
                JLI_ReportErrorMessage(JRE_ERROR11);
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   286
                return JNI_FALSE;
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   287
            }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   288
            (void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL);   /* Add crt dll */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   289
            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
   290
            if (_access(crtpath, 0) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   291
                if (LoadLibrary(crtpath) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   292
                    JLI_ReportErrorMessage(DLL_ERROR4, crtpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   293
                    return JNI_FALSE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   294
                }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   295
            }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   296
        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   297
#endif /* CRT_DLL */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   298
#endif /* _MSC_VER */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   299
        loaded = 1;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   300
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   301
    return JNI_TRUE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   302
}
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   303
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   304
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * Find path to JRE based on .exe's location or registry settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
GetJREPath(char *path, jint pathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    char javadll[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    if (GetApplicationHome(path, pathsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        /* Is JRE co-located with the application? */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   316
        JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (stat(javadll, &s) == 0) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   318
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   319
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        /* 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
   323
        JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (stat(javadll, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            JLI_StrCat(path, "\\jre");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   326
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   327
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /* Look for a public JRE on this machine. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    if (GetPublicJREHome(path, pathsize)) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   333
        JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   334
        return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   337
    JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 * Given a JRE location and a JVM type, construct what the name the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 * JVM shared library will be.  Return true, if such a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * exists, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
           char *jvmpath, jint jvmpathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   353
        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    } else {
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   355
        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL,
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   356
                     jrepath, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (stat(jvmpath, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * Load a jvm from "jvmpath" and initialize the invocation functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    HINSTANCE handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * The Microsoft C Runtime Library needs to be loaded first.  A copy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * assumed to be present in the "JRE path" directory.  If it is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * there (or "JRE path" fails to resolve), skip the explicit load and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * 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
   380
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   382
    LoadMSVCRT();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /* Load the Java VM DLL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if ((handle = LoadLibrary(jvmpath)) == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   386
        JLI_ReportErrorMessage(DLL_ERROR4, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /* Now get the function addresses */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    ifn->CreateJavaVM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        (void *)GetProcAddress(handle, "JNI_CreateJavaVM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    ifn->GetDefaultJavaVMInitArgs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        (void *)GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    if (ifn->CreateJavaVM == 0 || ifn->GetDefaultJavaVMInitArgs == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   396
        JLI_ReportErrorMessage(JNI_ERROR1, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 * If app is "c:\foo\bin\javac", then put "c:\foo" into buf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
GetApplicationHome(char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    GetModuleFileName(0, buf, bufsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    *JLI_StrRChr(buf, '\\') = '\0'; /* remove .exe file name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    if ((cp = JLI_StrRChr(buf, '\\')) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        /* This happens if the application is in a drive root, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         * there is no bin directory. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    *cp = '\0';  /* remove the bin\ part */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 * Helpers to look in the registry for a public JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    /* Same for 1.5.0, 1.5.1, 1.5.2 etc. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
#define JRE_KEY     "Software\\JavaSoft\\Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
GetStringFromRegistry(HKEY key, const char *name, char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    DWORD type, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    if (RegQueryValueEx(key, name, 0, &type, 0, &size) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        && type == REG_SZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        && (size < (unsigned int)bufsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (RegQueryValueEx(key, name, 0, 0, buf, &size) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
GetPublicJREHome(char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    HKEY key, subkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    char version[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Note: There is a very similar implementation of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * registry reading code in the Windows java control panel (javacp.cpl).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * If there are bugs here, a similar bug probably exists there.  Hence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * changes here require inspection there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /* Find the current version of the JRE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY, 0, KEY_READ, &key) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   458
        JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (!GetStringFromRegistry(key, "CurrentVersion",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                               version, sizeof(version))) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   464
        JLI_ReportErrorMessage(REG_ERROR2, JRE_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    if (JLI_StrCmp(version, GetDotVersion()) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   470
        JLI_ReportErrorMessage(REG_ERROR3, JRE_KEY, version, GetDotVersion()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /* Find directory where the current version is installed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    if (RegOpenKeyEx(key, version, 0, KEY_READ, &subkey) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   478
        JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    if (!GetStringFromRegistry(subkey, "JavaHome", buf, bufsize)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   484
        JLI_ReportErrorMessage(REG_ERROR4, JRE_KEY, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        RegCloseKey(subkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        char micro[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (!GetStringFromRegistry(subkey, "MicroVersion", micro,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                   sizeof(micro))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            printf("Warning: Can't read MicroVersion\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            micro[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        printf("Version major.minor.micro = %s.%s\n", version, micro);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    RegCloseKey(subkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
 * Support for doing cheap, accurate interval timing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
static jboolean counterAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
static jboolean counterInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
static LARGE_INTEGER counterFrequency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
jlong CounterGet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    LARGE_INTEGER count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    if (!counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        counterAvailable = QueryPerformanceFrequency(&counterFrequency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        counterInitialized = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    if (!counterAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    QueryPerformanceCounter(&count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    return (jlong)(count.QuadPart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
jlong Counter2Micros(jlong counts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    if (!counterAvailable || !counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    return (counts * 1000 * 1000)/counterFrequency.QuadPart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
}
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   534
/*
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   535
 * windows snprintf does not guarantee a null terminator in the buffer,
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   536
 * 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
   537
 * 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
   538
 * 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
   539
 * 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
   540
 * 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
   541
 * 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
   542
 * ensure storage for the null terminator.
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   543
 */
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   544
int
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   545
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
   546
    int rc;
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   547
    va_list vl;
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   548
    if (size == 0 || buffer == NULL)
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   549
        return -1;
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   550
    buffer[0] = '\0';
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   551
    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
   552
    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
   553
    va_end(vl);
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   554
    /* 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
   555
    if (rc < 0) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   556
        /* apply ansi semantics */
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   557
        buffer[size - 1] = '\0';
16091
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   558
        return size;
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   559
    } else if (rc == size) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   560
        /* force a null terminator */
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   561
        buffer[size - 1] = '\0';
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
   562
    }
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   563
    return rc;
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   564
}
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   565
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
void
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   567
JLI_ReportErrorMessage(const char* fmt, ...) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    va_start(vl,fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        int n = _vscprintf(fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        message = (char *)JLI_MemAlloc(n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        _vsnprintf(message, n, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        message[n]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
/*
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   591
 * Just like JLI_ReportErrorMessage, except that it concatenates the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
 * error message if any, its upto the calling routine to correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
 * format the separation of the messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
void
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   596
JLI_ReportErrorMessageSys(const char *fmt, ...)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    int save_errno = errno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    DWORD       errval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    jboolean freeit = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    char  *errtext = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (errtext == NULL || n == 0) {                /* Paranoia check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            errtext = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            freeit = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (n > 2) {                                /* Drop final CR, LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                if (errtext[n - 1] == '\n') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (errtext[n - 1] == '\r') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                errtext[n] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    } else {   /* C runtime error that has no corresponding DOS error code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        errtext = strerror(save_errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        int mlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        int len = mlen =  _vscprintf(fmt, vl) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (freeit) {
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 6535
diff changeset
   632
           mlen += (int)JLI_StrLen(errtext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        message = (char *)JLI_MemAlloc(mlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        _vsnprintf(message, len, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        message[len]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
           JLI_StrCat(message, errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
           fprintf(stderr, "%s", errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        (void)LocalFree((HLOCAL)errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   659
void  JLI_ReportExceptionDescription(JNIEnv * env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
       /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        * This code should be replaced by code which opens a window with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        * the exception detail message, for now atleast put a dialog up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
               (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
ServerClassMachine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    return (GetErgoPolicy() == ALWAYS_SERVER_CLASS) ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
 * Determine if there is an acceptable JRE in the registry directory top_key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
 * Upon locating the "best" one, return a fully qualified path to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
 * "Best" is defined as the most advanced JRE meeting the constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
 * contained in the manifest_info. If no JRE in this directory meets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
 * constraints, return NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
 * It doesn't matter if we get an error reading the registry, or we just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
 * don't find anything interesting in the directory.  We just return NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
 * in either case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
ProcessDir(manifest_info* info, HKEY top_key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    DWORD   index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    HKEY    ver_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    char    name[MAXNAMELEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    int     len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    char    *best = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Enumerate "<top_key>/SOFTWARE/JavaSoft/Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * searching for the best available version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    while (RegEnumKey(top_key, index, name, MAXNAMELEN) == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (JLI_AcceptableRelease(name, info->jre_version))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            if ((best == NULL) || (JLI_ExactVersionId(name, best) > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                if (best != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                best = JLI_StringDup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * Extract "JavaHome" from the "best" registry directory and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * that path.  If no appropriate version was located, or there is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * error in extracting the "JavaHome" string, return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    if (best == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        if (RegOpenKeyEx(top_key, best, 0, KEY_READ, &ver_key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        len = MAXNAMELEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (RegQueryValueEx(ver_key, "JavaHome", NULL, NULL, (LPBYTE)name, &len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
          != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        return (JLI_StringDup(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * This is the global entry point. It examines the host for the optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * JRE to be used by scanning a set of registry entries.  This set of entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 * is hardwired on Windows as "Software\JavaSoft\Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 * under the set of roots "{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
 * This routine simply opens each of these registry directories before passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 * control onto ProcessDir().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
LocateJRE(manifest_info* info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    HKEY    key = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    char    *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    int     key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    HKEY    root_keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    for (key_index = 0; key_index <= 1; key_index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (RegOpenKeyEx(root_keys[key_index], JRE_KEY, 0, KEY_READ, &key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
          == ERROR_SUCCESS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if ((path = ProcessDir(info, key)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                if (key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                return (path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 * Local helper routine to isolate a single token (option or argument)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 * from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
 * This routine accepts a pointer to a character pointer.  The first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * token (as defined by MSDN command-line argument syntax) is isolated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 * from that string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 * Upon return, the input character pointer pointed to by the parameter s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
 * is updated to point to the remainding, unscanned, portion of the string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
 * or to a null character if the entire string has been consummed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
 * This function returns a pointer to a null-terminated string which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
 * contains the isolated first token, or to the null character if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
 * token could be isolated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
 * Note the side effect of modifying the input string s by the insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 * of a null character, making it two strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
 * See "Parsing C Command-Line Arguments" in the MSDN Library for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
 * parsing rule details.  The rule summary from that specification is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
 *  * Arguments are delimited by white space, which is either a space or a tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
 *  * A string surrounded by double quotation marks is interpreted as a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
 *    argument, regardless of white space contained within. A quoted string can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 *    be embedded in an argument. Note that the caret (^) is not recognized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 *    an escape character or delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 *  * A double quotation mark preceded by a backslash, \", is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 *    literal double quotation mark (").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 *  * Backslashes are interpreted literally, unless they immediately precede a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 *    double quotation mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
 *  * If an even number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
 *    backslashes (\\), and the double quotation mark (") is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
 *    string delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
 *  * If an odd number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
 *    backslashes (\\) and the double quotation mark is interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
 *    escape sequence by the remaining backslash, causing a literal double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
 *    quotation mark (") to be placed in argv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
static char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
nextarg(char** s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    char    *p = *s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    char    *head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    int     slashes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    int     inquote = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Strip leading whitespace, which MSDN defines as only space or tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * (Hence, no locale specific "isspace" here.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    while (*p != (char)0 && (*p == ' ' || *p == '\t'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    head = p;                   /* Save the start of the token to return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Isolate a token from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    while (*p != (char)0 && (inquote || !(*p == ' ' || *p == '\t'))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (*p == '\\' && *(p+1) == '"' && slashes % 2 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        else if (*p == '"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            inquote = !inquote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        slashes = (*p++ == '\\') ? slashes + 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * If the token isolated isn't already terminated in a "char zero",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * then replace the whitespace character with one and move to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * next character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    if (*p != (char)0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        *p++ = (char)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Update the parameter to point to the head of the remaining string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * reflecting the command line and return a pointer to the leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * token which was isolated from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    *s = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    return (head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 * Local helper routine to return a string equivalent to the input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
 * s, but with quotes removed so the result is a string as would be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
 * in argv[].  The returned string should be freed by a call to JLI_MemFree().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
 * The rules for quoting (and escaped quotes) are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
 *  1 A double quotation mark preceded by a backslash, \", is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
 *    literal double quotation mark (").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
 *  2 Backslashes are interpreted literally, unless they immediately precede a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
 *    double quotation mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
 *  3 If an even number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
 *    backslashes (\\), and the double quotation mark (") is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
 *    string delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
 *  4 If an odd number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
 *    backslashes (\\) and the double quotation mark is interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 *    escape sequence by the remaining backslash, causing a literal double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 *    quotation mark (") to be placed in argv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
static char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
unquote(const char *s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    const char *p = s;          /* Pointer to the tail of the original string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    char *un = (char*)JLI_MemAlloc(JLI_StrLen(s) + 1);  /* Ptr to unquoted string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    char *pun = un;             /* Pointer to the tail of the unquoted string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    while (*p != '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (*p == '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        } else if (*p == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            const char *q = p + JLI_StrSpn(p,"\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if (*q == '"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    *pun++ = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    p += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                 } while (*p == '\\' && p < q);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                while (p < q)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                    *pun++ = *p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            *pun++ = *p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    *pun = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    return un;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 * Given a path to a jre to execute, this routine checks if this process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 * is indeed that jre.  If not, it exec's that jre.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 * We want to actually check the paths rather than just the version string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 * built into the executable, so that given version specification will yield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 * the exact same Java environment, regardless of the version of the arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 * launcher we start with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
ExecJRE(char *jre, char **argv) {
16077
92008ab562e0 7200499: Better data validation for options
ksrini
parents: 13411
diff changeset
   920
    jint     len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    char    path[MAXPATHLEN + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    const char *progname = GetProgramName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Resolve the real path to the currently running launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    len = GetModuleFileName(NULL, path, MAXPATHLEN + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    if (len == 0 || len > MAXPATHLEN) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   930
        JLI_ReportErrorMessageSys(JRE_ERROR9, progname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    JLI_TraceLauncher("ExecJRE: old: %s\n", path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    JLI_TraceLauncher("ExecJRE: new: %s\n", jre);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * If the path to the selected JRE directory is a match to the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * portion of the path to the currently executing JRE, we have a winner!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * If so, just return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    if (JLI_StrNCaseCmp(jre, path, JLI_StrLen(jre)) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return;                 /* I am the droid you were looking for */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * If this isn't the selected version, exec the selected version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     */
6535
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6522
diff changeset
   948
    JLI_Snprintf(path, sizeof(path), "%s\\bin\\%s.exe", jre, progname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * Although Windows has an execv() entrypoint, it doesn't actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * overlay a process: it can only create a new process and terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * the old process.  Therefore, any processes waiting on the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * process wake up and they shouldn't.  Hence, a chain of pseudo-zombie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * processes must be retained to maintain the proper wait semantics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * Fortunately the image size of the launcher isn't too large at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * If it weren't for this semantic flaw, the code below would be ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     *     execv(path, argv);
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   962
     *     JLI_ReportErrorMessage("Error: Exec of %s failed\n", path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *     exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * The incorrect exec semantics could be addressed by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *     exit((int)spawnv(_P_WAIT, path, argv));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * Unfortunately, a bug in Windows spawn/exec impementation prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * this from completely working.  All the Windows POSIX process creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * interfaces are implemented as wrappers around the native Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * function CreateProcess().  CreateProcess() takes a single string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * to specify command line options and arguments, so the POSIX routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * wrappers build a single string from the argv[] array and in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * process, any quoting information is lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * The solution to this to get the original command line, to process it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * to remove the new multiple JRE options (if any) as was done for argv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * in the common SelectVersion() routine and finally to pass it directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * to the native CreateProcess() Windows process control interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        char    *cmdline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        char    *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        char    *np;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        char    *ocl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        char    *ccl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        char    *unquoted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        DWORD   exitCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        STARTUPINFO si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        PROCESS_INFORMATION pi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
         * The following code block gets and processes the original command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
         * line, replacing the argv[0] equivalent in the command line with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
         * the path to the new executable and removing the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
         * Multiple JRE support options. Note that similar logic exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
         * in the platform independent SelectVersion routine, but is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * replicated here due to the syntax of CreateProcess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         * The magic "+ 4" characters added to the command line length are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         * 2 possible quotes around the path (argv[0]), a space after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         * path and a terminating null character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        ocl = GetCommandLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        np = ccl = JLI_StringDup(ocl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        p = nextarg(&np);               /* Discard argv[0] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        cmdline = (char *)JLI_MemAlloc(JLI_StrLen(path) + JLI_StrLen(np) + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if (JLI_StrChr(path, (int)' ') == NULL && JLI_StrChr(path, (int)'\t') == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            cmdline = JLI_StrCpy(cmdline, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            cmdline = JLI_StrCat(JLI_StrCat(JLI_StrCpy(cmdline, "\""), path), "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        while (*np != (char)0) {                /* While more command-line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            if (*p != (char)0) {                /* If a token was isolated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                unquoted = unquote(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                if (*unquoted == '-') {         /* Looks like an option */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                    if (JLI_StrCmp(unquoted, "-classpath") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                      JLI_StrCmp(unquoted, "-cp") == 0) {       /* Unique cp syntax */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                        cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                        p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                        if (*p != (char)0)      /* If a token was isolated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                            cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    } else if (JLI_StrNCmp(unquoted, "-version:", 9) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                      JLI_StrCmp(unquoted, "-jre-restrict-search") != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                      JLI_StrCmp(unquoted, "-no-jre-restrict-search") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                        cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                } else {                        /* End of options */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                    cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                    cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    JLI_MemFree((void *)unquoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                JLI_MemFree((void *)unquoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        JLI_MemFree((void *)ccl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            np = ccl = JLI_StringDup(cmdline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            printf("ReExec Command: %s (%s)\n", path, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            printf("ReExec Args: %s\n", np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            JLI_MemFree((void *)ccl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        (void)fflush(stdout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        (void)fflush(stderr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         * The following code is modeled after a model presented in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * Microsoft Technical Article "Moving Unix Applications to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         * Windows NT" (March 6, 1994) and "Creating Processes" on MSDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         * (Februrary 2005).  It approximates UNIX spawn semantics with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         * the parent waiting for termination of the child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        memset(&si, 0, sizeof(si));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        si.cb =sizeof(STARTUPINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        memset(&pi, 0, sizeof(pi));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        if (!CreateProcess((LPCTSTR)path,       /* executable name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
          (LPTSTR)cmdline,                      /* command line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
          (LPSECURITY_ATTRIBUTES)NULL,          /* process security attr. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
          (LPSECURITY_ATTRIBUTES)NULL,          /* thread security attr. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
          (BOOL)TRUE,                           /* inherits system handles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
          (DWORD)0,                             /* creation flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
          (LPVOID)NULL,                         /* environment block */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
          (LPCTSTR)NULL,                        /* current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
          (LPSTARTUPINFO)&si,                   /* (in) startup information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
          (LPPROCESS_INFORMATION)&pi)) {        /* (out) process information */
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1072
            JLI_ReportErrorMessageSys(SYS_ERROR1, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            if (GetExitCodeProcess(pi.hProcess, &exitCode) == FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                exitCode = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        } else {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1080
            JLI_ReportErrorMessage(SYS_ERROR2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            exitCode = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        CloseHandle(pi.hThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        CloseHandle(pi.hProcess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        exit(exitCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
 * Wrapper for platform dependent unsetenv function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
UnsetEnv(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    int ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    buf = JLI_StrCat(JLI_StrCpy(buf, name), "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    ret = _putenv(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    JLI_MemFree(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    return (ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
/* --- Splash Screen shared library support --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
static const char* SPLASHSCREEN_SO = "\\bin\\splashscreen.dll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
static HMODULE hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
void* SplashProcAddress(const char* name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    char libraryPath[MAXPATHLEN]; /* some extra space for JLI_StrCat'ing SPLASHSCREEN_SO */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    if (!GetJREPath(libraryPath, MAXPATHLEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    if (JLI_StrLen(libraryPath)+JLI_StrLen(SPLASHSCREEN_SO) >= MAXPATHLEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    JLI_StrCat(libraryPath, SPLASHSCREEN_SO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    if (!hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        hSplashLib = LoadLibrary(libraryPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        return GetProcAddress(hSplashLib, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
void SplashFreeLibrary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        FreeLibrary(hSplashLib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
jlong_format_specifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    return "%I64d";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
 * Block current thread and continue execution in a new thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    int rslt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    unsigned thread_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
#define STACK_SIZE_PARAM_IS_A_RESERVATION  (0x10000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * supported on older version of Windows. Try first with the flag; and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * if that fails try again without the flag. See MSDN document or HotSpot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * source (os_win32.cpp) for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    HANDLE thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                             STACK_SIZE_PARAM_IS_A_RESERVATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    if (thread_handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
      thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1178
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1179
    /* AWT preloading (AFTER main thread start) */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1180
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1181
    /* D3D preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1182
    if (awtPreloadD3D != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1183
        char *envValue;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1184
        /* 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
  1185
         * command line params was specified
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1186
         */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1187
        envValue = getenv("J2D_D3D");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1188
        if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1189
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1190
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1191
        /* 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
  1192
        envValue = getenv("J2D_D3D_PRELOAD");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1193
        if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1194
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1195
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1196
        if (awtPreloadD3D < 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1197
            /* If awtPreloadD3D is still undefined (-1), test
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1198
             * 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
  1199
             * By default it's turned OFF.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1200
             */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1201
            awtPreloadD3D = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1202
            if (envValue != NULL && JLI_StrCaseCmp(envValue, "true") == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1203
                awtPreloadD3D = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1204
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1205
         }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1206
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1207
    if (awtPreloadD3D) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1208
        AWTPreload(D3D_PRELOAD_FUNC);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1209
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1210
#endif /* ENABLE_AWT_PRELOAD */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1211
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    if (thread_handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
      WaitForSingleObject(thread_handle, INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
      GetExitCodeThread(thread_handle, &rslt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
      CloseHandle(thread_handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
      rslt = continuation(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1219
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1220
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1221
    if (awtPreloaded) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1222
        AWTPreloadStop();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1223
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1224
#endif /* ENABLE_AWT_PRELOAD */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    return rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1229
/* Unix only, empty on windows. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
void SetJavaLauncherPlatformProps() {}
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1231
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1232
/*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1233
 * The implementation for finding classes from the bootstrap
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1234
 * class loader, refer to java.h
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1235
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1236
static FindClassFromBootLoader_t *findBootClass = NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1237
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1238
jclass FindBootStrapClass(JNIEnv *env, const char *classname)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1239
{
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1240
   HMODULE hJvm;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1241
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1242
   if (findBootClass == NULL) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1243
       hJvm = GetModuleHandle(JVM_DLL);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1244
       if (hJvm == NULL) return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1245
       /* need to use the demangled entry point */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1246
       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
  1247
            "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1248
       if (findBootClass == NULL) {
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 3111
diff changeset
  1249
          JLI_ReportErrorMessage(DLL_ERROR4, "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1250
          return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1251
       }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1252
   }
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 3111
diff changeset
  1253
   return findBootClass(env, classname);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1254
}
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1255
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1256
void
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1257
InitLauncher(boolean javaw)
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1258
{
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1259
    INITCOMMONCONTROLSEX icx;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1260
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1261
    /*
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1262
     * Required for javaw mode MessageBox output as well as for
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1263
     * HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1264
     * flag field is sufficient to perform the basic UI initialization.
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1265
     */
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1266
    memset(&icx, 0, sizeof(INITCOMMONCONTROLSEX));
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1267
    icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1268
    InitCommonControlsEx(&icx);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1269
    _isjavaw = javaw;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1270
    JLI_SetTraceLauncher();
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1271
}
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1272
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1273
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1274
/* ============================== */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1275
/* AWT preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1276
#ifdef ENABLE_AWT_PRELOAD
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1277
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1278
typedef int FnPreloadStart(void);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1279
typedef void FnPreloadStop(void);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1280
static FnPreloadStop *fnPreloadStop = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1281
static HMODULE hPreloadAwt = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1282
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1283
/*
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1284
 * Starts AWT preloading
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1285
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1286
int AWTPreload(const char *funcName)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1287
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1288
    int result = -1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1289
    /* 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
  1290
    if (hPreloadAwt == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1291
        /* awt.dll is not loaded yet */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1292
        char libraryPath[MAXPATHLEN];
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1293
        int jrePathLen = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1294
        HMODULE hJava = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1295
        HMODULE hVerify = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1296
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1297
        while (1) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1298
            /* awt.dll depends on jvm.dll & java.dll;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1299
             * 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
  1300
             * java.dll depends on MSVCRT lib & verify.dll.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1301
             */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1302
            if (!GetJREPath(libraryPath, MAXPATHLEN)) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1303
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1304
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1305
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1306
            /* save path length */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1307
            jrePathLen = JLI_StrLen(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1308
25538
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1309
            if (jrePathLen + JLI_StrLen("\\bin\\verify.dll") >= MAXPATHLEN) {
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1310
              /* jre path is too long, the library path will not fit there;
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1311
               * report and abort preloading
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1312
               */
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1313
              JLI_ReportErrorMessage(JRE_ERROR11);
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1314
              break;
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1315
            }
421c18d84c71 8037046: Validate libraries to be loaded
kizune
parents: 22279
diff changeset
  1316
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1317
            /* load msvcrt 1st */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1318
            LoadMSVCRT();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1319
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1320
            /* load verify.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1321
            JLI_StrCat(libraryPath, "\\bin\\verify.dll");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1322
            hVerify = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1323
            if (hVerify == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1324
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1325
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1326
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1327
            /* restore jrePath */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1328
            libraryPath[jrePathLen] = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1329
            /* load java.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1330
            JLI_StrCat(libraryPath, "\\bin\\" JAVA_DLL);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1331
            hJava = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1332
            if (hJava == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1333
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1334
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1335
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1336
            /* restore jrePath */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1337
            libraryPath[jrePathLen] = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1338
            /* load awt.dll */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1339
            JLI_StrCat(libraryPath, "\\bin\\awt.dll");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1340
            hPreloadAwt = LoadLibrary(libraryPath);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1341
            if (hPreloadAwt == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1342
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1343
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1344
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1345
            /* get "preloadStop" func ptr */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1346
            fnPreloadStop = (FnPreloadStop *)GetProcAddress(hPreloadAwt, "preloadStop");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1347
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1348
            break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1349
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1350
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1351
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1352
    if (hPreloadAwt != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1353
        FnPreloadStart *fnInit = (FnPreloadStart *)GetProcAddress(hPreloadAwt, funcName);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1354
        if (fnInit != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1355
            /* don't forget to stop preloading */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1356
            awtPreloaded = 1;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1357
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1358
            result = fnInit();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1359
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1360
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1361
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1362
    return result;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1363
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1364
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1365
/*
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1366
 * Terminates AWT preloading
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1367
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1368
void AWTPreloadStop() {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1369
    if (fnPreloadStop != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1370
        fnPreloadStop();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1371
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1372
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1373
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6535
diff changeset
  1374
#endif /* ENABLE_AWT_PRELOAD */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1375
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1376
int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1377
JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1378
        int argc, char **argv,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1379
        int mode, char *what, int ret)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1380
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1381
    ShowSplashScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1382
    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1383
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1384
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1385
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1386
PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1387
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1388
    // stubbed out for windows and *nixes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1389
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1390
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1391
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1392
RegisterThread()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1393
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1394
    // stubbed out for windows and *nixes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1395
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1396
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1397
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1398
 * 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
  1399
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1400
jboolean
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1401
ProcessPlatformOption(const char *arg)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1402
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1403
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9842
diff changeset
  1404
}
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1405
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1406
/*
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1407
 * 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
  1408
 * 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
  1409
 * needs expansion. cmdtoargs will specify this if it finds a bare
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1410
 * (unquoted) argument containing a glob character(s) ie. * or ?
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1411
 */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1412
jobjectArray
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1413
CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1414
{
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1415
    int i, j, idx, tlen;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1416
    jobjectArray outArray, inArray;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1417
    char *ostart, *astart, **nargv;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1418
    jboolean needs_expansion = JNI_FALSE;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1419
    jmethodID mid;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1420
    int stdargc;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1421
    StdArg *stdargs;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1422
    jclass cls = GetLauncherHelperClass(env);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1423
    NULL_CHECK0(cls);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1424
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1425
    if (argc == 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1426
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1427
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1428
    // the holy grail we need to compare with.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1429
    stdargs = JLI_GetStdArgs();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1430
    stdargc = JLI_GetStdArgc();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1431
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1432
    // sanity check, this should never happen
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1433
    if (argc > stdargc) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1434
        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
  1435
        JLI_TraceLauncher("passing arguments as-is.\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1436
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1437
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1438
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1439
    // sanity check, match the args we have, to the holy grail
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1440
    idx = stdargc - argc;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1441
    ostart = stdargs[idx].arg;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1442
    astart = strv[0];
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1443
    // sanity check, ensure that the first argument of the arrays are the same
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1444
    if (JLI_StrCmp(ostart, astart) != 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1445
        // some thing is amiss the args don't match
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1446
        JLI_TraceLauncher("Warning: app args parsing error\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1447
        JLI_TraceLauncher("passing arguments as-is\n");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1448
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1449
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1450
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1451
    // 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
  1452
    nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1453
    for (i = 0, j = idx; i < argc; i++, j++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1454
        jboolean arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1455
                                ? stdargs[j].has_wildcard
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1456
                                : JNI_FALSE;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1457
        if (needs_expansion == JNI_FALSE)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1458
            needs_expansion = arg_expand;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1459
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1460
        // indicator char + String + NULL terminator, the java method will strip
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1461
        // out the first character, the indicator character, so no matter what
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1462
        // we add the indicator
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1463
        tlen = 1 + JLI_StrLen(strv[i]) + 1;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1464
        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
  1465
        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
  1466
                         strv[i]) < 0) {
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1467
            return NULL;
4eb1062acb5b 8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents: 16077
diff changeset
  1468
        }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1469
        JLI_TraceLauncher("%s\n", nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1470
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1471
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1472
    if (!needs_expansion) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1473
        // clean up any allocated memory and return back the old arguments
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1474
        for (i = 0 ; i < argc ; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1475
            JLI_MemFree(nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1476
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1477
        JLI_MemFree(nargv);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1478
        return NewPlatformStringArray(env, strv, argc);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1479
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1480
    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1481
                                                "expandArgs",
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1482
                                                "([Ljava/lang/String;)[Ljava/lang/String;"));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1483
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1484
    // expand the arguments that require expansion, the java method will strip
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1485
    // out the indicator character.
22279
877c94f9476b 8031494: [launcher] java launcher should check for JNI Pending exceptions.
ksrini
parents: 22066
diff changeset
  1486
    NULL_CHECK0(inArray = NewPlatformStringArray(env, nargv, argc));
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1487
    outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1488
    for (i = 0; i < argc; i++) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1489
        JLI_MemFree(nargv[i]);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1490
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1491
    JLI_MemFree(nargv);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1492
    return outArray;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12047
diff changeset
  1493
}