2

I'm using Java 8. According to the docs, the system property java.compiler should be present. However when I run even a basic class, it's not.

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()));
    }

}

I run it with the following command:

java SystemPropertiesPrinter

And here's the result:

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                   ->

As you can see, the property java.compiler is absent from my list. Is this normal? Shouldn't it be present, if we refer to the docs, especially as it's not marked as "depecrated"? This question states that this property can take specific value, but it mentions nowhere that it can be absent.

Community
  • 1
  • 1
Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137

4 Answers4

2

According to the docs, the system property java.compiler should be present

No, this is not what the doc says.

From the doc:

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 [...]

The doc says that if no set of properties is defined a new one will be generated. The generated one will always have the properties listed in the docs. Not all sets will have them, just the one that is generated by that class. If the system already has a properties set, you aren't guaranteed to find all those keys in it.

BackSlash
  • 21,927
  • 22
  • 96
  • 136
  • The highlight is ambiguous as "**this set**" doesn't explicitly refer to the "newly created" set of properties or the "current", isn't it? I'd say that your interpretation is as good as mine. – Olivier Grégoire Apr 11 '17 at 14:59
  • @OlivierGrégoire "This" usually refers to the latest available subject in the context. In this case, it is "The set of properties that gets firstly created and initialized if no current set of system properties is defined", so no, it's not ambiguous – BackSlash Apr 11 '17 at 15:08
  • Ok, I can accept that interpretation (you got my +1, I still need to think for the accepted answer). By any chance, do you know how I can force the creation of the said set of system properties? – Olivier Grégoire Apr 11 '17 at 15:14
  • @OlivierGrégoire I honestly don't know, you usually add properties with the `-D` flag, but with `java.compiler` it doesn't seem to work – BackSlash Apr 11 '17 at 15:20
  • @BackSlash -Djava.compiler will only work when there is a successful instantiation of java.lang.Compiler, and that is dependent upon specifying a valid JIT implementation library. – VivekRatanSinha Apr 11 '17 at 15:37
  • Indeed, I played a bit with the property. Set it to a dummy value and Java acts as if it's not there (and doesn't set it in the properties). Set it to the name of a loadable DLL file and the property is finally set. This is baffling. – Olivier Grégoire Apr 11 '17 at 15:46
  • @OlivierGrégoire Oh ok, so it means that it's checked to avoid wrong values... This makes me think that all `java.*` properties are checked before being saved if they provided via command line – BackSlash Apr 11 '17 at 16:21
1

My understanding is that "java.compiler" is a property that you set to tell the JVM to use a particular JIT compiler. If it is not set, the JVM uses the (platform dependent) default JIT compiler.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • You hint that the `java.compiler` property is optional. The [`java.lang.Compiler` documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/Compiler.html) seems to confirm this: "[...] it determines if the system property `java.compiler` exists." You might want to add this to your answer, as it completes it. – Olivier Grégoire Apr 11 '17 at 15:32
  • I am download JDK9 source code because I want to confirm some things ... – Stephen C Apr 11 '17 at 15:38
1

java.compiler property was intended to be set by the invoker of the JVM to specify a JIT implementation.

Open JDK talks of deprecating this property here: https://bugs.openjdk.java.net/browse/JDK-8041676

API Doc: "The current set of system properties for use by the getProperty(String) method is returned as a Properties object."

Since you are specifying NONE when you start your JVM, it is null.

VivekRatanSinha
  • 596
  • 1
  • 4
  • 17
0

If you are using a JVM published by Oracle, then the property key should be sun.management.compiler. See this link for System properties from Sun. Or you can print the VM settings through the following command

java -server -XshowSettings -version 2>&1   

Learned the latter this from this post.

Jeremy
  • 86
  • 6