Substitution (aka aliases)
Mandy Chung
mandy.chung at oracle.com
Thu Apr 5 15:58:19 PDT 2012
I have implemented the runtime support for substitution, aka aliases,
that supports refactoring via aggregation and also allows a module to
resolve against any one of a set of equivalent implementation modules
[1]. The provides clause declares an alias name for a module:
module foo {
provides bar;
}
Any module requiring bar can be satisfied by foo.
Webrev:
http://cr.openjdk.java.net/~mchung/jigsaw/webrevs/aliases/
The main change is in the SimpleLibrary which now saves the module ids
(views and aliases) for all installed modules in a file "%mids" that
keeps a map from a ModuleId to its providing ModuleId (which I call it
module id directory. During installation and resolution, this module id
directory is locked while being updated.
There are cases that will want to find the declaring modules or only the
module-info (e.g. finding the service providers, find the modules with
an entry point). A few new methods are added in the Catalog class:
gatherLocalDeclaringModuleIds, listLocalDeclaringModuleIds,
listDeclaringModuleIds.
With this alias support, the default platform module is now "java.base"
[2]. In addition, each platform module also provides an alias name (I'm
open to any suggestion to any better names and they are what I came up
with for now).
As noted in [2], whether aliases should have version numbers is an open
issue which will be resolved separately from this prototype. However,
the compiler currently synthesizes a dependence on java.base with a
version constraint of>= N version constraint in the module-info.class if
the module doesn't declare an explicit dependence on java.base or not
the java.base module itself. Below shows the output from javap -v on
module-info.class for foo above:
$ javap -v module-info.class
Classfile foo/module-info.class
....
SourceFile: "module-info.java"
Module: foo
ModuleRequires:
1 // modules
#7,10000 // requires synthesized java/base@>=8
...
As a query of "java.base@>=8" does not match a ModuleId "java.base" with
no version, I workaround this issue in the Resolver implementation by
allowing a synthesized dependence on "java.base" to match with an alias
name.
Thanks
Mandy
[1]
http://openjdk.java.net/projects/jigsaw/doc/draft-java-module-system-requirements-12#substitution
[2] http://cr.openjdk.java.net/~mr/jigsaw/notes/jigsaw-big-picture-01
More information about the jigsaw-dev
mailing list