< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfigBase.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 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 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import java.lang.reflect.Field;
  28 import java.lang.reflect.Modifier;
  29 
  30 import org.graalvm.compiler.api.replacements.Fold;
  31 import org.graalvm.compiler.api.replacements.Fold.InjectedParameter;
  32 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  33 import org.graalvm.compiler.options.OptionValues;
  34 
  35 import jdk.vm.ci.common.JVMCIError;
  36 import jdk.vm.ci.hotspot.HotSpotVMConfigAccess;
  37 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
  38 import jdk.vm.ci.meta.MetaAccessProvider;

  39 
  40 /**
  41  * This is a source with different versions for various JDKs.
  42  */
  43 public abstract class GraalHotSpotVMConfigBase extends HotSpotVMConfigAccess {
  44 
  45     GraalHotSpotVMConfigBase(HotSpotVMConfigStore store) {
  46         super(store);
  47         assert this instanceof GraalHotSpotVMConfig;
  48         versioned = new GraalHotSpotVMConfigVersioned(store);
  49         assert checkVersioned();
  50     }
  51 
  52     private boolean checkVersioned() {
  53         Class<? extends GraalHotSpotVMConfigVersioned> c = versioned.getClass();
  54         for (Field field : c.getDeclaredFields()) {
  55             int modifiers = field.getModifiers();
  56             if (!Modifier.isStatic(modifiers)) {
  57                 // javac inlines non-static final fields which means
  58                 // versioned values are ignored in non-flattened Graal
  59                 assert !Modifier.isFinal(modifiers) : "Non-static field in " + c.getName() + " must not be final: " + field.getName();
  60             }
  61         }
  62         return true;
  63     }
  64 












  65     /**
  66      * Contains values that are different between JDK versions.
  67      */
  68     protected final GraalHotSpotVMConfigVersioned versioned;
  69 
  70     /**
  71      * Sentinel value to use for an {@linkplain InjectedParameter injected}
  72      * {@link GraalHotSpotVMConfig} parameter to a {@linkplain Fold foldable} method.
  73      */
  74     public static final GraalHotSpotVMConfig INJECTED_VMCONFIG = null;
  75     public static final MetaAccessProvider INJECTED_METAACCESS = null;
  76     public static final OptionValues INJECTED_OPTIONVALUES = null;
  77     public static final IntrinsicContext INJECTED_INTRINSIC_CONTEXT = null;
  78 
  79     public final String osName = getHostOSName();
  80     public final String osArch = getHostArchitectureName();
  81     public final boolean windowsOs = System.getProperty("os.name", "").startsWith("Windows");
  82     public final boolean linuxOs = System.getProperty("os.name", "").startsWith("Linux");
  83 
  84     /**
  85      * Gets the host operating system name.
  86      */
  87     private static String getHostOSName() {
  88         String osName = System.getProperty("os.name");
  89         switch (osName) {
  90             case "Linux":
  91                 osName = "linux";
  92                 break;
  93             case "SunOS":
  94                 osName = "solaris";
  95                 break;
  96             case "Mac OS X":
  97                 osName = "bsd";
  98                 break;
  99             default:
 100                 // Of course Windows is different...
 101                 if (osName.startsWith("Windows")) {
 102                     osName = "windows";
 103                 } else {
 104                     throw new JVMCIError("Unexpected OS name: " + osName);
 105                 }
 106         }
 107         return osName;
 108     }
 109 
 110     private static String getHostArchitectureName() {
 111         String arch = System.getProperty("os.arch");
 112         switch (arch) {
 113             case "x86_64":
 114                 arch = "amd64";
 115                 break;
 116             case "sparcv9":
 117                 arch = "sparc";
 118                 break;
 119         }
 120         return arch;
 121     }
 122 
 123     protected final Integer intRequiredOnAMD64 = osArch.equals("amd64") ? null : 0;
 124     protected final Long longRequiredOnAMD64 = osArch.equals("amd64") ? null : 0L;
 125 }
   1 /*
   2  * Copyright (c) 2011, 2019, 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 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import java.lang.reflect.Field;
  28 import java.lang.reflect.Modifier;
  29 
  30 import org.graalvm.compiler.api.replacements.Fold;
  31 import org.graalvm.compiler.api.replacements.Fold.InjectedParameter;
  32 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  33 import org.graalvm.compiler.options.OptionValues;
  34 
  35 import jdk.vm.ci.common.JVMCIError;
  36 import jdk.vm.ci.hotspot.HotSpotVMConfigAccess;
  37 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
  38 import jdk.vm.ci.meta.MetaAccessProvider;
  39 import jdk.vm.ci.services.Services;
  40 
  41 /**
  42  * Base class of class hierarchy for accessing HotSpot VM configuration.
  43  */
  44 public abstract class GraalHotSpotVMConfigBase extends HotSpotVMConfigAccess {
  45 
  46     GraalHotSpotVMConfigBase(HotSpotVMConfigStore store) {
  47         super(store);
  48         assert this instanceof GraalHotSpotVMConfig;
  49         versioned = new GraalHotSpotVMConfigVersioned(store);
  50         assert checkVersioned();
  51     }
  52 
  53     private boolean checkVersioned() {
  54         Class<? extends GraalHotSpotVMConfigVersioned> c = versioned.getClass();
  55         for (Field field : c.getDeclaredFields()) {
  56             int modifiers = field.getModifiers();
  57             if (!Modifier.isStatic(modifiers)) {
  58                 // javac inlines non-static final fields which means
  59                 // versioned values are ignored in non-flattened Graal
  60                 assert !Modifier.isFinal(modifiers) : "Non-static field in " + c.getName() + " must not be final: " + field.getName();
  61             }
  62         }
  63         return true;
  64     }
  65 
  66     private static String getProperty(String name, String def) {
  67         String value = Services.getSavedProperties().get(name);
  68         if (value == null) {
  69             return def;
  70         }
  71         return value;
  72     }
  73 
  74     private static String getProperty(String name) {
  75         return getProperty(name, null);
  76     }
  77 
  78     /**
  79      * Contains values that are different between JDK versions.
  80      */
  81     protected final GraalHotSpotVMConfigVersioned versioned;
  82 
  83     /**
  84      * Sentinel value to use for an {@linkplain InjectedParameter injected}
  85      * {@link GraalHotSpotVMConfig} parameter to a {@linkplain Fold foldable} method.
  86      */
  87     public static final GraalHotSpotVMConfig INJECTED_VMCONFIG = null;
  88     public static final MetaAccessProvider INJECTED_METAACCESS = null;
  89     public static final OptionValues INJECTED_OPTIONVALUES = null;
  90     public static final IntrinsicContext INJECTED_INTRINSIC_CONTEXT = null;
  91 
  92     public final String osName = getHostOSName();
  93     public final String osArch = getHostArchitectureName();
  94     public final boolean windowsOs = getProperty("os.name", "").startsWith("Windows");
  95     public final boolean linuxOs = getProperty("os.name", "").startsWith("Linux");
  96 
  97     /**
  98      * Gets the host operating system name.
  99      */
 100     private static String getHostOSName() {
 101         String osName = getProperty("os.name");
 102         switch (osName) {
 103             case "Linux":
 104                 osName = "linux";
 105                 break;
 106             case "SunOS":
 107                 osName = "solaris";
 108                 break;
 109             case "Mac OS X":
 110                 osName = "bsd";
 111                 break;
 112             default:
 113                 // Of course Windows is different...
 114                 if (osName.startsWith("Windows")) {
 115                     osName = "windows";
 116                 } else {
 117                     throw new JVMCIError("Unexpected OS name: " + osName);
 118                 }
 119         }
 120         return osName;
 121     }
 122 
 123     private static String getHostArchitectureName() {
 124         String arch = getProperty("os.arch");
 125         switch (arch) {
 126             case "x86_64":
 127                 arch = "amd64";
 128                 break;
 129             case "sparcv9":
 130                 arch = "sparc";
 131                 break;
 132         }
 133         return arch;
 134     }
 135 
 136     protected final Integer intRequiredOnAMD64 = osArch.equals("amd64") ? null : 0;
 137     protected final Long longRequiredOnAMD64 = osArch.equals("amd64") ? null : 0L;
 138 }
< prev index next >