/*******************************************************************************1* Copyright (c) 2002, 2019 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* @brief This file contains implementations of the Sun VM interface (JVM_ functions)24* which simply forward to a concrete implementation located either in the JCL library25* or proxy forwarder.26*/2728#include <stdlib.h>29#include "j9.h"30#include "sunvmi_api.h"3132#include "../util/ut_module.h"33#undef UT_MODULE_LOADED34#undef UT_MODULE_UNLOADED35#define _UTE_STATIC_36#include "ut_j9scar.h"3738extern J9JavaVM *BFUjavaVM;39SunVMI* g_VMI;4041/**42* Initializes the VM-interface from the supplied JNIEnv.43*44*/45void46initializeVMI(void)47{48PORT_ACCESS_FROM_JAVAVM(BFUjavaVM);49jint result;5051/* Register this module with trace */52UT_MODULE_LOADED(J9_UTINTERFACE_FROM_VM(BFUjavaVM));53Trc_SC_VMInitStages_Event1(BFUjavaVM->mainThread);54result = (BFUjavaVM)->internalVMFunctions->GetEnv((JavaVM*)BFUjavaVM, (void**)&g_VMI, SUNVMI_VERSION_1_1);55if (result != JNI_OK) {56j9tty_printf(PORTLIB, "FATAL ERROR: Could not obtain SUNVMI from VM.\n");57exit(-1);58}59}6061jobject JNICALL62JVM_LatestUserDefinedLoader(JNIEnv *env)63{64ENSURE_VMI();65return g_VMI->JVM_LatestUserDefinedLoader(env);66}676869jobject JNICALL70#if JAVA_SPEC_VERSION >= 1171JVM_GetCallerClass(JNIEnv *env)72#else /* JAVA_SPEC_VERSION >= 11 */73JVM_GetCallerClass(JNIEnv *env, jint depth)74#endif /* JAVA_SPEC_VERSION >= 11 */75{76ENSURE_VMI();77#if JAVA_SPEC_VERSION >= 1178return g_VMI->JVM_GetCallerClass(env);79#else /* JAVA_SPEC_VERSION >= 11 */80return g_VMI->JVM_GetCallerClass(env, depth);81#endif /* JAVA_SPEC_VERSION >= 11 */82}838485jobject JNICALL86JVM_NewInstanceFromConstructor(JNIEnv * env, jobject c, jobjectArray args)87{88ENSURE_VMI();89return g_VMI->JVM_NewInstanceFromConstructor(env, c, args);90}919293jobject JNICALL94JVM_InvokeMethod(JNIEnv * env, jobject method, jobject obj, jobjectArray args)95{96ENSURE_VMI();97return g_VMI->JVM_InvokeMethod(env, method, obj, args);98}99100101jint JNICALL102JVM_GetClassAccessFlags(JNIEnv * env, jclass clazzRef)103{104ENSURE_VMI();105return g_VMI->JVM_GetClassAccessFlags(env, clazzRef);106}107108109jobject JNICALL110JVM_GetClassContext(JNIEnv *env)111{112ENSURE_VMI();113return g_VMI->JVM_GetClassContext(env);114}115116117void JNICALL118JVM_Halt(jint exitCode)119{120ENSURE_VMI();121g_VMI->JVM_Halt(exitCode);122}123124125void JNICALL126JVM_GCNoCompact(void)127{128ENSURE_VMI();129g_VMI->JVM_GCNoCompact();130}131132133void JNICALL134JVM_GC(void)135{136ENSURE_VMI();137g_VMI->JVM_GC();138}139140141/**142* JVM_TotalMemory143*/144jlong JNICALL145JVM_TotalMemory(void)146{147ENSURE_VMI();148return g_VMI->JVM_TotalMemory();149}150151152jlong JNICALL153JVM_FreeMemory(void)154{155ENSURE_VMI();156return g_VMI->JVM_FreeMemory();157}158159160jobject JNICALL161JVM_GetSystemPackages(JNIEnv* env)162{163ENSURE_VMI();164return g_VMI->JVM_GetSystemPackages(env);165}166167168/**169* Returns the package information for the specified package name. Package information is the directory or170* jar file name from where the package was loaded (separator is to be '/' and for a directory the return string is171* to end with a '/' character). If the package is not loaded then null is to be returned.172*173* @arg[in] env - JNI environment.174* @arg[in] pkgName - A Java string for the name of a package. The package must be separated with '/' and optionally end with a '/' character.175*176* @return Package information as a string.177*178* @note In the current implementation, the separator is not guaranteed to be '/', not is a directory guaranteed to be179* terminated with a slash. It is also unclear what the expected implementation is for UNC paths.180*181* @note see CMVC defects 81175 and 92979182*/183jstring JNICALL184JVM_GetSystemPackage(JNIEnv* env, jstring pkgName)185{186ENSURE_VMI();187return g_VMI->JVM_GetSystemPackage(env, pkgName);188}189190191jobject JNICALL192JVM_AllocateNewObject(JNIEnv *env, jclass caller, jclass current, jclass init)193{194ENSURE_VMI();195return g_VMI->JVM_AllocateNewObject(env, caller, current, init);196}197198199jobject JNICALL200JVM_AllocateNewArray(JNIEnv *env, jclass caller, jclass current, jint length)201{202ENSURE_VMI();203return g_VMI->JVM_AllocateNewArray(env, caller, current, length);204}205206207jobject JNICALL208JVM_GetClassLoader(JNIEnv *env, jobject obj)209{210ENSURE_VMI();211return g_VMI->JVM_GetClassLoader(env, obj);212}213214215void* JNICALL216JVM_GetThreadInterruptEvent(void)217{218ENSURE_VMI();219return g_VMI->JVM_GetThreadInterruptEvent();220}221222223jlong JNICALL224JVM_MaxObjectInspectionAge(void)225{226ENSURE_VMI();227return g_VMI->JVM_MaxObjectInspectionAge();228}229230jlong JNICALL231JVM_MaxMemory(void) {232ENSURE_VMI();233return g_VMI->JVM_MaxMemory();234}235236237