duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
ksrini | 07e328d | 2013-05-07 13:15:28 -0700 | [diff] [blame] | 2 | * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. Oracle designates this |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef _JAVA_H_ |
| 27 | #define _JAVA_H_ |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <limits.h> |
| 33 | |
| 34 | #include <jni.h> |
| 35 | #include <jvm.h> |
| 36 | |
| 37 | /* |
| 38 | * Get system specific defines. |
| 39 | */ |
| 40 | #include "emessages.h" |
| 41 | #include "java_md.h" |
| 42 | #include "jli_util.h" |
| 43 | |
| 44 | #include "manifest_info.h" |
| 45 | #include "version_comp.h" |
| 46 | #include "wildcard.h" |
| 47 | #include "splashscreen.h" |
| 48 | |
| 49 | # define KB (1024UL) |
| 50 | # define MB (1024UL * KB) |
| 51 | # define GB (1024UL * MB) |
| 52 | |
| 53 | #define CURRENT_DATA_MODEL (CHAR_BIT * sizeof(void*)) |
| 54 | |
| 55 | /* |
| 56 | * The following environment variable is used to influence the behavior |
| 57 | * of the jre exec'd through the SelectVersion routine. The command line |
| 58 | * options which specify the version are not passed to the exec'd version, |
| 59 | * because that jre may be an older version which wouldn't recognize them. |
| 60 | * This environment variable is known to this (and later) version and serves |
| 61 | * to suppress the version selection code. This is not only for efficiency, |
| 62 | * but also for correctness, since any command line options have been |
| 63 | * removed which would cause any value found in the manifest to be used. |
| 64 | * This would be incorrect because the command line options are defined |
| 65 | * to take precedence. |
| 66 | * |
| 67 | * The value associated with this environment variable is the MainClass |
| 68 | * name from within the executable jar file (if any). This is strictly a |
| 69 | * performance enhancement to avoid re-reading the jar file manifest. |
| 70 | * |
| 71 | */ |
| 72 | #define ENV_ENTRY "_JAVA_VERSION_SET" |
| 73 | |
| 74 | #define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE" |
| 75 | #define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR" |
| 76 | |
| 77 | /* |
| 78 | * Pointers to the needed JNI invocation API, initialized by LoadJavaVM. |
| 79 | */ |
| 80 | typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args); |
| 81 | typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args); |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 82 | typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 83 | |
| 84 | typedef struct { |
| 85 | CreateJavaVM_t CreateJavaVM; |
| 86 | GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs; |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 87 | GetCreatedJavaVMs_t GetCreatedJavaVMs; |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 88 | } InvocationFunctions; |
| 89 | |
| 90 | int |
| 91 | JLI_Launch(int argc, char ** argv, /* main argc, argc */ |
| 92 | int jargc, const char** jargv, /* java args */ |
| 93 | int appclassc, const char** appclassv, /* app classpath */ |
| 94 | const char* fullversion, /* full version defined */ |
| 95 | const char* dotversion, /* dot version defined */ |
| 96 | const char* pname, /* program name */ |
| 97 | const char* lname, /* launcher name */ |
| 98 | jboolean javaargs, /* JAVA_ARGS */ |
| 99 | jboolean cpwildcard, /* classpath wildcard */ |
| 100 | jboolean javaw, /* windows-only javaw */ |
| 101 | jint ergo_class /* ergnomics policy */ |
| 102 | ); |
| 103 | |
| 104 | /* |
| 105 | * Prototypes for launcher functions in the system specific java_md.c. |
| 106 | */ |
| 107 | |
| 108 | jboolean |
| 109 | LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn); |
| 110 | |
| 111 | void |
| 112 | GetXUsagePath(char *buf, jint bufsize); |
| 113 | |
| 114 | jboolean |
| 115 | GetApplicationHome(char *buf, jint bufsize); |
| 116 | |
| 117 | #define GetArch() GetArchPath(CURRENT_DATA_MODEL) |
| 118 | |
ksrini | e3ec45d | 2010-07-09 11:04:34 -0700 | [diff] [blame] | 119 | /* |
| 120 | * Different platforms will implement this, here |
| 121 | * pargc is a pointer to the original argc, |
| 122 | * pargv is a pointer to the original argv, |
| 123 | * jrepath is an accessible path to the jre as determined by the call |
| 124 | * so_jrepath is the length of the buffer jrepath |
| 125 | * jvmpath is an accessible path to the jvm as determined by the call |
| 126 | * so_jvmpath is the length of the buffer jvmpath |
| 127 | */ |
| 128 | void CreateExecutionEnvironment(int *argc, char ***argv, |
| 129 | char *jrepath, jint so_jrepath, |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 130 | char *jvmpath, jint so_jvmpath, |
| 131 | char *jvmcfg, jint so_jvmcfg); |
ksrini | e3ec45d | 2010-07-09 11:04:34 -0700 | [diff] [blame] | 132 | |
ksrini | 0e81716 | 2008-08-26 10:21:20 -0700 | [diff] [blame] | 133 | /* Reports an error message to stderr or a window as appropriate. */ |
| 134 | void JLI_ReportErrorMessage(const char * message, ...); |
| 135 | |
| 136 | /* Reports a system error message to stderr or a window */ |
| 137 | void JLI_ReportErrorMessageSys(const char * message, ...); |
| 138 | |
| 139 | /* Reports an error message only to stderr. */ |
| 140 | void JLI_ReportMessage(const char * message, ...); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 141 | |
| 142 | /* |
ksrini | 0e81716 | 2008-08-26 10:21:20 -0700 | [diff] [blame] | 143 | * Reports an exception which terminates the vm to stderr or a window |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 144 | * as appropriate. |
| 145 | */ |
ksrini | 0e81716 | 2008-08-26 10:21:20 -0700 | [diff] [blame] | 146 | void JLI_ReportExceptionDescription(JNIEnv * env); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 147 | void PrintMachineDependentOptions(); |
| 148 | |
| 149 | const char *jlong_format_specifier(); |
| 150 | |
| 151 | /* |
| 152 | * Block current thread and continue execution in new thread |
| 153 | */ |
| 154 | int ContinueInNewThread0(int (JNICALL *continuation)(void *), |
| 155 | jlong stack_size, void * args); |
| 156 | |
| 157 | /* sun.java.launcher.* platform properties. */ |
| 158 | void SetJavaLauncherPlatformProps(void); |
mchung | ea290e2 | 2011-01-21 09:43:57 -0800 | [diff] [blame] | 159 | void SetJavaCommandLineProp(char* what, int argc, char** argv); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 160 | void SetJavaLauncherProp(void); |
| 161 | |
| 162 | /* |
| 163 | * Functions defined in java.c and used in java_md.c. |
| 164 | */ |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 165 | jint ReadKnownVMs(const char *jvmcfg, jboolean speculative); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 166 | char *CheckJvmType(int *argc, char ***argv, jboolean speculative); |
| 167 | void AddOption(char *str, void *info); |
| 168 | |
| 169 | enum ergo_policy { |
| 170 | DEFAULT_POLICY = 0, |
| 171 | NEVER_SERVER_CLASS, |
| 172 | ALWAYS_SERVER_CLASS |
| 173 | }; |
| 174 | |
| 175 | const char* GetProgramName(); |
| 176 | const char* GetDotVersion(); |
| 177 | const char* GetFullVersion(); |
| 178 | jboolean IsJavaArgs(); |
| 179 | jboolean IsJavaw(); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 180 | jint GetErgoPolicy(); |
| 181 | |
| 182 | jboolean ServerClassMachine(); |
| 183 | |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 184 | int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize, |
| 185 | int argc, char** argv, |
| 186 | int mode, char *what, int ret); |
| 187 | |
| 188 | int JVMInit(InvocationFunctions* ifn, jlong threadStackSize, |
| 189 | int argc, char** argv, |
| 190 | int mode, char *what, int ret); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 191 | |
ksrini | 52cded2 | 2008-03-06 07:51:28 -0800 | [diff] [blame] | 192 | /* |
| 193 | * Initialize platform specific settings |
| 194 | */ |
| 195 | void InitLauncher(jboolean javaw); |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 196 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 197 | /* |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 198 | * For MacOSX and Windows/Unix compatibility we require these |
| 199 | * entry points, some of them may be stubbed out on Windows/Unixes. |
| 200 | */ |
| 201 | void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm); |
| 202 | void ShowSplashScreen(); |
| 203 | void RegisterThread(); |
| 204 | /* |
| 205 | * this method performs additional platform specific processing and |
| 206 | * should return JNI_TRUE to indicate the argument has been consumed, |
| 207 | * otherwise returns JNI_FALSE to allow the calling logic to further |
| 208 | * process the option. |
| 209 | */ |
| 210 | jboolean ProcessPlatformOption(const char *arg); |
| 211 | |
| 212 | /* |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 213 | * This allows for finding classes from the VM's bootstrap class loader directly, |
| 214 | * FindClass uses the application class loader internally, this will cause |
| 215 | * unnecessary searching of the classpath for the required classes. |
| 216 | * |
| 217 | */ |
| 218 | typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env, |
mchung | b2ce941 | 2009-08-06 16:35:24 -0700 | [diff] [blame] | 219 | const char *name)); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 220 | jclass FindBootStrapClass(JNIEnv *env, const char *classname); |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 221 | |
ksrini | e97d400 | 2012-07-31 06:14:28 -0700 | [diff] [blame] | 222 | jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc); |
| 223 | jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); |
| 224 | jclass GetLauncherHelperClass(JNIEnv *env); |
| 225 | |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 226 | int JNICALL JavaMain(void * args); /* entry point */ |
| 227 | |
| 228 | enum LaunchMode { // cf. sun.launcher.LauncherHelper |
| 229 | LM_UNKNOWN = 0, |
| 230 | LM_CLASS, |
| 231 | LM_JAR |
| 232 | }; |
| 233 | |
| 234 | static const char *launchModeNames[] |
| 235 | = { "Unknown", "Main class", "JAR file" }; |
| 236 | |
| 237 | typedef struct { |
| 238 | int argc; |
| 239 | char **argv; |
| 240 | int mode; |
| 241 | char *what; |
| 242 | InvocationFunctions ifn; |
| 243 | } JavaMainArgs; |
| 244 | |
ksrini | 07e328d | 2013-05-07 13:15:28 -0700 | [diff] [blame] | 245 | #define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \ |
| 246 | do { \ |
| 247 | if ((NCRV_check_pointer) == NULL) { \ |
| 248 | JLI_ReportErrorMessage(JNI_ERROR); \ |
| 249 | return NCRV_return_value; \ |
| 250 | } \ |
| 251 | } while (JNI_FALSE) |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 252 | |
ksrini | 07e328d | 2013-05-07 13:15:28 -0700 | [diff] [blame] | 253 | #define NULL_CHECK0(NC0_check_pointer) \ |
| 254 | NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0) |
| 255 | |
| 256 | #define NULL_CHECK(NC_check_pointer) \ |
| 257 | NULL_CHECK_RETURN_VALUE(NC_check_pointer, ) |
michaelm | 5ac8c15 | 2012-03-06 20:34:38 +0000 | [diff] [blame] | 258 | |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 259 | #endif /* _JAVA_H_ */ |