http://weblogs.java.net/blog/enicholas/archive/2006/09/java_browser_ed.html
"Java Browser Edition": New name, first stepsPosted by
enicholas on September 06, 2006 at 01:28 PM |
Comments (52)
"Java Browser Edition" HistorySome time ago I proposed the idea of a
Java Browser Edition.The basic idea was that the current Java Runtime Environment is simplytoo big, and most programs require only a small subset of thefunctionality. The "browser edition" that I suggested would enable youto install exactly the subset of Java that your particular programrequired, but would be able to download all of the other functionalityon demand (and thus be fully compatible with J2SE). I wasn't quiteprepared for the response that this entry generated. In addition togenerating a lot of comments and further discussions, it ultimatelyplayed a role in my getting hired by the deployment team at Sun.
I was cautioned by several folks at Sun that the Browser Editionwould simply never happen. It would never be approved as a feature inthe first place, and even if it were approved, we would never be ableto actually pull it off. I'm told that this basic idea has actuallybeen attempted within Sun twice before, and in both cases the resultingsize reduction wasn't enough to be worthwhile. The core VM, it seems,is simply too big, and trying to make it smaller is too hard. There haseven been a detailed
analysis of the idea which paints a rather bleak picture of the potential gains.
New Name: Java KernelThe feature did in fact get submitted as a proposal for Java 7,under the name "Java Kernel" (the idea being that you download a small"kernel" of Java functionality, which is in turn capable of downloadingthe rest of it). And, amazingly enough, it was accepted. And, lucky me,I'm part of the team responsible for implementing it.
Afterhaving been told that it's been tried a couple of times before and thatit's basically impossible -- not a situation which inspires tremendousconfidence.
Building a minimal JREThe first thing I have to do is establish that this project isfeasible. Remember that even though it has been approved, it couldalway be un-approved (disapproved?) at any point in the future ifthings aren't looking good. So I figured I would start out by creatinga simple, stripped-down JRE installer that contained only thefunctionality necessary to run System.out.println("Hello world!"),to get an estimate of the size reduction we could expect. Stripping outthe unecessary classes is easy -- you just run Java with the -verboseoption to get a list of all of the classes it loads while running theHello World program. Those classes are all that we need to include in rt.jar.
The real problem is the
rest of the functionality. My develbuild of the Java 6 JRE contains 683 files totalling 119MB. Many ofthem are not necessary to run Hello World, but which ones? Determiningwhich files were truly necessary and which weren't could be a toughjob, so I made my computer determine it for me. I wrote a simpleprogram which would iterate through all of the files in the JRE. Itwould remove a file and then attempt to run the Hello World programusing this stripped-down JRE. If the test succeeded, the file wasevidently unnecessary. If the test failed, the file was deemednecessary and restored.
After going through all of the files in this fashion, I was leftwith an extremely minimal JRE that could run Hello World and... well,that's about it. But it at least provided a starting point. Building aworking installer from this JRE was itself a challenge, because severalof the files that weren't necessary to run Hello World were stillnecessary to successful install the JRE, but I persevered and now havea fully functioning, minimal JRE.
ResultsI built two JREs using this methodology: one with a program that prints "Hello World" to System.out, and one with a program that displays an empty java.awt.Frame. Here are the results:
| Java 6 Runtime Environment: | 15.5MB |
| "Hello World" JRE: | 2.6MB |
| java.awt.Frame JRE: | 3.5MB |
Things to noteBefore you get excited, remember that this is just an experiment andthat the JREs I built aren't the least bit useful. They don't includethe Java Plug-In, Web Start, or indeed much of anything, and any "real"program will need at least some of these components. These JREs also donot have the ability to download the missing components, and willsimply fail if an attempt is made to access missing functionality. Theinstallers we ultimately ship with Java 7 may well be bigger than this.
Next stepsDespite the cautions above, I find these results extremely exciting.Keep in mind that so far we haven't done anything the least bitsophisticated -- just omitted unnecessary files and classes -- andwe've already gotten the JRE below 3MB for a non-visual program.Classes compress extremely well, so this installer would stay under 3MBmark even with a lot of additional classes included. And there arestill a lot of things we can do to improve the size further, such asbreak up big DLLs to get better granularity.
It's hard to say how big the final Java 7 installers will end upbeing, but my personal goal is to make an installer that can handlebasic Java applets in under 3MB. This is a difficult goal, and it mayend up being too optimistic, but we're going to get as close as we can.So, what do you think? If the Java installer were 3MB instead of 15MB,would you find the idea of using Java applets (or Java Web Startprograms) more appealing?