Re: java memory allocation with gcj

isuru herath <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
Hi Andrew,

I am really sorry for what happened. I pressed the wrong button. Please see 
the original mail below.

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

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.

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.

I really appreciate your help.

thanks and regards,
Isuru


--- On Thu, 11/5/09, Andrew Haley <[email protected]> wrote:

> From: Andrew Haley <[email protected]>
> Subject: Re: java memory allocation with gcj
> To: "isuru herath" <[email protected]>
> Date: Thursday, November 5, 2009, 4:09 AM
> isuru herath wrote:
> > Hi Andrew,
> > 
> > Thanks for the reply. So I was thinking soon after the
> call to _Jv_NewPrimArray the eax register should have the
> starting location of the the memory allocated by the mmap.
> But the value at the eax register was 166816.
> 
> So, if you're in gdb, try
> 
>   x $eax
> 
> 166816 doesn't seem unreasonable.  It can be a valid
> address.
> 
> > When I tried this with C, the value at the eax
> register after the malloc call was 155648008. I also put a
> printf(&name) in the C code and it prints the same
> address.
> > Then I tried store a value in the Java array and then
> tried to read the memory address 166816 and it wasnot giving
> me the value that I stored in my program. 
> 
> I think I need to see a test case.  Please, I need the
> code, and the steps
> you took.
> 
> > Even the memory addresses given from C and java are
> different in sizes as well.
> > 
> > Am I missing something here. I just need to know how
> to find the address of the block allocated by the "new" when
> running as native binary.
> > 
> > any help/advice on this regard is greatly
> appreciated.
> 
> Hard to say.  I know you must be doing something
> wrong, but I don't
> know what.  If you can send me a test case that
> illustrates what
> you're doing, I'll have a look.
> 
> Andrew.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.