/*******************************************************************************1* Copyright (c) 1991, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122/**23* @file24* @ingroup VMInterface25* @brief VM interface specification26*/2728#ifndef vmi_h29#define vmi_h3031/* @ddr_namespace: default */32#ifdef __cplusplus33extern "C" {34#endif3536#include "j9cfg.h"37#include "jni.h"38#include "j9port.h"3940#if defined(J9VM_OPT_VM_LOCAL_STORAGE)41#include "j9vmls.h"42#endif4344/**45* @enum vmiError46* Enumeration of all possible return codes from VM interface functions47*/48typedef enum49{50VMI_ERROR_NONE = 0, /**< Success */51VMI_ERROR_UNKNOWN = 1, /**< Unknown error */52VMI_ERROR_UNIMPLEMENTED = 2, /**< Function has not been implemented */53VMI_ERROR_UNSUPPORTED_VERSION = 3, /**< The requested VM interface version is not supported */54VMI_ERROR_OUT_OF_MEMORY= 4, /**< Not enough memory was available to complete the request */55VMI_ERROR_NOT_FOUND= 5, /**< The requested system property was not found */56VMI_ERROR_READ_ONLY= 6, /**< An attempt was made to modify a read-only item */57VMI_ERROR_INITIALIZATION_FAILED = 7, /**< Initialization of the VM interface failed */5859vmiErrorEnsureWideEnum = 0x1000000 /* ensure 4-byte enum */60} vmiError;6162/**63* @enum vmiVersion64* VM interface version identifier65*/66typedef enum67{68VMI_VERSION_UNKNOWN = 0x00000000, /**< Unknown VMInterface version */69VMI_VERSION_1_0 = 0x00010000, /**< VMInterface version 1.0 */70VMI_VERSION_2_0 = 0x00020000, /**< VMInterface version 2.0 */71vmiVersionEnsureWideEnum = 0x1000000 /* ensure 4-byte enum */72} vmiVersion;7374/**75* @typedef vmiSystemPropertyIterator76* Specification of the iterator function to provide to IterateSystemProperties77*78* @code void iterator(char* key, char* value, void* userData); @endcode79*/80typedef void (JNICALL *vmiSystemPropertyIterator)(char* key, char* value, void* userData);8182struct VMInterface_;83struct VMInterfaceFunctions_;8485/**86* @typedef VMInterface87* The VM interface structure. Points to the @ref VMInterfaceFunctions_ "VM interface function table".88* Implementations will likely choose to store opaque data off this structure.89*/90typedef const struct VMInterfaceFunctions_* VMInterface;9192#if defined(J9VM_OPT_ZIP_SUPPORT)93#include "vmizip.h"94#endif9596/**97* @struct VMInterfaceFunctions_98* The VM interface function table.99*100* Example usage:101* @code102* JavaVM* vm = (*vmi)->GetJavaVM(vmi);103* @endcode104*/105struct VMInterfaceFunctions_106{107vmiError (JNICALL * CheckVersion)(VMInterface* vmi, vmiVersion* version);108JavaVM* (JNICALL * GetJavaVM) (VMInterface* vmi);109J9PortLibrary* (JNICALL * GetPortLibrary) (VMInterface* vmi);110#if defined(J9VM_OPT_VM_LOCAL_STORAGE)111J9VMLSFunctionTable* (JNICALL * GetVMLSFunctions) (VMInterface* vmi);112#else113void* reserved1;114#endif115#if defined(J9VM_OPT_ZIP_SUPPORT)116VMIZipFunctionTable* (JNICALL * GetZipFunctions) (VMInterface* vmi);117#else118void* reserved2;119#endif120JavaVMInitArgs* (JNICALL * GetInitArgs) (VMInterface* vmi);121vmiError (JNICALL * GetSystemProperty) (VMInterface* vmi, char* key, char** valuePtr);122vmiError (JNICALL * SetSystemProperty) (VMInterface* vmi, char* key, char* value);123vmiError (JNICALL * CountSystemProperties) (VMInterface* vmi, int* countPtr);124vmiError (JNICALL * IterateSystemProperties) (VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData);125};126127128/**129*130* @name VM Interface Support Functions131* @htmlonly <a name='VMIExports'> </a> @endhtmlonly Non-table VM interface functions. Directly exported from the VMI library.132*/133134/*@{*/135/*@}*/136137/**138* Retrieves a VMInterface pointer given a JavaVM.139* @param vm The VM instance from which to obtain the VMI.140* @return A VMInterface or NULL.141*/142VMInterface *JNICALL GetVMIFromJavaVM(JavaVM * vm);143144/**145* Retrieves a VMInterface pointer given a JNIEnv.146* @param env The JNIEnv from which to obtain the VMI.147* @return A VMInterface or NULL.148*/149VMInterface *JNICALL GetVMIFromJNIEnv(JNIEnv * env);150151/** @name VM Interface Access Macros152*153* Convenience macros for acquiring a VMInterface154*/155/*@{*/156#define VMI_ACCESS_FROM_ENV(env) VMInterface* privateVMI = GetVMIFromJNIEnv(env)157#define VMI_ACCESS_FROM_JAVAVM(javaVM) VMInterface* privateVMI = GetVMIFromJavaVM(javaVM)158#define VMI privateVMI159/*@}*/160161/**162* @fn VMInterfaceFunctions_::CheckVersion163* Check the version of the VM interface164*165* @code vmiError JNICALL CheckVersion(VMInterface* vmi, vmiVersion* version); @endcode166*167* @param[in] vmi The VM interface pointer168* @param[in,out] version Pass in the version to check, or @ref VMI_VERSION_UNKNOWN. Returns the current version.169*170* @return a @ref vmiError "VMI error code"171*172* @note The CheckVersion function allows a class library to verify that the VM provides the required interface functions.173* If the version requested is @ref VMI_VERSION_UNKNOWN, then the function will reply with the current version and not return an error.174* If a specific version is passed, it will be compatibility checked against the current, and @ref VMI_ERROR_UNSUPPORTED_VERSION175* may be returned.176*/177vmiError JNICALL178CheckVersion(VMInterface* vmi, vmiVersion* version);179180/**181* @fn VMInterfaceFunctions_::GetJavaVM182* Return the JNI JavaVM associated with the VM interface183*184* @code JavaVM* JNICALL GetJavaVM(VMInterface* vmi); @endcode185*186* @param[in] vmi The VM interface pointer187*188* @return a JavaVM pointer189*/190JavaVM* JNICALL191GetJavaVM(VMInterface* vmi);192193/**194* @fn VMInterfaceFunctions_::GetPortLibrary195* Return a pointer to an initialized J9PortLibrary structure.196*197* @code J9PortLibrary* JNICALL GetPortLibrary(VMInterface* vmi); @endcode198*199* The @ref j9port.h "port library" is a table of functions that implement useful platform specific200* capability. For example, file and socket manipulation, memory management, etc.201* It is the responsibility of the VM to create the port library.202*203* @param[in] vmi The VM interface pointer204*205* @return the J9PortLibrary associated with the VMI206*207* @see j9port.c208*/209J9PortLibrary* JNICALL210GetPortLibrary(VMInterface* vmi);211212/**213* @fn VMInterfaceFunctions_::GetVMLSFunctions214* Return a pointer to a J9VMLSFunctionTable. This is a table of functions for allocating,215* freeing, getting, and setting thread local storage.216*217* @code J9VMLSFunctionTable* JNICALL GetVMLSFunctions(VMInterface* vmi); @endcode218*219* @param[in] vmi The VM interface pointer220*221* @return the VM local storage function table222*/223J9VMLSFunctionTable* JNICALL224GetVMLSFunctions(VMInterface* vmi);225226#if defined(J9VM_OPT_ZIP_SUPPORT)227/**228* @fn VMInterfaceFunctions_::GetZipFunctions229* Return a pointer to a VMIZipFunctionTable. This is a table of functions for managing zip files.230*231* @code VMIZipFunctionTable* JNICALL GetZipFunctions(VMInterface* vmi); @endcode232*233* @param[in] vmi The VM interface pointer234*235* @return a VMIZipFunctionTable pointer236*/237VMIZipFunctionTable* JNICALL238GetZipFunctions(VMInterface* vmi);239#endif240241/**242* @fn VMInterfaceFunctions_::GetInitArgs243* Return a pointer to a JavaVMInitArgs structure as defined by the 1.2 JNI244* specification. This structure contains the arguments used to invoke the vm.245*246* @code JavaVMInitArgs* JNICALL GetInitArgs(VMInterface* vmi); @endcode247*248* @param[in] vmi The VM interface pointer249*250* @return the VM invocation arguments251*/252JavaVMInitArgs* JNICALL253GetInitArgs(VMInterface* vmi);254255/**256* @fn VMInterfaceFunctions_::GetSystemProperty257* Retrieve the value of a VM system property.258*259* @code vmiError JNICALL GetSystemProperty (VMInterface* vmi, char* key, char** valuePtr); @endcode260*261* The following properties must be defined by the vm.262*263* <TABLE>264* <TR><TD><B>Property Name</B></TD> <TD><B>Example Value or Description</B></TD></TR>265* <TR><TD>java.vendor</TD> <TD>"Eclipse OpenJ9"</TD></TR>266* <TR><TD>java.vendor.url</TD> <TD>"http://www.eclipse.org/openj9"</TD></TR>267* <TR><TD>java.specification.version</TD> <TD>"1.8"</TD></TR>268* <TR><TD>java.vm.specification.version</TD> <TD>"1.8"</TD></TR>269* <TR><TD>java.vm.specification.vendor</TD> <TD>"Oracle Corporation"</TD></TR>270* <TR><TD>java.vm.specification.name</TD> <TD>"Java Virtual Machine Specification"</TD></TR>271* <TR><TD>java.vm.version</TD> <TD>"main-1ca0ab98"</TD></TR>272* <TR><TD>java.vm.vendor</TD> <TD>"Eclipse OpenJ9"</TD></TR>273* <TR><TD>java.vm.name </TD> <TD>"Eclipse OpenJ9 VM"</TD></TR>274* <TR><TD>java.vm.info</TD> <TD>"JRE 1.8.0 Linux amd64-64-Bit Compressed References 20180601_201 (JIT enabled, AOT enabled)275<BR>OpenJ9 - 1ca0ab98276<BR>OMR - 05d2b8a2277<BR>JCL - c2aa0348 based on jdk8u172-b11"</TD></TR>278* <TR><TD>java.compiler</TD> <TD>"j9jit29"</TD></TR>279* <TR><TD>java.class.version</TD> <TD>"52.0"</TD></TR>280* <TR><TD>java.home</TD> <TD>the absolute path of the parent directory of the directory containing the vm281<BR>i.e. for a vm /clear/bin/vm.exe, java.home is /clear</TD></TR>282* <TR><TD>java.class.path</TD> <TD>the application class path</TD></TR>283* <TR><TD>java.library.path</TD> <TD>the application library path</TD></TR>284* <TR><TD> </TD><TD> </TD></TR>285* <TR><TD>com.ibm.oti.vm.bootstrap.library.path <TD>the bootstrap library path</TD></TR>286* <TR><TD>com.ibm.oti.vm.library.version <TD>"29"</TD></TR>287* </TABLE>288*289* @return a @ref vmiError "VMI error code"290*291* @note The returned string is owned by the VM, and should not be freed.292*/293vmiError JNICALL294GetSystemProperty (VMInterface* vmi, char* key, char** valuePtr);295296/**297* @fn VMInterfaceFunctions_::SetSystemProperty298* Override the value of a VM system property299*300* @code vmiError JNICALL SetSystemProperty(VMInterface* vmi, char* key, char* value); @endcode301*302* @param[in] vmi The VM interface pointer303* @param[in] key The system property to override304* @param[in] value The value of the system property305*306* @return a @ref vmiError "VMI error code"307*308* @note New properties can be added by this mechanism, but may not be available from309* Java after VM bootstrap is complete.310*311* @note See GetSystemProperty() for the list of properties that must be defined312* by the vm.313*/314vmiError JNICALL315SetSystemProperty(VMInterface* vmi, char* key, char* value);316317/**318* @fn VMInterfaceFunctions_::CountSystemProperties319* Return the number of VM system properties320*321* @code vmiError JNICALL CountSystemProperties(VMInterface* vmi, int* countPtr); @endcode322*323* @param[in] vmi The VM interface pointer324* @param[out] countPtr The location to store the number of system properties325*326* @return a @ref vmiError "VMI error code"327*328* @note See GetSystemProperty() for the list of properties that must be defined329* by the vm.330*/331vmiError JNICALL332CountSystemProperties(VMInterface* vmi, int* countPtr);333334/**335* @fn VMInterfaceFunctions_::IterateSystemProperties336* Iterate over the VM system properties calling a function.337*338* @code vmiError JNICALL IterateSystemProperties(VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData); @endcode339*340* @param[in] vmi The VM interface pointer341* @param[in] iterator The iterator function to call with each property342* @param[in] userData Opaque data to pass to the iterator function343*344* @return a @ref vmiError "VMI error code"345*346* @note The returned strings are owned by the VM, and should not be freed.347*348* @note See GetSystemProperty() for the list of properties that must be defined349* by the vm.350*/351vmiError JNICALL352IterateSystemProperties(VMInterface* vmi, vmiSystemPropertyIterator iterator, void* userData);353354#ifdef __cplusplus355}356#endif357358#endif /* vmi_h */359360361