Create binary from GCJ generated assembly

Bryce McKinlay bmckinlay@gmail.com
Wed Oct 28 15:22:00 GMT 2009


On Wed, Oct 28, 2009 at 11:05 AM, isuru herath <isuru81@yahoo.com> wrote:

> Thanks a lot for the quick reply. I did accordingly. But results were not the same. My program is a multi threaded shared counter.
> so in my Java code I have
>
> counter++
>
> I need to surround this with two xchg instructions. like
>
> xchg
> counter++
> xchg
>
> so that I can count number of read and write operations between two xchg instructions.
>
> with gcc I got both as 1 which is correct.
> with gcj and JNI I got 47 read operations and 29 write operations
> with gcj and CNI I got 6 read operations and 6 write operations

This is because you are making calls into native code from Java. GCJ
cannot inline native code into your Java code. Calls are not free -
you are measuring the overhead of returning back from native code into
Java code and vice-versa.

If you need to add asm instructions to GCJ compiled code, you can
generate assembler using something like:

gcj -S MyClass.java

Then, edit the resulting assembler .s file to add the instructions.
Finally, link it with something like:

 gcj MyClass.s --main=MyClass

Bryce



More information about the Java mailing list