[antlr-interest] ANTLR Java Code Generation

Christian Ernst christian.ernst at poet.de
Mon Jan 7 03:37:53 PST 2002


Hy Terence !
Sorry was OOO for Christmas and New Year

Terence Parr wrote:

> Christian,
>
> Seems like this ought to be combined with the optimization I just put
> that makes individual static methods for each bitset intialization due
> to the overflow of the main static{} section.  Does your solution run
> into problems with huge static{} sections?  For example, 2.7.2a1 is
> generating stuff like this:
>
> private static final long[] mk_tokenSet_26() {
>         long[] data = { 576179277326712832L, -4611686018427281408L, 65532L,
> 0L, 0L, 0L };
>         return data;
> }
> public static final BitSet _tokenSet_26 = new BitSet(mk_tokenSet_26());
>
> BTW, does your optimization only reduce space for .class files or does
> it make initialization faster?  seems like it would be about the same as
> you are doing the same number of operations minus loop overhead, right?

I can only judge about the parser/lexer we where developing which parse
a Java Like Language.
This is a modified Version of the Java Grammar of the ANTLR Website.

There it reduce the Classsize from about 50k to 18k.
The performance gain wasn't measured, but must be there
because only the initializing is done for fields <> 0L.

In our Lexer which has 3 static field (~2000,~2000,3) Elements
this means only intializing of (~1000,~1000,3) Elements.

But as i say we can't judge about all the differnet typs of parser created by
ANTLR.
But if it is common that these static fields contains huge number of identical
sequences of
0L or other identical values it seems to be a good solution.

In our case it also cuts down the Codesize of the static section to a few
bytes, so no 65 k problem happens.
----
Another Solution we where evaluating is the use
of the Java Class 'java.util.Arrays'
which offers special Functions for
filling parts of an Array with identical values
fill(...)

But it is difficult to measure the Performance gain.
because in the Java Source of this Class this only done in a normal for loop.

But this is a Java Core Class wich could be hard wired in different Java VM's
and some weired native code is doing this.
So there could be a dramatical performance gain.

mfg
Christian









 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list