1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,252 @@ 1.4 +/* 1.5 + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "runtime/os.hpp" 1.30 +#include "vm_version_sparc.hpp" 1.31 + 1.32 +# include <sys/auxv.h> 1.33 +# include <sys/auxv_SPARC.h> 1.34 +# include <sys/systeminfo.h> 1.35 +# include <kstat.h> 1.36 + 1.37 +// We need to keep these here as long as we have to build on Solaris 1.38 +// versions before 10. 1.39 +#ifndef SI_ARCHITECTURE_32 1.40 +#define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */ 1.41 +#endif 1.42 + 1.43 +#ifndef SI_ARCHITECTURE_64 1.44 +#define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */ 1.45 +#endif 1.46 + 1.47 +static void do_sysinfo(int si, const char* string, int* features, int mask) { 1.48 + char tmp; 1.49 + size_t bufsize = sysinfo(si, &tmp, 1); 1.50 + 1.51 + // All SI defines used below must be supported. 1.52 + guarantee(bufsize != -1, "must be supported"); 1.53 + 1.54 + char* buf = (char*) malloc(bufsize); 1.55 + 1.56 + if (buf == NULL) 1.57 + return; 1.58 + 1.59 + if (sysinfo(si, buf, bufsize) == bufsize) { 1.60 + // Compare the string. 1.61 + if (strcmp(buf, string) == 0) { 1.62 + *features |= mask; 1.63 + } 1.64 + } 1.65 + 1.66 + free(buf); 1.67 +} 1.68 + 1.69 +int VM_Version::platform_features(int features) { 1.70 + // getisax(2), SI_ARCHITECTURE_32, and SI_ARCHITECTURE_64 are 1.71 + // supported on Solaris 10 and later. 1.72 + if (os::Solaris::supports_getisax()) { 1.73 + 1.74 + // Check 32-bit architecture. 1.75 + do_sysinfo(SI_ARCHITECTURE_32, "sparc", &features, v8_instructions_m); 1.76 + 1.77 + // Check 64-bit architecture. 1.78 + do_sysinfo(SI_ARCHITECTURE_64, "sparcv9", &features, generic_v9_m); 1.79 + 1.80 + // Extract valid instruction set extensions. 1.81 + uint_t avs[2]; 1.82 + uint_t avn = os::Solaris::getisax(avs, 2); 1.83 + assert(avn <= 2, "should return two or less av's"); 1.84 + uint_t av = avs[0]; 1.85 + 1.86 +#ifndef PRODUCT 1.87 + if (PrintMiscellaneous && Verbose) { 1.88 + tty->print("getisax(2) returned: " PTR32_FORMAT, av); 1.89 + if (avn > 1) { 1.90 + tty->print(", " PTR32_FORMAT, avs[1]); 1.91 + } 1.92 + tty->cr(); 1.93 + } 1.94 +#endif 1.95 + 1.96 + if (av & AV_SPARC_MUL32) features |= hardware_mul32_m; 1.97 + if (av & AV_SPARC_DIV32) features |= hardware_div32_m; 1.98 + if (av & AV_SPARC_FSMULD) features |= hardware_fsmuld_m; 1.99 + if (av & AV_SPARC_V8PLUS) features |= v9_instructions_m; 1.100 + if (av & AV_SPARC_POPC) features |= hardware_popc_m; 1.101 + if (av & AV_SPARC_VIS) features |= vis1_instructions_m; 1.102 + if (av & AV_SPARC_VIS2) features |= vis2_instructions_m; 1.103 + if (avn > 1) { 1.104 + uint_t av2 = avs[1]; 1.105 +#ifndef AV2_SPARC_SPARC5 1.106 +#define AV2_SPARC_SPARC5 0x00000008 /* The 29 new fp and sub instructions */ 1.107 +#endif 1.108 + if (av2 & AV2_SPARC_SPARC5) features |= sparc5_instructions_m; 1.109 + } 1.110 + 1.111 + // Next values are not defined before Solaris 10 1.112 + // but Solaris 8 is used for jdk6 update builds. 1.113 +#ifndef AV_SPARC_ASI_BLK_INIT 1.114 +#define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */ 1.115 +#endif 1.116 + if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m; 1.117 + 1.118 +#ifndef AV_SPARC_FMAF 1.119 +#define AV_SPARC_FMAF 0x0100 /* Fused Multiply-Add */ 1.120 +#endif 1.121 + if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m; 1.122 + 1.123 +#ifndef AV_SPARC_FMAU 1.124 +#define AV_SPARC_FMAU 0x0200 /* Unfused Multiply-Add */ 1.125 +#endif 1.126 + if (av & AV_SPARC_FMAU) features |= fmau_instructions_m; 1.127 + 1.128 +#ifndef AV_SPARC_VIS3 1.129 +#define AV_SPARC_VIS3 0x0400 /* VIS3 instruction set extensions */ 1.130 +#endif 1.131 + if (av & AV_SPARC_VIS3) features |= vis3_instructions_m; 1.132 + 1.133 +#ifndef AV_SPARC_CBCOND 1.134 +#define AV_SPARC_CBCOND 0x10000000 /* compare and branch instrs supported */ 1.135 +#endif 1.136 + if (av & AV_SPARC_CBCOND) features |= cbcond_instructions_m; 1.137 + 1.138 +#ifndef AV_SPARC_AES 1.139 +#define AV_SPARC_AES 0x00020000 /* aes instrs supported */ 1.140 +#endif 1.141 + if (av & AV_SPARC_AES) features |= aes_instructions_m; 1.142 + 1.143 + } else { 1.144 + // getisax(2) failed, use the old legacy code. 1.145 +#ifndef PRODUCT 1.146 + if (PrintMiscellaneous && Verbose) 1.147 + tty->print_cr("getisax(2) is not supported."); 1.148 +#endif 1.149 + 1.150 + char tmp; 1.151 + size_t bufsize = sysinfo(SI_ISALIST, &tmp, 1); 1.152 + char* buf = (char*) malloc(bufsize); 1.153 + 1.154 + if (buf != NULL) { 1.155 + if (sysinfo(SI_ISALIST, buf, bufsize) == bufsize) { 1.156 + // Figure out what kind of sparc we have 1.157 + char *sparc_string = strstr(buf, "sparc"); 1.158 + if (sparc_string != NULL) { features |= v8_instructions_m; 1.159 + if (sparc_string[5] == 'v') { 1.160 + if (sparc_string[6] == '8') { 1.161 + if (sparc_string[7] == '-') { features |= hardware_mul32_m; 1.162 + features |= hardware_div32_m; 1.163 + } else if (sparc_string[7] == 'p') features |= generic_v9_m; 1.164 + else features |= generic_v8_m; 1.165 + } else if (sparc_string[6] == '9') features |= generic_v9_m; 1.166 + } 1.167 + } 1.168 + 1.169 + // Check for visualization instructions 1.170 + char *vis = strstr(buf, "vis"); 1.171 + if (vis != NULL) { features |= vis1_instructions_m; 1.172 + if (vis[3] == '2') features |= vis2_instructions_m; 1.173 + } 1.174 + } 1.175 + free(buf); 1.176 + } 1.177 + } 1.178 + 1.179 + // Determine the machine type. 1.180 + do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m); 1.181 + 1.182 + { 1.183 + // Using kstat to determine the machine type. 1.184 + kstat_ctl_t* kc = kstat_open(); 1.185 + kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, NULL); 1.186 + const char* implementation = "UNKNOWN"; 1.187 + if (ksp != NULL) { 1.188 + if (kstat_read(kc, ksp, NULL) != -1 && ksp->ks_data != NULL) { 1.189 + kstat_named_t* knm = (kstat_named_t *)ksp->ks_data; 1.190 + for (int i = 0; i < ksp->ks_ndata; i++) { 1.191 + if (strcmp((const char*)&(knm[i].name),"implementation") == 0) { 1.192 +#ifndef KSTAT_DATA_STRING 1.193 +#define KSTAT_DATA_STRING 9 1.194 +#endif 1.195 + if (knm[i].data_type == KSTAT_DATA_CHAR) { 1.196 + // VM is running on Solaris 8 which does not have value.str. 1.197 + implementation = &(knm[i].value.c[0]); 1.198 + } else if (knm[i].data_type == KSTAT_DATA_STRING) { 1.199 + // VM is running on Solaris 10. 1.200 +#ifndef KSTAT_NAMED_STR_PTR 1.201 + // Solaris 8 was used to build VM, define the structure it misses. 1.202 + struct str_t { 1.203 + union { 1.204 + char *ptr; /* NULL-term string */ 1.205 + char __pad[8]; /* 64-bit padding */ 1.206 + } addr; 1.207 + uint32_t len; /* # bytes for strlen + '\0' */ 1.208 + }; 1.209 +#define KSTAT_NAMED_STR_PTR(knptr) (( (str_t*)&((knptr)->value) )->addr.ptr) 1.210 +#endif 1.211 + implementation = KSTAT_NAMED_STR_PTR(&knm[i]); 1.212 + } 1.213 +#ifndef PRODUCT 1.214 + if (PrintMiscellaneous && Verbose) { 1.215 + tty->print_cr("cpu_info.implementation: %s", implementation); 1.216 + } 1.217 +#endif 1.218 + // Convert to UPPER case before compare. 1.219 + char* impl = strdup(implementation); 1.220 + 1.221 + for (int i = 0; impl[i] != 0; i++) 1.222 + impl[i] = (char)toupper((uint)impl[i]); 1.223 + if (strstr(impl, "SPARC64") != NULL) { 1.224 + features |= sparc64_family_m; 1.225 + } else if (strstr(impl, "SPARC-M") != NULL) { 1.226 + // M-series SPARC is based on T-series. 1.227 + features |= (M_family_m | T_family_m); 1.228 + } else if (strstr(impl, "SPARC-T") != NULL) { 1.229 + features |= T_family_m; 1.230 + if (strstr(impl, "SPARC-T1") != NULL) { 1.231 + features |= T1_model_m; 1.232 + } 1.233 + } else { 1.234 + if (strstr(impl, "SPARC") == NULL) { 1.235 +#ifndef PRODUCT 1.236 + // kstat on Solaris 8 virtual machines (branded zones) 1.237 + // returns "(unsupported)" implementation. 1.238 + warning("kstat cpu_info implementation = '%s', should contain SPARC", impl); 1.239 +#endif 1.240 + implementation = "SPARC"; 1.241 + } 1.242 + } 1.243 + free((void*)impl); 1.244 + break; 1.245 + } 1.246 + } // for( 1.247 + } 1.248 + } 1.249 + assert(strcmp(implementation, "UNKNOWN") != 0, 1.250 + "unknown cpu info (changed kstat interface?)"); 1.251 + kstat_close(kc); 1.252 + } 1.253 + 1.254 + return features; 1.255 +}