javac: "legacy" mode

Jonathan Gibbons jonathan.gibbons at oracle.com
Sat Jan 28 08:37:03 PST 2012


On 01/27/2012 09:49 PM, Ekaterina Pavlova wrote:
> On 1/27/12 5:28 PM, Mandy Chung wrote:
>> On 1/27/2012 1:37 PM, Jonathan Gibbons wrote:
>>> Until recently, javac implicitly supported "legacy" compilations 
>>> (meaning compilations that were valid in JDK 7 or earlier). This was 
>>> as side-effect by design of
>>> "single-module mode", because the default requires if none was given 
>>> was "jdk at 8-ea".
>>>
>>> Now, we have changed the default requires to "java.base@>=8". This 
>>> means that without any other changes, a legacy compilation 
>>> referencing non-base classes will fail to
>>> compile.
>>>
>>> There are two possible solutions.
>>>
>>> 1. Have javac support -Xmode:legacy, which would change the default 
>>> requires. It would also require everyone to change the way they use 
>>> javac for legacy compilations.
>>>
>>
>> This seems a major compatibility concern but it might worth taking 
>> the migration story into account. What if javac
>> -source 7 -target 7 uses the entire "jdk" as the default
>> and keep "java.base" as the default for -source 8 -target 8 (possibly 
>> provide a switch to say using the entire "jdk"
>> rather than just the base)? I'm in two minds and I
>> think it deserves some more thought.
>
> Perhaps introduce something like -Xmode:module and keep legacy mode as 
> default one
> is more safe as the compatibility will not be broken.
> Later defaults can be changed.
>
> -katya

I think it is more helpful to have javac just "do the right thing".   
There are three recognizable types of compilation for javac, roughly 
corresponding to 0, 1, many module-info files in the compilation.

legacy mode:
     no module-path option, no module-info to be compiled or on classpath
     source hierarchy is organized by packages, as now
     output dir will be organized by packages, as now

single module mode:
     class path set, or module path not set
     source hierarchy is organized by packages, as now
     output dir will be organized by packages, as now

multi-module mode
     module path set but not class path.
     source hierarchy must be organized by modules.
     output dir will be organized by modules

The presumption is that in legacy mode, you should have access to all 
JDK classes.  In either module mode, unless you specify otherwise, a 
module will only have access to the classes in the java.base module.

I also think we should add to -verbose, so that javac can be more 
informative about the type of compilation it is doing

-- Jon



More information about the jigsaw-dev mailing list