Path: blob/master/src/java.management/share/native/libmanagement/MemoryPoolImpl.c
41149 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <jni.h>26#include "management.h"27#include "sun_management_MemoryPoolImpl.h"2829JNIEXPORT jobject JNICALL30Java_sun_management_MemoryPoolImpl_getMemoryManagers031(JNIEnv *env, jobject pool)32{33jobject mgrs = jmm_interface->GetMemoryManagers(env, pool);34if (mgrs == NULL) {35// Throw internal error since this implementation expects the36// pool will never become invalid.37JNU_ThrowInternalError(env, "Memory Pool not found");38}39return mgrs;40}4142JNIEXPORT jobject JNICALL43Java_sun_management_MemoryPoolImpl_getUsage044(JNIEnv *env, jobject pool)45{46jobject usage = jmm_interface->GetMemoryPoolUsage(env, pool);47if (usage == NULL) {48// Throw internal error since this implementation expects the49// pool will never become invalid.50JNU_ThrowInternalError(env, "Memory Pool not found");51}52return usage;53}5455JNIEXPORT jobject JNICALL56Java_sun_management_MemoryPoolImpl_getPeakUsage057(JNIEnv *env, jobject pool)58{59jobject usage = jmm_interface->GetPeakMemoryPoolUsage(env, pool);60if (usage == NULL) {61// Throw internal error since this implementation expects the62// pool will never become invalid.63JNU_ThrowInternalError(env, "Memory Pool not found");64}65return usage;66}6768JNIEXPORT void JNICALL69Java_sun_management_MemoryPoolImpl_setUsageThreshold070(JNIEnv *env, jobject pool, jlong current, jlong newThreshold)71{72// Set both high and low threshold to the same threshold73if (newThreshold > current) {74// high threshold has to be set first so that high >= low75jmm_interface->SetPoolThreshold(env, pool,76JMM_USAGE_THRESHOLD_HIGH, newThreshold);77jmm_interface->SetPoolThreshold(env, pool,78JMM_USAGE_THRESHOLD_LOW, newThreshold);79} else {80// low threshold has to be set first so that high >= low81jmm_interface->SetPoolThreshold(env, pool,82JMM_USAGE_THRESHOLD_LOW, newThreshold);83jmm_interface->SetPoolThreshold(env, pool,84JMM_USAGE_THRESHOLD_HIGH, newThreshold);85}86}8788JNIEXPORT void JNICALL89Java_sun_management_MemoryPoolImpl_setCollectionThreshold090(JNIEnv *env, jobject pool, jlong current, jlong newThreshold)91{92// Set both high and low threshold to the same threshold93if (newThreshold > current) {94// high threshold has to be set first so that high >= low95jmm_interface->SetPoolThreshold(env, pool,96JMM_COLLECTION_USAGE_THRESHOLD_HIGH,97newThreshold);98jmm_interface->SetPoolThreshold(env, pool,99JMM_COLLECTION_USAGE_THRESHOLD_LOW,100newThreshold);101} else {102// low threshold has to be set first so that high >= low103jmm_interface->SetPoolThreshold(env, pool,104JMM_COLLECTION_USAGE_THRESHOLD_LOW,105newThreshold);106jmm_interface->SetPoolThreshold(env, pool,107JMM_COLLECTION_USAGE_THRESHOLD_HIGH,108newThreshold);109}110}111112JNIEXPORT void JNICALL113Java_sun_management_MemoryPoolImpl_resetPeakUsage0114(JNIEnv *env, jobject pool)115{116jvalue value;117value.l = pool;118jmm_interface->ResetStatistic(env, value, JMM_STAT_PEAK_POOL_USAGE);119}120121JNIEXPORT void JNICALL122Java_sun_management_MemoryPoolImpl_setPoolUsageSensor123(JNIEnv *env, jobject pool, jobject sensor)124{125jmm_interface->SetPoolSensor(env, pool,126JMM_USAGE_THRESHOLD_HIGH, sensor);127}128129JNIEXPORT void JNICALL130Java_sun_management_MemoryPoolImpl_setPoolCollectionSensor131(JNIEnv *env, jobject pool, jobject sensor)132{133jmm_interface->SetPoolSensor(env, pool,134JMM_COLLECTION_USAGE_THRESHOLD_HIGH, sensor);135}136137JNIEXPORT jobject JNICALL138Java_sun_management_MemoryPoolImpl_getCollectionUsage0139(JNIEnv *env, jobject pool)140{141return jmm_interface->GetPoolCollectionUsage(env, pool);142}143144145