java memory allocation with gcj

isuru herath isuru81@yahoo.com
Fri Nov 6 12:44:00 GMT 2009


Hi Andrew,
Thanks a lot for the reply. Here is the code.
before change
globl _ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE
 .type _ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE, @function
_ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE:
.LFB2:
 pushl %ebp
.LCFI0:
 movl %esp, %ebp
.LCFI1:
 subl 40,ドル %esp
.LCFI2:
 movl $_ZN13test_java_new6class$E, (%esp)
 call _Jv_InitClass
.LBB2:
 movl 2,ドル 4(%esp)
 movl $_Jv_intClass, (%esp)
 call _Jv_NewPrimArray
 movl %eax, -4(%ebp)
 movl -4(%ebp), %eax
 movl %eax, -20(%ebp)
 movl -20(%ebp), %edx
 movl 4(%edx), %eax
 testl %eax, %eax
 jne .L2
 movl 0,ドル (%esp)
 call _Jv_ThrowBadArrayIndex
.L2:
 movl 0,ドル %eax
 movl -20(%ebp), %edx
 movl 12345,ドル 8(%edx,%eax,4)
.LBE2:
 leave
 ret
after change
.globl _ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE
 .type _ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE, @function
_ZN13test_java_new4mainEJvP6JArrayIPN4java4lang6StringEE:
.LFB2:
 pushl %ebp
.LCFI0:
 movl %esp, %ebp
.LCFI1:
 subl 40,ドル %esp
.LCFI2:
 movl $_ZN13test_java_new6class$E, (%esp)
 call _Jv_InitClass
.LBB2:
 movl 2,ドル 4(%esp)
 movl $_Jv_intClass, (%esp)
 call _Jv_NewPrimArray
#;added by isuru
 pushl %ecx #;for start location
 movl %eax, %ecx #;copy value in eax to ecx
 push %eax #;the memory tag
 movl 5,ドル %eax #;set eax to HEAP tag
 xchg %bx, %bx #;magic instruction
 popl %eax
 popl %ecx
#;added by isuru
 movl %eax, -4(%ebp)
 movl -4(%ebp), %eax
 movl %eax, -20(%ebp)
 movl -20(%ebp), %edx
 movl 4(%edx), %eax
 testl %eax, %eax
 jne .L2
 movl 0,ドル (%esp)
 call _Jv_ThrowBadArrayIndex
.L2:
 movl 0,ドル %eax
 movl -20(%ebp), %edx
 movl 12345,ドル 8(%edx,%eax,4)
.LBE2:
 leave
 ret
the steps I follwed.
1. gcj -S test_java_new.java
2. edit the test_java_new.s file
3. as test_java_new.s -o test_java_new.o
4. gcj --main=test_java_new -o test_java_new test_java_new.o
Is there anything wrong or do I need to do anything extra.
your help on this regard is greatly appreciated.
sincerely,
isuru
--- On Fri, 11/6/09, Andrew Haley <aph@redhat.com> wrote:
> From: Andrew Haley <aph@redhat.com>
> Subject: Re: java memory allocation with gcj
> To: "isuru herath" <isuru81@yahoo.com>
> Cc: java@gcc.gnu.org
> Date: Friday, November 6, 2009, 1:54 AM
> isuru herath wrote:
>> > Thanks for the reply. I tried in x $eax gdb after the new being executed an it was giving me the following.
> > 0x804a0e0 <_ZN13test_java_new6class$E>: 0xb7a4afe8
> >
> > When converted to decimal it was 134521056 which seems close to that of C.
> > Could you please tell me what the other value represents here.
> >
> > Seems like the way I was doing is wrong. But I couldn't find another way.
> >
> > This is my Java class.
> >
> > class test_java_new
> > {
> > public static
> void main(String[]args)
> > {
> > 
> int isuru[]=new int[2];
> > 
> isuru[0] = 12345;
> > }
> > }
> >
> > Then I compiled this with gcj -S. Then I open the
> test_java_new.s file.
> > There I add following lines after the
> > call _Jv_NewPrimArray line.
> >
> > The lines I am adding are
> > 
> pushl %ecx 
> #;for start location
> > movl 
> %eax, %ecx #;copy value in eax to
> ecx
> > push 
> %eax #;the
> memory tag
> > movl 
> 5,ドル %eax #;set eax to HEAP
> tag
> > xchg 
> %bx, %bx #;magic
> instruction
> > popl 
> %eax
> > popl 
> %ecx
>> This looks right.
>> > Why I am doing this is, when the xchg %bx, %bx is
> executed my
> > simulator (Simics) triggers an event and my hardware
> module can get
> > the control of the system. So that I can pass
> information from the
> > user program to my hardware module. But when I check
> the eax
> > register at my hardware module after xchg %bx, %bx , I
> got that
> > small number which is 166816. But when I add the same
> assembly code
> > soon after the call malloc in a gcc generated assembly
> of a C
> > program, my hardware module gets the correct address.
> Therefore I
> > was thinking it should be the same here.
>> It certainly should be. We know that when you print
> out $eax in gdb,
> you get the correct value.
>> > Some other thing I noticed is that when I invoke x
> $eax after the
> > isuru[0] = 12345; I got 0X28bc0 which is quite similar
> to 166848. I
> > don't know this helps you to help me to clarify my
> problem.
>> Let's see the assembly code of the whole function, before
> and after
> your changes.
>> Andrew.
>>
 


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /