通过将自己的应用程序类添加到 classes.jsa 来加速应用程序启动 [英] Speed up application start by adding own application classes to classes.jsa

查看:28
本文介绍了通过将自己的应用程序类添加到 classes.jsa 来加速应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了加快 JVM 的启动时间,Sun 开发人员认为最好在安装 JVM 期间为平台预编译标准运行时类.可以找到这些预编译的类,例如在:

To speed up the startup time of the JVM, the Sun developers decided it is a good idea to precompile the standard runtime classes for a platform during installation of the JVM. These precompiled classes can be found e.g. at:

$JAVA_HOMEjreinclientclasses.jsa

$JAVA_HOMEjreinclientclasses.jsa

我的公司目前正在开发一个带有自己的 JRE 的 Java 独立应用程序,因此通过将我们自己的应用程序类也添加到此 jsa 文件中来加快我们的应用程序启动时间将是一个绝佳的选择.

My company currently develops a Java standalone application which brings its own JRE, so it would be a fantastic option to speed up our application start time by adding our own application classes to this jsa file, too.

我不相信 JSA 文件是魔术创建的,所以:它是如何创建的?以及如何欺骗 JVM 合并我自己的类?

I don't believe the JSA file was created by magic, so: How is it created? And how can I trick the JVM into incorporating my own classes?

编辑:我已经发现了以下内容:

EDIT: I already found out the following:

classes.jsa 由命令创建

The classes.jsa is created by the command

java -Xshare:dump

可以在 $JAVA_HOME/jre/lib/classlist 中找到要合并到转储中的类列表.

The list of classes to incorporate in the dump can be found in $JAVA_HOME/jre/lib/classlist.

我什至设法在这里添加了我自己的类(并将它们添加到 rt.jar 中以便 java 找到它们),并在类列表文件下生成我自己的校验和.

I even managed to add my own classes here (and to add them into the rt.jar for java to find them), and to generate my own checksum below the classlist file.

最后一个问题是:似乎只有包 java、com.sun 和 org.w3c 中的类被识别,如果我将相同的类留在原来的包中,它们将不会被加载.我在整个 OpenJDK 源代码中搜索了关于此的指针,但它似乎与保护域有关.如果有人对此主题足够感兴趣并且知识渊博,请添加一些指针供我进一步调查.

The final problem is: Only classes in the packages java, com.sun, and org.w3c seem to be recognized, if I leave the same classes in their original packages, they won't be loaded. I searched the whole OpenJDK source for pointer about this, but it seems to have something to do with protection domains. If someone is interested enough in this topic and knowledgeable enough, please add some pointers for me to investigaete further.

推荐答案

从 Java 8u40(和 Embedded Java 8u51)开始,Java 现在支持应用程序类数据共享 (AppCDS)(即共享存档中您自己的类).在我们的嵌入式 Java 上,我们发现启动改进超过 40%!非常棒,因为我们几乎没有任何工作......

As of Java 8u40 (and Embedded Java 8u51), Java now supports Application Class Data Sharing (AppCDS) (ie your own classes in the shared archive). On our embedded java, we've found a startup improvement of >40%! Pretty awesome for almost no work on our part...

https://blogs.oracle.com/thejavatutorials/entry/jdk_8u40_released

这篇关于通过将自己的应用程序类添加到 classes.jsa 来加速应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆