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 33 import jdk.vm.ci.common.JVMCIError; 34 import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; 35 import jdk.vm.ci.hotspot.HotSpotVMConfigStore; 36 import jdk.vm.ci.meta.MetaAccessProvider; 37 38 /** 39 * This is a source with different versions for various JDKs. 40 */ 41 public abstract class GraalHotSpotVMConfigBase extends HotSpotVMConfigAccess { 42 43 GraalHotSpotVMConfigBase(HotSpotVMConfigStore store) { 44 super(store); 45 assert this instanceof GraalHotSpotVMConfig; 46 versioned = new GraalHotSpotVMConfigVersioned(store); 47 assert checkVersioned(); 48 } 49 50 private boolean checkVersioned() { 51 Class<? extends GraalHotSpotVMConfigVersioned> c = versioned.getClass(); 52 for (Field field : c.getDeclaredFields()) { 53 int modifiers = field.getModifiers(); 54 if (!Modifier.isStatic(modifiers)) { 55 // javac inlines non-static final fields which means 56 // versioned values are ignored in non-flattened Graal 57 assert !Modifier.isFinal(modifiers) : "Non-static field in " + c.getName() + " must not be final: " + field.getName(); 58 } 59 } 60 return true; 61 } 62 63 /** 64 * Contains values that are different between JDK versions. 65 */ 66 protected final GraalHotSpotVMConfigVersioned versioned; 67 68 /** 69 * Sentinel value to use for an {@linkplain InjectedParameter injected} 70 * {@link GraalHotSpotVMConfig} parameter to a {@linkplain Fold foldable} method. 71 */ 72 public static final GraalHotSpotVMConfig INJECTED_VMCONFIG = null; 73 public static final MetaAccessProvider INJECTED_METAACCESS = null; 74 75 public final String osName = getHostOSName(); 76 public final String osArch = getHostArchitectureName(); 77 public final boolean windowsOs = System.getProperty("os.name", "").startsWith("Windows"); 78 public final boolean linuxOs = System.getProperty("os.name", "").startsWith("Linux"); 79 80 /** 81 * Gets the host operating system name. 82 */ 83 private static String getHostOSName() { 84 String osName = System.getProperty("os.name"); 85 switch (osName) { 86 case "Linux": 87 osName = "linux"; 88 break; 89 case "SunOS": 90 osName = "solaris"; 91 break; 92 case "Mac OS X": 93 osName = "bsd"; 94 break; 95 default: 96 // Of course Windows is different... 97 if (osName.startsWith("Windows")) { 98 osName = "windows"; 99 } else { 100 throw new JVMCIError("Unexpected OS name: " + osName); 101 } 102 } 103 return osName; 104 } 105 106 private static String getHostArchitectureName() { 107 String arch = System.getProperty("os.arch"); 108 switch (arch) { 109 case "x86_64": 110 arch = "amd64"; 111 break; 112 case "sparcv9": 113 arch = "sparc"; 114 break; 115 } 116 return arch; 117 } 118 119 protected final Integer intRequiredOnAMD64 = osArch.equals("amd64") ? null : 0; 120 protected final Long longRequiredOnAMD64 = osArch.equals("amd64") ? null : 0L; 121 }