| 1 | /* |
| 2 | * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Oracle designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Oracle in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
| 24 | */ |
| 25 | |
| 26 | #include <jni.h> |
| 27 | #include "management.h" |
| 28 | #include "sun_management_MemoryPoolImpl.h" |
| 29 | |
| 30 | JNIEXPORT jobject JNICALL |
| 31 | Java_sun_management_MemoryPoolImpl_getMemoryManagers0 |
| 32 | (JNIEnv *env, jobject pool) |
| 33 | { |
| 34 | jobject mgrs = jmm_interface->GetMemoryManagers(env, pool); |
| 35 | if (mgrs == NULL) { |
| 36 | // Throw internal error since this implementation expects the |
| 37 | // pool will never become invalid. |
| 38 | JNU_ThrowInternalError(env, "Memory Pool not found" ); |
| 39 | } |
| 40 | return mgrs; |
| 41 | } |
| 42 | |
| 43 | JNIEXPORT jobject JNICALL |
| 44 | Java_sun_management_MemoryPoolImpl_getUsage0 |
| 45 | (JNIEnv *env, jobject pool) |
| 46 | { |
| 47 | jobject usage = jmm_interface->GetMemoryPoolUsage(env, pool); |
| 48 | if (usage == NULL) { |
| 49 | // Throw internal error since this implementation expects the |
| 50 | // pool will never become invalid. |
| 51 | JNU_ThrowInternalError(env, "Memory Pool not found" ); |
| 52 | } |
| 53 | return usage; |
| 54 | } |
| 55 | |
| 56 | JNIEXPORT jobject JNICALL |
| 57 | Java_sun_management_MemoryPoolImpl_getPeakUsage0 |
| 58 | (JNIEnv *env, jobject pool) |
| 59 | { |
| 60 | jobject usage = jmm_interface->GetPeakMemoryPoolUsage(env, pool); |
| 61 | if (usage == NULL) { |
| 62 | // Throw internal error since this implementation expects the |
| 63 | // pool will never become invalid. |
| 64 | JNU_ThrowInternalError(env, "Memory Pool not found" ); |
| 65 | } |
| 66 | return usage; |
| 67 | } |
| 68 | |
| 69 | JNIEXPORT void JNICALL |
| 70 | Java_sun_management_MemoryPoolImpl_setUsageThreshold0 |
| 71 | (JNIEnv *env, jobject pool, jlong current, jlong newThreshold) |
| 72 | { |
| 73 | // Set both high and low threshold to the same threshold |
| 74 | if (newThreshold > current) { |
| 75 | // high threshold has to be set first so that high >= low |
| 76 | jmm_interface->SetPoolThreshold(env, pool, |
| 77 | JMM_USAGE_THRESHOLD_HIGH, newThreshold); |
| 78 | jmm_interface->SetPoolThreshold(env, pool, |
| 79 | JMM_USAGE_THRESHOLD_LOW, newThreshold); |
| 80 | } else { |
| 81 | // low threshold has to be set first so that high >= low |
| 82 | jmm_interface->SetPoolThreshold(env, pool, |
| 83 | JMM_USAGE_THRESHOLD_LOW, newThreshold); |
| 84 | jmm_interface->SetPoolThreshold(env, pool, |
| 85 | JMM_USAGE_THRESHOLD_HIGH, newThreshold); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | JNIEXPORT void JNICALL |
| 90 | Java_sun_management_MemoryPoolImpl_setCollectionThreshold0 |
| 91 | (JNIEnv *env, jobject pool, jlong current, jlong newThreshold) |
| 92 | { |
| 93 | // Set both high and low threshold to the same threshold |
| 94 | if (newThreshold > current) { |
| 95 | // high threshold has to be set first so that high >= low |
| 96 | jmm_interface->SetPoolThreshold(env, pool, |
| 97 | JMM_COLLECTION_USAGE_THRESHOLD_HIGH, |
| 98 | newThreshold); |
| 99 | jmm_interface->SetPoolThreshold(env, pool, |
| 100 | JMM_COLLECTION_USAGE_THRESHOLD_LOW, |
| 101 | newThreshold); |
| 102 | } else { |
| 103 | // low threshold has to be set first so that high >= low |
| 104 | jmm_interface->SetPoolThreshold(env, pool, |
| 105 | JMM_COLLECTION_USAGE_THRESHOLD_LOW, |
| 106 | newThreshold); |
| 107 | jmm_interface->SetPoolThreshold(env, pool, |
| 108 | JMM_COLLECTION_USAGE_THRESHOLD_HIGH, |
| 109 | newThreshold); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | JNIEXPORT void JNICALL |
| 114 | Java_sun_management_MemoryPoolImpl_resetPeakUsage0 |
| 115 | (JNIEnv *env, jobject pool) |
| 116 | { |
| 117 | jvalue value; |
| 118 | value.l = pool; |
| 119 | jmm_interface->ResetStatistic(env, value, JMM_STAT_PEAK_POOL_USAGE); |
| 120 | } |
| 121 | |
| 122 | JNIEXPORT void JNICALL |
| 123 | Java_sun_management_MemoryPoolImpl_setPoolUsageSensor |
| 124 | (JNIEnv *env, jobject pool, jobject sensor) |
| 125 | { |
| 126 | jmm_interface->SetPoolSensor(env, pool, |
| 127 | JMM_USAGE_THRESHOLD_HIGH, sensor); |
| 128 | } |
| 129 | |
| 130 | JNIEXPORT void JNICALL |
| 131 | Java_sun_management_MemoryPoolImpl_setPoolCollectionSensor |
| 132 | (JNIEnv *env, jobject pool, jobject sensor) |
| 133 | { |
| 134 | jmm_interface->SetPoolSensor(env, pool, |
| 135 | JMM_COLLECTION_USAGE_THRESHOLD_HIGH, sensor); |
| 136 | } |
| 137 | |
| 138 | JNIEXPORT jobject JNICALL |
| 139 | Java_sun_management_MemoryPoolImpl_getCollectionUsage0 |
| 140 | (JNIEnv *env, jobject pool) |
| 141 | { |
| 142 | return jmm_interface->GetPoolCollectionUsage(env, pool); |
| 143 | } |
| 144 | |