5 ms·
They've been working on a module system for Java for years (codename Jigsaw), one goal of which is to modularize Java itself, and the other goal is to have a mo
by dfabulich 9y ago
They've been working on a module system for Java for years (codename Jigsaw), one goal of which is to modularize Java itself, and the other goal is to have a module system that developers would use. It hasn't gone very well.
Today, to run a hello world app, you have to have the entire Java SE platform on disk, including GUI code, XML parsing, CORBA, a MIDI player, etc. A lot of that code is itself written in Java; you'll find there's a 64MB "rt.jar" file that provides a lot of stuff. One goal of Jigsaw is to allow you to write smaller Java applications on memory-constrained devices.
Jigsaw does an OK job at modularizing Java, but has mostly failed at its other goal: to provide a standard module system that Java developers would use. I'm sure somebody's excited to use Jigsaw in their application code, but not many.
For example, Jigsaw's module system has no notion of libraries with versions. Imagine using Maven or Gradle without any version numbers. That's Jigsaw.
Jigsaw also set a bunch of other rules that get broken a lot in practice: no circular dependencies, immutable dependencies declared up front, resolve all modules eagerly, etc. These are good guidelines, but it may not be appropriate to make them iron clad rules.
In contrast, there's a hugely complicated monster module system implemented in Java userland, OSGi. OSGi has a ton of features, including letting you load multiple versions of the "same" jar at once, so one part of your app can use the old version while another part uses a newer version. (And then there's Maven, Gradle, etc.)
This certainly wouldn't be the first time Java tried to deliver a "standard" solution for a problem that we used to solve in userland that went ignored by Java's dev community. (Logging?!) If we all ignored Jigsaw and kept using Maven/Gradle/OSGi, but the Java platform became more modular, that's probably a win.
But Jigsaw includes another poisonous feature; it "improves security" by forbidding access to internal JDK APIs like sun.misc.Unsafe, which provides access to direct memory management. For better or worse, that internal API has been used and abused by a lot of popular Java infrastructure libraries, so they're now introducing a new Unsafe feature in Java 9, but it's not the same one, "breaking" compatibility. It's their reserved right to break that API, but but but.
And finally there's the fact that Java 9 has taken a hugely long time, and this is significantly due to Jigsaw. If Jigsaw misses Java 9, does it land in Java 10? Throw it out completely? (Does Java ever get modularized?)
- nmadden 9y agoI haven't followed the process, but if they just wanted to break up rt.jar, why didn't they do just that and break it into smaller jars that you may/may not include on the classpath?
- mike_hearn 9y agoThat's pretty much what they've done. Java modules are just JARs with an additional file in them that states what they depend on, along some other stuff like which packages are meant to be used and which are internal. Look at this module graph: http://download.java.net/java/jdk9/docs/api/javafx.web-summary.html http://download.java.net/java/jdk9/docs/api/javafx.web-summa... To figure out the set of JARs you need, you need to specify which JARs your program needs, and then follow the dependencies. Which is what the new jlink tool does.
- mike_hearn 9y agoRestricting access by default to internal APIs isn't necessarily a part of Jigsaw. Any app with a security manager installed had such restrictions too, because internal APIs can be used to bypass permissions. And, sun.misc.Unsafe isn't actually restricted. Plenty of other internal APIs are but they did actually look at what apps were using the most frequently and not restrict them: you can still access Unsafe (or most of it at least) in java 9 apps (and any internal API by just setting some command line flags).