< prev index next >

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 2016, 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.vm.ci.hotspot;
  24 


  25 import jdk.vm.ci.code.CompilationRequest;
  26 import jdk.vm.ci.common.JVMCIError;
  27 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
  28 import jdk.vm.ci.runtime.JVMCICompiler;
  29 import jdk.vm.ci.runtime.JVMCICompilerFactory;
  30 import jdk.vm.ci.runtime.JVMCIRuntime;
  31 import jdk.vm.ci.services.JVMCIPermission;
  32 import jdk.vm.ci.services.JVMCIServiceLocator;
  33 import jdk.vm.ci.services.internal.ReflectionAccessJDK;
  34 
  35 final class HotSpotJVMCICompilerConfig {
  36 
  37     /**
  38      * 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
  40      * without requiring a compiler implementation to be available.
  41      */
  42     private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler {
  43 
  44         @Override
  45         public HotSpotCompilationRequestResult compileMethod(CompilationRequest request) {
  46             throw new JVMCIError("no JVMCI compiler selected");
  47         }
  48 
  49         @Override
  50         public String getCompilerName() {
  51             return "null";
  52         }
  53 


  73         if (compilerFactory == null) {
  74             JVMCICompilerFactory factory = null;
  75             String compilerName = Option.Compiler.getString();
  76             if (compilerName != null) {
  77                 if (compilerName.isEmpty() || compilerName.equals("null")) {
  78                     factory = new DummyCompilerFactory();
  79                 } else {
  80                     for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
  81                         if (f.getCompilerName().equals(compilerName)) {
  82                             factory = f;
  83                         }
  84                     }
  85                     if (factory == null) {
  86                         throw new JVMCIError("JVMCI compiler '%s' not found", compilerName);
  87                     }
  88                 }
  89             } else {
  90                 // Auto select a single available compiler
  91                 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
  92                     if (factory == null) {
  93                         ReflectionAccessJDK.openJVMCITo(f.getClass());
  94                         factory = f;
  95                     } else {
  96                         // Multiple factories seen - cancel auto selection
  97                         factory = null;
  98                         break;
  99                     }
 100                 }
 101                 if (factory == null) {
 102                     factory = new DummyCompilerFactory();
 103                 }
 104             }
 105             factory.onSelection();
 106             compilerFactory = factory;
 107         }
 108         return compilerFactory;
 109     }
















 110 }
   1 /*
   2  * Copyright (c) 2015, 2018, 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.vm.ci.hotspot;
  24 
  25 import java.util.Set;
  26 
  27 import jdk.vm.ci.code.CompilationRequest;
  28 import jdk.vm.ci.common.JVMCIError;
  29 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
  30 import jdk.vm.ci.runtime.JVMCICompiler;
  31 import jdk.vm.ci.runtime.JVMCICompilerFactory;
  32 import jdk.vm.ci.runtime.JVMCIRuntime;
  33 import jdk.vm.ci.services.JVMCIPermission;
  34 import jdk.vm.ci.services.JVMCIServiceLocator;

  35 
  36 final class HotSpotJVMCICompilerConfig {
  37 
  38     /**
  39      * This factory allows JVMCI initialization to succeed but raises an error if the VM asks JVMCI
  40      * to perform a compilation. This allows the reflective parts of the JVMCI API to be used
  41      * without requiring a compiler implementation to be available.
  42      */
  43     private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler {
  44 
  45         @Override
  46         public HotSpotCompilationRequestResult compileMethod(CompilationRequest request) {
  47             throw new JVMCIError("no JVMCI compiler selected");
  48         }
  49 
  50         @Override
  51         public String getCompilerName() {
  52             return "null";
  53         }
  54 


  74         if (compilerFactory == null) {
  75             JVMCICompilerFactory factory = null;
  76             String compilerName = Option.Compiler.getString();
  77             if (compilerName != null) {
  78                 if (compilerName.isEmpty() || compilerName.equals("null")) {
  79                     factory = new DummyCompilerFactory();
  80                 } else {
  81                     for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
  82                         if (f.getCompilerName().equals(compilerName)) {
  83                             factory = f;
  84                         }
  85                     }
  86                     if (factory == null) {
  87                         throw new JVMCIError("JVMCI compiler '%s' not found", compilerName);
  88                     }
  89                 }
  90             } else {
  91                 // Auto select a single available compiler
  92                 for (JVMCICompilerFactory f : JVMCIServiceLocator.getProviders(JVMCICompilerFactory.class)) {
  93                     if (factory == null) {
  94                         openJVMCITo(f.getClass().getModule());
  95                         factory = f;
  96                     } else {
  97                         // Multiple factories seen - cancel auto selection
  98                         factory = null;
  99                         break;
 100                     }
 101                 }
 102                 if (factory == null) {
 103                     factory = new DummyCompilerFactory();
 104                 }
 105             }
 106             factory.onSelection();
 107             compilerFactory = factory;
 108         }
 109         return compilerFactory;
 110     }
 111 
 112     /**
 113      * Opens all JVMCI packages to {@code otherModule}.
 114      */
 115     private static void openJVMCITo(Module otherModule) {
 116         Module jvmci = HotSpotJVMCICompilerConfig.class.getModule();
 117         if (jvmci != otherModule) {
 118             Set<String> packages = jvmci.getPackages();
 119             for (String pkg : packages) {
 120                 boolean opened = jvmci.isOpen(pkg, otherModule);
 121                 if (!opened) {
 122                     jvmci.addOpens(pkg, otherModule);
 123                 }
 124             }
 125         }
 126     }
 127 }
< prev index next >