Path: blob/master/src/java.base/share/native/libjli/java.h
67722 views
/*1* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef _JAVA_H_26#define _JAVA_H_2728#include <stdio.h>29#include <stdlib.h>30#include <string.h>31#include <limits.h>3233#include <jni.h>34#include <jvm.h>3536/*37* Get system specific defines.38*/39#include "emessages.h"40#include "java_md.h"41#include "jli_util.h"42#include "manifest_info.h"43#include "wildcard.h"44#include "splashscreen.h"4546# define KB (1024UL)47# define MB (1024UL * KB)48# define GB (1024UL * MB)4950#define CURRENT_DATA_MODEL (CHAR_BIT * sizeof(void*))5152/*53* The following environment variable is used to influence the behavior54* of the jre exec'd through the SelectVersion routine. The command line55* options which specify the version are not passed to the exec'd version,56* because that jre may be an older version which wouldn't recognize them.57* This environment variable is known to this (and later) version and serves58* to suppress the version selection code. This is not only for efficiency,59* but also for correctness, since any command line options have been60* removed which would cause any value found in the manifest to be used.61* This would be incorrect because the command line options are defined62* to take precedence.63*64* The value associated with this environment variable is the MainClass65* name from within the executable jar file (if any). This is strictly a66* performance enhancement to avoid re-reading the jar file manifest.67*68*/69#define ENV_ENTRY "_JAVA_VERSION_SET"7071#define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE"72#define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR"73#define JDK_JAVA_OPTIONS "JDK_JAVA_OPTIONS"7475/*76* Pointers to the needed JNI invocation API, initialized by LoadJavaVM.77*/78typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);79typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);80typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);8182typedef struct {83CreateJavaVM_t CreateJavaVM;84GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;85GetCreatedJavaVMs_t GetCreatedJavaVMs;86} InvocationFunctions;8788JNIEXPORT int JNICALL89JLI_Launch(int argc, char ** argv, /* main argc, argc */90int jargc, const char** jargv, /* java args */91int appclassc, const char** appclassv, /* app classpath */92const char* fullversion, /* full version defined */93const char* dotversion, /* dot version defined */94const char* pname, /* program name */95const char* lname, /* launcher name */96jboolean javaargs, /* JAVA_ARGS */97jboolean cpwildcard, /* classpath wildcard */98jboolean javaw, /* windows-only javaw */99jint ergo_class /* ergnomics policy */100);101102/*103* Prototypes for launcher functions in the system specific java_md.c.104*/105106jboolean107LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn);108109void110GetXUsagePath(char *buf, jint bufsize);111112jboolean113GetApplicationHome(char *buf, jint bufsize);114115jboolean116GetApplicationHomeFromDll(char *buf, jint bufsize);117118#define GetArch() GetArchPath(CURRENT_DATA_MODEL)119120/*121* Different platforms will implement this, here122* pargc is a pointer to the original argc,123* pargv is a pointer to the original argv,124* jrepath is an accessible path to the jre as determined by the call125* so_jrepath is the length of the buffer jrepath126* jvmpath is an accessible path to the jvm as determined by the call127* so_jvmpath is the length of the buffer jvmpath128*/129void CreateExecutionEnvironment(int *argc, char ***argv,130char *jrepath, jint so_jrepath,131char *jvmpath, jint so_jvmpath,132char *jvmcfg, jint so_jvmcfg);133134/* Reports an error message to stderr or a window as appropriate. */135JNIEXPORT void JNICALL136JLI_ReportErrorMessage(const char * message, ...);137138/* Reports a system error message to stderr or a window */139JNIEXPORT void JNICALL140JLI_ReportErrorMessageSys(const char * message, ...);141142/* Reports an error message only to stderr. */143JNIEXPORT void JNICALL144JLI_ReportMessage(const char * message, ...);145146/* Reports a message only to stdout. */147void JLI_ShowMessage(const char * message, ...);148149/*150* Reports an exception which terminates the vm to stderr or a window151* as appropriate.152*/153JNIEXPORT void JNICALL154JLI_ReportExceptionDescription(JNIEnv * env);155void PrintMachineDependentOptions();156157/*158* Block current thread and continue execution in new thread.159*/160int CallJavaMainInNewThread(jlong stack_size, void* args);161162/* sun.java.launcher.* platform properties. */163void SetJavaCommandLineProp(char* what, int argc, char** argv);164165/*166* Functions defined in java.c and used in java_md.c.167*/168jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);169char *CheckJvmType(int *argc, char ***argv, jboolean speculative);170void AddOption(char *str, void *info);171jboolean IsWhiteSpaceOption(const char* name);172jlong CurrentTimeMicros();173174// Utility function defined in args.c175int isTerminalOpt(char *arg);176jboolean IsJavaw();177178int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,179int argc, char** argv,180int mode, char *what, int ret);181182int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,183int argc, char** argv,184int mode, char *what, int ret);185186/*187* Initialize platform specific settings188*/189void InitLauncher(jboolean javaw);190191/*192* For MacOSX and Windows/Unix compatibility we require these193* entry points, some of them may be stubbed out on Windows/Unixes.194*/195void PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm);196void ShowSplashScreen();197void RegisterThread();198/*199* this method performs additional platform specific processing and200* should return JNI_TRUE to indicate the argument has been consumed,201* otherwise returns JNI_FALSE to allow the calling logic to further202* process the option.203*/204jboolean ProcessPlatformOption(const char *arg);205206/*207* This allows for finding classes from the VM's bootstrap class loader directly,208* FindClass uses the application class loader internally, this will cause209* unnecessary searching of the classpath for the required classes.210*211*/212typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,213const char *name));214jclass FindBootStrapClass(JNIEnv *env, const char *classname);215216jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc);217jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);218jclass GetLauncherHelperClass(JNIEnv *env);219220/*221* Entry point.222*/223int JavaMain(void* args);224225enum LaunchMode { // cf. sun.launcher.LauncherHelper226LM_UNKNOWN = 0,227LM_CLASS,228LM_JAR,229LM_MODULE,230LM_SOURCE231};232233static const char *launchModeNames[]234= { "Unknown", "Main class", "JAR file", "Module", "Source" };235236typedef struct {237int argc;238char **argv;239int mode;240char *what;241InvocationFunctions ifn;242} JavaMainArgs;243244#define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \245do { \246if ((NCRV_check_pointer) == NULL) { \247JLI_ReportErrorMessage(JNI_ERROR); \248return NCRV_return_value; \249} \250} while (JNI_FALSE)251252#define NULL_CHECK0(NC0_check_pointer) \253NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0)254255#define NULL_CHECK(NC_check_pointer) \256NULL_CHECK_RETURN_VALUE(NC_check_pointer, )257258#define CHECK_EXCEPTION_RETURN_VALUE(CER_value) \259do { \260if ((*env)->ExceptionOccurred(env)) { \261return CER_value; \262} \263} while (JNI_FALSE)264265#define CHECK_EXCEPTION_RETURN() \266do { \267if ((*env)->ExceptionOccurred(env)) { \268return; \269} \270} while (JNI_FALSE)271272#endif /* _JAVA_H_ */273274275