src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp

Fri, 07 Dec 2012 01:09:03 -0800

author
roland
date
Fri, 07 Dec 2012 01:09:03 -0800
changeset 4325
d2f8c38e543d
parent 4153
b9a9ed0f8eeb
child 6312
04d32e7fad07
permissions
-rw-r--r--

Merge

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "runtime/os.hpp"
stefank@2314 27 #include "vm_version_sparc.hpp"
duke@435 28
twisti@1076 29 # include <sys/auxv.h>
twisti@1076 30 # include <sys/auxv_SPARC.h>
duke@435 31 # include <sys/systeminfo.h>
kvn@2403 32 # include <kstat.h>
duke@435 33
twisti@1076 34 // We need to keep these here as long as we have to build on Solaris
twisti@1076 35 // versions before 10.
twisti@1076 36 #ifndef SI_ARCHITECTURE_32
twisti@1076 37 #define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */
twisti@1076 38 #endif
twisti@1076 39
twisti@1076 40 #ifndef SI_ARCHITECTURE_64
twisti@1076 41 #define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */
twisti@1076 42 #endif
twisti@1076 43
twisti@1076 44 static void do_sysinfo(int si, const char* string, int* features, int mask) {
twisti@1076 45 char tmp;
twisti@1076 46 size_t bufsize = sysinfo(si, &tmp, 1);
twisti@1076 47
twisti@1076 48 // All SI defines used below must be supported.
twisti@1076 49 guarantee(bufsize != -1, "must be supported");
twisti@1076 50
twisti@1076 51 char* buf = (char*) malloc(bufsize);
twisti@1076 52
twisti@1076 53 if (buf == NULL)
twisti@1076 54 return;
twisti@1076 55
twisti@1076 56 if (sysinfo(si, buf, bufsize) == bufsize) {
twisti@1076 57 // Compare the string.
twisti@1076 58 if (strcmp(buf, string) == 0) {
twisti@1076 59 *features |= mask;
twisti@1076 60 }
twisti@1076 61 }
twisti@1076 62
twisti@1076 63 free(buf);
twisti@1076 64 }
twisti@1076 65
duke@435 66 int VM_Version::platform_features(int features) {
twisti@1076 67 // getisax(2), SI_ARCHITECTURE_32, and SI_ARCHITECTURE_64 are
twisti@1076 68 // supported on Solaris 10 and later.
twisti@1076 69 if (os::Solaris::supports_getisax()) {
duke@435 70
twisti@1076 71 // Check 32-bit architecture.
twisti@1076 72 do_sysinfo(SI_ARCHITECTURE_32, "sparc", &features, v8_instructions_m);
duke@435 73
twisti@1076 74 // Check 64-bit architecture.
twisti@1076 75 do_sysinfo(SI_ARCHITECTURE_64, "sparcv9", &features, generic_v9_m);
duke@435 76
twisti@1076 77 // Extract valid instruction set extensions.
twisti@1076 78 uint_t av;
twisti@1076 79 uint_t avn = os::Solaris::getisax(&av, 1);
twisti@1076 80 assert(avn == 1, "should only return one av");
twisti@1076 81
kvn@2269 82 #ifndef PRODUCT
kvn@2269 83 if (PrintMiscellaneous && Verbose)
kvn@2269 84 tty->print_cr("getisax(2) returned: " PTR32_FORMAT, av);
kvn@2269 85 #endif
kvn@2269 86
twisti@1076 87 if (av & AV_SPARC_MUL32) features |= hardware_mul32_m;
twisti@1076 88 if (av & AV_SPARC_DIV32) features |= hardware_div32_m;
twisti@1076 89 if (av & AV_SPARC_FSMULD) features |= hardware_fsmuld_m;
twisti@1076 90 if (av & AV_SPARC_V8PLUS) features |= v9_instructions_m;
twisti@1078 91 if (av & AV_SPARC_POPC) features |= hardware_popc_m;
twisti@1076 92 if (av & AV_SPARC_VIS) features |= vis1_instructions_m;
twisti@1076 93 if (av & AV_SPARC_VIS2) features |= vis2_instructions_m;
kvn@2269 94
kvn@2269 95 // Next values are not defined before Solaris 10
kvn@2269 96 // but Solaris 8 is used for jdk6 update builds.
kvn@2269 97 #ifndef AV_SPARC_ASI_BLK_INIT
kvn@2269 98 #define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */
kvn@2269 99 #endif
kvn@2403 100 if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m;
kvn@2403 101
kvn@2269 102 #ifndef AV_SPARC_FMAF
kvn@2403 103 #define AV_SPARC_FMAF 0x0100 /* Fused Multiply-Add */
kvn@2269 104 #endif
kvn@2269 105 if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m;
kvn@2403 106
kvn@2403 107 #ifndef AV_SPARC_FMAU
kvn@2403 108 #define AV_SPARC_FMAU 0x0200 /* Unfused Multiply-Add */
kvn@2403 109 #endif
kvn@2403 110 if (av & AV_SPARC_FMAU) features |= fmau_instructions_m;
kvn@2403 111
kvn@2403 112 #ifndef AV_SPARC_VIS3
kvn@2403 113 #define AV_SPARC_VIS3 0x0400 /* VIS3 instruction set extensions */
kvn@2403 114 #endif
kvn@2403 115 if (av & AV_SPARC_VIS3) features |= vis3_instructions_m;
kvn@2403 116
kvn@3037 117 #ifndef AV_SPARC_CBCOND
kvn@3037 118 #define AV_SPARC_CBCOND 0x10000000 /* compare and branch instrs supported */
kvn@3037 119 #endif
kvn@3037 120 if (av & AV_SPARC_CBCOND) features |= cbcond_instructions_m;
kvn@3037 121
twisti@1076 122 } else {
twisti@1076 123 // getisax(2) failed, use the old legacy code.
twisti@1076 124 #ifndef PRODUCT
twisti@1076 125 if (PrintMiscellaneous && Verbose)
kvn@2269 126 tty->print_cr("getisax(2) is not supported.");
twisti@1076 127 #endif
twisti@1076 128
twisti@1076 129 char tmp;
twisti@1076 130 size_t bufsize = sysinfo(SI_ISALIST, &tmp, 1);
twisti@1076 131 char* buf = (char*) malloc(bufsize);
twisti@1076 132
twisti@1076 133 if (buf != NULL) {
twisti@1076 134 if (sysinfo(SI_ISALIST, buf, bufsize) == bufsize) {
twisti@1076 135 // Figure out what kind of sparc we have
twisti@1076 136 char *sparc_string = strstr(buf, "sparc");
twisti@1076 137 if (sparc_string != NULL) { features |= v8_instructions_m;
twisti@1076 138 if (sparc_string[5] == 'v') {
twisti@1076 139 if (sparc_string[6] == '8') {
twisti@1076 140 if (sparc_string[7] == '-') { features |= hardware_mul32_m;
twisti@1076 141 features |= hardware_div32_m;
twisti@1076 142 } else if (sparc_string[7] == 'p') features |= generic_v9_m;
twisti@1076 143 else features |= generic_v8_m;
twisti@1076 144 } else if (sparc_string[6] == '9') features |= generic_v9_m;
twisti@1076 145 }
twisti@1076 146 }
twisti@1076 147
twisti@1076 148 // Check for visualization instructions
twisti@1076 149 char *vis = strstr(buf, "vis");
twisti@1076 150 if (vis != NULL) { features |= vis1_instructions_m;
twisti@1076 151 if (vis[3] == '2') features |= vis2_instructions_m;
duke@435 152 }
duke@435 153 }
twisti@1076 154 free(buf);
duke@435 155 }
duke@435 156 }
duke@435 157
twisti@1076 158 // Determine the machine type.
twisti@1076 159 do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m);
duke@435 160
kvn@2403 161 {
kvn@2403 162 // Using kstat to determine the machine type.
kvn@2403 163 kstat_ctl_t* kc = kstat_open();
kvn@2403 164 kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, NULL);
kvn@2403 165 const char* implementation = "UNKNOWN";
kvn@2403 166 if (ksp != NULL) {
kvn@2403 167 if (kstat_read(kc, ksp, NULL) != -1 && ksp->ks_data != NULL) {
kvn@2403 168 kstat_named_t* knm = (kstat_named_t *)ksp->ks_data;
kvn@2403 169 for (int i = 0; i < ksp->ks_ndata; i++) {
kvn@2403 170 if (strcmp((const char*)&(knm[i].name),"implementation") == 0) {
kvn@2403 171 #ifndef KSTAT_DATA_STRING
kvn@2403 172 #define KSTAT_DATA_STRING 9
kvn@2403 173 #endif
kvn@2403 174 if (knm[i].data_type == KSTAT_DATA_CHAR) {
kvn@2403 175 // VM is running on Solaris 8 which does not have value.str.
kvn@2403 176 implementation = &(knm[i].value.c[0]);
kvn@2403 177 } else if (knm[i].data_type == KSTAT_DATA_STRING) {
kvn@2403 178 // VM is running on Solaris 10.
kvn@2403 179 #ifndef KSTAT_NAMED_STR_PTR
kvn@2403 180 // Solaris 8 was used to build VM, define the structure it misses.
kvn@2403 181 struct str_t {
kvn@2403 182 union {
kvn@2403 183 char *ptr; /* NULL-term string */
kvn@2403 184 char __pad[8]; /* 64-bit padding */
kvn@2403 185 } addr;
kvn@2403 186 uint32_t len; /* # bytes for strlen + '\0' */
kvn@2403 187 };
kvn@2403 188 #define KSTAT_NAMED_STR_PTR(knptr) (( (str_t*)&((knptr)->value) )->addr.ptr)
kvn@2403 189 #endif
kvn@2403 190 implementation = KSTAT_NAMED_STR_PTR(&knm[i]);
kvn@2403 191 }
kvn@2403 192 #ifndef PRODUCT
kvn@2403 193 if (PrintMiscellaneous && Verbose) {
kvn@2403 194 tty->print_cr("cpu_info.implementation: %s", implementation);
kvn@2403 195 }
kvn@2403 196 #endif
kvn@2554 197 // Convert to UPPER case before compare.
kvn@2554 198 char* impl = strdup(implementation);
kvn@2554 199
kvn@2554 200 for (int i = 0; impl[i] != 0; i++)
kvn@2554 201 impl[i] = (char)toupper((uint)impl[i]);
kvn@2554 202 if (strstr(impl, "SPARC64") != NULL) {
kvn@2403 203 features |= sparc64_family_m;
kvn@3972 204 } else if (strstr(impl, "SPARC-M") != NULL) {
kvn@3972 205 // M-series SPARC is based on T-series.
kvn@3972 206 features |= (M_family_m | T_family_m);
kvn@2554 207 } else if (strstr(impl, "SPARC-T") != NULL) {
kvn@2403 208 features |= T_family_m;
kvn@2554 209 if (strstr(impl, "SPARC-T1") != NULL) {
kvn@2403 210 features |= T1_model_m;
kvn@2403 211 }
kvn@2554 212 } else {
kvn@3972 213 if (strstr(impl, "SPARC") == NULL) {
kvn@3972 214 #ifndef PRODUCT
kvn@3972 215 // kstat on Solaris 8 virtual machines (branded zones)
kvn@3972 216 // returns "(unsupported)" implementation.
kvn@3972 217 warning("kstat cpu_info implementation = '%s', should contain SPARC", impl);
kvn@3972 218 #endif
kvn@3972 219 implementation = "SPARC";
kvn@3972 220 }
kvn@2403 221 }
kvn@2554 222 free((void*)impl);
kvn@2403 223 break;
kvn@2403 224 }
kvn@2403 225 } // for(
kvn@2403 226 }
kvn@2403 227 }
kvn@2403 228 assert(strcmp(implementation, "UNKNOWN") != 0,
kvn@2403 229 "unknown cpu info (changed kstat interface?)");
kvn@2403 230 kstat_close(kc);
kvn@2403 231 }
kvn@2403 232
duke@435 233 return features;
duke@435 234 }

mercurial