1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.internal.jvmci.hotspot; 24 25 import jdk.internal.jvmci.code.*; 26 import jdk.internal.jvmci.common.*; 27 import jdk.internal.jvmci.compiler.*; 28 import jdk.internal.jvmci.compiler.Compiler; 29 import jdk.internal.jvmci.meta.*; 30 import jdk.internal.jvmci.runtime.*; 31 import jdk.internal.jvmci.service.*; 32 33 final class HotSpotJVMCICompilerConfig { 34 35 private static class DummyCompilerFactory implements CompilerFactory, Compiler { 36 37 public void compileMethod(ResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { 38 throw new JVMCIError("no JVMCI compiler selected"); 39 } 40 41 public String getCompilerName() { 42 return "<none>"; 43 } 44 45 public Architecture initializeArchitecture(Architecture arch) { 46 return arch; 47 } 48 49 public Compiler createCompiler(JVMCIRuntime runtime) { 50 return this; 51 } 52 } 53 54 private static CompilerFactory compilerFactory; 55 56 /** 57 * Selects the system compiler. 58 * 59 * Called from VM. This method has an object return type to allow it to be called with a VM 60 * utility function used to call other static initialization methods. 61 */ 62 static Boolean selectCompiler(String compilerName) { 63 assert compilerFactory == null; 64 for (CompilerFactory factory : Services.load(CompilerFactory.class)) { 65 if (factory.getCompilerName().equals(compilerName)) { 66 compilerFactory = factory; 67 return Boolean.TRUE; 68 } 69 } 70 71 throw new JVMCIError("JVMCI compiler '%s' not found", compilerName); 72 } 73 74 static CompilerFactory getCompilerFactory() { 75 if (compilerFactory == null) { 76 compilerFactory = new DummyCompilerFactory(); 77 } 78 return compilerFactory; 79 } 80 }