[gclist] Question from a newbie

Bakul Shah bakul@bitblocks.com
Sun, 11 May 2003 13:57:12 -0700


> Just for reference, so that you will have some idea what
> a Java (bytecode) compiler might do, this program:
> 
> class bar {
>   public static void main(String[] args) {
>     for (int i = 0; i < 1000000; i++) {
>       for (int j = 0; j < 1000; j++) {
> 	int[] a = new int[2000000];
===========> X
>       }
>     }
>   }
> }
> 
> runs in 5 seconds under a particular Java VM (not Sun's :-).
> 
> If you do a little math, you will realize that it cannot
> possibly be allocating (and zeroing!) all that storage
> (8,000,000,000,000,000 bytes).
> 
> Note that "a" has no finalizer, nor is it used.  The program
> cannot detect the optimization, so it is legal.

A couple of comments.  First, why isn't the entire loop being
removed?  Since nothing is returned the program can not
detect the optimization, right?  That'd shave off 5
seconds:-)

Second, even under a `debuggability' criterion (at point X
you should be able to look at the current value of `a') you
only need space for 2,000,000 ints.

My beef is with any `premature GC'.  If -g but no -o is
specified, one should be able to examine variables even when
the compiler thinks they are dead and be tempted to GC.

-- bakul