简体   繁体   English

如何加速 JVM?

[英]How do I speed up the JVM?

I'm writing some java software that is being run on both Linux and Windows XP Embedded on a Vortex86 Chip.我正在编写一些 java 软件,该软件正在 Linux 和 Windows XP 上运行,该 XP 嵌入在 Vortex86 芯片上。 The software usually loads in 2-3 seconds in Windows XP but when I try and load it in Linux it takes around 10-12 seconds.该软件通常在 Windows XP 中加载 2-3 秒,但是当我尝试在 Linux 中加载它时大约需要 10-12 秒。 I don't think its a code optimization issue because it takes 1 second to run a Hello World program.我认为这不是代码优化问题,因为运行 Hello World 程序需要 1 秒。

Any suggestions would be greatly appreciated.任何建议将不胜感激。 Pre-loading java is an option because the machine will only be running these programs but I have no idea how to do that.预加载 java 是一个选项,因为机器只会运行这些程序,但我不知道该怎么做。

As Matt pointed out, there are many factors at play.正如马特所指出的,有很多因素在起作用。 With your incomplete description, it's impossible to make targeted recommendations.由于您的描述不完整,因此无法做出有针对性的推荐。 Having said that, here are a few things to try:话虽如此,这里有几件事可以尝试:

  • Profile your memory utilization with -verbose:gc and increase the memory allotted to your program (java -Xms512m -Xmx512m)使用 -verbose:gc 分析您的 memory 利用率并增加分配给您的程序的 memory (java -Xms512m -Xmx512m)
  • Check that the version of Java on both machines is roughly equivalent检查两台机器上Java的版本大致相当
  • Check that the hardware on both machines is roughly equivalent检查两台机器上的硬件是否大致相同
  • Check whether both machines are quiet when you're measuring performance测量性能时检查两台机器是否安静
  • Make sure both are running in either 32-bit or 64-bit, and you're not reporting results from a mixed profile.确保两者都在 32 位或 64 位中运行,并且您没有报告来自混合配置文件的结果。
  • Check for startup scripts that your program may be using for one platform, but may be missing for the other (eg a run.properties)检查您的程序可能在一个平台上使用但在另一个平台上可能缺少的启动脚本(例如 run.properties)

If you have run Java before, the shared files and rt.jar will be in memory.如果您之前运行过 Java,则共享文件和 rt.jar 将在 memory 中。 ie pre-loaded for you.即为您预先加载。 I can only imagine your Linux machine is very low on memory and it has to load everything from disk each time.我只能想象您的 Linux 机器在 memory 上非常低,并且每次都必须从磁盘加载所有内容。

On my Linux box在我的 Linux 盒子上

$ time java -cp . HelloWorld
Hello World.

real     0m0.043s
user     0m0.030s
sys      0m0.010s

The total time to start and run is 0.043 seconds.启动和运行的总时间为 0.043 秒。 Can you do a similar test with your hello world?你能用你的hello world做一个类似的测试吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM