我正在Windows 7 64位计算机上运行由swing创建的图形化Java应用程序。
我的应用程序是一个可运行的jar文件,可通过使用以下命令从命令提示符启动:
C:\path\to\jre\java.exe -jar myProg.jar
我的问题是,当我使用JRE8 32位而不是JRE7 32位或JRE8 64位时,会遇到巨大的性能问题。
请注意,应用程序使用相同的jar文件运行;唯一的区别是它是由不同的JRE运行的。
我尝试了不同的JRE8版本,问题仍然存在...
当我使用“-verbose”参数比较两个输出时,我看到JRE7的文本输出为1500多个:“[从共享对象文件中加载xxxxxx]”,而JRE8则没有。
也许它可能以某种方式联系在一起?
有谁知道可能是什么问题?
这是JRE7的一些输出
[Loaded MainFrame.MainFrame$XtrFileFilter from rsrc:./]
[Loaded java.awt.event.HierarchyListener from shared objects file]
[Loaded java.lang.InterruptedException from shared objects file]
[Loaded java.io.FileWriter from shared objects file]
[Loaded javax.swing.CellEditor from shared objects file]
[Loaded javax.swing.table.TableCellEditor from shared objects file]
[Loaded java.awt.image.RenderedImage from shared objects file]
[Loaded java.awt.image.WritableRenderedImage from shared objects file]
[Loaded java.awt.image.BufferedImage from shared objects file]
[Loaded sun.awt.util.IdentityArrayList from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded java.awt.Window$Type from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded java.util.concurrent.atomic.AtomicBoolean from shared objects file]
[Loaded sun.awt.AWTAccessor$WindowAccessor from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded java.awt.Window$1 from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded sun.awt.AWTAccessor$FrameAccessor from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded java.awt.Frame$1 from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded java.awt.ComponentOrientation from shared objects file]
[Loaded java.awt.Component$3 from c:\Program Files (x86)\Java\jdk1.7.0_45\jre\lib\rt.jar]
[Loaded javax.swing.ImageIcon from shared objects file]
[Loaded MainFrame.Simulation.Simulation from rsrc:./]
[Loaded MainFrame.Optimization.Optimization from rsrc:./]
[Loaded MainFrame.Convergence.Convergence from rsrc:./]
[Loaded java.awt.event.WindowEvent from shared objects file]
[Loaded MainFrame.Menu from rsrc:./]
这是一些JRE8输出
[Loaded MainFrame.MainFrame from rsrc:./]
[Loaded java.util.EventListener from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded java.awt.event.ActionListener from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded javax.swing.Action from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.reflect.NativeMethodAccessorImpl from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.reflect.DelegatingMethodAccessorImpl from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded javax.swing.UIManager from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded javax.swing.UIManager$LookAndFeelInfo from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.OSInfo from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.OSInfo$WindowsVersion from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.OSInfo$1 from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.OSInfo$OSType from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded java.awt.Toolkit from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.AWTAccessor$ToolkitAccessor from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded java.awt.Toolkit$4 from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.awt.AWTAccessor from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded java.awt.Toolkit$5 from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded java.util.ResourceBundle$Control from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
[Loaded sun.util.CoreResourceBundleControl from c:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar]
我为JRE7和JRE8运行了Xshare:dump,得到了以下结果:
JRE7:
Loading classes to share ... done.
Rewriting and unlinking classes ... done.
Calculating hash values for String objects .. done.
Calculating fingerprints ... done.
Removing unshareable information ... done.
Moving common symbols to metadata section at 0x3a033570 ... done.
Moving vmSymbols to metadata section at 0x3a1d2170 ... done.
Moving the remaining symbols to metadata section at 0x3a1d3478 ... done.
Moved 44361 symbols, 1703760 bytes.
Moving pre-ordered read-only objects to shared space at 0x38a30000 ... done.
Moving read-only objects to shared space at 0x38e129b0 ... done.
Moving string char arrays to shared space at 0x38e20cd8 ... done.
Moving pre-ordered read-write objects to shared space at 0x39430000 ... done.
Moving read-write objects to shared space at 0x399e8fb0 ... done.
Moving String objects to shared space at 0x39a3e920 ... done.
Read-write space ends at 0x39a7dd28, 6610216 bytes.
Updating references to shared objects ... done.
An error has occurred while processing the shared archive file.
Unable to create shared archive file c:\Program Files (x86)\Java\jdk1.7.0_45\jre\bin\client\classes.jsa.
Error occurred during initialization of VM
Unable to use shared archive.
JRE8:
Allocated shared space: 27394048 bytes at 0x14a00000
Loading classes to share ...
Preload Warning: Cannot find javax/swing/JComponent$2
Preload Warning: Cannot find javax/swing/RepaintManager$1$1
Preload Warning: Cannot find javax/swing/plaf/metal/MetalLookAndFeel$MetalLazyValue
Preload Warning: Cannot find javax/swing/plaf/metal/MetalLookAndFeel$MetalLazyValue$1
Preload Warning: Cannot find javax/swing/text/AbstractDocument$InsertStringResult
Preload Warning: Cannot find sun/awt/windows/WToolkit$3$1
Preload Warning: Cannot find sun/java2d/Disposer$2
Preload Warning: Cannot find sun/java2d/d3d/D3DScreenUpdateManager$1
Preload Warning: Cannot find sun/java2d/d3d/D3DScreenUpdateManager$1$1
Loading classes to share: done.
Rewriting and linking classes ...
Rewriting and linking classes: done
Number of classes 2383
instance classes = 2369
obj array classes = 6
type array classes = 8
Calculating fingerprints ... done.
Removing unshareable information ... done.
Shared Lookup Cache Table Buckets = 4108 bytes
Shared Lookup Cache Table Body = 50352 bytes
ro space: 5650016 [ 47.7% of total] out of 12582912 bytes [44.9% used] at 0x14a00000
rw space: 5396096 [ 45.6% of total] out of 12582912 bytes [42.9% used] at 0x15600000
md space: 753892 [ 6.4% of total] out of 2097152 bytes [35.9% used] at 0x16200000
mc space: 34032 [ 0.3% of total] out of 131072 bytes [26.0% used] at 0x16400000
total : 11834036 [100.0% of total] out of 27394048 bytes [43.2% used]
最佳答案
也许您安装的Shared Class Data归档文件丢失或损坏。
您可以按照“Regenerating the Shared Archive”下文档中的建议进行尝试
要重新生成存档,请以管理员身份登录;在联网情况下,登录到与Java SE安装具有相同体系结构的计算机,并确保您具有写入安装目录的权限。然后执行命令java -Xshare:dump
将在生成归档文件时打印诊断信息。
请注意,如果失败,您可以强制使用共享数据来获取错误消息(而不是减速),如同一页所述:
手动控制班级数据共享
当条件允许时,将自动启用类数据共享功能。以下命令行选项主要用于诊断和调试,在以后的发行版中可能会更改或删除。-Xshare:off
禁用类数据共享。-Xshare:on
需要启用类数据共享。如果由于各种原因而无法启用它,请打印一条错误消息并退出。-Xshare:auto
默认值;尽可能启用类数据共享。