Trying to build a more hackable compiler...

Robert Olofsson robert.olofsson at khelekore.org
Tue Jan 19 19:08:22 UTC 2016


Hi!

Some time ago I started reading the code for javac and I realized that
it is not a project that is easy to work on. I also realized that there
are other people that want a compiler that is easier to hack. A few
of the things that are requested are:
* Grammar based parser
* Better multi threading

I did try to make a few patches for javac to at least make it better
multi threaded, but realized that this was really hard to do, at
least for the code I looked at. Too much global state in the lexer
and parser.

I realized that I actually did take a few compiler related courses
so time to build something on my own, as a proof of concept. In case
you want to take a look: https://github.com/robert-olofsson/parjac

Initial thoughts:
* Making lexing + parsing run in parallel is easy
* Setting classes on types in parallel is easy
* Checking other semantics in parallel is easy
* Writing bytecode in parallel is easy

Parsing a reasonably big code tree (27195 files with 
11022 of them being java) and outputting class files
containing hello-world like methods with the correct signatures 
is quite a lot faster than javac doing a full compile and my
computer is a nuc i7, so not many cores.
Sure, this is a bit of apples vs oranges, but it still
indicates that it is quite possible to fulfill the wishes
of a grammar based multi threaded compiler. The heavy
part is currently parsing.

I do know of the antlr-javac experiment, but it seems to
have died, not sure what will happen to it. My experiments
with antlr indicated that it is too hard to use for a java 8
grammar and it seems like it ended up being slower than 
ordinary javac.

If this is considered advertising a non javac-compiler I do
apologize, my end goal is to make javac (based on current code or some
other code) be a better compiler and for now I only want to show that it
seems possible to make it better.

/robo


More information about the compiler-dev mailing list