jdk/src/jdk.management/share/native/libmanagement_ext/GcInfoBuilder.c
author sjiang
Fri, 17 Apr 2015 09:40:02 +0200
changeset 30355 e37c7eba132f
parent 25859 jdk/src/java.management/share/native/libmanagement/GcInfoBuilder.c@3317bb8137f4
child 40689 13289e482d77
permissions -rw-r--r--
8042901: Allow com.sun.management to be in a different module to java.lang.management Reviewed-by: mchung, dfuchs, erikj, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2015, 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 <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <jni.h>
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
    29
#include "management_ext.h"
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
    30
#include "com_sun_management_internal_GcInfoBuilder.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
    32
JNIEXPORT jint JNICALL Java_com_sun_management_internal_GcInfoBuilder_getNumGcExtAttributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  (JNIEnv *env, jobject dummy, jobject gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    jlong value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    if (gc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    value = jmm_interface->GetLongAttribute(env, gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                            JMM_GC_EXT_ATTRIBUTE_INFO_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    return (jint) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
    45
JNIEXPORT void JNICALL Java_com_sun_management_internal_GcInfoBuilder_fillGcAttributeInfo
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  (JNIEnv *env, jobject dummy, jobject gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
   jint num_attributes, jobjectArray attributeNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   jcharArray types, jobjectArray descriptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    jmmExtAttributeInfo* ext_att_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    jchar* nativeTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    jstring attName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    jstring desc = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jint ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    if (gc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
    62
    if (num_attributes <= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        JNU_ThrowIllegalArgumentException(env, "Invalid num_attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
    67
    ext_att_info = (jmmExtAttributeInfo*) malloc((size_t)num_attributes *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                                 sizeof(jmmExtAttributeInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    if (ext_att_info == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    ret = jmm_interface->GetGCExtAttributeInfo(env, gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                               ext_att_info, num_attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    if (ret != num_attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        JNU_ThrowInternalError(env, "Unexpected num_attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        free(ext_att_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
    81
    nativeTypes = (jchar*) malloc((size_t)num_attributes * sizeof(jchar));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    if (nativeTypes == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        free(ext_att_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    for (i = 0; i < num_attributes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        nativeTypes[i] = ext_att_info[i].type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        attName = (*env)->NewStringUTF(env, ext_att_info[i].name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        desc = (*env)->NewStringUTF(env, ext_att_info[i].description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        (*env)->SetObjectArrayElement(env, attributeNames, i, attName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        (*env)->SetObjectArrayElement(env, descriptions, i, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    (*env)->SetCharArrayRegion(env, types, 0, num_attributes, nativeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (ext_att_info != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        free(ext_att_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    if (nativeTypes != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        free(nativeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
static void setLongValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                      jsize index, jlong value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    static const char* class_name = "java/lang/Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static const char* signature = "(J)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
static void setBooleanValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                         jsize index, jboolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static const char* class_name = "java/lang/Boolean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    static const char* signature = "(Z)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static void setByteValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                      jsize index, jbyte value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static const char* class_name = "java/lang/Byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static const char* signature = "(B)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
static void setIntValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                     jsize index, jint value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    static const char* class_name = "java/lang/Integer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    static const char* signature = "(I)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
static void setShortValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                       jsize index, jshort value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    static const char* class_name = "java/lang/Short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    static const char* signature = "(S)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
static void setDoubleValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                        jsize index, jdouble value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static const char* class_name = "java/lang/Double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    static const char* signature = "(D)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static void setFloatValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                       jsize index, jfloat value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    static const char* class_name = "java/lang/Float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static const char* signature = "(D)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
static void setCharValueAtObjectArray(JNIEnv *env, jobjectArray array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                      jsize index, jchar value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    static const char* class_name = "java/lang/Character";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static const char* signature = "(C)V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    (*env)->SetObjectArrayElement(env, array, index, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
   176
JNIEXPORT jobject JNICALL Java_com_sun_management_internal_GcInfoBuilder_getLastGcInfo0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  (JNIEnv *env, jobject builder, jobject gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
   jint ext_att_count, jobjectArray ext_att_values, jcharArray ext_att_types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
   jobjectArray usageBeforeGC, jobjectArray usageAfterGC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    jmmGCStat   gc_stat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    jchar*      nativeTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    jsize       i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    jvalue      v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    if (gc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   191
    if (ext_att_count <= 0) {
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   192
        JNU_ThrowIllegalArgumentException(env, "Invalid ext_att_count");
23924
f07c4b86aa2e 8033301: Build more informative InfoBuilder
jbachorik
parents: 23890
diff changeset
   193
        return 0;
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   194
    }
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   195
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    gc_stat.usage_before_gc = usageBeforeGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    gc_stat.usage_after_gc = usageAfterGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    gc_stat.gc_ext_attribute_values_size = ext_att_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    if (ext_att_count > 0) {
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   200
        gc_stat.gc_ext_attribute_values = (jvalue*) malloc((size_t)ext_att_count *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                                           sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (gc_stat.gc_ext_attribute_values == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        gc_stat.gc_ext_attribute_values = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    jmm_interface->GetLastGCStat(env, gc, &gc_stat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if (gc_stat.gc_index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (gc_stat.gc_ext_attribute_values != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            free(gc_stat.gc_ext_attribute_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    // convert the ext_att_types to native types
23890
b8388c5af315 8029735: Enhance service mgmt natives
jbachorik
parents: 5506
diff changeset
   220
    nativeTypes = (jchar*) malloc((size_t)ext_att_count * sizeof(jchar));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (nativeTypes == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (gc_stat.gc_ext_attribute_values != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            free(gc_stat.gc_ext_attribute_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    (*env)->GetCharArrayRegion(env, ext_att_types, 0, ext_att_count, nativeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    for (i = 0; i < ext_att_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
       v = gc_stat.gc_ext_attribute_values[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
       switch (nativeTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                setBooleanValueAtObjectArray(env, ext_att_values, i, v.z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            case 'B':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                setByteValueAtObjectArray(env, ext_att_values, i, v.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                setCharValueAtObjectArray(env, ext_att_values, i, v.c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            case 'S':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                setShortValueAtObjectArray(env, ext_att_values, i, v.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            case 'I':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                setIntValueAtObjectArray(env, ext_att_values, i, v.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            case 'J':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                setLongValueAtObjectArray(env, ext_att_values, i, v.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                setFloatValueAtObjectArray(env, ext_att_values, i, v.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                setDoubleValueAtObjectArray(env, ext_att_values, i, v.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                if (gc_stat.gc_ext_attribute_values != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    free(gc_stat.gc_ext_attribute_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (nativeTypes != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    free(nativeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                JNU_ThrowInternalError(env, "Unsupported attribute type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    if (gc_stat.gc_ext_attribute_values != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        free(gc_stat.gc_ext_attribute_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    if (nativeTypes != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        free(nativeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
       "com/sun/management/GcInfo",
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 25859
diff changeset
   276
       "(Lcom/sun/management/internal/GcInfoBuilder;JJJ[Ljava/lang/management/MemoryUsage;[Ljava/lang/management/MemoryUsage;[Ljava/lang/Object;)V",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
       builder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
       gc_stat.gc_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
       gc_stat.start_time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
       gc_stat.end_time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
       usageBeforeGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
       usageAfterGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
       ext_att_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}