1 /* This test checks for two slightly different overflow scenarios in
4 * The first is that the number of bytes needed for an array size
5 * overflows on a 32 bit machine.
7 * The second is that on a 64 machine, the number of bytes silently
8 * gets truncated, resulting in too small an object being
11 class newarray_overflow
13 static boolean failed = false;
15 static void int_check()
20 x = new int [1 << 30];
22 catch (OutOfMemoryError e)
26 /* If we really get away with it (64 bit machine), that's cool. */
28 System.err.println ("int check: new returned null.");
34 // Only check a few places so we don't thrash too badly.
35 for (int i = 0; i < x.length; i += (1 << 24))
41 System.err.print ("int check: ");
42 System.err.println (e);
47 static void object_check()
52 x = new Object [1 << 30];
53 System.err.println ("Alloc succeeded.");
54 System.err.println (x);
56 catch (OutOfMemoryError e)
60 /* If we really get away with it (64 bit machine), that's cool. */
62 System.err.println ("Object check: new returned null.");
68 for (int i = 0; i < x.length; i += (1 << 24))
74 System.err.print ("Object check: ");
75 System.err.println (e);
80 public static void main (String[] ignore)
86 System.out.println ("ok");