[gclist] Question from a newbie

David Chase chase@world.std.com
Thu, 08 May 2003 22:02:44 -0400


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];
      }
    }
  }
}

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.

David Chase