diff options
author | Stephane Eranian <eranian@google.com> | 2016-10-13 06:59:35 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-10-24 10:07:37 -0400 |
commit | cdd75e3b0d1e668bc498f18f0ea8353f9f955114 (patch) | |
tree | 51915eb6423a74ee333c2f06f4533015d4fc1232 /tools | |
parent | 5fef5f3f096d4852d63239836d0e57a0861f9b73 (diff) |
perf jit: Improve error messages from JVMTI
This patch improves the usefulness of error messages generated by the
JVMTI interfac.e This can help identify the root cause of a problem by
printing the actual error code. The patch adds a new helper function
called print_error().
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1476356383-30100-2-git-send-email-eranian@google.com
[ Handle failure to convert numeric error to a string in print_error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/jvmti/libjvmti.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c index ac12e4b91a92..5612641c69b4 100644 --- a/tools/perf/jvmti/libjvmti.c +++ b/tools/perf/jvmti/libjvmti.c | |||
@@ -12,6 +12,19 @@ | |||
12 | static int has_line_numbers; | 12 | static int has_line_numbers; |
13 | void *jvmti_agent; | 13 | void *jvmti_agent; |
14 | 14 | ||
15 | static void print_error(jvmtiEnv *jvmti, const char *msg, jvmtiError ret) | ||
16 | { | ||
17 | char *err_msg = NULL; | ||
18 | jvmtiError err; | ||
19 | err = (*jvmti)->GetErrorName(jvmti, ret, &err_msg); | ||
20 | if (err == JVMTI_ERROR_NONE) { | ||
21 | warnx("%s failed with %s", msg, err_msg); | ||
22 | (*jvmti)->Deallocate(jvmti, (unsigned char *)err_msg); | ||
23 | } else { | ||
24 | warnx("%s failed with an unknown error %d", msg, ret); | ||
25 | } | ||
26 | } | ||
27 | |||
15 | static jvmtiError | 28 | static jvmtiError |
16 | do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci, | 29 | do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci, |
17 | jvmti_line_info_t *tab, jint *nr) | 30 | jvmti_line_info_t *tab, jint *nr) |
@@ -22,8 +35,10 @@ do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci, | |||
22 | jvmtiError ret; | 35 | jvmtiError ret; |
23 | 36 | ||
24 | ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab); | 37 | ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab); |
25 | if (ret != JVMTI_ERROR_NONE) | 38 | if (ret != JVMTI_ERROR_NONE) { |
39 | print_error(jvmti, "GetLineNumberTable", ret); | ||
26 | return ret; | 40 | return ret; |
41 | } | ||
27 | 42 | ||
28 | for (i = 0; i < nr_lines; i++) { | 43 | for (i = 0; i < nr_lines; i++) { |
29 | if (loc_tab[i].start_location < bci) { | 44 | if (loc_tab[i].start_location < bci) { |
@@ -71,6 +86,8 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, jvmti_line_info_t ** | |||
71 | /* free what was allocated for nothing */ | 86 | /* free what was allocated for nothing */ |
72 | (*jvmti)->Deallocate(jvmti, (unsigned char *)lne); | 87 | (*jvmti)->Deallocate(jvmti, (unsigned char *)lne); |
73 | nr_total += (int)nr; | 88 | nr_total += (int)nr; |
89 | } else { | ||
90 | print_error(jvmti, "GetLineNumberTable", ret); | ||
74 | } | 91 | } |
75 | } | 92 | } |
76 | } | 93 | } |
@@ -130,7 +147,7 @@ compiled_method_load_cb(jvmtiEnv *jvmti, | |||
130 | ret = (*jvmti)->GetMethodDeclaringClass(jvmti, method, | 147 | ret = (*jvmti)->GetMethodDeclaringClass(jvmti, method, |
131 | &decl_class); | 148 | &decl_class); |
132 | if (ret != JVMTI_ERROR_NONE) { | 149 | if (ret != JVMTI_ERROR_NONE) { |
133 | warnx("jvmti: cannot get declaring class"); | 150 | print_error(jvmti, "GetMethodDeclaringClass", ret); |
134 | return; | 151 | return; |
135 | } | 152 | } |
136 | 153 | ||
@@ -144,21 +161,21 @@ compiled_method_load_cb(jvmtiEnv *jvmti, | |||
144 | 161 | ||
145 | ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name); | 162 | ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name); |
146 | if (ret != JVMTI_ERROR_NONE) { | 163 | if (ret != JVMTI_ERROR_NONE) { |
147 | warnx("jvmti: cannot get source filename ret=%d", ret); | 164 | print_error(jvmti, "GetSourceFileName", ret); |
148 | goto error; | 165 | goto error; |
149 | } | 166 | } |
150 | 167 | ||
151 | ret = (*jvmti)->GetClassSignature(jvmti, decl_class, | 168 | ret = (*jvmti)->GetClassSignature(jvmti, decl_class, |
152 | &class_sign, NULL); | 169 | &class_sign, NULL); |
153 | if (ret != JVMTI_ERROR_NONE) { | 170 | if (ret != JVMTI_ERROR_NONE) { |
154 | warnx("jvmti: getclassignature failed"); | 171 | print_error(jvmti, "GetClassSignature", ret); |
155 | goto error; | 172 | goto error; |
156 | } | 173 | } |
157 | 174 | ||
158 | ret = (*jvmti)->GetMethodName(jvmti, method, &func_name, | 175 | ret = (*jvmti)->GetMethodName(jvmti, method, &func_name, |
159 | &func_sign, NULL); | 176 | &func_sign, NULL); |
160 | if (ret != JVMTI_ERROR_NONE) { | 177 | if (ret != JVMTI_ERROR_NONE) { |
161 | warnx("jvmti: failed getmethodname"); | 178 | print_error(jvmti, "GetMethodName", ret); |
162 | goto error; | 179 | goto error; |
163 | } | 180 | } |
164 | 181 | ||
@@ -253,7 +270,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused) | |||
253 | 270 | ||
254 | ret = (*jvmti)->AddCapabilities(jvmti, &caps1); | 271 | ret = (*jvmti)->AddCapabilities(jvmti, &caps1); |
255 | if (ret != JVMTI_ERROR_NONE) { | 272 | if (ret != JVMTI_ERROR_NONE) { |
256 | warnx("jvmti: acquire compiled_method capability failed"); | 273 | print_error(jvmti, "AddCapabilities", ret); |
257 | return -1; | 274 | return -1; |
258 | } | 275 | } |
259 | ret = (*jvmti)->GetJLocationFormat(jvmti, &format); | 276 | ret = (*jvmti)->GetJLocationFormat(jvmti, &format); |
@@ -264,7 +281,9 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused) | |||
264 | ret = (*jvmti)->AddCapabilities(jvmti, &caps1); | 281 | ret = (*jvmti)->AddCapabilities(jvmti, &caps1); |
265 | if (ret == JVMTI_ERROR_NONE) | 282 | if (ret == JVMTI_ERROR_NONE) |
266 | has_line_numbers = 1; | 283 | has_line_numbers = 1; |
267 | } | 284 | } else if (ret != JVMTI_ERROR_NONE) |
285 | print_error(jvmti, "GetJLocationFormat", ret); | ||
286 | |||
268 | 287 | ||
269 | memset(&cb, 0, sizeof(cb)); | 288 | memset(&cb, 0, sizeof(cb)); |
270 | 289 | ||
@@ -273,21 +292,21 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved __unused) | |||
273 | 292 | ||
274 | ret = (*jvmti)->SetEventCallbacks(jvmti, &cb, sizeof(cb)); | 293 | ret = (*jvmti)->SetEventCallbacks(jvmti, &cb, sizeof(cb)); |
275 | if (ret != JVMTI_ERROR_NONE) { | 294 | if (ret != JVMTI_ERROR_NONE) { |
276 | warnx("jvmti: cannot set event callbacks"); | 295 | print_error(jvmti, "SetEventCallbacks", ret); |
277 | return -1; | 296 | return -1; |
278 | } | 297 | } |
279 | 298 | ||
280 | ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, | 299 | ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, |
281 | JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL); | 300 | JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL); |
282 | if (ret != JVMTI_ERROR_NONE) { | 301 | if (ret != JVMTI_ERROR_NONE) { |
283 | warnx("jvmti: setnotification failed for method_load"); | 302 | print_error(jvmti, "SetEventNotificationMode(METHOD_LOAD)", ret); |
284 | return -1; | 303 | return -1; |
285 | } | 304 | } |
286 | 305 | ||
287 | ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, | 306 | ret = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, |
288 | JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL); | 307 | JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL); |
289 | if (ret != JVMTI_ERROR_NONE) { | 308 | if (ret != JVMTI_ERROR_NONE) { |
290 | warnx("jvmti: setnotification failed on code_generated"); | 309 | print_error(jvmti, "SetEventNotificationMode(CODE_GENERATED)", ret); |
291 | return -1; | 310 | return -1; |
292 | } | 311 | } |
293 | return 0; | 312 | return 0; |