src/jdk.management/share/native/libmanagement_ext/DiagnosticCommandImpl.c
author egahlin
Fri, 27 Sep 2019 13:20:04 +0200
branchJEP-349-branch
changeset 58373 849a45ac808a
parent 47216 71c04702a3d5
permissions -rw-r--r--
Improve test coverage for RecordingStream::enable(...) and RecordingStream:disable(...)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     1
/*
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     4
 *
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    10
 *
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    15
 * accompanied this code).
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    16
 *
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    20
 *
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    23
 * questions.
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    24
 */
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    25
22605
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
    26
#include <stdlib.h>
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    27
#include <jni.h>
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
    28
#include "management_ext.h"
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
    29
#include "com_sun_management_internal_DiagnosticCommandImpl.h"
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    30
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
    31
JNIEXPORT void JNICALL Java_com_sun_management_internal_DiagnosticCommandImpl_setNotificationEnabled
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    32
(JNIEnv *env, jobject dummy, jboolean enabled) {
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
    33
    if (jmm_version <= JMM_VERSION_1_2_2) {
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    34
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    35
                        "JMX interface to diagnostic framework notifications is not supported by this VM");
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
    36
        return;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    37
    }
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
    38
    jmm_interface->SetDiagnosticFrameworkNotificationEnabled(env, enabled);
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    39
}
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    40
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    41
JNIEXPORT jobjectArray JNICALL
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
    42
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    43
  (JNIEnv *env, jobject dummy)
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    44
{
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    45
  return jmm_interface->GetDiagnosticCommands(env);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    46
}
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    47
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    48
#define EXCEPTION_CHECK_AND_FREE(x) do { \
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    49
                                        if ((*env)->ExceptionCheck(env)) { \
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    50
                                            free(x); \
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    51
                                            return NULL; \
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    52
                                        } \
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    53
                                    } while(0)
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    54
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    55
jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    56
                                              int num_arg) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    57
  int i;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    58
  jobject obj;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    59
  jobjectArray result;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    60
  dcmdArgInfo* dcmd_arg_info_array;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    61
  jclass dcmdArgInfoCls;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    62
  jclass arraysCls;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    63
  jmethodID mid;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    64
  jobject resultList;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    65
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    66
  dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo));
22605
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
    67
  /* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
    68
  if (dcmd_arg_info_array == NULL && num_arg != 0) {
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    69
    JNU_ThrowOutOfMemoryError(env, 0);
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    70
    return NULL;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    71
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    72
  jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    73
                                                   dcmd_arg_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    74
  dcmdArgInfoCls = (*env)->FindClass(env,
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
    75
                                     "com/sun/management/internal/DiagnosticCommandArgumentInfo");
27192
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
    76
  if ((*env)->ExceptionCheck(env)) {
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
    77
    free(dcmd_arg_info_array);
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
    78
    return NULL;
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
    79
  }
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
    80
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    81
  result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    82
  if (result == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    83
    free(dcmd_arg_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    84
    return NULL;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    85
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
    86
  for (i=0; i<num_arg; i++) {
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    87
    jstring jname, jdesc,jtype,jdefStr;
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    88
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    89
    jname = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].name);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    90
    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    91
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    92
    jdesc = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    93
    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    94
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    95
    jtype = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    96
    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    97
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    98
    jdefStr = (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
    99
    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   100
    obj = JNU_NewObjectByName(env,
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
   101
                              "com/sun/management/internal/DiagnosticCommandArgumentInfo",
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   102
                              "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V",
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   103
                              jname, jdesc, jtype,
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   104
                              dcmd_arg_info_array[i].default_string == NULL ? NULL: jdefStr,
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   105
                              dcmd_arg_info_array[i].mandatory,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   106
                              dcmd_arg_info_array[i].option,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   107
                              dcmd_arg_info_array[i].multiple,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   108
                              dcmd_arg_info_array[i].position);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   109
    if (obj == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   110
      free(dcmd_arg_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   111
      return NULL;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   112
    }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   113
    (*env)->SetObjectArrayElement(env, result, i, obj);
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   114
    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   115
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   116
  free(dcmd_arg_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   117
  arraysCls = (*env)->FindClass(env, "java/util/Arrays");
27192
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   118
  if ((*env)->ExceptionCheck(env)) {
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   119
    return NULL;
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   120
  }
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   121
  mid = (*env)->GetStaticMethodID(env, arraysCls,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   122
                                  "asList", "([Ljava/lang/Object;)Ljava/util/List;");
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   123
  resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result);
27192
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   124
  if ((*env)->ExceptionCheck(env)) {
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   125
    // Make sure we return NULL in case of OOM inside Java
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   126
    return NULL;
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   127
  }
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   128
  return resultList;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   129
}
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   130
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   131
/* Throws IllegalArgumentException if at least one of the diagnostic command
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   132
 * passed in argument is not supported by the JVM
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   133
 */
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   134
JNIEXPORT jobjectArray JNICALL
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
   135
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   136
(JNIEnv *env, jobject dummy, jobjectArray commands)
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   137
{
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   138
  int i;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   139
  jclass dcmdInfoCls;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   140
  jobject result;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   141
  jobjectArray args;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   142
  jobject obj;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   143
  jmmOptionalSupport mos;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   144
  jint ret = jmm_interface->GetOptionalSupport(env, &mos);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   145
  jsize num_commands;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   146
  dcmdInfo* dcmd_info_array;
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   147
  jstring jname, jdesc, jimpact;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   148
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   149
  if (commands == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   150
      JNU_ThrowNullPointerException(env, "Invalid String Array");
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   151
      return NULL;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   152
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   153
  num_commands = (*env)->GetArrayLength(env, commands);
22605
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   154
  dcmdInfoCls = (*env)->FindClass(env,
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
   155
                                  "com/sun/management/internal/DiagnosticCommandInfo");
27192
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   156
  if ((*env)->ExceptionCheck(env)) {
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   157
    return NULL;
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   158
  }
a16236cd61d7 8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents: 25859
diff changeset
   159
22605
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   160
  result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL);
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   161
  if (result == NULL) {
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
   162
      return NULL;
22605
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   163
  }
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   164
  if (num_commands == 0) {
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   165
      /* Handle the 'zero commands' case specially to avoid calling 'malloc()' */
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   166
      /* with a zero argument because that may legally return a NULL pointer.  */
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   167
      return result;
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   168
  }
dba3d6b22818 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents: 18299
diff changeset
   169
  dcmd_info_array = (dcmdInfo*) malloc(num_commands * sizeof(dcmdInfo));
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   170
  if (dcmd_info_array == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   171
      JNU_ThrowOutOfMemoryError(env, NULL);
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
   172
      return NULL;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   173
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   174
  jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   175
  for (i=0; i<num_commands; i++) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   176
      args = getDiagnosticCommandArgumentInfoArray(env,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   177
                                                   (*env)->GetObjectArrayElement(env,commands,i),
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   178
                                                   dcmd_info_array[i].num_arguments);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   179
      if (args == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   180
          free(dcmd_info_array);
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
   181
          return NULL;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   182
      }
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   183
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   184
      jname = (*env)->NewStringUTF(env,dcmd_info_array[i].name);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   185
      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   186
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   187
      jdesc = (*env)->NewStringUTF(env,dcmd_info_array[i].description);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   188
      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   189
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   190
      jimpact = (*env)->NewStringUTF(env,dcmd_info_array[i].impact);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   191
      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   192
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   193
      obj = JNU_NewObjectByName(env,
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
   194
                                "com/sun/management/internal/DiagnosticCommandInfo",
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   195
                                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V",
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   196
                                jname, jdesc, jimpact,
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   197
                                dcmd_info_array[i].permission_class==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_class),
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   198
                                dcmd_info_array[i].permission_name==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_name),
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   199
                                dcmd_info_array[i].permission_action==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_action),
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   200
                                dcmd_info_array[i].enabled,
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   201
                                args);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   202
      if (obj == NULL) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   203
          free(dcmd_info_array);
22624
860bde7fa0eb 8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents: 22605
diff changeset
   204
          return NULL;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   205
      }
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   206
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   207
      (*env)->SetObjectArrayElement(env, result, i, obj);
41197
d98087633032 8161448: 4 JNI exception pending defect groups in DiagnosticCommandImpl.c
vtewari
parents: 30355
diff changeset
   208
      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   209
  }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   210
  free(dcmd_info_array);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   211
  return result;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   212
}
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   213
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   214
/* Throws IllegalArgumentException if the diagnostic command
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   215
 * passed in argument is not supported by the JVM
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   216
 */
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   217
JNIEXPORT jstring JNICALL
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27192
diff changeset
   218
Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   219
(JNIEnv *env, jobject dummy, jstring command) {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   220
  return jmm_interface->ExecuteDiagnosticCommand(env, command);
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents:
diff changeset
   221
}