/*******************************************************************************1* Copyright (c) 1991, 2020 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 VMLS25* @brief VM Local Storage Header26*/2728#ifndef J9VMLS_H29#define J9VMLS_H3031/* @ddr_namespace: default */32#ifdef __cplusplus33extern "C" {34#endif3536#include "j9comp.h"37#include "j9cfg.h"38#include "jni.h"3940#define J9VMLS_MAX_KEYS 2564142/**43* @struct J9VMLSFunctionTable44* The VM local storage function table.45*/46typedef struct J9VMLSFunctionTable {47UDATA (JNICALL *J9VMLSAllocKeys)(JNIEnv * env, UDATA * pInitCount, ...) ;48void (JNICALL *J9VMLSFreeKeys)(JNIEnv * env, UDATA * pInitCount, ...) ;49void* (JNICALL *J9VMLSGet)(JNIEnv * env, void * key) ;50void* (JNICALL *J9VMLSSet)(JNIEnv * env, void ** pKey, void * value) ;51} J9VMLSFunctionTable;5253/**54* @fn J9VMLSFunctionTable::J9VMLSAllocKeys55* Allocate one or more slots of VM local storage.56*57* @code UDATA JNICALL J9VMLSAllocKeys(JNIEnv * env, UDATA * pInitCount, ...); @endcode58*59* @param[in] env A JNIEnv pointer60* @param[in] pInitCount Pointer to the reference count for these slots61* @param[out] ... Locations to store the allocated keys62*63* @return 0 on success, 1 on failure.64*65* @note Newly allocated VMLS slots contain NULL in all VMs.66*/6768/**69* @fn J9VMLSFunctionTable::J9VMLSFreeKeys70* Destroy one or more slots of VM local storage.71*72* @code void JNICALL J9VMLSFreeKeys(JNIEnv * env, UDATA * pInitCount, ...); @endcode73*74* @param[in] env A JNIEnv pointer75* @param[in] pInitCount Pointer to the reference count for these slots76* @param[out] ... Pointers to the allocated keys77*/7879/**80* @fn J9VMLSFunctionTable::J9VMLSGet81* Retrieve the value in a VM local storage slot.82*83* @code void* JNICALL J9VMLSGet(JNIEnv * env, void * key); @endcode84*85* @param[in] env JNIEnv pointer86* @param[in] key The VMLS key87*88* @return The contents of the VM local storage slot in the VM that contains the specified env89*/9091/**92* @fn J9VMLSFunctionTable::J9VMLSSet93* Store a value into a VM local storage slot.94*95* @code void* JNICALL J9VMLSSet(JNIEnv * env, void ** pKey, void * value); @endcode96*97* @param[in] env JNIEnv pointer98* @param[in] pKey Pointer to the VM local storage key99* @param[in] value Value to store100*101* @return The value stored102*/103104#define J9VMLS_FNTBL(env) ((J9VMLSFunctionTable *) ((((void ***) (env))[offsetof(J9VMThread,javaVM)/sizeof(UDATA)])[offsetof(J9JavaVM,vmLocalStorageFunctions)/sizeof(UDATA)]))105106#ifdef J9VM_OPT_MULTI_VM107#define J9VMLS_GET(env, key) (J9VMLS_FNTBL(env)->J9VMLSGet(env, (key)))108#define J9VMLS_SET(env, key, value) (J9VMLS_FNTBL(env)->J9VMLSSet(env, &(key), (void *) (value)))109#else110#define J9VMLS_GET(env, key) (key)111#define J9VMLS_SET(env, key, value) ((key) = (void *) (value))112#endif113114#ifdef __cplusplus115}116#endif117118#endif /* J9VMLS_H */119120121