Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/include/vmi.h
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
/**
24
* @file
25
* @ingroup VMInterface
26
* @brief VM interface specification
27
*/
28
29
#ifndef vmi_h
30
#define vmi_h
31
32
/* @ddr_namespace: default */
33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36
37
#include "j9cfg.h"
38
#include "jni.h"
39
#include "j9port.h"
40
41
#if defined(J9VM_OPT_VM_LOCAL_STORAGE)
42
#include "j9vmls.h"
43
#endif
44
45
/**
46
* @enum vmiError
47
* Enumeration of all possible return codes from VM interface functions
48
*/
49
typedef enum
50
{
51
VMI_ERROR_NONE = 0, /**< Success */
52
VMI_ERROR_UNKNOWN = 1, /**< Unknown error */
53
VMI_ERROR_UNIMPLEMENTED = 2, /**< Function has not been implemented */
54
VMI_ERROR_UNSUPPORTED_VERSION = 3, /**< The requested VM interface version is not supported */
55
VMI_ERROR_OUT_OF_MEMORY= 4, /**< Not enough memory was available to complete the request */
56
VMI_ERROR_NOT_FOUND= 5, /**< The requested system property was not found */
57
VMI_ERROR_READ_ONLY= 6, /**< An attempt was made to modify a read-only item */
58
VMI_ERROR_INITIALIZATION_FAILED = 7, /**< Initialization of the VM interface failed */
59
60
vmiErrorEnsureWideEnum = 0x1000000 /* ensure 4-byte enum */
61
} vmiError;
62
63
/**
64
* @enum vmiVersion
65
* VM interface version identifier
66
*/
67
typedef enum
68
{
69
VMI_VERSION_UNKNOWN = 0x00000000, /**< Unknown VMInterface version */
70
VMI_VERSION_1_0 = 0x00010000, /**< VMInterface version 1.0 */
71
VMI_VERSION_2_0 = 0x00020000, /**< VMInterface version 2.0 */
72
vmiVersionEnsureWideEnum = 0x1000000 /* ensure 4-byte enum */
73
} vmiVersion;
74
75
/**
76
* @typedef vmiSystemPropertyIterator
77
* Specification of the iterator function to provide to IterateSystemProperties
78
*
79
* @code void iterator(char* key, char* value, void* userData); @endcode
80
*/
81
typedef void (JNICALL *vmiSystemPropertyIterator)(char* key, char* value, void* userData);
82
83
struct VMInterface_;
84
struct VMInterfaceFunctions_;
85
86
/**
87
* @typedef VMInterface
88
* The VM interface structure. Points to the @ref VMInterfaceFunctions_ "VM interface function table".
89
* Implementations will likely choose to store opaque data off this structure.
90
*/
91
typedef const struct VMInterfaceFunctions_* VMInterface;
92
93
#if defined(J9VM_OPT_ZIP_SUPPORT)
94
#include "vmizip.h"
95
#endif
96
97
/**
98
* @struct VMInterfaceFunctions_
99
* The VM interface function table.
100
*
101
* Example usage:
102
* @code
103
* JavaVM* vm = (*vmi)->GetJavaVM(vmi);
104
* @endcode
105
*/
106
struct VMInterfaceFunctions_
107
{
108
vmiError (JNICALL * CheckVersion)(VMInterface* vmi, vmiVersion* version);
109
JavaVM* (JNICALL * GetJavaVM) (VMInterface* vmi);
110
J9PortLibrary* (JNICALL * GetPortLibrary) (VMInterface* vmi);
111
#if defined(J9VM_OPT_VM_LOCAL_STORAGE)
112
J9VMLSFunctionTable* (JNICALL * GetVMLSFunctions) (VMInterface* vmi);
113
#else
114
void* reserved1;
115
#endif
116
#if defined(J9VM_OPT_ZIP_SUPPORT)
117
VMIZipFunctionTable* (JNICALL * GetZipFunctions) (VMInterface* vmi);
118
#else
119
void* reserved2;
120
#endif
121
JavaVMInitArgs* (JNICALL * GetInitArgs) (VMInterface* vmi);
122
vmiError (JNICALL * GetSystemProperty) (VMInterface* vmi, char* key, char** valuePtr);
123
vmiError (JNICALL * SetSystemProperty) (VMInterface* vmi, char* key, char* value);
124
vmiError (JNICALL * CountSystemProperties) (VMInterface* vmi, int* countPtr);
125
vmiError (JNICALL * IterateSystemProperties) (VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData);
126
};
127
128
129
/**
130
*
131
* @name VM Interface Support Functions
132
* @htmlonly <a name='VMIExports'>&nbsp;</a> @endhtmlonly Non-table VM interface functions. Directly exported from the VMI library.
133
*/
134
135
/*@{*/
136
/*@}*/
137
138
/**
139
* Retrieves a VMInterface pointer given a JavaVM.
140
* @param vm The VM instance from which to obtain the VMI.
141
* @return A VMInterface or NULL.
142
*/
143
VMInterface *JNICALL GetVMIFromJavaVM(JavaVM * vm);
144
145
/**
146
* Retrieves a VMInterface pointer given a JNIEnv.
147
* @param env The JNIEnv from which to obtain the VMI.
148
* @return A VMInterface or NULL.
149
*/
150
VMInterface *JNICALL GetVMIFromJNIEnv(JNIEnv * env);
151
152
/** @name VM Interface Access Macros
153
*
154
* Convenience macros for acquiring a VMInterface
155
*/
156
/*@{*/
157
#define VMI_ACCESS_FROM_ENV(env) VMInterface* privateVMI = GetVMIFromJNIEnv(env)
158
#define VMI_ACCESS_FROM_JAVAVM(javaVM) VMInterface* privateVMI = GetVMIFromJavaVM(javaVM)
159
#define VMI privateVMI
160
/*@}*/
161
162
/**
163
* @fn VMInterfaceFunctions_::CheckVersion
164
* Check the version of the VM interface
165
*
166
* @code vmiError JNICALL CheckVersion(VMInterface* vmi, vmiVersion* version); @endcode
167
*
168
* @param[in] vmi The VM interface pointer
169
* @param[in,out] version Pass in the version to check, or @ref VMI_VERSION_UNKNOWN. Returns the current version.
170
*
171
* @return a @ref vmiError "VMI error code"
172
*
173
* @note The CheckVersion function allows a class library to verify that the VM provides the required interface functions.
174
* If the version requested is @ref VMI_VERSION_UNKNOWN, then the function will reply with the current version and not return an error.
175
* If a specific version is passed, it will be compatibility checked against the current, and @ref VMI_ERROR_UNSUPPORTED_VERSION
176
* may be returned.
177
*/
178
vmiError JNICALL
179
CheckVersion(VMInterface* vmi, vmiVersion* version);
180
181
/**
182
* @fn VMInterfaceFunctions_::GetJavaVM
183
* Return the JNI JavaVM associated with the VM interface
184
*
185
* @code JavaVM* JNICALL GetJavaVM(VMInterface* vmi); @endcode
186
*
187
* @param[in] vmi The VM interface pointer
188
*
189
* @return a JavaVM pointer
190
*/
191
JavaVM* JNICALL
192
GetJavaVM(VMInterface* vmi);
193
194
/**
195
* @fn VMInterfaceFunctions_::GetPortLibrary
196
* Return a pointer to an initialized J9PortLibrary structure.
197
*
198
* @code J9PortLibrary* JNICALL GetPortLibrary(VMInterface* vmi); @endcode
199
*
200
* The @ref j9port.h "port library" is a table of functions that implement useful platform specific
201
* capability. For example, file and socket manipulation, memory management, etc.
202
* It is the responsibility of the VM to create the port library.
203
*
204
* @param[in] vmi The VM interface pointer
205
*
206
* @return the J9PortLibrary associated with the VMI
207
*
208
* @see j9port.c
209
*/
210
J9PortLibrary* JNICALL
211
GetPortLibrary(VMInterface* vmi);
212
213
/**
214
* @fn VMInterfaceFunctions_::GetVMLSFunctions
215
* Return a pointer to a J9VMLSFunctionTable. This is a table of functions for allocating,
216
* freeing, getting, and setting thread local storage.
217
*
218
* @code J9VMLSFunctionTable* JNICALL GetVMLSFunctions(VMInterface* vmi); @endcode
219
*
220
* @param[in] vmi The VM interface pointer
221
*
222
* @return the VM local storage function table
223
*/
224
J9VMLSFunctionTable* JNICALL
225
GetVMLSFunctions(VMInterface* vmi);
226
227
#if defined(J9VM_OPT_ZIP_SUPPORT)
228
/**
229
* @fn VMInterfaceFunctions_::GetZipFunctions
230
* Return a pointer to a VMIZipFunctionTable. This is a table of functions for managing zip files.
231
*
232
* @code VMIZipFunctionTable* JNICALL GetZipFunctions(VMInterface* vmi); @endcode
233
*
234
* @param[in] vmi The VM interface pointer
235
*
236
* @return a VMIZipFunctionTable pointer
237
*/
238
VMIZipFunctionTable* JNICALL
239
GetZipFunctions(VMInterface* vmi);
240
#endif
241
242
/**
243
* @fn VMInterfaceFunctions_::GetInitArgs
244
* Return a pointer to a JavaVMInitArgs structure as defined by the 1.2 JNI
245
* specification. This structure contains the arguments used to invoke the vm.
246
*
247
* @code JavaVMInitArgs* JNICALL GetInitArgs(VMInterface* vmi); @endcode
248
*
249
* @param[in] vmi The VM interface pointer
250
*
251
* @return the VM invocation arguments
252
*/
253
JavaVMInitArgs* JNICALL
254
GetInitArgs(VMInterface* vmi);
255
256
/**
257
* @fn VMInterfaceFunctions_::GetSystemProperty
258
* Retrieve the value of a VM system property.
259
*
260
* @code vmiError JNICALL GetSystemProperty (VMInterface* vmi, char* key, char** valuePtr); @endcode
261
*
262
* The following properties must be defined by the vm.
263
*
264
* <TABLE>
265
* <TR><TD><B>Property Name</B></TD> <TD><B>Example Value or Description</B></TD></TR>
266
* <TR><TD>java.vendor</TD> <TD>"Eclipse OpenJ9"</TD></TR>
267
* <TR><TD>java.vendor.url</TD> <TD>"http://www.eclipse.org/openj9"</TD></TR>
268
* <TR><TD>java.specification.version</TD> <TD>"1.8"</TD></TR>
269
* <TR><TD>java.vm.specification.version</TD> <TD>"1.8"</TD></TR>
270
* <TR><TD>java.vm.specification.vendor</TD> <TD>"Oracle Corporation"</TD></TR>
271
* <TR><TD>java.vm.specification.name</TD> <TD>"Java Virtual Machine Specification"</TD></TR>
272
* <TR><TD>java.vm.version</TD> <TD>"main-1ca0ab98"</TD></TR>
273
* <TR><TD>java.vm.vendor</TD> <TD>"Eclipse OpenJ9"</TD></TR>
274
* <TR><TD>java.vm.name </TD> <TD>"Eclipse OpenJ9 VM"</TD></TR>
275
* <TR><TD>java.vm.info</TD> <TD>"JRE 1.8.0 Linux amd64-64-Bit Compressed References 20180601_201 (JIT enabled, AOT enabled)
276
<BR>OpenJ9 - 1ca0ab98
277
<BR>OMR - 05d2b8a2
278
<BR>JCL - c2aa0348 based on jdk8u172-b11"</TD></TR>
279
* <TR><TD>java.compiler</TD> <TD>"j9jit29"</TD></TR>
280
* <TR><TD>java.class.version</TD> <TD>"52.0"</TD></TR>
281
* <TR><TD>java.home</TD> <TD>the absolute path of the parent directory of the directory containing the vm
282
<BR>i.e. for a vm /clear/bin/vm.exe, java.home is /clear</TD></TR>
283
* <TR><TD>java.class.path</TD> <TD>the application class path</TD></TR>
284
* <TR><TD>java.library.path</TD> <TD>the application library path</TD></TR>
285
* <TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
286
* <TR><TD>com.ibm.oti.vm.bootstrap.library.path <TD>the bootstrap library path</TD></TR>
287
* <TR><TD>com.ibm.oti.vm.library.version <TD>"29"</TD></TR>
288
* </TABLE>
289
*
290
* @return a @ref vmiError "VMI error code"
291
*
292
* @note The returned string is owned by the VM, and should not be freed.
293
*/
294
vmiError JNICALL
295
GetSystemProperty (VMInterface* vmi, char* key, char** valuePtr);
296
297
/**
298
* @fn VMInterfaceFunctions_::SetSystemProperty
299
* Override the value of a VM system property
300
*
301
* @code vmiError JNICALL SetSystemProperty(VMInterface* vmi, char* key, char* value); @endcode
302
*
303
* @param[in] vmi The VM interface pointer
304
* @param[in] key The system property to override
305
* @param[in] value The value of the system property
306
*
307
* @return a @ref vmiError "VMI error code"
308
*
309
* @note New properties can be added by this mechanism, but may not be available from
310
* Java after VM bootstrap is complete.
311
*
312
* @note See GetSystemProperty() for the list of properties that must be defined
313
* by the vm.
314
*/
315
vmiError JNICALL
316
SetSystemProperty(VMInterface* vmi, char* key, char* value);
317
318
/**
319
* @fn VMInterfaceFunctions_::CountSystemProperties
320
* Return the number of VM system properties
321
*
322
* @code vmiError JNICALL CountSystemProperties(VMInterface* vmi, int* countPtr); @endcode
323
*
324
* @param[in] vmi The VM interface pointer
325
* @param[out] countPtr The location to store the number of system properties
326
*
327
* @return a @ref vmiError "VMI error code"
328
*
329
* @note See GetSystemProperty() for the list of properties that must be defined
330
* by the vm.
331
*/
332
vmiError JNICALL
333
CountSystemProperties(VMInterface* vmi, int* countPtr);
334
335
/**
336
* @fn VMInterfaceFunctions_::IterateSystemProperties
337
* Iterate over the VM system properties calling a function.
338
*
339
* @code vmiError JNICALL IterateSystemProperties(VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData); @endcode
340
*
341
* @param[in] vmi The VM interface pointer
342
* @param[in] iterator The iterator function to call with each property
343
* @param[in] userData Opaque data to pass to the iterator function
344
*
345
* @return a @ref vmiError "VMI error code"
346
*
347
* @note The returned strings are owned by the VM, and should not be freed.
348
*
349
* @note See GetSystemProperty() for the list of properties that must be defined
350
* by the vm.
351
*/
352
vmiError JNICALL
353
IterateSystemProperties(VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData);
354
355
#ifdef __cplusplus
356
}
357
#endif
358
359
#endif /* vmi_h */
360
361