Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/bin/java.h
38767 views
/*1* Copyright (c) 1998, 2015, 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"4243#include "manifest_info.h"44#include "version_comp.h"45#include "wildcard.h"46#include "splashscreen.h"4748# define KB (1024UL)49# define MB (1024UL * KB)50# define GB (1024UL * MB)5152#define CURRENT_DATA_MODEL (CHAR_BIT * sizeof(void*))5354/*55* The following environment variable is used to influence the behavior56* of the jre exec'd through the SelectVersion routine. The command line57* options which specify the version are not passed to the exec'd version,58* because that jre may be an older version which wouldn't recognize them.59* This environment variable is known to this (and later) version and serves60* to suppress the version selection code. This is not only for efficiency,61* but also for correctness, since any command line options have been62* removed which would cause any value found in the manifest to be used.63* This would be incorrect because the command line options are defined64* to take precedence.65*66* The value associated with this environment variable is the MainClass67* name from within the executable jar file (if any). This is strictly a68* performance enhancement to avoid re-reading the jar file manifest.69*70*/71#define ENV_ENTRY "_JAVA_VERSION_SET"7273#define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE"74#define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR"7576/*77* Pointers to the needed JNI invocation API, initialized by LoadJavaVM.78*/79typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);80typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);81typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);8283typedef struct {84CreateJavaVM_t CreateJavaVM;85GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;86GetCreatedJavaVMs_t GetCreatedJavaVMs;87} InvocationFunctions;8889int90JLI_Launch(int argc, char ** argv, /* main argc, argc */91int jargc, const char** jargv, /* java args */92int appclassc, const char** appclassv, /* app classpath */93const char* fullversion, /* full version defined */94const char* dotversion, /* dot version defined */95const char* pname, /* program name */96const char* lname, /* launcher name */97jboolean javaargs, /* JAVA_ARGS */98jboolean cpwildcard, /* classpath wildcard */99jboolean javaw, /* windows-only javaw */100jint ergo_class /* ergnomics policy */101);102103/*104* Prototypes for launcher functions in the system specific java_md.c.105*/106107jboolean108LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn);109110void111GetXUsagePath(char *buf, jint bufsize);112113jboolean114GetApplicationHome(char *buf, jint bufsize);115116#define GetArch() GetArchPath(CURRENT_DATA_MODEL)117118/*119* Different platforms will implement this, here120* pargc is a pointer to the original argc,121* pargv is a pointer to the original argv,122* jrepath is an accessible path to the jre as determined by the call123* so_jrepath is the length of the buffer jrepath124* jvmpath is an accessible path to the jvm as determined by the call125* so_jvmpath is the length of the buffer jvmpath126*/127void CreateExecutionEnvironment(int *argc, char ***argv,128char *jrepath, jint so_jrepath,129char *jvmpath, jint so_jvmpath,130char *jvmcfg, jint so_jvmcfg);131132/* Reports an error message to stderr or a window as appropriate. */133void JLI_ReportErrorMessage(const char * message, ...);134135/* Reports a system error message to stderr or a window */136void JLI_ReportErrorMessageSys(const char * message, ...);137138/* Reports an error message only to stderr. */139void JLI_ReportMessage(const char * message, ...);140141/*142* Reports an exception which terminates the vm to stderr or a window143* as appropriate.144*/145void JLI_ReportExceptionDescription(JNIEnv * env);146void PrintMachineDependentOptions();147148const char *jlong_format_specifier();149150/*151* Block current thread and continue execution in new thread152*/153int ContinueInNewThread0(int (JNICALL *continuation)(void *),154jlong stack_size, void * args);155156/* sun.java.launcher.* platform properties. */157void SetJavaLauncherPlatformProps(void);158void SetJavaCommandLineProp(char* what, int argc, char** argv);159void SetJavaLauncherProp(void);160161/*162* Functions defined in java.c and used in java_md.c.163*/164jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);165char *CheckJvmType(int *argc, char ***argv, jboolean speculative);166void AddOption(char *str, void *info);167168enum ergo_policy {169DEFAULT_POLICY = 0,170NEVER_SERVER_CLASS,171ALWAYS_SERVER_CLASS172};173174const char* GetProgramName();175const char* GetDotVersion();176const char* GetFullVersion();177jboolean IsJavaArgs();178jboolean IsJavaw();179jint GetErgoPolicy();180181jboolean ServerClassMachine();182183int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,184int argc, char** argv,185int mode, char *what, int ret);186187int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,188int argc, char** argv,189int mode, char *what, int ret);190191/*192* Initialize platform specific settings193*/194void InitLauncher(jboolean javaw);195196/*197* For MacOSX and Windows/Unix compatibility we require these198* entry points, some of them may be stubbed out on Windows/Unixes.199*/200void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm);201void ShowSplashScreen();202void RegisterThread();203/*204* this method performs additional platform specific processing and205* should return JNI_TRUE to indicate the argument has been consumed,206* otherwise returns JNI_FALSE to allow the calling logic to further207* process the option.208*/209jboolean ProcessPlatformOption(const char *arg);210211/*212* This allows for finding classes from the VM's bootstrap class loader directly,213* FindClass uses the application class loader internally, this will cause214* unnecessary searching of the classpath for the required classes.215*216*/217typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,218const char *name));219jclass FindBootStrapClass(JNIEnv *env, const char *classname);220221jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc);222jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);223jclass GetLauncherHelperClass(JNIEnv *env);224225int JNICALL JavaMain(void * args); /* entry point */226227enum LaunchMode { // cf. sun.launcher.LauncherHelper228LM_UNKNOWN = 0,229LM_CLASS,230LM_JAR231};232233static const char *launchModeNames[]234= { "Unknown", "Main class", "JAR file" };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() \259do { \260if ((*env)->ExceptionOccurred(env)) { \261return; \262} \263} while (JNI_FALSE)264265/*266* For JNI calls :267* - check for thrown exceptions268* - check for null return269*270* JNI calls can return null and/or throw an exception. Check for these.271*272* : CHECK_JNI_RETURN_EXCEPTION()273* return the specified RETURNVALUE if exception was generated274* : CHECK_JNI_RETURN_0(JNISTATEMENT) : check if JNISTATEMENT was successful, return 0 if not275* : CHECK_JNI_RETURN_VOID(JNISTATEMENT) : check if JNISTATEMENT was successful, return void if not276* : CHECK_JNI_RETURN_VALUE(JNISTATEMENT,n) : check if JNISTATEMENT was successful, return n if not277*278* These macros need at least one parameter, the JNI statement [ JNISTATEMENT ].279*280* E.G.: check the JNI statement, and specify a value to return if a failure was detected.281*282* CHECK_JNI_RETURN_VALUE(str = (*env)->CallStaticObjectMethod(env, cls,283* makePlatformStringMID, USE_STDERR, ary), -1);284*/285286#define RETURNVOID return287#define RETURN0 return 0288#define RETURN(N) return (N)289290#define CHECK_JNI_RETURN_EXCEPTION(RETURNVALUE) \291if ((((*env)->ExceptionOccurred(env))!=NULL)) { \292RETURNVALUE; \293}294295#define CHECK_JNI_RETURN_0(JNISTATEMENT) \296CHECK_JNI_RETURN_EXCEPTION(RETURN0); \297NULL_CHECK0(JNISTATEMENT);298299#define CHECK_JNI_RETURN_VOID(JNISTATEMENT) \300CHECK_JNI_RETURN_EXCEPTION(RETURNVOID); \301NULL_CHECK(JNISTATEMENT);302303#define CHECK_JNI_RETURN_VALUE(JNISTATEMENT, NCRV_return_value) \304CHECK_JNI_RETURN_EXCEPTION(RETURN(NCRV_return_value)); \305NULL_CHECK_RETURN_VALUE(JNISTATEMENT, NCRV_return_value);306307308#endif /* _JAVA_H_ */309310311