OpenJDK parser internals
Rémi Forax
forax at univ-mlv.fr
Sun Sep 25 16:09:06 PDT 2011
On 09/26/2011 12:38 AM, Dr Andrew John Hughes wrote:
> On 23:27 Sun 25 Sep , Steve S wrote:
>> Hi All,
>>
>> I'm just started deeply digging into OpenJDK sources (jdk6, langtools).
>> The following strikes me as odd:
>>
>> 1. Ast tree members (JCTree descendants) expose all theirs members in public
>> access.
>> Do I understand right that this is done due to: (1) simplicity, (2)
>> performance gain?
>> Is the option to rewrite it with final fields and getters ever considered?
>>
>> 2. Lots of code with old-fashioned for-loop instead of for-each loop (e.g.
>> iterating over internal linked List).
For-each loop creates an iterator, which has a performance impact,
but this need to be tested again because hotspot now does escape analysis.
>>
>> 3. Verbose exception handling approach - e.g. .tools.javac.tree.Pretty - all
>> the visitor methods wraps implementation in try-catch block though it is
>> sufficient to provide Pretty.print implementation that only wraps out.write
>> to try-catch block with throwing UncheckedIOException.
No, you want printExpr to throw an IOException.
Here the main problem is that the visitor is not written in a way that
let propagate checked exception.
public class Visitor<E extends Exception> {
public void visit(JCAssert tree) throw E;
...
}
>>
>> 4... Lots of other stuff like code duplication, violation of encapsulation,
>> etc.
>>
>> Does someone have a "plan" to refactor this code? I never ever seen in the
>> jdk7, 8 forks - may be it's worth it?
>> Looks like it'd be a real pain due to lots of forks and would result in a
>> outrageously complex merge.
>>
>> ---
>> Best Regards,
>> Alex
> As a first suggestion, I'd look at the jdk8 code as that's where
> active development takes place, specifically
> http://hg.openjdk.java.net/jdk8/tl/langtools. The OpenJDK6 code is
> very outdated, with only a few backports since it was forked from
> OpenJDK7 around b22.
Rémi
More information about the compiler-dev
mailing list