Generated code: what you see is not what you get!

Hi!

I've just discovered that the code shown by org.jnode.test.TestCompiler is different from the code actually generated. I know that TestCompiler uses the TextX86Stream, but I assumed that the code is generated by the same calls, thus the same (I even set StackManager.DISABLED = 1 to disable the pop/push optimization).

Here's the results:

1. With TestCompiler:
mov eax,0x89ABCDEF
mov edx,0x01234567
push edx
push eax
jmp Q43org5jnode2vm18MemoryBlockManager23clear2e28Lorg2fjnode2fvm2fAddress3bJ29V__bci_19_end_of_inline
Q43org5jnode2vm18MemoryBlockManager23clear2e28Lorg2fjnode2fvm2fAddress3bJ29V__bci_19_end_of_inline:
pop eax
pop edx
push eax
pop dword [ebp-4]

2. With ndisasm -u bootimage.bin
001BC490 6867452301 push dword 0x1234567
001BC495 68EFCDAB89 push dword 0x89abcdef
001BC49A 90 nop
001BC49B 90 nop
001BC49C 90 nop
001BC49D 90 nop
001BC49E 90 nop
001BC49F 58 pop eax
001BC4A0 5A pop edx
001BC4A1 50 push eax
001BC4A2 5E pop esi
001BC4A3 8975FC mov [ebp-0x4],esi

Obviously ndisasm is the "authoritative" answer, but why are the two dumps so different? Where is the difference inserted?

Thanks,
Patrik

not so different

I am not sure of what you are speaking. But it seems to me that except the nop in 2, and the lines ending with 'inline' in 1. The code number 2 is an optimisation of the 1. However I am not an x86 assembler expert so I may be wrong.

Maybe the method called in 1 is inlined in 2 and this method do nops. I think these nop are a bug or something not yet implemented.

Fabien

Here's the catch....

The first code is a dump from TestCompiler, the second one is a dump with ndisasm from the generated bootimage.

The difference is in a few optimizations like...

push eax
pop dword [ebp-4]

becomes

001BC4A1 50 push eax
001BC4A2 5E pop esi
001BC4A3 8975FC mov [ebp-0x4],esi

In this case the bootimage's code is less optimized than the dump, but in the same code snippets the opposite also happens.

I really don't understand why the push/pop code is different (I understand why the useless jmp is turned into the nops), in particular because I did switch off that optimization in the compiler.

The major problem is time: to generate a boot image requires much longer than dumping a single class (4 to 15 minutes depending on the machine I use), and I would be happy to use the class dump instead.

Thanks,
Patrik