Jacks, gij and the GC

Christopher Marshall christopherlmarshall@yahoo.com
Fri Apr 23 14:31:00 GMT 2004

I am trying to use the GC_MAXIMUM_HEAP_SIZE environment variable to limit heap usage and I can't
get it to work.

I wrote a simple java program to allocate a large array on the heap:

import java.io.*;

public class heap {
   public static void main(String args[]) throws Exception {
      int n=Integer.parseInt(args[0]);

      System.out.println("about to allocate double array with "+n+" elements");

      double x[]= new double[n];
      for (int i=0; i<n; i++){
         x[i]= 2.0;

      System.out.println("array allocated");

And I use the following bash script run it:


   export GC_MAXIMUM_HEAP_SIZE=1000000
   ./heap 1000000 &
   #gij -mx 1000000 heap 100000 &

   xterm -e "top p $!"

When I run it under gij, the -mx option causes an OutOfMemory exception to be thrown.

When I run it as a native binary, however, the environment variable doesn't seem to limit the heap

What am I missing?

Here is my Makefile:

	gcj --classpath=. -c heap.java -o heap.o
	gcj --classpath=. -C heap.java
	gcj --main=heap -o heap heap.o

Chris Marshall

--- Bryce McKinlay <mckinlay@redhat.com> wrote:
> Ranjit Mathew wrote:
> >Anyways, to cut a long story short, I have
> >these questions:
> >
> >1. Doesn't anyone else see this behaviour on Linux?
> >
> >2. Why should the GC print out the "GC Warning" if
> >   we are throwing an OutOfMemoryError anyway?
> >  
> >
> It shouldn't. I think we should be able to fix things so that an 
> OutOfMemoryError gets thrown correctly, if you have set a maximum heap 
> size. Like Andrew says, its harder to get things right when the heap is 
> unbounded. I suspect the kernel should probably end up killing your app 
> before virtual memory is really exhausted.
> >4. Is there an option corresponding to "-mx" to limit
> >   the heap size for natively compiled executables?
> >  
> >
> There is the GC_MAXIMUM_HEAP_SIZE environment variable. However one 
> thing I want to add is a GCJ_ARGS environment variable so that you can 
> specify runtime arguments when running a gcj compiled application in a 
> similar way to what you'd do when running gij. For example:
> GCJ_ARGS="-mx=64m" ./mygcjapp
> Regards
> Bryce.

Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢

More information about the Java mailing list