永中首页 | 产品聚焦 | 销售渠道 | 服务支持 | 教育专栏 | 二次开发 | 在线订购 | 产品注册 | 免费下载 | 新闻中心 | 关于永中 | 永中未来星
发新话题
打印

JAVA7有望减少运行期内核尺寸到5M以下

JAVA7有望减少运行期内核尺寸到5M以下

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?
智者有虑,行者无疆。

TOP

能否翻译成中文?俺看了就头晕

TOP

引用:
原帖由 环秀居士 于 2006-9-19 08:08 发表
能否翻译成中文?俺看了就头晕
谁要你大学时不好好学呢..

TOP

我小学毕业!!

TOP

那大学毕业后再看 :cool:

TOP

抱歉!是我实在没有空,10.1前一定找个时间翻译一下给大家重新贴上来

:funk:
智者有虑,行者无疆。

TOP

引用:
原帖由 XSI 于 2006-9-26 12:42 发表
那大学毕业后再看 :cool:
行,那俺再从ABC学起……

TOP

谁叫你大学时不好好念书呢^^:lol:

TOP

[quote]原帖由 deli 于 2006-9-26 13:56 发表
抱歉!是我实在没有空,10.1前一定找个时间翻译一下给大家重新贴上来
大哥,十一到了,哈哈

TOP

翻译出来了,不准确的地方望大家见谅

"Java Browser Edition": 新名词,先行
Posted by enicholas on September 06, 2006 at 01:28 PM | Comments (58)
"Java Browser Edition" 历史
Some time ago I proposed the idea of a Java Browser Edition.
曾经我提出过JAVA Browser Edition的思想。现在的JAVA运行环境都太大了,而大部分的应用程序仅仅需要的只是它的一个功能子集。依据"browser edition" 思想,可以实现根据特定程序的需要安装确实需要的JAVA运行环境子集,并且能够根据需要下载其他的JAVA功能部分。我为了本文做了相当的准备。希望得到更多意见反馈和引起更广泛讨论,并希望最终被SUN的开发团队所接受。
在SUN公司的一些人曾经警告过我,浏览器版肯定肯定不会出现,即时它最终被批准,也不会在第一个阶段被批准为一个特性。我被告知,这个简单的思路实际上曾经两次在SUN内被提出尝试,最终证明减少的内存占用不够大,没有价值。核心VM看上去很明显太大了,并且让它变得更小一些的努力是非常困难的。曾经有过详细的分析,这种思想描绘了实际上非常黯淡的前景收益。
新名词: Java Kernel
事实上,这个特性确实被提交为JAVA 7的一个提案,以Java Kernel的名义 (思路是,下载一个很小的JAVA功能的核,这个核具备下载其他部分的能力).并且,令人惊讶的是居然被接受了。并且,我自然成为了实现该特性团队的一名成员,而在这之前,我已经被告知,这个思想被尝试过两次,证明基本上不可能。
打造最小的 JRE
我必须做的第一件事情是,让这个项目变得可行。请记住,即时此建议被批准了,它也可能在将来的一些阶段点变成永远不被批准,如果某些方面看起来不好。 年,我曾指出,我会开始传剑一个简单的,经过剥离的仅仅包含运行”System.out.println("***o world!")”所需功过能的JRE安装器,用来评估我们期望减少JRE尺寸的大小.剥离不必须的类非常容易— 仅运行JAVA冗余模式JAVA -verbose 来装在所需要的类即可. 那些运行***o world的类全在rt.jar中。
真正的问题是剩下的那些功能单元怎么办。我的一个 Java 6 JRE重大 build版本包含683个文件,包含总共119MB。 他们中的大部分对于运行***o world来说都是不需要的。但哪些文件需要呢?决定哪些文件需要,哪些不需要是一个艰难的任务。因此我让我的计算机来为我判断。我泄了一个简单的程序,它能迭代所有的JRE文件,它能够删除一个文件然后再使用剥离后的JRE来运行***o world。 如果这个测试成功,那么显然,这个文件就不是必须的。如果测试失败,那么表明这个文件需要,并要进行恢复。
在遍历所有的文件后,剩下了一个相当小的JRE来运行***o world程序。但是它至少提供了一个开始点。从JRE自身来打造一个能用的installer是一个挑战,因为一些文件对于运行***o world不是必须,但仍然需要用来成功安装JRE。但我坚持认为现在拥有了一个完全可用的最小的JRE。
结论
根据这种方法论,我建立了两个JRE: 一个用来打印***o world(通过system.out), 另一个用来显示空的 java.awt.Frame.  下面是测试结果:
Java 6 Runtime Environment:        15.5MB
"***o World" JRE:        2.6MB
java.awt.FrameJRE:        3.5MB
需要注意的事情
在你激动之前,记住这是一个试验,并且我建立的这两个JRE没有达到最小。他们不包含Java Plug-In, Web Start, 或者确实需要的其他的冬冬,和任何真实程序所需这些组建的最小部分. 这些JRE也没有能力下载丢失的组件,如果访问到丢失的组建,仅仅是返回失败。在JAVA 7 中带来的最终的installer可能会比上面的结果更大。
下一步
尽管有上面的警告,我仍然对上面的结果非常激动。保留在脑海中如此长,以至于我们不曾作任何关于最小化复杂的事情— 只是忽略掉不需要的文件和类— 我们已经为非可视程序获得了一个小于3MB的JRE。类本身的压缩极其好,因此installer可以保持在3MB,即时也包含一些额外的类。并且仍然有很多我们可以作的事情来提高剥离量, 例如分割DLL,来实现更小的粒度。
很难说最终的Java 7 Installer会有多大。但我个人的目标是能够处理基本JAVA APPLET的JRE尺寸小于3MB。这是一个艰难的目标,它可能会胎死腹中,这个目标太乐观了,但是我尽我们所能得来靠近它。
那么你是如何看呢? 如果Java Installer是3MB大小,而不是15MB,你会发现人们更加诉求使用Java applets吗?
智者有虑,行者无疆。

TOP

注意被*过滤掉的是h e l l o

这个论坛引擎比较蠢。
智者有虑,行者无疆。

TOP

我认为现在JAVA要改的地方最主要的是速度,然后是体积。

TOP

jdk7使用的是GPL协议

TOP

发新话题