12

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?

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
prathmesh.kallurkar
  • 5,468
  • 8
  • 39
  • 50
  • Would you be able to outline how you instrumented QEMU? (In the past I have tried something similar, but on my first attempts only managed to gather the first IP of each of QEMU's translation blocks, and not every IP.) Also, if you time your programs on native hardware, does your Java program show the expected linear slowdown? – davidg Mar 30 '14 at 09:55
  • 1
    Qemu uses dynamic translation mechanism. It converts guest block to native block and keeps it in the code cache. You should not add the tracing mechanism in the translation part. Instead, generate a helper function which is called for each instruction. A helper function is called during the execution of each instruction – prathmesh.kallurkar Mar 31 '14 at 06:22

1 Answers1

2

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

ruediste
  • 2,434
  • 1
  • 21
  • 30