Create binary from GCJ generated assembly
Andrew Haley
aph@redhat.com
Tue Oct 27 09:42:00 GMT 2009
isuru herath wrote:
> I want to add two assembly instructions to my Java program. Earlier
> I was doing it in C with "asm volatile". To get the same behavior in
> Java I used JNI. I used GCJ with -fjni flat to crate the binary. It
> executed and gave the correct output. But when I checked the memory
> references between two assembly instructions it is very high
> compared to the C program. Thereafter I got the assembly version of
> both C and Java codes with -S option. In C version, assembly
> instructions are directly inserted in the proper places. But in Java
> version library calls are placed in the places where assembly should
> be inserted. I doubt this may be the case for larger memory
> references. So my question is is there a way to edit the gcj
> generated assembly and insert assembly instructions and compile it
> to a binary. I tried two different ways(trial and error). Nothing
> worked.
>
> [1]
> gcj --main=new_shared_counter -o new_shared_counter new_shared_counter.s
>
> [2]
> gcc shared_counter.s
>
gcj can't handle inline asm.
There are a few ways to do this:
* Write the code with the asm in C++ using CNI. This is the easiest
way, and gives you results identical to using asm volatile in C.
* Add a compiler intrinsic. This requires specialist knowledge.
* Post-process the assembler output from gcj to replace a call with
some assembly instructions. Nasty, but it'd work. Again, this
requires specialist knowledge.
> Any help on how to compile a gcj generated assembly to binary would
> be greatly appreciated.
Use the assembler, "as".
Andrew.
More information about the Java
mailing list