class lookup in javac

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Aug 7 17:52:58 UTC 2014


Hi Jochen,
I would say that the root of all magic lies in Resolve.loadClass - i.e. 
that method is called whenever a class needs to be resolved given its 
qualified name. This triggers a lookup using ClassFinder (which is a new 
addition in JDK 9 compiler - if you are using older codebase you might 
find analogous routines under ClassReader). ClassFinder is responsible 
for resolving a qualified name into:

*) a source file (i.e. if the file being compiled references another 
file that is part of same compilation)
*) a class file (i.e. if the file being compiled references a class in 
the classpath)
*) both a class and a source file (if both the above case apply)

In the last case, ClassFinder will decide as to whether the source or 
the class file should be used by preferring the 'freshest' file (see 
ClassFinder.includeClassFile).

After ClassFinder has established where the bits should be coming from, 
javac will create a new ClassSymbol corresponding to the 'shell' of the 
newly found class. Whenever javac needs to access to members of this 
class, it will use a completer to do so - initially this completer will 
point to ClassFinder.complete() itself, which will then route completion 
to either JavaCompiler (source completion) or ClassReader (classfile 
completion).

I hope this helps.

Maurizio

On 07/08/14 13:50, Jochen Theodorou wrote:
> Hi,
>
> I am trying to understand javac internals a bit more and I am 
> currently trying to find out where exactly javac finds that it doesn't 
> know a class. I am also trying to identify where javac looks for a 
> precompiled class, and how that class is represented.
>
> Can I get some pointers from you guys?
>
> bye Jochen



More information about the compiler-dev mailing list