tools/perf/jvmti: generate correct debug information for inlined code
PATCH 3/3 tools/perf/jvmti: generate correct debug information for inlined code
From: Ben Gainey <[email protected]>
tools/perf/jvmti is broken in so far as it generates incorrect debug information. Specifically it attributes all debug lines to the original method being output even in the case that some code is being inlined from elsewhere. This patch fixes the issue.
To test (from within linux/tools/perf):
export JDIR=/usr/lib/jvm/java-8-openjdk-amd64/
make
cat << __EOF > Test.java
public class Test
{
private StringBuilder b = new StringBuilder();
private void loop(int i, String... args)
{
for (String a : args)
b.append(a);
long hc = b.hashCode() * System.nanoTime();
b = new StringBuilder();
b.append(hc);
System.out.printf("Iteration %d = %d\n", i, hc);
}
public void run(String... args)
{
for (int i = 0; i < 10000; ++i)
{
loop(i, args);
}
}
public static void main(String... args)
{
Test t = new Test();
t.run(args);
}
}__EOF
$JDIR/bin/javac Test.java
./perf record -F 10000 -g -k mono $JDIR/bin/java -agentpath:pwd/libperf-jvmti.so Test ./perf inject --jit -i perf.data -o perf.data.jitted
./perf annotate -i perf.data.jitted --stdio | grep Test\.java: | sort -u
Before this patch, Test.java line numbers get reported that are greater than the number of lines in the Test.java file. They come from the source file of the inlined function, e.g. java/lang/String.java:1085. For further validation one can examine those lines in the JDK source distribution and confirm that they map to inlined functions called by Test.java.
After this patch, the filename of the inlined function is output rather than the incorrect original source filename.
--- tools/perf/jvmti/jvmti_agent.c | 16 +++-- tools/perf/jvmti/jvmti_agent.h | 7 +- tools/perf/jvmti/libjvmti.c | 147 ++++++++++++++++++++++++++++++++++------- 3 files changed, 134 insertions(+), 36 deletions(-)
tools/perf/jvmti/jvmti_agent.c +9 -7
@@ -384,13 +384,13 @@ jvmti_write_code(void *agent, char const *sym, }int -jvmti_write_debug_info (void *agent,uint64_t code,const char *file, -jvmti_line_info_t *li,int nr_lines) +jvmti_write_debug_info (void *agent,uint64_t code, +int nr_lines,jvmti_line_info_t *li, +const char *const * file_names) {struct jr_code_debug_info rec; -size_t sret, len, size, flen; +size_t sret, len, size, flen =0 ;uint64_t addr; -const char *fn = file;FILE *fp = agent;int i;
@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + } rec.p.id =JIT_CODE_DEBUG_INFO ; size =sizeof (rec);
@@ -421,7 +423,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,* file[] : source file name */ size += nr_lines *sizeof (struct debug_entry ); - size += flen * nr_lines; + size += flen; rec.p.total_size = size;/*
@@ -452,7 +454,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,if (sret !=1 ) goto error; - sret =fwrite_unlocked (fn, flen,1 , fp); + sret =fwrite_unlocked (file_names[i],strlen (file_names[i]) +1 ,1 , fp);if (sret !=1 ) goto error; }
tools/perf/jvmti/jvmti_agent.h +3 -4
@@ -14,6 +14,7 @@ typedef struct {unsigned long pc;int line_number;int discrim;/* discriminator -- 0 for now */ +jmethodID methodID; } jvmti_line_info_t;void *jvmti_open (void );
@@ -22,11 +23,9 @@ int jvmti_write_code(void *agent, char const *symbol_name, uint64_t vma, void const *code, const unsigned int code_size); -int jvmti_write_debug_info (void *agent, -uint64_t code, -const char *file, +int jvmti_write_debug_info (void *agent,uint64_t code,int nr_lines,jvmti_line_info_t *li, -int nr_lines); +const char *const * file_names);#if defined(__cplusplus) }
tools/perf/jvmti/libjvmti.c +122 -25
195 lines not on this page · raw message
Signature · 1 line
2.15.0
Arnaldo Carvalho de Melo
maintainerEm Wed, Nov 22, 2017 at 06:25:41PM -0600, Kim Phillips escreveu:
tools/perf/jvmti/jvmti_agent.c jvmti_write_debug_info(void *agent, uint64_t code, const char *file, · line 410
Quoted 9 lines
From: Ben Gainey <[email protected]>
tools/perf/jvmti/jvmti_agent.c +3
-1@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + }
Please follow the coding standard used in this file and in tools/perf, which is the kernel one.
Thanks for providing instructions on how to reproduce the problem!
Stephane, can you please Ack this?
- Arnaldo
PATCH v2 1/1 tools/perf/jvmti: generate correct debug information for inlined code
From: Ben Gainey <[email protected]>
tools/perf/jvmti is broken in so far as it generates incorrect debug information. Specifically it attributes all debug lines to the original method being output even in the case that some code is being inlined from elsewhere. This patch fixes the issue.
To test (from within linux/tools/perf):
export JDIR=/usr/lib/jvm/java-8-openjdk-amd64/
make
cat << __EOF > Test.java
public class Test
{
private StringBuilder b = new StringBuilder();
private void loop(int i, String... args)
{
for (String a : args)
b.append(a);
long hc = b.hashCode() * System.nanoTime();
b = new StringBuilder();
b.append(hc);
System.out.printf("Iteration %d = %d\n", i, hc);
}
public void run(String... args)
{
for (int i = 0; i < 10000; ++i)
{
loop(i, args);
}
}
public static void main(String... args)
{
Test t = new Test();
t.run(args);
}
}__EOF
$JDIR/bin/javac Test.java
./perf record -F 10000 -g -k mono $JDIR/bin/java -agentpath:pwd/libperf-jvmti.so Test ./perf inject --jit -i perf.data -o perf.data.jitted
./perf annotate -i perf.data.jitted --stdio | grep Test\.java: | sort -u
Before this patch, Test.java line numbers get reported that are greater than the number of lines in the Test.java file. They come from the source file of the inlined function, e.g. java/lang/String.java:1085. For further validation one can examine those lines in the JDK source distribution and confirm that they map to inlined functions called by Test.java.
After this patch, the filename of the inlined function is output rather than the incorrect original source filename.
---
v2: checkpatch fixes to match kernel codingstyle (acme)
tools/perf/jvmti/jvmti_agent.c | 15 ++-- tools/perf/jvmti/jvmti_agent.h | 7 +- tools/perf/jvmti/libjvmti.c | 160 ++++++++++++++++++++++++++++++++++------- 3 files changed, 145 insertions(+), 37 deletions(-)
tools/perf/jvmti/jvmti_agent.c +8 -7
@@ -384,13 +384,12 @@ jvmti_write_code(void *agent, char const *sym, }int -jvmti_write_debug_info (void *agent,uint64_t code,const char *file, -jvmti_line_info_t *li,int nr_lines) +jvmti_write_debug_info (void *agent,uint64_t code,int nr_lines, +jvmti_line_info_t *li,const char *const *file_names) {struct jr_code_debug_info rec; -size_t sret, len, size, flen; +size_t sret, len, size, flen =0 ;uint64_t addr; -const char *fn = file;FILE *fp = agent;int i;
@@ -405,7 +404,8 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) + flen +=strlen (file_names[i]) +1 ; rec.p.id =JIT_CODE_DEBUG_INFO ; size =sizeof (rec);
@@ -421,7 +421,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,* file[] : source file name */ size += nr_lines *sizeof (struct debug_entry ); - size += flen * nr_lines; + size += flen; rec.p.total_size = size;/*
@@ -452,7 +452,8 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,if (sret !=1 ) goto error; - sret =fwrite_unlocked (fn, flen,1 , fp); + sret =fwrite_unlocked (file_names[i], +strlen (file_names[i]) +1 ,1 , fp);if (sret !=1 ) goto error; }
tools/perf/jvmti/jvmti_agent.h +3 -4
@@ -14,6 +14,7 @@ typedef struct {unsigned long pc;int line_number;int discrim;/* discriminator -- 0 for now */ +jmethodID methodID; } jvmti_line_info_t;void *jvmti_open (void );
@@ -22,11 +23,9 @@ int jvmti_write_code(void *agent, char const *symbol_name, uint64_t vma, void const *code, const unsigned int code_size); -int jvmti_write_debug_info (void *agent, -uint64_t code, -const char *file, +int jvmti_write_debug_info (void *agent,uint64_t code,int nr_lines,jvmti_line_info_t *li, -int nr_lines); +const char *const *file_names);#if defined(__cplusplus) }
tools/perf/jvmti/libjvmti.c +134 -26
214 lines not on this page · raw message
Signature · 1 line
2.15.0
Quoted 16 lines · Arnaldo Carvalho de Melo
Em Wed, Nov 22, 2017 at 06:25:41PM -0600, Kim Phillips escreveu:
tools/perf/jvmti/jvmti_agent.c jvmti_write_debug_info(void *agent, uint64_t code, const char *file, · line 410
Quoted 9 lines
From: Ben Gainey <[email protected]>
tools/perf/jvmti/jvmti_agent.c +3
-1@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + }Please follow the coding standard used in this file and in
tools/perf, which is the kernel one.
Quoted 4 lines
Thanks for providing instructions on how to reproduce the problem!
Stephane, can you please Ack this?
Trying to test this but do not see the source code from example, yet.
Quoted 2 lines
- Arnaldo
Quoted 20 lines · Stephane Eranian
Quoted 18 lines · Arnaldo Carvalho de Melo
Em Wed, Nov 22, 2017 at 06:25:41PM -0600, Kim Phillips escreveu:
tools/perf/jvmti/jvmti_agent.c jvmti_write_debug_info(void *agent, uint64_t · line 411
Quoted 10 lines
From: Ben Gainey <[email protected]>
tools/perf/jvmti/jvmti_agent.c +3
-1@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file, return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + }Please follow the coding standard used in this file and in
tools/perf,
which is the kernel one.
Quoted 6 lines
Quoted 4 lines
Thanks for providing instructions on how to reproduce the problem!
Stephane, can you please Ack this?
Trying to test this but do not see the source code from example, yet.
Hi Stephane, sorry can you please clarify; were you expecting to see source embedded in the output from perf annotate, or are just missing the source for the reproducer, or something else?
If it is the former, then there is no source in the output, only line numbers and filenames, but this is not a regression (that I am aware of) as it was not there before the patch either.
Quoted 5 lines
Quoted 3 lines
- Arnaldo
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Stephane Eranian
Tested-byHi,
Quoted 23 lines · Ben Gainey
Quoted 22 lines · Stephane Eranian
Quoted 20 lines · Arnaldo Carvalho de Melo
Em Wed, Nov 22, 2017 at 06:25:41PM -0600, Kim Phillips escreveu:
tools/perf/jvmti/jvmti_agent.c jvmti_write_debug_info(void *agent, uint64_t · line 411
Quoted 10 lines
From: Ben Gainey <[email protected]>
tools/perf/jvmti/jvmti_agent.c +3
-1@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file, return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + }Please follow the coding standard used in this file and in
tools/perf,
which is the kernel one.Thanks for providing instructions on how to reproduce the problem!
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Stephane, can you please Ack this?
Trying to test this but do not see the source code from example, yet.
Hi Stephane, sorry can you please clarify; were you expecting to see source embedded in the output from perf annotate, or are just missing the source for the reproducer, or something else?
No, I finally tracked down my issue. It was due to a broken perf build system where it would not detect libdw-dev when in fact it was there. I just posted a patch to fix this. With that fix, I am able to test your patch and things look good to me.
Quoted 4 lines
If it is the former, then there is no source in the output, only line numbers and filenames, but this is not a regression (that I am aware of) as it was not there before the patch either.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
- Arnaldo
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
tip-bot for Ben Gainey
merge bot[tip:perf/urgent] perf jvmti: Generate correct debug information for inlined code
In reply to Kim Phillipsperf jvmti: Generate correct debug information for inlined code
Commit-ID: ca58d7e64bdfc54f7dfe46713c1e2acc68d7522d Gitweb: https://git.kernel.org/tip/ca58d7e64bdfc54f7dfe46713c1e2acc68d7522d Author: Ben Gainey <[email protected]> AuthorDate: Wed, 22 Nov 2017 18:25:41 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 18 Dec 2017 11:54:08 -0300
perf jvmti: Generate correct debug information for inlined code
tools/perf/jvmti is broken in so far as it generates incorrect debug information. Specifically it attributes all debug lines to the original method being output even in the case that some code is being inlined from elsewhere. This patch fixes the issue.
To test (from within linux/tools/perf):
export JDIR=/usr/lib/jvm/java-8-openjdk-amd64/
make
cat << __EOF > Test.java
public class Test
{
private StringBuilder b = new StringBuilder();
private void loop(int i, String... args)
{
for (String a : args)
b.append(a);
long hc = b.hashCode() * System.nanoTime();
b = new StringBuilder();
b.append(hc);
System.out.printf("Iteration %d = %d\n", i, hc);
}
public void run(String... args)
{
for (int i = 0; i < 10000; ++i)
{
loop(i, args);
}
}
public static void main(String... args)
{
Test t = new Test();
t.run(args);
}
}__EOF
$JDIR/bin/javac Test.java
./perf record -F 10000 -g -k mono $JDIR/bin/java -agentpath:pwd/libperf-jvmti.so Test ./perf inject --jit -i perf.data -o perf.data.jitted
./perf annotate -i perf.data.jitted --stdio | grep Test\.java: | sort -u
Before this patch, Test.java line numbers get reported that are greater than the number of lines in the Test.java file. They come from the source file of the inlined function, e.g. java/lang/String.java:1085. For further validation one can examine those lines in the JDK source distribution and confirm that they map to inlined functions called by Test.java.
After this patch, the filename of the inlined function is output rather than the incorrect original source filename.
--- tools/perf/jvmti/jvmti_agent.c | 16 +++-- tools/perf/jvmti/jvmti_agent.h | 7 +- tools/perf/jvmti/libjvmti.c | 147 ++++++++++++++++++++++++++++++++++------- 3 files changed, 134 insertions(+), 36 deletions(-)
tools/perf/jvmti/jvmti_agent.c +9 -7
@@ -384,13 +384,13 @@ jvmti_write_code(void *agent, char const *sym, }int -jvmti_write_debug_info (void *agent,uint64_t code,const char *file, -jvmti_line_info_t *li,int nr_lines) +jvmti_write_debug_info (void *agent,uint64_t code, +int nr_lines,jvmti_line_info_t *li, +const char *const * file_names) {struct jr_code_debug_info rec; -size_t sret, len, size, flen; +size_t sret, len, size, flen =0 ;uint64_t addr; -const char *fn = file;FILE *fp = agent;int i;
@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,return -1 ; } - flen =strlen (file) +1 ; +for (i =0 ; i < nr_lines; ++i) { + flen +=strlen (file_names[i]) +1 ; + } rec.p.id =JIT_CODE_DEBUG_INFO ; size =sizeof (rec);
@@ -421,7 +423,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,* file[] : source file name */ size += nr_lines *sizeof (struct debug_entry ); - size += flen * nr_lines; + size += flen; rec.p.total_size = size;/*
@@ -452,7 +454,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,if (sret !=1 ) goto error; - sret =fwrite_unlocked (fn, flen,1 , fp); + sret =fwrite_unlocked (file_names[i],strlen (file_names[i]) +1 ,1 , fp);if (sret !=1 ) goto error; }
tools/perf/jvmti/jvmti_agent.h +3 -4
@@ -14,6 +14,7 @@ typedef struct {unsigned long pc;int line_number;int discrim;/* discriminator -- 0 for now */ +jmethodID methodID; } jvmti_line_info_t;void *jvmti_open (void );
@@ -22,11 +23,9 @@ int jvmti_write_code(void *agent, char const *symbol_name, uint64_t vma, void const *code, const unsigned int code_size); -int jvmti_write_debug_info (void *agent, -uint64_t code, -const char *file, +int jvmti_write_debug_info (void *agent,uint64_t code,int nr_lines,jvmti_line_info_t *li, -int nr_lines); +const char *const * file_names);#if defined(__cplusplus) }
tools/perf/jvmti/libjvmti.c +122 -25
195 lines not on this page · raw message