Hope, Fear, and Project Jigsaw
On 3rd December 2008, Sun announced that JSR 277 was — to all intents and purposes — dead, and that work on modularity would proceed under the new banner of “Project Jigsaw”. Furthermore, they promised to work entirely in the open and to co-operate with the OSGi Alliance in developing Jigsaw. This sounds great for those of us in the OSGi camp, and it could be a great opportunity to take OSGi to the next level, including modularisation of the Java runtime libraries and deeper integration with the Java language itself, the javac compiler and surrounding tools.
But, it could also turn out to be a total train-wreck. You see, the announcement, which appears here in Mark Reinhold’s blog, was very carefully and skilfully worded so as to promise very little while making Sun look like a great team player. But the actual outcome depends on Sun’s future behaviour.
Let’s look at what was announced a bit more closely. Jigsaw is supposedly a project for modularising the JRE itself, which is a very desirable goal, though one which Apache Harmony has already achieved. The first concrete item announced in the blog post is the death of JSR 277, or at least its suspension until after Java 7 (code-named “Godot”) arrives. There wasn’t much to love about 277 and most of the OSGi community either wished it would just die, or were working hard to try to fix its glaring flaws from the inside (like Brian Atsatt). So now it’s dead, surely the “just die” camp are happy?
Well, the one good thing about JSR 277 was that it was a JSR! As such, it was subject to the procedures of the Java Community Process (JCP), the most important of which being the ballot of the Executive Committee (EC), which every JSR must pass before it becomes an officially approved specification of the JCP. Not even Sun can force through a JSR against a majority of “no” votes in the EC, at least without unilaterally changing the rules of the JCP… and doing that would have shown up the whole JCP as a sham. So, if the final draft of JSR 277 had turned out anywhere near as awful as the first draft in October 2006, then the EC could have simply voted against it and that would be that. Let me just say that the OSGi community did not resist the creation of another module system because of fear or arrogance, but because we knew from long experience what a difficult and complicated task it would be. OSGi has been evolving and improving for ten years, and many lessons have been learned along the way. Invent something new if you must, but ignore the lessons of OSGi at your peril. JSR 277 seemed to go out of its way to ignore those lessons, shutting out OSGi experts and making technical decisions that were clearly doomed to failure. It’s fine to replace OSGi as long as you replace it with something better, but JSR 277 was going to be far worse.
Next, Mark goes on to explain that JSR 294 (the so-called “superpackages” JSR) will be revived. This JSR is all about support for modularity directly within the Java language, which is a relatively uncontroversial idea if done right. He then points out the success that OSGi has had in modularising Apache Harmony, but laments OSGi’s lack of integration with the Java language.
Now, it is not at all vital to have new keywords in the Java language in order to build modular applications today. Note that almost all of the J2EE application server vendors (including Sun itself) are either already building their servers in a modular fashion on top of OSGi, or are in the process of rebuilding them that way. Harmony shows that Java language support is also not a pre-requisite for building modular JREs. It would undoubtedly be a useful convenience to developers, as would enhancing the javac compiler to understand modularity better, but the absence of these conveniences is not a barrier to progress. Remember that, at Sun’s encouragement, more and more developers are using languages other than Java to build applications that run on the JRE. Some are using JRuby, a Sun-supported language project, others use Jython or Clojure or my own personal favourite, Scala. They can all use OSGi. So to discuss OSGi’s lack of Java language integration here seems like a distraction tactic. Nevertheless, Sun have promised to work with OSGi to make sure that OSGi can leverage the new language features when they become available, and that promise is very welcome.
Next Mark gets into the meat of the announcement about Jigsaw, and here I must quote him verbatim:
“This effort will, of necessity, create a simple, low-level module system whose design will be focused narrowly upon the goal of modularizing the JDK.”
“Of necessity”? What necessity is this? It is not explained either above or below. This seems like an appropriate time to point out that OSGi is also known as JSR 291 and is a fully approved official specification of the JCP. It should be the first choice when looking for a module system, unless there are sound technical reasons why it is inappropriate, in which case those reasons should be spelled out. Then the OSGi community could seeks ways to address those shortcomings, whatever they might be. There is certainly room for improvement in OSGi, but don’t simply replace it with something new (and probably inferior) just because it only does 98% of what you need.
Oh well, if Jigsaw is just an internal JRE thing then perhaps it’s not so bad… back to Mark:
“This module system will be available for developers to use in their own code, and will be fully supported by Sun…”
Right, so it’s NOT just an internal JRE thing. Developers of libraries and applications on top of the JRE will be encouraged by Sun to use Jigsaw. Presumably they will be encouraged to use it instead of OSGi, which sounds like a return to the bad old JSR 277… oh well, never fear, the Executive Committee will save us, won’t they? No, they won’t, because they can’t:
“…but it will not be an official part of the Java SE 7 Platform Specification and might not be supported by other SE 7 implementations.”
This work is being done outside of the JCP, so there will be no JSR for the Committee to vote on. Developers will be encouraged to use a proprietary module system cooked up by Sun rather than the JCP standard module system and if they do so they will be locked into just one Java implementation: Sun’s. The penultimate and final paragraphs attempt to put a positive spin on this bombshell, again I must quote them verbatim:
“In the meantime we’ll actively seek ways in which to interoperate with other module systems, and in particular with OSGi. All work on Project Jigsaw will be done completely in the open, in as transparent a manner as possible. We hope you’ll join us!”
This really goes to the heart of the problem. Yes, Java is (finally!) an open source project, OpenJDK, so any code that Sun checks into Project Jigsaw will immediately be visible to all who wish to see it. This is a huge improvement over JSR 277 where all of the work was done in secret. But there’s a big difference between open source and open governance. Sun employees constitute greater than 99% of the committers on OpenJDK, and any external committers are vetted by Sun and can be removed by Sun, so in practice no external parties will have the ability to significantly influence the direction of Jigsaw. A train-wreck happening in the open, and with no chance to stop it from happening, is still a train-wreck.
I don’t wish to be entirely negative. Jigsaw may be a great success, and Sun might actually keep their promise to work closely with OSGi. In my opinion the best way to interoperate with OSGi would be to simply use OSGi: they could use one of the existing open source implementations — they already employ the lead developer of one of them — or they could build a new implementation of their own. The specification is completely free and open for anyone to implement, and they certainly don’t lack the technical smarts to build an awesome implementation.
The future then is in Sun’s hands, for now the rest of us can only observe where they go with this. There is hope and opportunity in the Jigsaw announcement, but Sun has abused the trust of the OSGi community before so it’s naturally difficult to trust them now. However, I talked to Peter Kriens (the OSGi Alliance’s Director of Technology) and he said his plan is to work with Sun as closely as possible. Let’s call this his Sunshine Policy: by exposing Mark Reinhold and his team to OSGi as much as possible, he hopes to win them over. It could happen. Sunshine didn’t work for Kim Dae-jung, but it might for Peter… most developers I know have been won over by OSGi once they truly understood it.
Going back to the open governance question, I’d like to add my voice to the chorus calling for Java to be set free from Sun. A great analogy is with Eclipse: IBM released Eclipse as open source, but other vendors didn’t really get on board and build their own Eclipse-based tools until IBM spun it off as an independent entity. After that the ecosystem exploded (in a good way!), and created far more value for IBM than if they had held tightly onto the reins. And of course IBM is still very influential in that ecosystem although they hold no special status under the rules of the Eclipse Foundation. IBM is no altruist, they let Eclipse go for sound commercial reasons. Sun could do the same with Java, which I think would cause the Java ecosystem — already pretty huge — to expand to absolutely insane proportions.
Now, Mark, wouldn’t that be cool?


Hal:
Mark, wouldn’t that be cool?
Amen.
December 8, 2008, 1:14 amEd Merks:
Thanks for writing such an excellent post. You’ve got a great many good points for a point-free blog!
December 8, 2008, 12:54 pmben:
Can you explain to a noob why osgi is better than guice? Every time I look at those xml files and manifests I puke a little. I feel like it’s cancer creeping up on me, and we are losing the primary benefit of java: static analysis of bytecode.
December 8, 2008, 1:39 pmNeil:
@ben,
OSGi is not better than Guice, they are completely different things. Please read one of my introductory blog posts about what OSGi is, e.g. “What is OSGi For?” or perhaps the introduction to my book. I’ll leave you to find your own introductory guide to what Guice is.
Note that OSGi and Guice work well together, thanks to he efforts of Stuart McCulloch and his Peaberry project.
Also note that there is no XML in OSGi, and I can’t imagine why you think that OSGi causes us to lose static analysis of bytecode. In fact OSGi enables enhanced static analysis at the module level. I wonder if you have OSGi confused with Spring??
Regards, Neil
December 8, 2008, 2:02 pmben:
Hmm.. I thought osgi was what eclipse was built on. I have done a few plugins and it was horrible debugging things at runtime.
Ok, just looked at your article: Import-Package: org.apache.log4j Bundle-RequiredExecutionEnvironment: J2SE-1.5
Isn’t that just as bad, or WORSE than xml?
December 8, 2008, 2:08 pmNeil:
@ben, no it is not. Those are explicit declarations of what the module in question depends on. The alternative to manifests and/or XML is to simply not declare dependencies, which is what most JARs do. The result is dependencies are implicit, hidden within the bytecode and ready to jump out with NoClassDefFoundErrors at runtime.
I’m not sure whether you have a problem with the format of this metadata, or simply its existence. If the latter, then note that Guice uses lots of metadata too. If you think all metadata should be annotations, well that can be done easily enough, and it doesn’t require big changes to the JVM or Java language.
December 8, 2008, 2:12 pmben:
Why doesn’t someone in the osgi camp simply implement the changes to the jvm?
How would you approach it?
December 8, 2008, 2:29 pmben:
I am meaning the in-code metadata. Would it look like: // default package class MyModule extends MetaInformation { public MyModule(){ super(version(1.5.5)); requires(AnotherModule.version(1.6.0); requires(Java.version(1.7.0); } }
December 8, 2008, 2:34 pmNeil:
@ben, You could certainly use @annotations in source code to produce the metadata in the manifest.
The advantages of using MANIFEST.MF are that (1) every JAR file already has one (2) it’s text so you can read it, whereas source code gets compiled into unreadable bytecode, and (3) it’s still very efficiently read at runtime using libraries that are already present in the JRE.
For what it’s worth, I share your dislike of XML. The lower levels of OSGi cannot use XML because many Java runtimes (e.g. Java ME) do not include XML parsers.
December 8, 2008, 4:08 pmchhum:
Its very easy for people to sit on the sidelines and complain at Sun when things are not to there liking. I really hope that the OSGi camp, who so far have been ludicrously hostile to attempts by Sun and others in the community to solve this particular problem, will now actually get involved in the efforts to provide a workable solution.
December 8, 2008, 4:21 pmDavid Bosschaert:
Excellent post, Neil!
December 8, 2008, 4:31 pmCiro Cavani:
I have some experience with OSGi (mostly because I use it with in Eclipse RCP as base for a business user oriented product) and some with Seam/EJB3 (services on server side of the same product).
I think that the fundamentals of OSGi are very good, but the programming model is not so good.
Classloading, versioning and classes visibility are very interesting. But services, no-DI, no-Context and Java ME-constrain is not.
Things I would like for OSGi to turn it Java Modules:
Comes to my mind some king of integration with WebBeans. I think that WebBeans may became the Java DI (”javax.dependency” / “javax.contexts”). In other words, using OSGi infrastructure with WebBeans programming model sounds very good to me.
Other thing that bother me. OSGi is a JSR, but all specification is done outside JCP by OSGi Alliance. This doesn’t seems a good way to evolve core specifications. How other parties take place in JSR 291 without been part of OSGi Alliance?
Just my two cents…
December 9, 2008, 1:24 amCiro Cavani:
I get my answer from JCP votes page for JSR 291. So OSGi is very good (and I use it). But the specification process is made by OSGi Alliance. And some members of JSR have some concern about this.
In my list, I would add: OSGi really been part of JCP.
By the way, great post and book.
Thanks,
December 9, 2008, 1:50 amleonardoavs:
I believe that JSR-277 has some things good they are Repositories, and modules integrated in the language(JSR-294) this is not obligatory to have, but it help the development time.
I hate eclipse module system (OSGi based) because is not easy for a beginner, it is not good for install plug-ins.
OSGi is mature, big, and powerful, but need modules integrated in the language and repositories. Because the common developer has many problems to solve, they do not need to manage module dependencies by hand. And the common developer needs facilities to deploy modules like: web repositories, application repositories and so on. They need more easy of development features.
December 9, 2008, 3:24 amben:
Neil, not to be picky, but text files aren’t readable without a text editor either. As long as there is something convenient to view it with, it shouldn’t matter.
@ben, You could certainly use @annotations in source code to produce the metadata in the manifest. – I don’t like this approach, we need configuration by convention + overriding for those that like that sort of thing. Why not simply require a java class to do it? The reason I like this approach is because refactoring is free… and compile time errors occur when things aren’t right. It’s why in my opinion guice trumps spring.
The advantages of using MANIFEST.MF are that (1) every JAR file already has one (2) it’s text so you can read it, whereas source code gets compiled into unreadable bytecode, and (3) it’s still very efficiently read at runtime using libraries that are already present in the JRE. – Why not think of the best thing to do for java developers. If you could start again, what would you do?
For what it’s worth, I share your dislike of XML. The lower levels of OSGi cannot use XML because many Java runtimes (e.g. Java ME) do not include XML parsers. – The only reason I hate xml is because when there are errors in xml you don’t know until runtime. By moving everything we can towards java, we get the primary benefit of the language for free. Otherwise I would just use a dynamic language.
December 9, 2008, 5:35 amben:
Why was my last comment deleted?
December 13, 2008, 4:38 amNeil:
@ben
No comments have been deleted. I only delete spam, never real comments by humans no matter how much I may disagree with them. Did you get the CAPTCHA entry correct?
Neil
December 13, 2008, 10:43 amAditya:
We have been using OSGI alot.OSGi and the article by u(Neil) simply rocks !
December 17, 2008, 1:00 pmWAAAAAAAAAAAA:
Neil,
I don’t understand where you’re coming from.
There are tons of open source java projects that are not part of the JCP. I don’t like them all, and I don’t have to use them. If the project fails, no harm is done.
If you’re upset because you want to modularize the JRE and provide this capability to developers through pure OSGi, there’s nothing stopping you from starting your own open source project to do this.
Projects happen all the time outside of the JCP. Often times, once several similar projects have matured and shown their value, a JSR will be started to create a best-of-breed standard based on proven approaches (ejb3, webbeans, etc). Other times a JSR is started to adopt a specific solution (concurrency, joda time, etc).
Projects outside of the JCP are great for many reasons: - they typically evolve much faster then the JCP - they provide alternatives to developers - if they aren’t well received, it’s not Sun or Java’s failure
Truth be told, it might be a good idea for Sun to do more projects like this prior to creating JSRs. This way, the community will get to have/use the projects much sooner and once they have proven their worth and learned from their mistakes, a JSR should be started.
January 8, 2009, 6:24 pmJava Modularity - OSGi and Project Jigsaw : Software & Technology @kirkk.com:
[...] Neil Bartlett’s enlightening synopsis of Jigsaw in this blog post titled Hope, Fear, and Project Jigsaw. [...]
June 12, 2009, 1:43 pmJava Developers’ Feelings about Java SE 7 | PHP Hosts:
[...] to have seen some of the cut proposed features make it into Java SE 7, I am looking forward to better modularity, null safe operators, improved exception handling, and automatic resource management support. A JVM [...]
August 6, 2009, 6:43 am