1 /* 2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 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 #include "manifest_info.h" 44 #include "wildcard.h" 45 #include "splashscreen.h" 46 47 # define KB (1024UL) 48 # define MB (1024UL * KB) 49 # define GB (1024UL * MB) 50 51 #define CURRENT_DATA_MODEL (CHAR_BIT * sizeof(void*)) 52 53 /* 54 * The following environment variable is used to influence the behavior 55 * of the jre exec'd through the SelectVersion routine. The command line 56 * options which specify the version are not passed to the exec'd version, 57 * because that jre may be an older version which wouldn't recognize them. 58 * This environment variable is known to this (and later) version and serves 59 * to suppress the version selection code. This is not only for efficiency, 60 * but also for correctness, since any command line options have been 61 * removed which would cause any value found in the manifest to be used. 62 * This would be incorrect because the command line options are defined 63 * to take precedence. 64 * 65 * The value associated with this environment variable is the MainClass 66 * name from within the executable jar file (if any). This is strictly a 67 * performance enhancement to avoid re-reading the jar file manifest. 68 * 69 */ 70 #define ENV_ENTRY "_JAVA_VERSION_SET" 71 72 #define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE" 73 #define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR" 74 75 /* 76 * Pointers to the needed JNI invocation API, initialized by LoadJavaVM. 77 */ 78 typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args); 79 typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args); 80 typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs); 81 82 typedef struct { 83 CreateJavaVM_t CreateJavaVM; 84 GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs; 85 GetCreatedJavaVMs_t GetCreatedJavaVMs; 86 } InvocationFunctions; 87 88 int 89 JLI_Launch(int argc, char ** argv, /* main argc, argc */ 90 int jargc, const char** jargv, /* java args */ 91 int appclassc, const char** appclassv, /* app classpath */ 92 const char* fullversion, /* full version defined */ 93 const char* dotversion, /* dot version defined */ 94 const char* pname, /* program name */ 95 const char* lname, /* launcher name */ 96 jboolean javaargs, /* JAVA_ARGS */ 97 jboolean cpwildcard, /* classpath wildcard */ 98 jboolean javaw, /* windows-only javaw */ 99 jint ergo_class /* ergnomics policy */ 100 ); 101 102 /* 103 * Prototypes for launcher functions in the system specific java_md.c. 104 */ 105 106 jboolean 107 LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn); 108 109 void 110 GetXUsagePath(char *buf, jint bufsize); 111 112 jboolean 113 GetApplicationHome(char *buf, jint bufsize); 114 115 #define GetArch() GetArchPath(CURRENT_DATA_MODEL) 116 117 /* 118 * Different platforms will implement this, here 119 * pargc is a pointer to the original argc, 120 * pargv is a pointer to the original argv, 121 * jrepath is an accessible path to the jre as determined by the call 122 * so_jrepath is the length of the buffer jrepath 123 * jvmpath is an accessible path to the jvm as determined by the call 124 * so_jvmpath is the length of the buffer jvmpath 125 */ 126 void CreateExecutionEnvironment(int *argc, char ***argv, 127 char *jrepath, jint so_jrepath, 128 char *jvmpath, jint so_jvmpath, 129 char *jvmcfg, jint so_jvmcfg); 130 131 /* Reports an error message to stderr or a window as appropriate. */ 132 void JLI_ReportErrorMessage(const char * message, ...); 133 134 /* Reports a system error message to stderr or a window */ 135 void JLI_ReportErrorMessageSys(const char * message, ...); 136 137 /* Reports an error message only to stderr. */ 138 void JLI_ReportMessage(const char * message, ...); 139 140 /* 141 * Reports an exception which terminates the vm to stderr or a window 142 * as appropriate. 143 */ 144 void JLI_ReportExceptionDescription(JNIEnv * env); 145 void PrintMachineDependentOptions(); 146 147 const char *jlong_format_specifier(); 148 149 /* 150 * Block current thread and continue execution in new thread 151 */ 152 int ContinueInNewThread0(int (JNICALL *continuation)(void *), 153 jlong stack_size, void * args); 154 155 /* sun.java.launcher.* platform properties. */ 156 void SetJavaLauncherPlatformProps(void); 157 void SetJavaCommandLineProp(char* what, int argc, char** argv); 158 void SetJavaLauncherProp(void); 159 160 /* 161 * Functions defined in java.c and used in java_md.c. 162 */ 163 jint ReadKnownVMs(const char *jvmcfg, jboolean speculative); 164 char *CheckJvmType(int *argc, char ***argv, jboolean speculative); 165 void AddOption(char *str, void *info); 166 167 enum ergo_policy { 168 DEFAULT_POLICY = 0, 169 NEVER_SERVER_CLASS, 170 ALWAYS_SERVER_CLASS 171 }; 172 173 const char* GetProgramName(); 174 const char* GetDotVersion(); 175 const char* GetFullVersion(); 176 jboolean IsJavaArgs(); 177 jboolean IsJavaw(); 178 jint GetErgoPolicy(); 179 180 jboolean ServerClassMachine(); 181 182 int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize, 183 int argc, char** argv, 184 int mode, char *what, int ret); 185 186 int JVMInit(InvocationFunctions* ifn, jlong threadStackSize, 187 int argc, char** argv, 188 int mode, char *what, int ret); 189 190 /* 191 * Initialize platform specific settings 192 */ 193 void InitLauncher(jboolean javaw); 194 195 /* 196 * For MacOSX and Windows/Unix compatibility we require these 197 * entry points, some of them may be stubbed out on Windows/Unixes. 198 */ 199 void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm); 200 void ShowSplashScreen(); 201 void RegisterThread(); 202 /* 203 * this method performs additional platform specific processing and 204 * should return JNI_TRUE to indicate the argument has been consumed, 205 * otherwise returns JNI_FALSE to allow the calling logic to further 206 * process the option. 207 */ 208 jboolean ProcessPlatformOption(const char *arg); 209 210 /* 211 * This allows for finding classes from the VM's bootstrap class loader directly, 212 * FindClass uses the application class loader internally, this will cause 213 * unnecessary searching of the classpath for the required classes. 214 * 215 */ 216 typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env, 217 const char *name)); 218 jclass FindBootStrapClass(JNIEnv *env, const char *classname); 219 220 jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc); 221 jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); 222 jclass GetLauncherHelperClass(JNIEnv *env); 223 224 int JNICALL JavaMain(void * args); /* entry point */ 225 226 enum LaunchMode { // cf. sun.launcher.LauncherHelper 227 LM_UNKNOWN = 0, 228 LM_CLASS, 229 LM_JAR 230 }; 231 232 static const char *launchModeNames[] 233 = { "Unknown", "Main class", "JAR file" }; 234 235 typedef struct { 236 int argc; 237 char **argv; 238 int mode; 239 char *what; 240 InvocationFunctions ifn; 241 } JavaMainArgs; 242 243 #define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \ 244 do { \ 245 if ((NCRV_check_pointer) == NULL) { \ 246 JLI_ReportErrorMessage(JNI_ERROR); \ 247 return NCRV_return_value; \ 248 } \ 249 } while (JNI_FALSE) 250 251 #define NULL_CHECK0(NC0_check_pointer) \ 252 NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0) 253 254 #define NULL_CHECK(NC_check_pointer) \ 255 NULL_CHECK_RETURN_VALUE(NC_check_pointer, ) 256 257 #define CHECK_EXCEPTION_RETURN() \ 258 do { \ 259 if ((*env)->ExceptionOccurred(env)) { \ 260 return; \ 261 } \ 262 } while (JNI_FALSE) 263 264 #endif /* _JAVA_H_ */