[ragel-users] Re: Generating java source code

Adrian Thurston thurs... at cs.queensu.ca
Tue Feb 13 15:26:30 UTC 2007


Hi Erik, the message you read probably neglected to mention that the 
problem is with array initialization.

private static byte[] array = [ 1, 2, 3, 4, ... ];

Java initializes arrays by creating a function.

init()
{
	array[0] = 1;
	array[1] = 2;
	...
}

If there are too many elements you get the "code too large" error. This 
issue has been fixed in trunk however. Ragel now generates the 
initialization functions directly, and splits them when they get big.

Adrian

Erik van Oosten wrote:
> Hi,
> 
> I am examining the use of ragel for parsing Edifact messages to java
> beans. So I came across a message about a 64K limit of java arrays.
> 
> Well, unless I am missing something, this is simply not true. I just
> wrote a little program to test it. With -Xms1024M -Xmx1024M as JVM
> argument, the limit is somewhere between 234881023 (224M) and
> 251658239 (240M) items (I aborted the program, it was swapping too
> much).  With only 128M of memory, the limit is still a healthy
> 30955269 (29M) items.
> 
> Regards,
>      Erik.
> 
> 
> public class ArrayTest {
> 	private int getMaxArraySize(int minValue, int maxValue) {
> 		int min = minValue;
> 		int max = maxValue;
> 		while (min < max) {
> 			System.out.println(min + "\t\t" + max);
> 			int halfway = min + ((max - min) >> 1);
> 			try {
> 				Object[] arr = new Object[halfway];
> 				min = halfway;
> 			} catch (Error e) {
> 				max = halfway - 1;
> 			}
> 		}
> 		return min;
> 	}
> 
> 	public static void main(String[] args) {
> 		ArrayTest at = new ArrayTest();
> 		System.out.println(at.getMaxArraySize(0, Integer.MAX_VALUE));
> 	}
> }
> 
> 
> 



More information about the ragel-users mailing list