I am using QEMU emulator for tracing the execution of an user program. We have added a helper function which prints the IP of all the executed instructions. We have tested the working of this tool for two variants of prime-number program - one in C and another in Java. We tried 4 different input arguments for each program, expecting different number of instructions executed in each case. The C version of prime-number program follows expected linear trend i.e. the number of lines increase with larger inputs. However, the Java program gives exactly same number of instructions each time.
I feel that Java execution trace is capturing only the JVM code and not the actual code that is being run.
Where would the code modified by JVM run on QEMU? Is there any special way QEMU captures the execution of self modifying code?
The Hotspot JVM (the one you are probably using) has two modes of executing java code: interpreted and compiled. When you start a program it will first run in interpreted mode. If the JVM decides a block of code is executed often enough, it will compile it and use the compiled code.
So you should see the linear trend in the number of executed instructions, but as long as the JVM runs in interpreted mode, you will only see instructions from the interpreter, since there is no byte code corresponding to java code.
Are you aware of the performance counters of the x86 CPUs? They can be used to measure the number of instructions without the use of any virtual machine. https://perf.wiki.kernel.org/index.php/Main_Page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With