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