缺少 java.compiler 系统 属性
Missing java.compiler system property
我正在使用 Java 8. According to the docs,系统 属性 java.compiler
应该存在。然而,当我 运行 甚至是基本的 class 时,它都不是。
import java.util.Comparator;
import java.util.Map;
public class SystemPropertiesPrinter {
public static void main(String[] args) {
Map<String, String> properties = (Map) System.getProperties(); // It's a pain to sort without this artificial cast
properties.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.forEach(e -> System.out.printf("%-30s -> %s%n", e.getKey(), e.getValue()));
}
}
我运行它用下面的命令:
java SystemPropertiesPrinter
结果如下:
awt.toolkit -> sun.awt.windows.WToolkit
file.encoding -> Cp1252
file.encoding.pkg -> sun.io
file.separator -> \
java.awt.graphicsenv -> sun.awt.Win32GraphicsEnvironment
java.awt.printerjob -> sun.awt.windows.WPrinterJob
java.class.path -> .
java.class.version -> 52.0
java.endorsed.dirs -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\endorsed
java.ext.dirs -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
java.home -> C:\Program Files\Java\jdk1.8.0_66\jre
java.io.tmpdir -> C:\dev\cygwin64\tmp\
java.library.path -> <edited out>
java.runtime.name -> Java(TM) SE Runtime Environment
java.runtime.version -> 1.8.0_66-b18
java.specification.name -> Java Platform API Specification
java.specification.vendor -> Oracle Corporation
java.specification.version -> 1.8
java.vendor -> Oracle Corporation
java.vendor.url -> http://java.oracle.com/
java.vendor.url.bug -> http://bugreport.sun.com/bugreport/
java.version -> 1.8.0_66
java.vm.info -> mixed mode
java.vm.name -> Java HotSpot(TM) 64-Bit Server VM
java.vm.specification.name -> Java Virtual Machine Specification
java.vm.specification.vendor -> Oracle Corporation
java.vm.specification.version -> 1.8
java.vm.vendor -> Oracle Corporation
java.vm.version -> 25.66-b18
line.separator ->
os.arch -> amd64
os.name -> Windows 7
os.version -> 6.1
path.separator -> ;
sun.arch.data.model -> 64
sun.boot.class.path -> <edited out>
sun.boot.library.path -> C:\Program Files\Java\jdk1.8.0_66\jre\bin
sun.cpu.endian -> little
sun.cpu.isalist -> amd64
sun.desktop -> windows
sun.io.unicode.encoding -> UnicodeLittle
sun.java.command -> SystemPropertiesPrinter
sun.java.launcher -> SUN_STANDARD
sun.jnu.encoding -> Cp1252
sun.management.compiler -> HotSpot 64-Bit Tiered Compilers
sun.os.patch.level -> Service Pack 1
user.country -> GB
user.dir -> C:\Users\olivier\tmp
user.home -> C:\Users\olivier
user.language -> en
user.name -> olivier
user.script ->
user.timezone ->
user.variant ->
如您所见,属性 java.compiler
不在我的列表中。这是正常的吗?如果我们参考文档,特别是因为它没有标记为 "depecrated",它不应该存在吗? This question 表示这个 属性 可以取特定值,但它没有提到它可以不存在。
According to the docs, the system property java.compiler
should be present
不,这不是文档所说的。
来自文档:
The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys [...]
文档说如果没有定义一组属性,将生成一个新的。 生成的 将始终具有文档中列出的属性。不是所有的集合都有它们,只有那个 class 生成的集合。如果系统已经设置了属性,则不能保证在其中找到所有这些键。
我的理解是"java.compiler"是你设置的属性,告诉JVM使用特定的JIT编译器。如果未设置,JVM 使用(平台相关的)默认 JIT 编译器。
- Possible values for the "java.compiler" system property
java.compiler
属性 旨在由 JVM 的调用程序设置以指定 JIT 实现。
在此处打开 JDK 关于弃用此 属性 的讨论:
https://bugs.openjdk.java.net/browse/JDK-8041676
API 文件:
"The current set of system properties for use by the getProperty(String) method is returned as a Properties object."
由于您在启动 JVM 时指定 NONE,因此它为空。
如果您使用的是 Oracle 发布的 JVM,则 属性 键应为 sun.management.compiler
。有关 Sun 的系统属性,请参阅 this link。或者您可以通过以下命令打印 VM 设置
java -server -XshowSettings -version 2>&1
后者是从this post那里学到的。
我正在使用 Java 8. According to the docs,系统 属性 java.compiler
应该存在。然而,当我 运行 甚至是基本的 class 时,它都不是。
import java.util.Comparator;
import java.util.Map;
public class SystemPropertiesPrinter {
public static void main(String[] args) {
Map<String, String> properties = (Map) System.getProperties(); // It's a pain to sort without this artificial cast
properties.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.forEach(e -> System.out.printf("%-30s -> %s%n", e.getKey(), e.getValue()));
}
}
我运行它用下面的命令:
java SystemPropertiesPrinter
结果如下:
awt.toolkit -> sun.awt.windows.WToolkit
file.encoding -> Cp1252
file.encoding.pkg -> sun.io
file.separator -> \
java.awt.graphicsenv -> sun.awt.Win32GraphicsEnvironment
java.awt.printerjob -> sun.awt.windows.WPrinterJob
java.class.path -> .
java.class.version -> 52.0
java.endorsed.dirs -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\endorsed
java.ext.dirs -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
java.home -> C:\Program Files\Java\jdk1.8.0_66\jre
java.io.tmpdir -> C:\dev\cygwin64\tmp\
java.library.path -> <edited out>
java.runtime.name -> Java(TM) SE Runtime Environment
java.runtime.version -> 1.8.0_66-b18
java.specification.name -> Java Platform API Specification
java.specification.vendor -> Oracle Corporation
java.specification.version -> 1.8
java.vendor -> Oracle Corporation
java.vendor.url -> http://java.oracle.com/
java.vendor.url.bug -> http://bugreport.sun.com/bugreport/
java.version -> 1.8.0_66
java.vm.info -> mixed mode
java.vm.name -> Java HotSpot(TM) 64-Bit Server VM
java.vm.specification.name -> Java Virtual Machine Specification
java.vm.specification.vendor -> Oracle Corporation
java.vm.specification.version -> 1.8
java.vm.vendor -> Oracle Corporation
java.vm.version -> 25.66-b18
line.separator ->
os.arch -> amd64
os.name -> Windows 7
os.version -> 6.1
path.separator -> ;
sun.arch.data.model -> 64
sun.boot.class.path -> <edited out>
sun.boot.library.path -> C:\Program Files\Java\jdk1.8.0_66\jre\bin
sun.cpu.endian -> little
sun.cpu.isalist -> amd64
sun.desktop -> windows
sun.io.unicode.encoding -> UnicodeLittle
sun.java.command -> SystemPropertiesPrinter
sun.java.launcher -> SUN_STANDARD
sun.jnu.encoding -> Cp1252
sun.management.compiler -> HotSpot 64-Bit Tiered Compilers
sun.os.patch.level -> Service Pack 1
user.country -> GB
user.dir -> C:\Users\olivier\tmp
user.home -> C:\Users\olivier
user.language -> en
user.name -> olivier
user.script ->
user.timezone ->
user.variant ->
如您所见,属性 java.compiler
不在我的列表中。这是正常的吗?如果我们参考文档,特别是因为它没有标记为 "depecrated",它不应该存在吗? This question 表示这个 属性 可以取特定值,但它没有提到它可以不存在。
According to the docs, the system property
java.compiler
should be present
不,这不是文档所说的。
来自文档:
The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys [...]
文档说如果没有定义一组属性,将生成一个新的。 生成的 将始终具有文档中列出的属性。不是所有的集合都有它们,只有那个 class 生成的集合。如果系统已经设置了属性,则不能保证在其中找到所有这些键。
我的理解是"java.compiler"是你设置的属性,告诉JVM使用特定的JIT编译器。如果未设置,JVM 使用(平台相关的)默认 JIT 编译器。
- Possible values for the "java.compiler" system property
java.compiler
属性 旨在由 JVM 的调用程序设置以指定 JIT 实现。
在此处打开 JDK 关于弃用此 属性 的讨论: https://bugs.openjdk.java.net/browse/JDK-8041676
API 文件: "The current set of system properties for use by the getProperty(String) method is returned as a Properties object."
由于您在启动 JVM 时指定 NONE,因此它为空。
如果您使用的是 Oracle 发布的 JVM,则 属性 键应为 sun.management.compiler
。有关 Sun 的系统属性,请参阅 this link。或者您可以通过以下命令打印 VM 设置
java -server -XshowSettings -version 2>&1
后者是从this post那里学到的。