Tue, 25 Jul 2017 10:38:28 -0400
8177958: Possible uninitialized char* in vm_version_solaris_sparc.cpp
Reviewed-by: kvn, shade
duke@435 | 1 | /* |
kvn@7027 | 2 | * Copyright (c) 2006, 2014, 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 | |
iveresov@7135 | 29 | #include <sys/auxv.h> |
iveresov@7135 | 30 | #include <sys/auxv_SPARC.h> |
iveresov@7135 | 31 | #include <sys/systeminfo.h> |
iveresov@7135 | 32 | #include <kstat.h> |
iveresov@7135 | 33 | #include <picl.h> |
iveresov@7296 | 34 | #include <dlfcn.h> |
iveresov@7296 | 35 | #include <link.h> |
iveresov@7135 | 36 | |
iveresov@7766 | 37 | extern "C" static int PICL_visit_cpu_helper(picl_nodehdl_t nodeh, void *result); |
iveresov@7135 | 38 | |
iveresov@7296 | 39 | // Functions from the library we need (signatures should match those in picl.h) |
iveresov@7296 | 40 | extern "C" { |
iveresov@7296 | 41 | typedef int (*picl_initialize_func_t)(void); |
iveresov@7296 | 42 | typedef int (*picl_shutdown_func_t)(void); |
iveresov@7296 | 43 | typedef int (*picl_get_root_func_t)(picl_nodehdl_t *nodehandle); |
iveresov@7296 | 44 | typedef int (*picl_walk_tree_by_class_func_t)(picl_nodehdl_t rooth, |
iveresov@7296 | 45 | const char *classname, void *c_args, |
iveresov@7296 | 46 | int (*callback_fn)(picl_nodehdl_t hdl, void *args)); |
iveresov@7296 | 47 | typedef int (*picl_get_prop_by_name_func_t)(picl_nodehdl_t nodeh, const char *nm, |
iveresov@7296 | 48 | picl_prophdl_t *ph); |
iveresov@7296 | 49 | typedef int (*picl_get_propval_func_t)(picl_prophdl_t proph, void *valbuf, size_t sz); |
iveresov@7296 | 50 | typedef int (*picl_get_propinfo_func_t)(picl_prophdl_t proph, picl_propinfo_t *pi); |
iveresov@7296 | 51 | } |
iveresov@7296 | 52 | |
iveresov@7135 | 53 | class PICL { |
iveresov@7296 | 54 | // Pointers to functions in the library |
iveresov@7296 | 55 | picl_initialize_func_t _picl_initialize; |
iveresov@7296 | 56 | picl_shutdown_func_t _picl_shutdown; |
iveresov@7296 | 57 | picl_get_root_func_t _picl_get_root; |
iveresov@7296 | 58 | picl_walk_tree_by_class_func_t _picl_walk_tree_by_class; |
iveresov@7296 | 59 | picl_get_prop_by_name_func_t _picl_get_prop_by_name; |
iveresov@7296 | 60 | picl_get_propval_func_t _picl_get_propval; |
iveresov@7296 | 61 | picl_get_propinfo_func_t _picl_get_propinfo; |
iveresov@7296 | 62 | // Handle to the library that is returned by dlopen |
iveresov@7296 | 63 | void *_dl_handle; |
iveresov@7296 | 64 | |
iveresov@7296 | 65 | bool open_library(); |
iveresov@7296 | 66 | void close_library(); |
iveresov@7296 | 67 | |
iveresov@7296 | 68 | template<typename FuncType> bool bind(FuncType& func, const char* name); |
iveresov@7296 | 69 | bool bind_library_functions(); |
iveresov@7296 | 70 | |
iveresov@7135 | 71 | // Get a value of the integer property. The value in the tree can be either 32 or 64 bit |
iveresov@7135 | 72 | // depending on the platform. The result is converted to int. |
iveresov@7296 | 73 | int get_int_property(picl_nodehdl_t nodeh, const char* name, int* result) { |
iveresov@7135 | 74 | picl_propinfo_t pinfo; |
iveresov@7135 | 75 | picl_prophdl_t proph; |
iveresov@7296 | 76 | if (_picl_get_prop_by_name(nodeh, name, &proph) != PICL_SUCCESS || |
iveresov@7296 | 77 | _picl_get_propinfo(proph, &pinfo) != PICL_SUCCESS) { |
iveresov@7135 | 78 | return PICL_FAILURE; |
iveresov@7135 | 79 | } |
iveresov@7135 | 80 | |
iveresov@7135 | 81 | if (pinfo.type != PICL_PTYPE_INT && pinfo.type != PICL_PTYPE_UNSIGNED_INT) { |
iveresov@7135 | 82 | assert(false, "Invalid property type"); |
iveresov@7135 | 83 | return PICL_FAILURE; |
iveresov@7135 | 84 | } |
iveresov@7135 | 85 | if (pinfo.size == sizeof(int64_t)) { |
iveresov@7135 | 86 | int64_t val; |
iveresov@7296 | 87 | if (_picl_get_propval(proph, &val, sizeof(int64_t)) != PICL_SUCCESS) { |
iveresov@7135 | 88 | return PICL_FAILURE; |
iveresov@7135 | 89 | } |
iveresov@7135 | 90 | *result = static_cast<int>(val); |
iveresov@7135 | 91 | } else if (pinfo.size == sizeof(int32_t)) { |
iveresov@7135 | 92 | int32_t val; |
iveresov@7296 | 93 | if (_picl_get_propval(proph, &val, sizeof(int32_t)) != PICL_SUCCESS) { |
iveresov@7135 | 94 | return PICL_FAILURE; |
iveresov@7135 | 95 | } |
iveresov@7135 | 96 | *result = static_cast<int>(val); |
iveresov@7135 | 97 | } else { |
iveresov@7135 | 98 | assert(false, "Unexpected integer property size"); |
iveresov@7135 | 99 | return PICL_FAILURE; |
iveresov@7135 | 100 | } |
iveresov@7135 | 101 | return PICL_SUCCESS; |
iveresov@7135 | 102 | } |
iveresov@7135 | 103 | |
iveresov@7135 | 104 | // Visitor and a state machine that visits integer properties and verifies that the |
iveresov@7135 | 105 | // values are the same. Stores the unique value observed. |
iveresov@7135 | 106 | class UniqueValueVisitor { |
iveresov@7296 | 107 | PICL *_picl; |
iveresov@7135 | 108 | enum { |
iveresov@7135 | 109 | INITIAL, // Start state, no assignments happened |
iveresov@7135 | 110 | ASSIGNED, // Assigned a value |
iveresov@7135 | 111 | INCONSISTENT // Inconsistent value seen |
iveresov@7135 | 112 | } _state; |
iveresov@7135 | 113 | int _value; |
iveresov@7135 | 114 | public: |
iveresov@7296 | 115 | UniqueValueVisitor(PICL* picl) : _picl(picl), _state(INITIAL) { } |
iveresov@7135 | 116 | int value() { |
iveresov@7135 | 117 | assert(_state == ASSIGNED, "Precondition"); |
iveresov@7135 | 118 | return _value; |
iveresov@7135 | 119 | } |
iveresov@7135 | 120 | void set_value(int value) { |
iveresov@7135 | 121 | assert(_state == INITIAL, "Precondition"); |
iveresov@7135 | 122 | _value = value; |
iveresov@7135 | 123 | _state = ASSIGNED; |
iveresov@7135 | 124 | } |
iveresov@7135 | 125 | bool is_initial() { return _state == INITIAL; } |
iveresov@7135 | 126 | bool is_assigned() { return _state == ASSIGNED; } |
iveresov@7135 | 127 | bool is_inconsistent() { return _state == INCONSISTENT; } |
iveresov@7135 | 128 | void set_inconsistent() { _state = INCONSISTENT; } |
iveresov@7135 | 129 | |
iveresov@7767 | 130 | bool visit(picl_nodehdl_t nodeh, const char* name) { |
iveresov@7766 | 131 | assert(!is_inconsistent(), "Precondition"); |
iveresov@7135 | 132 | int curr; |
iveresov@7766 | 133 | if (_picl->get_int_property(nodeh, name, &curr) == PICL_SUCCESS) { |
iveresov@7766 | 134 | if (!is_assigned()) { // first iteration |
iveresov@7766 | 135 | set_value(curr); |
iveresov@7766 | 136 | } else if (curr != value()) { // following iterations |
iveresov@7766 | 137 | set_inconsistent(); |
iveresov@7135 | 138 | } |
iveresov@7767 | 139 | return true; |
iveresov@7135 | 140 | } |
iveresov@7767 | 141 | return false; |
iveresov@7766 | 142 | } |
iveresov@7766 | 143 | }; |
iveresov@7766 | 144 | |
iveresov@7766 | 145 | class CPUVisitor { |
iveresov@7766 | 146 | UniqueValueVisitor _l1_visitor; |
iveresov@7766 | 147 | UniqueValueVisitor _l2_visitor; |
iveresov@7766 | 148 | int _limit; // number of times visit() can be run |
iveresov@7766 | 149 | public: |
iveresov@7766 | 150 | CPUVisitor(PICL *picl, int limit) : _l1_visitor(picl), _l2_visitor(picl), _limit(limit) {} |
iveresov@7766 | 151 | static int visit(picl_nodehdl_t nodeh, void *arg) { |
iveresov@7766 | 152 | CPUVisitor *cpu_visitor = static_cast<CPUVisitor*>(arg); |
iveresov@7766 | 153 | UniqueValueVisitor* l1_visitor = cpu_visitor->l1_visitor(); |
iveresov@7766 | 154 | UniqueValueVisitor* l2_visitor = cpu_visitor->l2_visitor(); |
iveresov@7766 | 155 | if (!l1_visitor->is_inconsistent()) { |
iveresov@7766 | 156 | l1_visitor->visit(nodeh, "l1-dcache-line-size"); |
iveresov@7766 | 157 | } |
iveresov@7767 | 158 | static const char* l2_data_cache_line_property_name = NULL; |
iveresov@7767 | 159 | // On the first visit determine the name of the l2 cache line size property and memoize it. |
iveresov@7767 | 160 | if (l2_data_cache_line_property_name == NULL) { |
iveresov@7767 | 161 | assert(!l2_visitor->is_inconsistent(), "First iteration cannot be inconsistent"); |
iveresov@7767 | 162 | l2_data_cache_line_property_name = "l2-cache-line-size"; |
iveresov@7767 | 163 | if (!l2_visitor->visit(nodeh, l2_data_cache_line_property_name)) { |
iveresov@7767 | 164 | l2_data_cache_line_property_name = "l2-dcache-line-size"; |
iveresov@7767 | 165 | l2_visitor->visit(nodeh, l2_data_cache_line_property_name); |
iveresov@7767 | 166 | } |
iveresov@7767 | 167 | } else { |
iveresov@7767 | 168 | if (!l2_visitor->is_inconsistent()) { |
iveresov@7767 | 169 | l2_visitor->visit(nodeh, l2_data_cache_line_property_name); |
iveresov@7767 | 170 | } |
iveresov@7766 | 171 | } |
iveresov@7766 | 172 | |
iveresov@7766 | 173 | if (l1_visitor->is_inconsistent() && l2_visitor->is_inconsistent()) { |
iveresov@7766 | 174 | return PICL_WALK_TERMINATE; |
iveresov@7766 | 175 | } |
iveresov@7766 | 176 | cpu_visitor->_limit--; |
iveresov@7766 | 177 | if (cpu_visitor->_limit <= 0) { |
iveresov@7135 | 178 | return PICL_WALK_TERMINATE; |
iveresov@7135 | 179 | } |
iveresov@7135 | 180 | return PICL_WALK_CONTINUE; |
iveresov@7135 | 181 | } |
iveresov@7766 | 182 | UniqueValueVisitor* l1_visitor() { return &_l1_visitor; } |
iveresov@7766 | 183 | UniqueValueVisitor* l2_visitor() { return &_l2_visitor; } |
iveresov@7135 | 184 | }; |
iveresov@7135 | 185 | int _L1_data_cache_line_size; |
iveresov@7767 | 186 | int _L2_data_cache_line_size; |
iveresov@7135 | 187 | public: |
iveresov@7766 | 188 | static int visit_cpu(picl_nodehdl_t nodeh, void *state) { |
iveresov@7766 | 189 | return CPUVisitor::visit(nodeh, state); |
iveresov@7135 | 190 | } |
iveresov@7135 | 191 | |
poonam@7958 | 192 | PICL(bool is_fujitsu, bool is_sun4v) : _L1_data_cache_line_size(0), _L2_data_cache_line_size(0), _dl_handle(NULL) { |
iveresov@7296 | 193 | if (!open_library()) { |
iveresov@7296 | 194 | return; |
iveresov@7296 | 195 | } |
iveresov@7296 | 196 | if (_picl_initialize() == PICL_SUCCESS) { |
iveresov@7135 | 197 | picl_nodehdl_t rooth; |
iveresov@7296 | 198 | if (_picl_get_root(&rooth) == PICL_SUCCESS) { |
iveresov@7766 | 199 | const char* cpu_class = "cpu"; |
iveresov@7766 | 200 | // If it's a Fujitsu machine, it's a "core" |
iveresov@7766 | 201 | if (is_fujitsu) { |
iveresov@7766 | 202 | cpu_class = "core"; |
iveresov@7135 | 203 | } |
poonam@7958 | 204 | CPUVisitor cpu_visitor(this, (is_sun4v && !is_fujitsu) ? 1 : os::processor_count()); |
iveresov@7766 | 205 | _picl_walk_tree_by_class(rooth, cpu_class, &cpu_visitor, PICL_visit_cpu_helper); |
iveresov@7766 | 206 | if (cpu_visitor.l1_visitor()->is_assigned()) { // Is there a value? |
iveresov@7766 | 207 | _L1_data_cache_line_size = cpu_visitor.l1_visitor()->value(); |
iveresov@7135 | 208 | } |
iveresov@7766 | 209 | if (cpu_visitor.l2_visitor()->is_assigned()) { |
iveresov@7767 | 210 | _L2_data_cache_line_size = cpu_visitor.l2_visitor()->value(); |
iveresov@7135 | 211 | } |
iveresov@7135 | 212 | } |
iveresov@7296 | 213 | _picl_shutdown(); |
iveresov@7135 | 214 | } |
iveresov@7296 | 215 | close_library(); |
iveresov@7135 | 216 | } |
iveresov@7135 | 217 | |
iveresov@7135 | 218 | unsigned int L1_data_cache_line_size() const { return _L1_data_cache_line_size; } |
iveresov@7767 | 219 | unsigned int L2_data_cache_line_size() const { return _L2_data_cache_line_size; } |
iveresov@7135 | 220 | }; |
iveresov@7135 | 221 | |
iveresov@7766 | 222 | |
iveresov@7766 | 223 | extern "C" static int PICL_visit_cpu_helper(picl_nodehdl_t nodeh, void *result) { |
iveresov@7766 | 224 | return PICL::visit_cpu(nodeh, result); |
iveresov@7135 | 225 | } |
duke@435 | 226 | |
iveresov@7296 | 227 | template<typename FuncType> |
iveresov@7296 | 228 | bool PICL::bind(FuncType& func, const char* name) { |
iveresov@7296 | 229 | func = reinterpret_cast<FuncType>(dlsym(_dl_handle, name)); |
iveresov@7296 | 230 | return func != NULL; |
iveresov@7296 | 231 | } |
iveresov@7296 | 232 | |
iveresov@7296 | 233 | bool PICL::bind_library_functions() { |
iveresov@7296 | 234 | assert(_dl_handle != NULL, "library should be open"); |
iveresov@7296 | 235 | return bind(_picl_initialize, "picl_initialize" ) && |
iveresov@7296 | 236 | bind(_picl_shutdown, "picl_shutdown" ) && |
iveresov@7296 | 237 | bind(_picl_get_root, "picl_get_root" ) && |
iveresov@7296 | 238 | bind(_picl_walk_tree_by_class, "picl_walk_tree_by_class") && |
iveresov@7296 | 239 | bind(_picl_get_prop_by_name, "picl_get_prop_by_name" ) && |
iveresov@7296 | 240 | bind(_picl_get_propval, "picl_get_propval" ) && |
iveresov@7296 | 241 | bind(_picl_get_propinfo, "picl_get_propinfo" ); |
iveresov@7296 | 242 | } |
iveresov@7296 | 243 | |
iveresov@7296 | 244 | bool PICL::open_library() { |
iveresov@7296 | 245 | _dl_handle = dlopen("libpicl.so.1", RTLD_LAZY); |
iveresov@7296 | 246 | if (_dl_handle == NULL) { |
iveresov@7296 | 247 | return false; |
iveresov@7296 | 248 | } |
iveresov@7296 | 249 | if (!bind_library_functions()) { |
iveresov@7296 | 250 | assert(false, "unexpected PICL API change"); |
iveresov@7296 | 251 | close_library(); |
iveresov@7296 | 252 | return false; |
iveresov@7296 | 253 | } |
iveresov@7296 | 254 | return true; |
iveresov@7296 | 255 | } |
iveresov@7296 | 256 | |
iveresov@7296 | 257 | void PICL::close_library() { |
iveresov@7296 | 258 | assert(_dl_handle != NULL, "library should be open"); |
iveresov@7296 | 259 | dlclose(_dl_handle); |
iveresov@7296 | 260 | _dl_handle = NULL; |
iveresov@7296 | 261 | } |
iveresov@7296 | 262 | |
twisti@1076 | 263 | // We need to keep these here as long as we have to build on Solaris |
twisti@1076 | 264 | // versions before 10. |
kevinw@8731 | 265 | |
twisti@1076 | 266 | #ifndef SI_ARCHITECTURE_32 |
twisti@1076 | 267 | #define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */ |
twisti@1076 | 268 | #endif |
twisti@1076 | 269 | |
twisti@1076 | 270 | #ifndef SI_ARCHITECTURE_64 |
twisti@1076 | 271 | #define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */ |
twisti@1076 | 272 | #endif |
twisti@1076 | 273 | |
kevinw@8731 | 274 | #ifndef SI_CPUBRAND |
kevinw@8731 | 275 | #define SI_CPUBRAND 523 /* return cpu brand string */ |
kevinw@8731 | 276 | #endif |
twisti@1076 | 277 | |
kevinw@8731 | 278 | class Sysinfo { |
kevinw@8731 | 279 | char* _string; |
kevinw@8731 | 280 | public: |
kevinw@8731 | 281 | Sysinfo(int si) : _string(NULL) { |
kevinw@8731 | 282 | char tmp; |
kevinw@8731 | 283 | size_t bufsize = sysinfo(si, &tmp, 1); |
twisti@1076 | 284 | |
kevinw@8731 | 285 | if (bufsize != -1) { |
kevinw@8731 | 286 | char* buf = (char*) os::malloc(bufsize, mtInternal); |
kevinw@8731 | 287 | if (buf != NULL) { |
kevinw@8731 | 288 | if (sysinfo(si, buf, bufsize) == bufsize) { |
kevinw@8731 | 289 | _string = buf; |
kevinw@8731 | 290 | } else { |
kevinw@8731 | 291 | os::free(buf); |
kevinw@8731 | 292 | } |
kevinw@8731 | 293 | } |
kevinw@8731 | 294 | } |
kevinw@8731 | 295 | } |
twisti@1076 | 296 | |
kevinw@8731 | 297 | ~Sysinfo() { |
kevinw@8731 | 298 | if (_string != NULL) { |
kevinw@8731 | 299 | os::free(_string); |
twisti@1076 | 300 | } |
twisti@1076 | 301 | } |
twisti@1076 | 302 | |
kevinw@8731 | 303 | const char* value() const { |
kevinw@8731 | 304 | return _string; |
kevinw@8731 | 305 | } |
kevinw@8731 | 306 | |
kevinw@8731 | 307 | bool valid() const { |
kevinw@8731 | 308 | return _string != NULL; |
kevinw@8731 | 309 | } |
kevinw@8731 | 310 | |
kevinw@8731 | 311 | bool match(const char* s) const { |
kevinw@8731 | 312 | return valid() ? strcmp(_string, s) == 0 : false; |
kevinw@8731 | 313 | } |
kevinw@8731 | 314 | |
kevinw@8731 | 315 | bool match_substring(const char* s) const { |
kevinw@8731 | 316 | return valid() ? strstr(_string, s) != NULL : false; |
kevinw@8731 | 317 | } |
kevinw@8731 | 318 | }; |
kevinw@8731 | 319 | |
kevinw@8731 | 320 | class Sysconf { |
kevinw@8731 | 321 | int _value; |
kevinw@8731 | 322 | public: |
kevinw@8731 | 323 | Sysconf(int sc) : _value(-1) { |
kevinw@8731 | 324 | _value = sysconf(sc); |
kevinw@8731 | 325 | } |
kevinw@8731 | 326 | bool valid() const { |
kevinw@8731 | 327 | return _value != -1; |
kevinw@8731 | 328 | } |
kevinw@8731 | 329 | int value() const { |
kevinw@8731 | 330 | return _value; |
kevinw@8731 | 331 | } |
kevinw@8731 | 332 | }; |
kevinw@8731 | 333 | |
kevinw@8731 | 334 | |
kevinw@8731 | 335 | #ifndef _SC_DCACHE_LINESZ |
kevinw@8731 | 336 | #define _SC_DCACHE_LINESZ 508 /* Data cache line size */ |
kevinw@8731 | 337 | #endif |
kevinw@8731 | 338 | |
kevinw@8731 | 339 | #ifndef _SC_L2CACHE_LINESZ |
kevinw@8731 | 340 | #define _SC_L2CACHE_LINESZ 527 /* Size of L2 cache line */ |
kevinw@8731 | 341 | #endif |
kevinw@8731 | 342 | |
twisti@1076 | 343 | |
duke@435 | 344 | int VM_Version::platform_features(int features) { |
anoll@8728 | 345 | assert(os::Solaris::supports_getisax(), "getisax() must be available"); |
duke@435 | 346 | |
anoll@8728 | 347 | // Check 32-bit architecture. |
kevinw@8731 | 348 | if (Sysinfo(SI_ARCHITECTURE_32).match("sparc")) { |
kevinw@8731 | 349 | features |= v8_instructions_m; |
kevinw@8731 | 350 | } |
duke@435 | 351 | |
anoll@8728 | 352 | // Check 64-bit architecture. |
kevinw@8731 | 353 | if (Sysinfo(SI_ARCHITECTURE_64).match("sparcv9")) { |
kevinw@8731 | 354 | features |= generic_v9_m; |
kevinw@8731 | 355 | } |
duke@435 | 356 | |
anoll@8728 | 357 | // Extract valid instruction set extensions. |
anoll@8728 | 358 | uint_t avs[2]; |
anoll@8728 | 359 | uint_t avn = os::Solaris::getisax(avs, 2); |
anoll@8728 | 360 | assert(avn <= 2, "should return two or less av's"); |
anoll@8728 | 361 | uint_t av = avs[0]; |
twisti@1076 | 362 | |
kvn@2269 | 363 | #ifndef PRODUCT |
anoll@8728 | 364 | if (PrintMiscellaneous && Verbose) { |
anoll@8728 | 365 | tty->print("getisax(2) returned: " PTR32_FORMAT, av); |
anoll@8728 | 366 | if (avn > 1) { |
anoll@8728 | 367 | tty->print(", " PTR32_FORMAT, avs[1]); |
jmasa@6325 | 368 | } |
anoll@8728 | 369 | tty->cr(); |
anoll@8728 | 370 | } |
kvn@2269 | 371 | #endif |
kvn@2269 | 372 | |
anoll@8728 | 373 | if (av & AV_SPARC_MUL32) features |= hardware_mul32_m; |
anoll@8728 | 374 | if (av & AV_SPARC_DIV32) features |= hardware_div32_m; |
anoll@8728 | 375 | if (av & AV_SPARC_FSMULD) features |= hardware_fsmuld_m; |
anoll@8728 | 376 | if (av & AV_SPARC_V8PLUS) features |= v9_instructions_m; |
anoll@8728 | 377 | if (av & AV_SPARC_POPC) features |= hardware_popc_m; |
anoll@8728 | 378 | if (av & AV_SPARC_VIS) features |= vis1_instructions_m; |
anoll@8728 | 379 | if (av & AV_SPARC_VIS2) features |= vis2_instructions_m; |
anoll@8728 | 380 | if (avn > 1) { |
anoll@8728 | 381 | uint_t av2 = avs[1]; |
jmasa@6325 | 382 | #ifndef AV2_SPARC_SPARC5 |
jmasa@6325 | 383 | #define AV2_SPARC_SPARC5 0x00000008 /* The 29 new fp and sub instructions */ |
jmasa@6325 | 384 | #endif |
anoll@8728 | 385 | if (av2 & AV2_SPARC_SPARC5) features |= sparc5_instructions_m; |
anoll@8728 | 386 | } |
kvn@2269 | 387 | |
anoll@8728 | 388 | // We only build on Solaris 10 and up, but some of the values below |
anoll@8728 | 389 | // are not defined on all versions of Solaris 10, so we define them, |
anoll@8728 | 390 | // if necessary. |
kvn@2269 | 391 | #ifndef AV_SPARC_ASI_BLK_INIT |
kvn@2269 | 392 | #define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */ |
kvn@2269 | 393 | #endif |
anoll@8728 | 394 | if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m; |
kvn@2403 | 395 | |
kvn@2269 | 396 | #ifndef AV_SPARC_FMAF |
kvn@2403 | 397 | #define AV_SPARC_FMAF 0x0100 /* Fused Multiply-Add */ |
kvn@2269 | 398 | #endif |
anoll@8728 | 399 | if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m; |
kvn@2403 | 400 | |
kvn@2403 | 401 | #ifndef AV_SPARC_FMAU |
anoll@8728 | 402 | #define AV_SPARC_FMAU 0x0200 /* Unfused Multiply-Add */ |
kvn@2403 | 403 | #endif |
anoll@8728 | 404 | if (av & AV_SPARC_FMAU) features |= fmau_instructions_m; |
kvn@2403 | 405 | |
kvn@2403 | 406 | #ifndef AV_SPARC_VIS3 |
anoll@8728 | 407 | #define AV_SPARC_VIS3 0x0400 /* VIS3 instruction set extensions */ |
kvn@2403 | 408 | #endif |
anoll@8728 | 409 | if (av & AV_SPARC_VIS3) features |= vis3_instructions_m; |
kvn@2403 | 410 | |
kvn@3037 | 411 | #ifndef AV_SPARC_CBCOND |
kvn@3037 | 412 | #define AV_SPARC_CBCOND 0x10000000 /* compare and branch instrs supported */ |
kvn@3037 | 413 | #endif |
anoll@8728 | 414 | if (av & AV_SPARC_CBCOND) features |= cbcond_instructions_m; |
kvn@3037 | 415 | |
kvn@6312 | 416 | #ifndef AV_SPARC_AES |
kvn@6312 | 417 | #define AV_SPARC_AES 0x00020000 /* aes instrs supported */ |
kvn@6312 | 418 | #endif |
anoll@8728 | 419 | if (av & AV_SPARC_AES) features |= aes_instructions_m; |
kvn@6312 | 420 | |
kvn@7027 | 421 | #ifndef AV_SPARC_SHA1 |
kvn@7027 | 422 | #define AV_SPARC_SHA1 0x00400000 /* sha1 instruction supported */ |
kvn@7027 | 423 | #endif |
anoll@8728 | 424 | if (av & AV_SPARC_SHA1) features |= sha1_instruction_m; |
kvn@7027 | 425 | |
kvn@7027 | 426 | #ifndef AV_SPARC_SHA256 |
kvn@7027 | 427 | #define AV_SPARC_SHA256 0x00800000 /* sha256 instruction supported */ |
kvn@7027 | 428 | #endif |
anoll@8728 | 429 | if (av & AV_SPARC_SHA256) features |= sha256_instruction_m; |
kvn@7027 | 430 | |
kvn@7027 | 431 | #ifndef AV_SPARC_SHA512 |
kvn@7027 | 432 | #define AV_SPARC_SHA512 0x01000000 /* sha512 instruction supported */ |
kvn@7027 | 433 | #endif |
anoll@8728 | 434 | if (av & AV_SPARC_SHA512) features |= sha512_instruction_m; |
duke@435 | 435 | |
twisti@1076 | 436 | // Determine the machine type. |
kevinw@8731 | 437 | if (Sysinfo(SI_MACHINE).match("sun4v")) { |
kevinw@8731 | 438 | features |= sun4v_m; |
kevinw@8731 | 439 | } |
duke@435 | 440 | |
kevinw@8732 | 441 | // If SI_CPUBRAND works, that means Solaris 12 API to get the cache line sizes |
kevinw@8732 | 442 | // is available to us as well |
kevinw@8732 | 443 | Sysinfo cpu_info(SI_CPUBRAND); |
kevinw@8732 | 444 | bool use_solaris_12_api = cpu_info.valid(); |
shshahma@8880 | 445 | const char* impl = "unknown"; |
kevinw@8732 | 446 | int impl_m = 0; |
kevinw@8732 | 447 | if (use_solaris_12_api) { |
kevinw@8732 | 448 | impl = cpu_info.value(); |
kevinw@8732 | 449 | #ifndef PRODUCT |
kevinw@8732 | 450 | if (PrintMiscellaneous && Verbose) { |
kevinw@8732 | 451 | tty->print_cr("Parsing CPU implementation from %s", impl); |
kevinw@8732 | 452 | } |
kevinw@8732 | 453 | #endif |
kevinw@8732 | 454 | impl_m = parse_features(impl); |
kevinw@8731 | 455 | } else { |
kevinw@8731 | 456 | // Otherwise use kstat to determine the machine type. |
kvn@2403 | 457 | kstat_ctl_t* kc = kstat_open(); |
kevinw@8732 | 458 | if (kc != NULL) { |
kevinw@8732 | 459 | kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, NULL); |
kevinw@8732 | 460 | if (ksp != NULL) { |
kevinw@8732 | 461 | if (kstat_read(kc, ksp, NULL) != -1 && ksp->ks_data != NULL) { |
kevinw@8732 | 462 | kstat_named_t* knm = (kstat_named_t *)ksp->ks_data; |
kevinw@8732 | 463 | for (int i = 0; i < ksp->ks_ndata; i++) { |
kevinw@8732 | 464 | if (strcmp((const char*)&(knm[i].name), "implementation") == 0) { |
kevinw@8732 | 465 | impl = KSTAT_NAMED_STR_PTR(&knm[i]); |
kvn@2403 | 466 | #ifndef PRODUCT |
kevinw@8732 | 467 | if (PrintMiscellaneous && Verbose) { |
kevinw@8732 | 468 | tty->print_cr("Parsing CPU implementation from %s", impl); |
kevinw@8732 | 469 | } |
kevinw@8732 | 470 | #endif |
kevinw@8732 | 471 | impl_m = parse_features(impl); |
kevinw@8732 | 472 | break; |
kvn@2403 | 473 | } |
kvn@2403 | 474 | } |
kevinw@8732 | 475 | } |
kvn@2403 | 476 | } |
kevinw@8732 | 477 | kstat_close(kc); |
kvn@2403 | 478 | } |
kvn@2403 | 479 | } |
shshahma@8880 | 480 | assert(impl_m != 0, err_msg("Unrecognized CPU implementation %s", impl)); |
kevinw@8732 | 481 | features |= impl_m; |
kvn@2403 | 482 | |
kevinw@8731 | 483 | bool is_sun4v = (features & sun4v_m) != 0; |
kevinw@8731 | 484 | if (use_solaris_12_api && is_sun4v) { |
kevinw@8731 | 485 | // If Solaris 12 API is supported and it's sun4v use sysconf() to get the cache line sizes |
kevinw@8731 | 486 | Sysconf l1_dcache_line_size(_SC_DCACHE_LINESZ); |
kevinw@8731 | 487 | if (l1_dcache_line_size.valid()) { |
kevinw@8731 | 488 | _L1_data_cache_line_size = l1_dcache_line_size.value(); |
kevinw@8731 | 489 | } |
iveresov@7135 | 490 | |
kevinw@8731 | 491 | Sysconf l2_dcache_line_size(_SC_L2CACHE_LINESZ); |
kevinw@8731 | 492 | if (l2_dcache_line_size.valid()) { |
kevinw@8731 | 493 | _L2_data_cache_line_size = l2_dcache_line_size.value(); |
kevinw@8731 | 494 | } |
kevinw@8731 | 495 | } else { |
kevinw@8731 | 496 | // Otherwise figure out the cache line sizes using PICL |
kevinw@8731 | 497 | bool is_fujitsu = (features & sparc64_family_m) != 0; |
kevinw@8731 | 498 | PICL picl(is_fujitsu, is_sun4v); |
kevinw@8731 | 499 | _L1_data_cache_line_size = picl.L1_data_cache_line_size(); |
kevinw@8731 | 500 | _L2_data_cache_line_size = picl.L2_data_cache_line_size(); |
kevinw@8731 | 501 | } |
duke@435 | 502 | return features; |
duke@435 | 503 | } |