Path: blob/master/runtime/jcl/common/mgmtclassloading.c
6000 views
/*******************************************************************************1* Copyright (c) 1998, 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#include "jni.h"23#include "j9.h"24#include "jvminit.h"25#include "verbose_api.h"2627jboolean JNICALL28Java_com_ibm_java_lang_management_internal_ClassLoadingMXBeanImpl_isVerboseImpl(JNIEnv *env, jobject beanInstance)29{30J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM;3132return ( (javaVM->verboseLevel & VERBOSE_CLASS) == VERBOSE_CLASS );33}3435jlong JNICALL36Java_openj9_internal_management_ClassLoaderInfoBaseImpl_getLoadedClassCountImpl(JNIEnv *env, jobject beanInstance)37{38jlong result = 0;39J9JavaLangManagementData *mgmt = ((J9VMThread *) env)->javaVM->managementData;4041omrthread_rwmutex_enter_read(mgmt->managementDataLock);42result = (jlong)(mgmt->totalClassLoads - mgmt->totalClassUnloads);43omrthread_rwmutex_exit_read(mgmt->managementDataLock);4445return result;46}4748jlong JNICALL49Java_com_ibm_java_lang_management_internal_ClassLoadingMXBeanImpl_getTotalLoadedClassCountImpl(JNIEnv *env, jobject beanInstance)50{51J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM;52jlong result;53J9JavaLangManagementData *mgmt = javaVM->managementData;5455omrthread_rwmutex_enter_read( mgmt->managementDataLock );5657result = (jlong)mgmt->totalClassLoads;5859omrthread_rwmutex_exit_read( mgmt->managementDataLock );6061return result;62}6364jlong JNICALL65Java_openj9_internal_management_ClassLoaderInfoBaseImpl_getUnloadedClassCountImpl(JNIEnv *env, jobject beanInstance)66{67J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM;68jlong result;69J9JavaLangManagementData *mgmt = javaVM->managementData;7071omrthread_rwmutex_enter_read( mgmt->managementDataLock );7273result = (jlong)mgmt->totalClassUnloads;7475omrthread_rwmutex_exit_read( mgmt->managementDataLock );7677return result;78}7980void JNICALL81Java_com_ibm_java_lang_management_internal_ClassLoadingMXBeanImpl_setVerboseImpl(JNIEnv *env, jobject beanInstance, jboolean value)82{83J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM;84J9VerboseSettings verboseOptions;8586memset(&verboseOptions, 0, sizeof(J9VerboseSettings));87if( javaVM->setVerboseState != NULL ) {88verboseOptions.vclass = value? VERBOSE_SETTINGS_SET: VERBOSE_SETTINGS_CLEAR;89javaVM->setVerboseState( javaVM, &verboseOptions, NULL );90}91}929394