[Gc] question about mmap code

Tom Tromey tromey at redhat.com
Wed Mar 10 15:54:10 PST 2004

Recently I ran into a problem on a PPC Linux machine, where a certain
invocation of gij (the java bytecode interpreter that comes with gcj)
will give:

    Out of Memory!  Returning NIL!

This occurs on a development OS and in a hard-to-set-up environment.
We've also got a patch in the GC to always enable USE_MMAP on Linux.

Anyway, I took a look at the mmap code:

    static ptr_t last_addr = HEAP_START;
      result = mmap(last_addr, bytes, PROT_READ | PROT_WRITE | OPT_PROT_EXEC,
		    GC_MMAP_FLAGS | MAP_ANON, -1, 0/* offset */);
    if (result == MAP_FAILED) return(0);
    last_addr = (ptr_t)result + bytes + GC_page_size - 1;

This seems a bit odd to me.  Won't this cause problems if the process
is calling mmap elsewhere?  According to the glibc manual:

     ADDRESS gives a preferred starting address for the mapping.
     `NULL' expresses no preference. Any previous mapping at that
     address is automatically removed.

So couldn't we end up unmapping memory already mapped for some other

I'm not certain that this is what is happening in my situation
(unfortunately debugging on this machine is also problematic...).  It
is just one theory I had.

Does the GC need memory to be mapped in contiguous regions like this?
Could we instead just `mmap(NULL, ...)'?  I haven't found the time to
try this yet, but I probably will sooner or later.


More information about the Gc mailing list