hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/jvmti/libjvmti.c
....@@ -7,7 +7,9 @@
77 #include <stdlib.h>
88 #include <err.h>
99 #include <jvmti.h>
10
+#ifdef HAVE_JVMTI_CMLR
1011 #include <jvmticmlr.h>
12
+#endif
1113 #include <limits.h>
1214
1315 #include "jvmti_agent.h"
....@@ -28,35 +30,43 @@
2830 }
2931 }
3032
33
+#ifdef HAVE_JVMTI_CMLR
3134 static jvmtiError
32
-do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
33
- jvmti_line_info_t *tab, jint *nr)
35
+do_get_line_number(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
36
+ jvmti_line_info_t *tab)
3437 {
35
- jint i, lines = 0;
36
- jint nr_lines = 0;
38
+ jint i, nr_lines = 0;
3739 jvmtiLineNumberEntry *loc_tab = NULL;
3840 jvmtiError ret;
41
+ jint src_line = -1;
3942
4043 ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab);
41
- if (ret != JVMTI_ERROR_NONE) {
44
+ if (ret == JVMTI_ERROR_ABSENT_INFORMATION || ret == JVMTI_ERROR_NATIVE_METHOD) {
45
+ /* No debug information for this method */
46
+ return ret;
47
+ } else if (ret != JVMTI_ERROR_NONE) {
4248 print_error(jvmti, "GetLineNumberTable", ret);
4349 return ret;
4450 }
4551
46
- for (i = 0; i < nr_lines; i++) {
47
- if (loc_tab[i].start_location < bci) {
48
- tab[lines].pc = (unsigned long)pc;
49
- tab[lines].line_number = loc_tab[i].line_number;
50
- tab[lines].discrim = 0; /* not yet used */
51
- tab[lines].methodID = m;
52
- lines++;
53
- } else {
54
- break;
55
- }
52
+ for (i = 0; i < nr_lines && loc_tab[i].start_location <= bci; i++) {
53
+ src_line = i;
5654 }
55
+
56
+ if (src_line != -1) {
57
+ tab->pc = (unsigned long)pc;
58
+ tab->line_number = loc_tab[src_line].line_number;
59
+ tab->discrim = 0; /* not yet used */
60
+ tab->methodID = m;
61
+
62
+ ret = JVMTI_ERROR_NONE;
63
+ } else {
64
+ ret = JVMTI_ERROR_ABSENT_INFORMATION;
65
+ }
66
+
5767 (*jvmti)->Deallocate(jvmti, (unsigned char *)loc_tab);
58
- *nr = lines;
59
- return JVMTI_ERROR_NONE;
68
+
69
+ return ret;
6070 }
6171
6272 static jvmtiError
....@@ -64,9 +74,8 @@
6474 {
6575 const jvmtiCompiledMethodLoadRecordHeader *hdr;
6676 jvmtiCompiledMethodLoadInlineRecord *rec;
67
- jvmtiLineNumberEntry *lne = NULL;
6877 PCStackInfo *c;
69
- jint nr, ret;
78
+ jint ret;
7079 int nr_total = 0;
7180 int i, lines_total = 0;
7281
....@@ -79,21 +88,7 @@
7988 for (hdr = compile_info; hdr != NULL; hdr = hdr->next) {
8089 if (hdr->kind == JVMTI_CMLR_INLINE_INFO) {
8190 rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr;
82
- for (i = 0; i < rec->numpcs; i++) {
83
- c = rec->pcinfo + i;
84
- nr = 0;
85
- /*
86
- * unfortunately, need a tab to get the number of lines!
87
- */
88
- ret = (*jvmti)->GetLineNumberTable(jvmti, c->methods[0], &nr, &lne);
89
- if (ret == JVMTI_ERROR_NONE) {
90
- /* free what was allocated for nothing */
91
- (*jvmti)->Deallocate(jvmti, (unsigned char *)lne);
92
- nr_total += (int)nr;
93
- } else {
94
- print_error(jvmti, "GetLineNumberTable", ret);
95
- }
96
- }
91
+ nr_total += rec->numpcs;
9792 }
9893 }
9994
....@@ -112,20 +107,32 @@
112107 rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr;
113108 for (i = 0; i < rec->numpcs; i++) {
114109 c = rec->pcinfo + i;
115
- nr = 0;
116
- ret = do_get_line_numbers(jvmti, c->pc,
117
- c->methods[0],
118
- c->bcis[0],
119
- *tab + lines_total,
120
- &nr);
110
+ /*
111
+ * c->methods is the stack of inlined method calls
112
+ * at c->pc. [0] is the leaf method. Caller frames
113
+ * are ignored at the moment.
114
+ */
115
+ ret = do_get_line_number(jvmti, c->pc,
116
+ c->methods[0],
117
+ c->bcis[0],
118
+ *tab + lines_total);
121119 if (ret == JVMTI_ERROR_NONE)
122
- lines_total += nr;
120
+ lines_total++;
123121 }
124122 }
125123 }
126124 *nr_lines = lines_total;
127125 return JVMTI_ERROR_NONE;
128126 }
127
+#else /* HAVE_JVMTI_CMLR */
128
+
129
+static jvmtiError
130
+get_line_numbers(jvmtiEnv *jvmti __maybe_unused, const void *compile_info __maybe_unused,
131
+ jvmti_line_info_t **tab __maybe_unused, int *nr_lines __maybe_unused)
132
+{
133
+ return JVMTI_ERROR_NONE;
134
+}
135
+#endif /* HAVE_JVMTI_CMLR */
129136
130137 static void
131138 copy_class_filename(const char * class_sign, const char * file_name, char * result, size_t max_length)
....@@ -234,8 +241,6 @@
234241 char *class_sign = NULL;
235242 char *func_name = NULL;
236243 char *func_sign = NULL;
237
- char *file_name = NULL;
238
- char fn[PATH_MAX];
239244 uint64_t addr = (uint64_t)(uintptr_t)code_addr;
240245 jvmtiError ret;
241246 int nr_lines = 0; /* in line_tab[] */
....@@ -252,7 +257,9 @@
252257 if (has_line_numbers && map && map_length) {
253258 ret = get_line_numbers(jvmti, compile_info, &line_tab, &nr_lines);
254259 if (ret != JVMTI_ERROR_NONE) {
255
- warnx("jvmti: cannot get line table for method");
260
+ if (ret != JVMTI_ERROR_NOT_FOUND) {
261
+ warnx("jvmti: cannot get line table for method");
262
+ }
256263 nr_lines = 0;
257264 } else if (nr_lines > 0) {
258265 line_file_names = malloc(sizeof(char*) * nr_lines);
....@@ -270,12 +277,6 @@
270277 }
271278 }
272279
273
- ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name);
274
- if (ret != JVMTI_ERROR_NONE) {
275
- print_error(jvmti, "GetSourceFileName", ret);
276
- goto error;
277
- }
278
-
279280 ret = (*jvmti)->GetClassSignature(jvmti, decl_class,
280281 &class_sign, NULL);
281282 if (ret != JVMTI_ERROR_NONE) {
....@@ -289,8 +290,6 @@
289290 print_error(jvmti, "GetMethodName", ret);
290291 goto error;
291292 }
292
-
293
- copy_class_filename(class_sign, file_name, fn, PATH_MAX);
294293
295294 /*
296295 * write source line info record if we have it
....@@ -311,7 +310,6 @@
311310 (*jvmti)->Deallocate(jvmti, (unsigned char *)func_name);
312311 (*jvmti)->Deallocate(jvmti, (unsigned char *)func_sign);
313312 (*jvmti)->Deallocate(jvmti, (unsigned char *)class_sign);
314
- (*jvmti)->Deallocate(jvmti, (unsigned char *)file_name);
315313 free(line_tab);
316314 while (line_file_names && (nr_lines > 0)) {
317315 if (line_file_names[nr_lines - 1]) {