comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java @ 24144:b0077339d77e

use existence of <java.home>/lib/use-jvmci-compiler-by-default to override default value of UseJVMCICompiler
author Doug Simon <doug.simon@oracle.com>
date Thu, 15 Jun 2017 12:04:08 +0200
parents 42cc0c2dd4a7
children
comparison
equal deleted inserted replaced
24143:15ab3e226b0d 24144:b0077339d77e
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package jdk.vm.ci.hotspot; 23 package jdk.vm.ci.hotspot;
24 24
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.ArrayList;
28 import java.util.List;
29
25 import jdk.vm.ci.code.CompilationRequest; 30 import jdk.vm.ci.code.CompilationRequest;
26 import jdk.vm.ci.code.CompilationRequestResult; 31 import jdk.vm.ci.code.CompilationRequestResult;
27 import jdk.vm.ci.common.JVMCIError; 32 import jdk.vm.ci.common.JVMCIError;
28 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; 33 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
29 import jdk.vm.ci.runtime.JVMCICompiler; 34 import jdk.vm.ci.runtime.JVMCICompiler;
30 import jdk.vm.ci.runtime.JVMCICompilerFactory; 35 import jdk.vm.ci.runtime.JVMCICompilerFactory;
31 import jdk.vm.ci.runtime.JVMCIRuntime; 36 import jdk.vm.ci.runtime.JVMCIRuntime;
37 import jdk.vm.ci.services.JVMCIPermission;
32 import jdk.vm.ci.services.JVMCIServiceLocator; 38 import jdk.vm.ci.services.JVMCIServiceLocator;
33 import jdk.vm.ci.services.JVMCIPermission; 39 import sun.misc.VM;
34 40
35 final class HotSpotJVMCICompilerConfig { 41 final class HotSpotJVMCICompilerConfig {
36 42
37 /** 43 /**
38 * This factory allows JVMCI initialization to succeed but raises an error if the VM asks JVMCI 44 * This factory allows JVMCI initialization to succeed but raises an error if the VM asks JVMCI
39 * to perform a compilation. This allows the reflective parts of the JVMCI API to be used 45 * to perform a compilation. This allows the reflective parts of the JVMCI API to be used
40 * without requiring a compiler implementation to be available. 46 * without requiring a compiler implementation to be available.
41 */ 47 */
42 private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler { 48 private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler {
43 49
50 private final String reason;
51
52 DummyCompilerFactory(String reason) {
53 this.reason = reason;
54 }
55
44 public CompilationRequestResult compileMethod(CompilationRequest request) { 56 public CompilationRequestResult compileMethod(CompilationRequest request) {
45 throw new JVMCIError("no JVMCI compiler selected"); 57 throw new JVMCIError("No JVMCI compiler selected. " + reason);
46 } 58 }
47 59
48 @Override 60 @Override
49 public String getCompilerName() { 61 public String getCompilerName() {
50 return "null"; 62 return "null";
72 if (compilerFactory == null) { 84 if (compilerFactory == null) {
73 JVMCICompilerFactory factory = null; 85 JVMCICompilerFactory factory = null;
74 String compilerName = Option.Compiler.getString(); 86 String compilerName = Option.Compiler.getString();
75 if (compilerName != null) { 87 if (compilerName != null) {
76 if (compilerName.isEmpty() || compilerName.equals("null")) { 88 if (compilerName.isEmpty() || compilerName.equals("null")) {
77 factory = new DummyCompilerFactory(); 89 factory = new DummyCompilerFactory("Value of " + Option.Compiler.getPropertyName() + " property is \"" +
90 compilerName + "\" which denotes the null JVMCI compiler.");
78 } else { 91 } else {
79 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) { 92 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
80 if (f.getCompilerName().equals(compilerName)) { 93 if (f.getCompilerName().equals(compilerName)) {
81 factory = f; 94 factory = f;
82 } 95 }
83 } 96 }
84 if (factory == null) { 97 if (factory == null) {
85 throw new JVMCIError("JVMCI compiler '%s' not found", compilerName); 98 throw new JVMCIError("JVMCI compiler \"%s\" not found", compilerName);
86 } 99 }
87 } 100 }
88 } else { 101 } else {
89 // Auto select a single available compiler 102 // Auto select a single available compiler
103 List<String> multiple = null;
90 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) { 104 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
91 if (factory == null) { 105 if (multiple != null) {
106 multiple.add(f.getCompilerName());
107 } else if (factory == null) {
92 factory = f; 108 factory = f;
93 } else { 109 } else {
94 // Multiple factories seen - cancel auto selection 110 multiple = new ArrayList<>();
111 multiple.add(f.getCompilerName());
112 multiple.add(factory.getCompilerName());
95 factory = null; 113 factory = null;
96 break;
97 } 114 }
98 } 115 }
99 if (factory == null) { 116 if (multiple != null) {
100 factory = new DummyCompilerFactory(); 117 factory = new DummyCompilerFactory("Multiple providers of " + JVMCICompilerFactory.class + " available: " +
118 String.join(", ", multiple) +
119 ". You can select one of these with the " + Option.Compiler.getPropertyName() + " property " +
120 "(e.g., -D" + Option.Compiler.getPropertyName() + "=" + multiple.get(0) + ").");
121 } else if (factory == null) {
122 Path jvmciDir = Paths.get(VM.getSavedProperty("java.home"), "lib", "jvmci");
123 factory = new DummyCompilerFactory("No providers of " + JVMCICompilerFactory.class + " found in " + jvmciDir +
124 " or on the class path specified by the jvmci.class.path.append property.");
101 } 125 }
102 } 126 }
103 factory.onSelection(); 127 factory.onSelection();
104 compilerFactory = factory; 128 compilerFactory = factory;
105 } 129 }