Woohoo! langtools becoming module aware

Jonathan Gibbons jonathan.gibbons at oracle.com
Thu May 20 17:50:35 PDT 2010


Other projects get flashy demos, showing nifty new GUI features, or 
nifty new language features.

Here's what passes for a nifty demo in the world of langtools on Jigsaw.

One of the consequences of eliminating "jar hell" with Jigsaw is that 
the correspondingly nifty use-with-great-caution -Xbootclasspath option 
has gone away. This affects how JDK developers can quickly build and 
test changes to a project without building the whole project. 
Previously, you could just build your new classes, put them on the 
bootclasspath and there you were, ready to go.

The replacement for -Xbootclasspath is Jigsaw's new -L option. Various 
JDK commands, including the java command, take a -L option, to specify 
the location of the module library to be used. The library that you 
specify needn't be a complete library -- it can contain just a few 
modules, and point to a parent library for the rest.  So that provides 
the basis for being able to change a part of the system without 
rebuilding the whole.

So check out what's new for when you build the langtools repository in a 
Jigsaw forest.   There's a new target "build-module-library", and here's 
an extract from the output of Ant showing a langtools module library 
being built. The exact output doesn't matter so much as that it shows a 
module library being built containing modules for javac and javadoc. (I 
haven't added the rules for the rest of the tools yet.) Also note I'm 
having to exec the jpkg and jmod utilities, since they don't have 
corresponding Ant tasks yet.


> check-module-javac-uptodate:
>
> -def-build-module:
>
> build-module-javac:
>     [mkdir] Created dir: 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javac/classes
>      [copy] Copying 1 file to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javac/classes
>      [copy] Copying 701 files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javac/classes
>     [mkdir] Created dir: 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javac/resources
>      [copy] Copying 1 file to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javac/resources
>     [mkdir] Created dir: /w/jjg/work/jigsaw/jigsaw.lt/dist/lib
>      [exec] Creating module file javac at 7-ea.jmod for javac
>
> build-classes-javadoc:
>  [pcompile] Generating 3 resource files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/gensrc
>     [javac] Compiling 72 source files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/classes
>
> build-classes-doclets:
>  [pcompile] Generating 6 resource files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/gensrc
>     [javac] Compiling 131 source files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/classes
>      [copy] Copying 2 files to /w/jjg/work/jigsaw/jigsaw.lt/build/classes
>
> check-module-javadoc-uptodate:
>
> build-module-javadoc:
>     [mkdir] Created dir: 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javadoc/classes
>      [copy] Copying 1 file to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javadoc/classes
>      [copy] Copying 235 files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javadoc/classes
>     [mkdir] Created dir: 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javadoc/resources
>      [copy] Copying 2 files to 
> /w/jjg/work/jigsaw/jigsaw.lt/build/modules/javadoc/resources
>      [exec] Creating module file javadoc at 7-ea.jmod for javadoc
>
> check-module-library-uptodate:
>
> -def-jmod:
>
> build-module-library:
>      [echo] jmod create -L 
> /w/jjg/work/jigsaw/jigsaw.lt/dist/lib/modules ...
>      [echo] jmod install -L 
> /w/jjg/work/jigsaw/jigsaw.lt/dist/lib/modules ...
>
> BUILD SUCCESSFUL
> Total time: 42 seconds


And, if you're still reading this, here's the demo:

> $ ../jigsaw.ref/build/linux-amd64/jre-module-image/bin/java -L 
> dist/lib/modules -m javac -XDshowClass -version
> javac 1.7.0-internal
> javac: show class: com.sun.tools.javac.Main
>   
> file:/w/jjg/work/jigsaw/jigsaw.lt/dist/lib/modules/javac/7-ea/classes/com/sun/tools/javac/Main.class
>   MD5 checksum: a82df5c829d770b21eb4f3d8b6291423

Examine that line carefully.  It's using a JRE image to execute javac, 
by providing a module library that I've just compiled in my copy of the 
langtools repo.   The first line of output is the version info, as 
requested by the -version option.  The remaining lines give information 
about one of the javac classes, as requested by the -XDshowClass option. 
With that option we can see exactly where the javac class 
com.sun.tools.javac.Main is coming from, and the file URL confirms that 
it is coming from the module library we just built.

This means that while developing new features in javac, we can just 
build and use a temporary module library containing the langtools 
modules, without having to rebuild all of JDK.

Pretty nifty, huh?

-- Jon







More information about the jigsaw-dev mailing list