32 Java_sun_management_HotSpotDiagnostic_dumpHeap |
32 Java_sun_management_HotSpotDiagnostic_dumpHeap |
33 (JNIEnv *env, jobject dummy, jstring outputfile, jboolean live) |
33 (JNIEnv *env, jobject dummy, jstring outputfile, jboolean live) |
34 { |
34 { |
35 jmm_interface->DumpHeap0(env, outputfile, live); |
35 jmm_interface->DumpHeap0(env, outputfile, live); |
36 } |
36 } |
37 |
|
38 JNIEXPORT jobjectArray JNICALL |
|
39 Java_sun_management_HotSpotDiagnostic_getDiagnosticCommands0 |
|
40 (JNIEnv *env, jobject dummy) |
|
41 { |
|
42 if ((jmm_version > JMM_VERSION_1_2_1) |
|
43 || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { |
|
44 return jmm_interface->GetDiagnosticCommands(env); |
|
45 } |
|
46 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
47 "Diagnostic commands are not supported by this VM"); |
|
48 } |
|
49 |
|
50 jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command, |
|
51 int num_arg) { |
|
52 int i; |
|
53 jobject obj; |
|
54 jobjectArray result; |
|
55 dcmdArgInfo* dcmd_arg_info_array; |
|
56 jclass dcmdArgInfoCls; |
|
57 jclass arraysCls; |
|
58 jmethodID mid; |
|
59 jobject resultList; |
|
60 |
|
61 dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo)); |
|
62 if (dcmd_arg_info_array == NULL) { |
|
63 return NULL; |
|
64 } |
|
65 jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command, |
|
66 dcmd_arg_info_array); |
|
67 dcmdArgInfoCls = (*env)->FindClass(env, |
|
68 "com/sun/management/DiagnosticCommandArgumentInfo"); |
|
69 result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL); |
|
70 if (result == NULL) { |
|
71 free(dcmd_arg_info_array); |
|
72 return NULL; |
|
73 } |
|
74 for (i=0; i<num_arg; i++) { |
|
75 obj = JNU_NewObjectByName(env, |
|
76 "com/sun/management/DiagnosticCommandArgumentInfo", |
|
77 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZI)V", |
|
78 (*env)->NewStringUTF(env,dcmd_arg_info_array[i].name), |
|
79 (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description), |
|
80 (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type), |
|
81 dcmd_arg_info_array[i].default_string == NULL ? NULL: |
|
82 (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string), |
|
83 dcmd_arg_info_array[i].mandatory, |
|
84 dcmd_arg_info_array[i].option, |
|
85 dcmd_arg_info_array[i].position); |
|
86 if (obj == NULL) { |
|
87 free(dcmd_arg_info_array); |
|
88 return NULL; |
|
89 } |
|
90 (*env)->SetObjectArrayElement(env, result, i, obj); |
|
91 } |
|
92 free(dcmd_arg_info_array); |
|
93 arraysCls = (*env)->FindClass(env, "java/util/Arrays"); |
|
94 mid = (*env)->GetStaticMethodID(env, arraysCls, |
|
95 "asList", "([Ljava/lang/Object;)Ljava/util/List;"); |
|
96 resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result); |
|
97 return resultList; |
|
98 } |
|
99 |
|
100 /* Throws IllegalArgumentException if at least one the diagnostic command |
|
101 * passed in argument is not supported by the JVM |
|
102 */ |
|
103 JNIEXPORT jobjectArray JNICALL |
|
104 Java_sun_management_HotSpotDiagnostic_getDiagnosticCommandInfo0 |
|
105 (JNIEnv *env, jobject dummy, jobjectArray commands) |
|
106 { |
|
107 int i; |
|
108 jclass dcmdInfoCls; |
|
109 jobject result; |
|
110 jobjectArray args; |
|
111 jobject obj; |
|
112 |
|
113 if (commands == NULL) { |
|
114 JNU_ThrowNullPointerException(env, "Invalid String Array"); |
|
115 return NULL; |
|
116 } |
|
117 if ((jmm_version > JMM_VERSION_1_2_1) |
|
118 || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { |
|
119 jsize num_commands = (*env)->GetArrayLength(env, commands); |
|
120 dcmdInfo* dcmd_info_array = (dcmdInfo*) malloc(num_commands * |
|
121 sizeof(dcmdInfo)); |
|
122 if (dcmd_info_array == NULL) { |
|
123 JNU_ThrowOutOfMemoryError(env, NULL); |
|
124 } |
|
125 jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array); |
|
126 dcmdInfoCls = (*env)->FindClass(env, |
|
127 "com/sun/management/DiagnosticCommandInfo"); |
|
128 result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL); |
|
129 if (result == NULL) { |
|
130 free(dcmd_info_array); |
|
131 JNU_ThrowOutOfMemoryError(env, 0); |
|
132 } |
|
133 for (i=0; i<num_commands; i++) { |
|
134 args = getDiagnosticCommandArgumentInfoArray(env, |
|
135 (*env)->GetObjectArrayElement(env,commands,i), |
|
136 dcmd_info_array[i].num_arguments); |
|
137 if (args == NULL) { |
|
138 free(dcmd_info_array); |
|
139 JNU_ThrowOutOfMemoryError(env, 0); |
|
140 } |
|
141 obj = JNU_NewObjectByName(env, |
|
142 "com/sun/management/DiagnosticCommandInfo", |
|
143 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V", |
|
144 (*env)->NewStringUTF(env,dcmd_info_array[i].name), |
|
145 (*env)->NewStringUTF(env,dcmd_info_array[i].description), |
|
146 (*env)->NewStringUTF(env,dcmd_info_array[i].impact), |
|
147 dcmd_info_array[i].enabled, |
|
148 args); |
|
149 if (obj == NULL) { |
|
150 free(dcmd_info_array); |
|
151 JNU_ThrowOutOfMemoryError(env, 0); |
|
152 } |
|
153 (*env)->SetObjectArrayElement(env, result, i, obj); |
|
154 } |
|
155 free(dcmd_info_array); |
|
156 return result; |
|
157 } |
|
158 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
159 "Diagnostic commands are not supported by this VM"); |
|
160 } |
|
161 |
|
162 /* Throws IllegalArgumentException if the diagnostic command |
|
163 * passed in argument is not supported by the JVM |
|
164 */ |
|
165 JNIEXPORT jstring JNICALL |
|
166 Java_sun_management_HotSpotDiagnostic_executeDiagnosticCommand0 |
|
167 (JNIEnv *env, jobject dummy, jstring command) { |
|
168 if((jmm_version > JMM_VERSION_1_2_1 ) |
|
169 || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { |
|
170 return jmm_interface->ExecuteDiagnosticCommand(env, command); |
|
171 } |
|
172 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
173 "Diagnostic commands are not supported by this VM"); |
|
174 } |
|