OpenJDK 默认选项始终使用服务器虚拟机

OpenJDK 默认选项始终使用服务器虚拟机

我收到一条警告消息:

jvm 使用客户端虚拟机,请确保java与服务器虚拟机一起运行,以获得最佳性能,方法是-server在命令行中添加

事实上,当我运行 java -version 时我得到:

OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-0ubuntu0.12.04.1)
OpenJDK Client VM (build 23.2-b09, mixed mode, sharing)

如何改变 OpenJDK 的默认设置,使其始终在服务器 VM 下启动?

答案1

假设您已安装客户端和服务器 VM,则只需更改 jvm.cfg 中各行的顺序,使 -server 优先。您可以按如下方式找到 jvm.cfg:

find $(dirname $(dirname $(readlink -f $(which java)))) -name jvm.cfg

在我的计算机上,它是/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/jvm.cfg

答案2

默认 Java VM 在您的文件中设置jvm.cfg。在 Windows 上,它位于 中的 Java 文件夹中C:\Program Files,在 Linux 上,路径可能会有所不同。

在我的 Ubuntu 12.04 amd64 系统上,通过以下方式安装了 Oracle Java JDK7Webupd8 ppa,文件位于/usr/lib/jvm/java-7-oracle/jre/lib/amd64。对于默认的 OpenJDK 6,文件位于/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/jvm.cfg。请注意,您需要安装 JDK 而不仅仅是 JRE。

编辑与您当前的默认jvm.cfgJava 版本相对应的 ( sudo nano /usr/lib/jvm/java-7-oracle/jre/lib/amd64/jvm.cfg)。切换-server KNOWN-server IGNORE-client IGNORE-client KNOWN

这将使-client flagjava 可执行文件“已知”,并使其忽略-server flag,从而使其成为默认值。

原始文件(默认为客户端虚拟机):

# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
#
# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
#
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
# and may not be available in a future release.
#
-server KNOWN
-client IGNORE
-hotspot ERROR
-classic WARN
-native ERROR
-green ERROR

修改后的文件(默认为服务器vm):

# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
#
# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
#
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
# and may not be available in a future release.
#
#-server KNOWN
-server IGNORE
#-client IGNORE
-client KNOWN
-hotspot ERROR
-classic WARN
-native ERROR
-green ERROR

现在测试一下改变是否有效:

$ java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

来源

相关内容