#242 Java profiling of 32-bit JVM on x86_64 does not work

Maynard Johnson

Doing Java profiling on x86_64 of a 32-bit JVM is problematic, in particular, if you are using the distro-supplied oprofile package, where the base tools are compiled 64-bit. It's an issue with struct padding. We don't see the issue on some other architectures, such as ppc64, where gcc will automatically pad for 8-byte alignment where appropriate -- whether you compile -m32 or -m64; but that padding isn't done on x86_64 when you compile with -m32. For example, a struct that looks like the following:
struct jitheader {
u32 magic;
u32 bfd_arch;
u32 bfd_mach;
u64 timestamp;
would always get an extra 4-bytes of padding between bfd_mach and timestamp when built on IBM Power; but on x86_64, it only gets the padding if it's built with -m64.

The libjvmti_oprofile writes out a binary JIT dump file, which is later read and interpreted by the opjitconv program. The libjvmti_oprofile library bitness has to match the bitness of the JVM. The opjitconv that's shipped with the x86_64 distro is typically 64-bit, so we'll have a mismatch when it's parsing a JIT dump file 'jitheader' struct from a 32-bit libjvmti_oprofile.

I think a solution to this would be to redefine the jitheader struct to include the padding.


  • A bit more detail on the error . . .

    First, you need to build oprofile twice -- once with -m64 and once with -m32. Install the full 64-bit version and then copy the 32-bit Java agent libs to the 64-bit installation -- of course, copying to the "lib" dir, not "lib64". For example:
    cp op32-install/lib/oprofile/* op64-install/lib/oprofile

    Now use the 64-bit operf to profile a 32-bit JVM, for example:

    operf /opt/ibm/java-i386-70/jre/bin/java -agentpath:/home/mpjohn/op64-install/lib/oprofile/libjvmti_oprofile.so myJavaTestApp

    You should see the following error:

    bfd_openw: Invalid bfd target
    JIT dump processing exited abnormally: 1

    The "bfd_openw" error comes from opjitconv/create_bfd.c:open_elf(). Debugging further shows the dump_bfd_target_name is not correct -- I see "2-i386".

    • assigned_to: hanseld
    • Group: -->
  • Daniel, can you please take a look at this bug?

  • Daniel, can you find time to fix this? Thanks.