Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/share/native/libjli/java.h
67722 views
1
/*
2
* Copyright (c) 1998, 2020, 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
#define JDK_JAVA_OPTIONS "JDK_JAVA_OPTIONS"
75
76
/*
77
* Pointers to the needed JNI invocation API, initialized by LoadJavaVM.
78
*/
79
typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
80
typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);
81
typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);
82
83
typedef struct {
84
CreateJavaVM_t CreateJavaVM;
85
GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;
86
GetCreatedJavaVMs_t GetCreatedJavaVMs;
87
} InvocationFunctions;
88
89
JNIEXPORT int JNICALL
90
JLI_Launch(int argc, char ** argv, /* main argc, argc */
91
int jargc, const char** jargv, /* java args */
92
int appclassc, const char** appclassv, /* app classpath */
93
const char* fullversion, /* full version defined */
94
const char* dotversion, /* dot version defined */
95
const char* pname, /* program name */
96
const char* lname, /* launcher name */
97
jboolean javaargs, /* JAVA_ARGS */
98
jboolean cpwildcard, /* classpath wildcard */
99
jboolean javaw, /* windows-only javaw */
100
jint ergo_class /* ergnomics policy */
101
);
102
103
/*
104
* Prototypes for launcher functions in the system specific java_md.c.
105
*/
106
107
jboolean
108
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn);
109
110
void
111
GetXUsagePath(char *buf, jint bufsize);
112
113
jboolean
114
GetApplicationHome(char *buf, jint bufsize);
115
116
jboolean
117
GetApplicationHomeFromDll(char *buf, jint bufsize);
118
119
#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
120
121
/*
122
* Different platforms will implement this, here
123
* pargc is a pointer to the original argc,
124
* pargv is a pointer to the original argv,
125
* jrepath is an accessible path to the jre as determined by the call
126
* so_jrepath is the length of the buffer jrepath
127
* jvmpath is an accessible path to the jvm as determined by the call
128
* so_jvmpath is the length of the buffer jvmpath
129
*/
130
void CreateExecutionEnvironment(int *argc, char ***argv,
131
char *jrepath, jint so_jrepath,
132
char *jvmpath, jint so_jvmpath,
133
char *jvmcfg, jint so_jvmcfg);
134
135
/* Reports an error message to stderr or a window as appropriate. */
136
JNIEXPORT void JNICALL
137
JLI_ReportErrorMessage(const char * message, ...);
138
139
/* Reports a system error message to stderr or a window */
140
JNIEXPORT void JNICALL
141
JLI_ReportErrorMessageSys(const char * message, ...);
142
143
/* Reports an error message only to stderr. */
144
JNIEXPORT void JNICALL
145
JLI_ReportMessage(const char * message, ...);
146
147
/* Reports a message only to stdout. */
148
void JLI_ShowMessage(const char * message, ...);
149
150
/*
151
* Reports an exception which terminates the vm to stderr or a window
152
* as appropriate.
153
*/
154
JNIEXPORT void JNICALL
155
JLI_ReportExceptionDescription(JNIEnv * env);
156
void PrintMachineDependentOptions();
157
158
/*
159
* Block current thread and continue execution in new thread.
160
*/
161
int CallJavaMainInNewThread(jlong stack_size, void* args);
162
163
/* sun.java.launcher.* platform properties. */
164
void SetJavaCommandLineProp(char* what, int argc, char** argv);
165
166
/*
167
* Functions defined in java.c and used in java_md.c.
168
*/
169
jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);
170
char *CheckJvmType(int *argc, char ***argv, jboolean speculative);
171
void AddOption(char *str, void *info);
172
jboolean IsWhiteSpaceOption(const char* name);
173
jlong CurrentTimeMicros();
174
175
// Utility function defined in args.c
176
int isTerminalOpt(char *arg);
177
jboolean IsJavaw();
178
179
int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
180
int argc, char** argv,
181
int mode, char *what, int ret);
182
183
int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
184
int argc, char** argv,
185
int mode, char *what, int ret);
186
187
/*
188
* Initialize platform specific settings
189
*/
190
void InitLauncher(jboolean javaw);
191
192
/*
193
* For MacOSX and Windows/Unix compatibility we require these
194
* entry points, some of them may be stubbed out on Windows/Unixes.
195
*/
196
void PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm);
197
void ShowSplashScreen();
198
void RegisterThread();
199
/*
200
* this method performs additional platform specific processing and
201
* should return JNI_TRUE to indicate the argument has been consumed,
202
* otherwise returns JNI_FALSE to allow the calling logic to further
203
* process the option.
204
*/
205
jboolean ProcessPlatformOption(const char *arg);
206
207
/*
208
* This allows for finding classes from the VM's bootstrap class loader directly,
209
* FindClass uses the application class loader internally, this will cause
210
* unnecessary searching of the classpath for the required classes.
211
*
212
*/
213
typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,
214
const char *name));
215
jclass FindBootStrapClass(JNIEnv *env, const char *classname);
216
217
jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc);
218
jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
219
jclass GetLauncherHelperClass(JNIEnv *env);
220
221
/*
222
* Entry point.
223
*/
224
int JavaMain(void* args);
225
226
enum LaunchMode { // cf. sun.launcher.LauncherHelper
227
LM_UNKNOWN = 0,
228
LM_CLASS,
229
LM_JAR,
230
LM_MODULE,
231
LM_SOURCE
232
};
233
234
static const char *launchModeNames[]
235
= { "Unknown", "Main class", "JAR file", "Module", "Source" };
236
237
typedef struct {
238
int argc;
239
char **argv;
240
int mode;
241
char *what;
242
InvocationFunctions ifn;
243
} JavaMainArgs;
244
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)
252
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, )
258
259
#define CHECK_EXCEPTION_RETURN_VALUE(CER_value) \
260
do { \
261
if ((*env)->ExceptionOccurred(env)) { \
262
return CER_value; \
263
} \
264
} while (JNI_FALSE)
265
266
#define CHECK_EXCEPTION_RETURN() \
267
do { \
268
if ((*env)->ExceptionOccurred(env)) { \
269
return; \
270
} \
271
} while (JNI_FALSE)
272
273
#endif /* _JAVA_H_ */
274
275