From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1608 invoked by alias); 27 Oct 2009 09:42:42 -0000 Received: (qmail 1600 invoked by uid 22791); 27 Oct 2009 09:42:41 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Oct 2009 09:42:37 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9R9gZAb027603; Tue, 27 Oct 2009 05:42:35 -0400 Received: from zebedee.pink (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9R9gXbM006709; Tue, 27 Oct 2009 05:42:34 -0400 Message-ID: <4AE6C089.3070302@redhat.com> Date: Tue, 27 Oct 2009 09:42:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.23 (X11/20090825) MIME-Version: 1.0 To: isuru herath CC: java@gcc.gnu.org Subject: Re: Create binary from GCJ generated assembly References: <427148.24689.qm@web56004.mail.re3.yahoo.com> In-Reply-To: <427148.24689.qm@web56004.mail.re3.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-10/txt/msg00068.txt.bz2 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.