1 /*
   2  * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2016, 2021 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "jvm.h"
  28 #include "asm/assembler.inline.hpp"
  29 #include "compiler/disassembler.hpp"
  30 #include "code/compiledIC.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/java.hpp"
  33 #include "runtime/stubCodeGenerator.hpp"
  34 #include "runtime/vm_version.hpp"
  35 
  36 # include <sys/sysinfo.h>
  37 
  38 bool VM_Version::_is_determine_features_test_running  = false;
  39 const char*   VM_Version::_model_string;
  40 
  41 unsigned long VM_Version::_features[_features_buffer_len]              = {0, 0, 0, 0};
  42 unsigned long VM_Version::_cipher_features_KM[_features_buffer_len]    = {0, 0, 0, 0};
  43 unsigned long VM_Version::_cipher_features_KMA[_features_buffer_len]   = {0, 0, 0, 0};
  44 unsigned long VM_Version::_cipher_features_KMF[_features_buffer_len]   = {0, 0, 0, 0};
  45 unsigned long VM_Version::_cipher_features_KMCTR[_features_buffer_len] = {0, 0, 0, 0};
  46 unsigned long VM_Version::_cipher_features_KMO[_features_buffer_len]   = {0, 0, 0, 0};
  47 unsigned long VM_Version::_msgdigest_features[_features_buffer_len]    = {0, 0, 0, 0};
  48 unsigned int  VM_Version::_nfeatures                                   = 0;
  49 unsigned int  VM_Version::_ncipher_features_KM                         = 0;
  50 unsigned int  VM_Version::_ncipher_features_KMA                        = 0;
  51 unsigned int  VM_Version::_ncipher_features_KMF                        = 0;
  52 unsigned int  VM_Version::_ncipher_features_KMCTR                      = 0;
  53 unsigned int  VM_Version::_ncipher_features_KMO                        = 0;
  54 unsigned int  VM_Version::_nmsgdigest_features                         = 0;
  55 unsigned int  VM_Version::_Dcache_lineSize                             = DEFAULT_CACHE_LINE_SIZE;
  56 unsigned int  VM_Version::_Icache_lineSize                             = DEFAULT_CACHE_LINE_SIZE;
  57 
  58 // The following list contains the (approximate) announcement/availability
  59 // dates of the many System z generations in existence as of now.
  60 // Information compiled from https://www.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/TD105503
  61 //   z900: 2000-10
  62 //   z990: 2003-06
  63 //   z9:   2005-09
  64 //   z10:  2007-04
  65 //   z10:  2008-02
  66 //   z196: 2010-08
  67 //   ec12: 2012-09
  68 //   z13:  2015-03
  69 //   z14:  2017-09
  70 //   z15:  2019-09
  71 
  72 static const char* z_gen[]      = {"  ", "G1",         "G2",         "G3",         "G4",         "G5",         "G6",         "G7",         "G8",         "G9"  };
  73 static const char* z_machine[]  = {"  ", "2064",       "2084",       "2094",       "2097",       "2817",       "2827",       "2964",       "3906",       "8561" };
  74 static const char* z_name[]     = {"  ", "z900",       "z990",       "z9 EC",      "z10 EC",     "z196 EC",    "ec12",       "z13",        "z14",        "z15" };
  75 static const char* z_WDFM[]     = {"  ", "2006-06-30", "2008-06-30", "2010-06-30", "2012-06-30", "2014-06-30", "2016-12-31", "2019-06-30", "2021-06-30", "tbd" };
  76 static const char* z_EOS[]      = {"  ", "2014-12-31", "2014-12-31", "2017-10-31", "2019-12-31", "2021-12-31", "tbd",        "tbd",        "tbd",        "tbd" };
  77 static const char* z_features[] = {"  ",
  78                                    "system-z, g1-z900, ldisp",
  79                                    "system-z, g2-z990, ldisp_fast",
  80                                    "system-z, g3-z9, ldisp_fast, extimm",
  81                                    "system-z, g4-z10, ldisp_fast, extimm, pcrel_load/store, cmpb",
  82                                    "system-z, g5-z196, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update",
  83                                    "system-z, g6-ec12, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm",
  84                                    "system-z, g7-z13, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr",
  85                                    "system-z, g8-z14, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1)",
  86                                    "system-z, g9-z15, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr, instrext2, venh1, instrext3, VEnh2 )"
  87                                   };
  88 
  89 void VM_Version::initialize() {
  90   determine_features();      // Get processor capabilities.
  91   set_features_string();     // Set a descriptive feature indication.
  92 
  93   if (Verbose || PrintAssembly || PrintStubCode) {
  94     print_features_internal("CPU Version as detected internally:", PrintAssembly || PrintStubCode);
  95   }
  96 
  97   intx cache_line_size = Dcache_lineSize(0);
  98 
  99 #ifdef COMPILER2
 100   MaxVectorSize = 8;
 101 #endif
 102 
 103   if (has_PrefetchRaw()) {
 104     if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) {  // not preset
 105       // 0 = no prefetch.
 106       // 1 = Prefetch instructions for each allocation.
 107       // 2 = Use TLAB watermark to gate allocation prefetch.
 108       AllocatePrefetchStyle = 1;
 109     }
 110 
 111     if (AllocatePrefetchStyle > 0) {  // Prefetching turned on at all?
 112       // Distance to prefetch ahead of allocation pointer.
 113       if (FLAG_IS_DEFAULT(AllocatePrefetchDistance) || (AllocatePrefetchDistance < 0)) {  // not preset
 114         AllocatePrefetchDistance = 0;
 115       }
 116 
 117       // Number of lines to prefetch ahead of allocation pointer.
 118       if (FLAG_IS_DEFAULT(AllocatePrefetchLines) || (AllocatePrefetchLines <= 0)) {      // not preset
 119         AllocatePrefetchLines = 3;
 120       }
 121 
 122       // Step size in bytes of sequential prefetch instructions.
 123       if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize) || (AllocatePrefetchStepSize <= 0)) { // not preset
 124         FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);
 125       } else if (AllocatePrefetchStepSize < cache_line_size) {
 126         FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);
 127       } else {
 128         FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);
 129       }
 130     } else {
 131       FLAG_SET_DEFAULT(AllocatePrefetchStyle, 0);
 132       AllocatePrefetchDistance = 0;
 133       AllocatePrefetchLines    = 0;
 134       // Can't be zero. Will SIGFPE during constraints checking.
 135       FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);
 136     }
 137 
 138   } else {
 139     FLAG_SET_DEFAULT(AllocatePrefetchStyle, 0);
 140     AllocatePrefetchDistance = 0;
 141     AllocatePrefetchLines    = 0;
 142     // Can't be zero. Will SIGFPE during constraints checking.
 143     FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);
 144   }
 145 
 146   // TODO:
 147   // On z/Architecture, cache line size is significantly large (256 bytes). Do we really need
 148   // to keep contended members that far apart? Performance tests are required.
 149   if (FLAG_IS_DEFAULT(ContendedPaddingWidth) && (cache_line_size > ContendedPaddingWidth)) {
 150     ContendedPaddingWidth = cache_line_size;
 151   }
 152 
 153   // On z/Architecture, the CRC32/CRC32C intrinsics are implemented "by hand".
 154   // TODO: Provide implementation based on the vector instructions available from z13.
 155   // Note: The CHECKSUM instruction, which has been there since the very beginning
 156   //       (of z/Architecture), computes "some kind of" a checksum.
 157   //       It has nothing to do with the CRC32 algorithm.
 158   if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
 159     FLAG_SET_DEFAULT(UseCRC32Intrinsics, true);
 160   }
 161   if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) {
 162     FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true);
 163   }
 164 
 165   // TODO: Provide implementation.
 166   if (UseAdler32Intrinsics) {
 167     warning("Adler32Intrinsics not available on this CPU.");
 168     FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
 169   }
 170 
 171   // On z/Architecture, we take UseAES as the general switch to enable/disable the AES intrinsics.
 172   // The specific, and yet to be defined, switches UseAESxxxIntrinsics will then be set
 173   // depending on the actual machine capabilities.
 174   // Explicitly setting them via CmdLine option takes precedence, of course.
 175   // TODO: UseAESIntrinsics must be made keylength specific.
 176   // As of March 2015 and Java8, only AES128 is supported by the Java Cryptographic Extensions.
 177   // Therefore, UseAESIntrinsics is of minimal use at the moment.
 178   if (FLAG_IS_DEFAULT(UseAES) && has_Crypto_AES()) {
 179     FLAG_SET_DEFAULT(UseAES, true);
 180   }
 181   if (UseAES && !has_Crypto_AES()) {
 182     warning("AES instructions are not available on this CPU");
 183     FLAG_SET_DEFAULT(UseAES, false);
 184   }
 185   if (UseAES) {
 186     if (FLAG_IS_DEFAULT(UseAESIntrinsics)) {
 187       FLAG_SET_DEFAULT(UseAESIntrinsics, true);
 188     }
 189   }
 190   if (UseAESIntrinsics && !has_Crypto_AES()) {
 191     warning("AES intrinsics are not available on this CPU");
 192     FLAG_SET_DEFAULT(UseAESIntrinsics, false);
 193   }
 194   if (UseAESIntrinsics && !UseAES) {
 195     warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled.");
 196     FLAG_SET_DEFAULT(UseAESIntrinsics, false);
 197   }
 198 
 199   // TODO: implement AES/CTR intrinsics
 200   if (UseAESCTRIntrinsics) {
 201     warning("AES/CTR intrinsics are not available on this CPU");
 202     FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false);
 203   }
 204 
 205   if (FLAG_IS_DEFAULT(UseGHASHIntrinsics) && has_Crypto_GHASH()) {
 206     FLAG_SET_DEFAULT(UseGHASHIntrinsics, true);
 207   }
 208   if (UseGHASHIntrinsics && !has_Crypto_GHASH()) {
 209     warning("GHASH intrinsics are not available on this CPU");
 210     FLAG_SET_DEFAULT(UseGHASHIntrinsics, false);
 211   }
 212 
 213   if (FLAG_IS_DEFAULT(UseFMA)) {
 214     FLAG_SET_DEFAULT(UseFMA, true);
 215   }
 216 
 217   // On z/Architecture, we take UseSHA as the general switch to enable/disable the SHA intrinsics.
 218   // The specific switches UseSHAxxxIntrinsics will then be set depending on the actual
 219   // machine capabilities.
 220   // Explicitly setting them via CmdLine option takes precedence, of course.
 221   if (FLAG_IS_DEFAULT(UseSHA) && has_Crypto_SHA()) {
 222     FLAG_SET_DEFAULT(UseSHA, true);
 223   }
 224   if (UseSHA && !has_Crypto_SHA()) {
 225     warning("SHA instructions are not available on this CPU");
 226     FLAG_SET_DEFAULT(UseSHA, false);
 227   }
 228   if (UseSHA && has_Crypto_SHA1()) {
 229     if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
 230       FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
 231     }
 232   } else if (UseSHA1Intrinsics) {
 233     warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
 234     FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
 235   }
 236   if (UseSHA && has_Crypto_SHA256()) {
 237     if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
 238       FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
 239     }
 240   } else if (UseSHA256Intrinsics) {
 241     warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.");
 242     FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
 243   }
 244   if (UseSHA && has_Crypto_SHA512()) {
 245     if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) {
 246       FLAG_SET_DEFAULT(UseSHA512Intrinsics, true);
 247     }
 248   } else if (UseSHA512Intrinsics) {
 249     warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.");
 250     FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
 251   }
 252 
 253   if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) {
 254     FLAG_SET_DEFAULT(UseSHA, false);
 255   }
 256 
 257 #ifdef COMPILER2
 258   if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
 259     FLAG_SET_DEFAULT(UseMultiplyToLenIntrinsic, true);
 260   }
 261   if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) {
 262     FLAG_SET_DEFAULT(UseMontgomeryMultiplyIntrinsic, true);
 263   }
 264   if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) {
 265     FLAG_SET_DEFAULT(UseMontgomerySquareIntrinsic, true);
 266   }
 267 #endif
 268   if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
 269     FLAG_SET_DEFAULT(UsePopCountInstruction, true);
 270   }
 271 
 272   // z/Architecture supports 8-byte compare-exchange operations
 273   // (see Atomic::cmpxchg)
 274   // and 'atomic long memory ops' (see Unsafe_GetLongVolatile).
 275   _supports_cx8 = true;
 276 
 277   _supports_atomic_getadd4 = VM_Version::has_LoadAndALUAtomicV1();
 278   _supports_atomic_getadd8 = VM_Version::has_LoadAndALUAtomicV1();
 279 
 280   // z/Architecture supports unaligned memory accesses.
 281   // Performance penalty is negligible. An additional tick or so
 282   // is lost if the accessed data spans a cache line boundary.
 283   // Unaligned accesses are not atomic, of course.
 284   if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) {
 285     FLAG_SET_DEFAULT(UseUnalignedAccesses, true);
 286   }
 287 }
 288 
 289 
 290 int VM_Version::get_model_index() {
 291   // returns the index used to access the various model-dependent strings.
 292   //  > 0 valid (known) model detected.
 293   //  = 0 model not recognized, maybe not yet supported.
 294   //  < 0 model detection is ambiguous. The absolute value of the returned value
 295   //      is the index of the oldest detected model.
 296   int ambiguity = 0;
 297   int model_ix  = 0;
 298   if (is_z15()) {
 299     model_ix = 9;
 300     ambiguity++;
 301   }
 302   if (is_z14()) {
 303     model_ix = 8;
 304     ambiguity++;
 305   }
 306   if (is_z13()) {
 307     model_ix = 7;
 308     ambiguity++;
 309   }
 310   if (is_ec12()) {
 311     model_ix = 6;
 312     ambiguity++;
 313   }
 314   if (is_z196()) {
 315     model_ix = 5;
 316     ambiguity++;
 317   }
 318   if (is_z10()) {
 319     model_ix = 4;
 320     ambiguity++;
 321   }
 322   if (is_z9()) {
 323     model_ix = 3;
 324     ambiguity++;
 325   }
 326   if (is_z990()) {
 327     model_ix = 2;
 328     ambiguity++;
 329   }
 330   if (is_z900()) {
 331     model_ix = 1;
 332     ambiguity++;
 333   }
 334 
 335   if (ambiguity > 1) {
 336     model_ix = -model_ix;
 337   }
 338   return model_ix;
 339 }
 340 
 341 
 342 void VM_Version::set_features_string() {
 343   // A note on the _features_string format:
 344   //   There are jtreg tests checking the _features_string for various properties.
 345   //   For some strange reason, these tests require the string to contain
 346   //   only _lowercase_ characters. Keep that in mind when being surprised
 347   //   about the unusual notation of features - and when adding new ones.
 348   //   Features may have one comma at the end.
 349   //   Furthermore, use one, and only one, separator space between features.
 350   //   Multiple spaces are considered separate tokens, messing up everything.
 351 
 352   int model_ix = get_model_index();
 353   char buf[512];
 354   if (model_ix == 0) {
 355     _model_string = "unknown model";
 356     strcpy(buf, "z/Architecture (unknown generation)");
 357   } else if (model_ix > 0) {
 358     _model_string = z_name[model_ix];
 359     jio_snprintf(buf, sizeof(buf), "%s, out-of-support_as_of_", z_features[model_ix], z_EOS[model_ix]);
 360   } else if (model_ix < 0) {
 361     tty->print_cr("*** WARNING *** Ambiguous z/Architecture detection!");
 362     tty->print_cr("                oldest detected generation is %s", z_features[-model_ix]);
 363     _model_string = "unknown model";
 364     strcpy(buf, "z/Architecture (ambiguous detection)");
 365   }
 366   _features_string = os::strdup(buf);
 367 
 368   if (has_Crypto_AES()) {
 369     assert(strlen(_features_string) + 3*8 < sizeof(buf), "increase buffer size");
 370     jio_snprintf(buf, sizeof(buf), "%s%s%s%s",
 371                  _features_string,
 372                  has_Crypto_AES128() ? ", aes128" : "",
 373                  has_Crypto_AES192() ? ", aes192" : "",
 374                  has_Crypto_AES256() ? ", aes256" : "");
 375     os::free((void *)_features_string);
 376     _features_string = os::strdup(buf);
 377   }
 378 
 379   if (has_Crypto_SHA()) {
 380     assert(strlen(_features_string) + 6 + 2*8 + 7 < sizeof(buf), "increase buffer size");
 381     jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s",
 382                  _features_string,
 383                  has_Crypto_SHA1()   ? ", sha1"   : "",
 384                  has_Crypto_SHA256() ? ", sha256" : "",
 385                  has_Crypto_SHA512() ? ", sha512" : "",
 386                  has_Crypto_GHASH()  ? ", ghash"  : "");
 387     os::free((void *)_features_string);
 388     _features_string = os::strdup(buf);
 389   }
 390 }
 391 
 392 // featureBuffer - bit array indicating availability of various features
 393 // featureNum    - bit index of feature to be tested
 394 //                 Featurenum < 0 requests test for any nonzero bit in featureBuffer.
 395 // bufLen        - length of featureBuffer in bits
 396 bool VM_Version::test_feature_bit(unsigned long* featureBuffer, int featureNum, unsigned int bufLen) {
 397   assert(bufLen > 0,             "buffer len must be positive");
 398   assert((bufLen & 0x0007) == 0, "unaligned buffer len");
 399   assert(((intptr_t)featureBuffer&0x0007) == 0, "unaligned feature buffer");
 400   if (featureNum < 0) {
 401     // Any bit set at all?
 402     bool anyBit = false;
 403     for (size_t i = 0; i < bufLen/(8*sizeof(long)); i++) {
 404       anyBit = anyBit || (featureBuffer[i] != 0);
 405     }
 406     return anyBit;
 407   } else {
 408     assert((unsigned int)featureNum < bufLen,    "feature index out of range");
 409     unsigned char* byteBuffer = (unsigned char*)featureBuffer;
 410     int   byteIndex  = featureNum/(8*sizeof(char));
 411     int   bitIndex   = featureNum%(8*sizeof(char));
 412     // Indexed bit set?
 413     return (byteBuffer[byteIndex] & (1U<<(7-bitIndex))) != 0;
 414   }
 415 }
 416 
 417 void VM_Version::print_features_internal(const char* text, bool print_anyway) {
 418   tty->print_cr("%s %s", text, features_string());
 419   tty->cr();
 420 
 421   if (Verbose || print_anyway) {
 422     // z900
 423     if (has_long_displacement()        ) tty->print_cr("available: %s", "LongDispFacility");
 424     // z990
 425     if (has_long_displacement_fast()   ) tty->print_cr("available: %s", "LongDispFacilityHighPerf");
 426     if (has_ETF2() && has_ETF3()       ) tty->print_cr("available: %s", "ETF2 and ETF3");
 427     if (has_Crypto()                   ) tty->print_cr("available: %s", "CryptoFacility");
 428     // z9
 429     if (has_extended_immediate()       ) tty->print_cr("available: %s", "ExtImmedFacility");
 430     if (has_StoreFacilityListExtended()) tty->print_cr("available: %s", "StoreFacilityListExtended");
 431     if (has_StoreClockFast()           ) tty->print_cr("available: %s", "StoreClockFast");
 432     if (has_ETF2Enhancements()         ) tty->print_cr("available: %s", "ETF2 Enhancements");
 433     if (has_ETF3Enhancements()         ) tty->print_cr("available: %s", "ETF3 Enhancements");
 434     if (has_HFPUnnormalized()          ) tty->print_cr("available: %s", "HFPUnnormalizedFacility");
 435     if (has_HFPMultiplyAndAdd()        ) tty->print_cr("available: %s", "HFPMultiplyAndAddFacility");
 436     // z10
 437     if (has_ParsingEnhancements()      ) tty->print_cr("available: %s", "Parsing Enhancements");
 438     if (has_ExtractCPUtime()           ) tty->print_cr("available: %s", "ExtractCPUTime");
 439     if (has_CompareSwapStore()         ) tty->print_cr("available: %s", "CompareSwapStore");
 440     if (has_GnrlInstrExtensions()      ) tty->print_cr("available: %s", "General Instruction Extensions");
 441     if (has_CompareBranch()            ) tty->print_cr("  available: %s", "Compare and Branch");
 442     if (has_CompareTrap()              ) tty->print_cr("  available: %s", "Compare and Trap");
 443     if (has_RelativeLoadStore()        ) tty->print_cr("  available: %s", "Relative Load/Store");
 444     if (has_MultiplySingleImm32()      ) tty->print_cr("  available: %s", "MultiplySingleImm32");
 445     if (has_Prefetch()                 ) tty->print_cr("  available: %s", "Prefetch");
 446     if (has_MoveImmToMem()             ) tty->print_cr("  available: %s", "Direct Moves Immediate to Memory");
 447     if (has_MemWithImmALUOps()         ) tty->print_cr("  available: %s", "Direct ALU Ops Memory .op. Immediate");
 448     if (has_ExtractCPUAttributes()     ) tty->print_cr("  available: %s", "Extract CPU Attributes");
 449     if (has_ExecuteExtensions()        ) tty->print_cr("available: %s", "ExecuteExtensions");
 450     if (has_FPSupportEnhancements()    ) tty->print_cr("available: %s", "FPSupportEnhancements");
 451     if (has_DecimalFloatingPoint()     ) tty->print_cr("available: %s", "DecimalFloatingPoint");
 452     // z196
 453     if (has_DistinctOpnds()            ) tty->print_cr("available: %s", "Distinct Operands");
 454     if (has_InterlockedAccessV1()      ) tty->print_cr("  available: %s", "InterlockedAccess V1 (fast)");
 455     if (has_PopCount()                 ) tty->print_cr("  available: %s", "PopCount");
 456     if (has_LoadStoreConditional()     ) tty->print_cr("  available: %s", "LoadStoreConditional");
 457     if (has_HighWordInstr()            ) tty->print_cr("  available: %s", "HighWord Instructions");
 458     if (has_FastSync()                 ) tty->print_cr("  available: %s", "FastSync (bcr 14,0)");
 459     if (has_AtomicMemWithImmALUOps()   ) tty->print_cr("available: %s", "Atomic Direct ALU Ops Memory .op. Immediate");
 460     if (has_FPExtensions()             ) tty->print_cr("available: %s", "Floatingpoint Extensions");
 461     if (has_CryptoExt3()               ) tty->print_cr("available: %s", "Crypto Extensions 3");
 462     if (has_CryptoExt4()               ) tty->print_cr("available: %s", "Crypto Extensions 4");
 463     // EC12
 464     if (has_MiscInstrExt()             ) tty->print_cr("available: %s", "Miscellaneous Instruction Extensions");
 465     if (has_ExecutionHint()            ) tty->print_cr("  available: %s", "Execution Hints (branch prediction)");
 466     if (has_ProcessorAssist()          ) tty->print_cr("  available: %s", "Processor Assists");
 467     if (has_LoadAndTrap()              ) tty->print_cr("  available: %s", "Load and Trap");
 468     if (has_TxMem()                    ) tty->print_cr("available: %s", "Transactional Memory");
 469     if (has_InterlockedAccessV2()      ) tty->print_cr("  available: %s", "InterlockedAccess V2 (fast)");
 470     if (has_DFPZonedConversion()       ) tty->print_cr("  available: %s", "DFP Zoned Conversions");
 471     // z13
 472     if (has_LoadStoreConditional2()    ) tty->print_cr("available: %s", "Load/Store Conditional 2");
 473     if (has_CryptoExt5()               ) tty->print_cr("available: %s", "Crypto Extensions 5");
 474     if (has_DFPPackedConversion()      ) tty->print_cr("available: %s", "DFP Packed Conversions");
 475     if (has_VectorFacility()           ) tty->print_cr("available: %s", "Vector Facility");
 476     // z14
 477     if (has_MiscInstrExt2()            ) tty->print_cr("available: %s", "Miscellaneous Instruction Extensions 2");
 478     if (has_VectorEnhancements1()      ) tty->print_cr("available: %s", "Vector Facility Enhancements 3");
 479     if (has_CryptoExt8()               ) tty->print_cr("available: %s", "Crypto Extensions 8");
 480     // z15
 481     if (has_MiscInstrExt3()            ) tty->print_cr("available: %s", "Miscellaneous Instruction Extensions 3");
 482     if (has_VectorEnhancements2()      ) tty->print_cr("available: %s", "Vector Facility Enhancements 3");
 483     if (has_CryptoExt9()               ) tty->print_cr("available: %s", "Crypto Extensions 9");
 484 
 485     if (has_Crypto()) {
 486       tty->cr();
 487       tty->print_cr("detailed availability of %s capabilities:", "CryptoFacility");
 488       if (test_feature_bit(&_cipher_features_KM[0], -1, 2*Cipher::_featureBits)) {
 489         tty->cr();
 490         tty->print_cr("  available: %s", "Message Cipher Functions");
 491       }
 492 
 493       if (test_feature_bit(&_cipher_features_KM[0], -1, (int)Cipher::_featureBits)) {
 494         tty->print_cr("    available Crypto Features of KM  (Cipher Message):");
 495         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 496           if (test_feature_bit(&_cipher_features_KM[0], i, (int)Cipher::_featureBits)) {
 497             switch (i) {
 498               case Cipher::_Query:              tty->print_cr("      available: KM   Query");                  break;
 499               case Cipher::_DEA:                tty->print_cr("      available: KM   DEA");                    break;
 500               case Cipher::_TDEA128:            tty->print_cr("      available: KM   TDEA-128");               break;
 501               case Cipher::_TDEA192:            tty->print_cr("      available: KM   TDEA-192");               break;
 502               case Cipher::_EncryptedDEA:       tty->print_cr("      available: KM   Encrypted DEA");          break;
 503               case Cipher::_EncryptedDEA128:    tty->print_cr("      available: KM   Encrypted DEA-128");      break;
 504               case Cipher::_EncryptedDEA192:    tty->print_cr("      available: KM   Encrypted DEA-192");      break;
 505               case Cipher::_AES128:             tty->print_cr("      available: KM   AES-128");                break;
 506               case Cipher::_AES192:             tty->print_cr("      available: KM   AES-192");                break;
 507               case Cipher::_AES256:             tty->print_cr("      available: KM   AES-256");                break;
 508               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KM   Encrypted-AES-128");      break;
 509               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KM   Encrypted-AES-192");      break;
 510               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KM   Encrypted-AES-256");      break;
 511               case Cipher::_XTSAES128:          tty->print_cr("      available: KM   XTS-AES-128");            break;
 512               case Cipher::_XTSAES256:          tty->print_cr("      available: KM   XTS-AES-256");            break;
 513               case Cipher::_EncryptedXTSAES128: tty->print_cr("      available: KM   XTS-Encrypted-AES-128");  break;
 514               case Cipher::_EncryptedXTSAES256: tty->print_cr("      available: KM   XTS-Encrypted-AES-256");  break;
 515               default: tty->print_cr("      available: unknown KM  code %d", i);      break;
 516             }
 517           }
 518         }
 519       }
 520 
 521       if (test_feature_bit(&_cipher_features_KM[2], -1, (int)Cipher::_featureBits)) {
 522         tty->print_cr("    available Crypto Features of KMC (Cipher Message with Chaining):");
 523         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 524           if (test_feature_bit(&_cipher_features_KM[2], i, (int)Cipher::_featureBits)) {
 525             switch (i) {
 526               case Cipher::_Query:              tty->print_cr("      available: KMC  Query");                  break;
 527               case Cipher::_DEA:                tty->print_cr("      available: KMC  DEA");                    break;
 528               case Cipher::_TDEA128:            tty->print_cr("      available: KMC  TDEA-128");               break;
 529               case Cipher::_TDEA192:            tty->print_cr("      available: KMC  TDEA-192");               break;
 530               case Cipher::_EncryptedDEA:       tty->print_cr("      available: KMC  Encrypted DEA");          break;
 531               case Cipher::_EncryptedDEA128:    tty->print_cr("      available: KMC  Encrypted DEA-128");      break;
 532               case Cipher::_EncryptedDEA192:    tty->print_cr("      available: KMC  Encrypted DEA-192");      break;
 533               case Cipher::_AES128:             tty->print_cr("      available: KMC  AES-128");                break;
 534               case Cipher::_AES192:             tty->print_cr("      available: KMC  AES-192");                break;
 535               case Cipher::_AES256:             tty->print_cr("      available: KMC  AES-256");                break;
 536               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KMC  Encrypted-AES-128");      break;
 537               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KMC  Encrypted-AES-192");      break;
 538               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KMC  Encrypted-AES-256");      break;
 539               case Cipher::_PRNG:               tty->print_cr("      available: KMC  PRNG");                   break;
 540               default: tty->print_cr("      available: unknown KMC code %d", i);      break;
 541             }
 542           }
 543         }
 544       }
 545     }
 546 
 547     if (has_CryptoExt4()) {
 548       if (test_feature_bit(&_cipher_features_KMF[0], -1, (int)Cipher::_featureBits)) {
 549         tty->print_cr("    available Crypto Features of KMF (Cipher Message with Cipher Feedback):");
 550         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 551           if (test_feature_bit(&_cipher_features_KMF[0], i, (int)Cipher::_featureBits)) {
 552             switch (i) {
 553               case Cipher::_Query:              tty->print_cr("      available: KMF  Query");                  break;
 554               case Cipher::_DEA:                tty->print_cr("      available: KMF  DEA");                    break;
 555               case Cipher::_TDEA128:            tty->print_cr("      available: KMF  TDEA-128");               break;
 556               case Cipher::_TDEA192:            tty->print_cr("      available: KMF  TDEA-192");               break;
 557               case Cipher::_EncryptedDEA:       tty->print_cr("      available: KMF  Encrypted DEA");          break;
 558               case Cipher::_EncryptedDEA128:    tty->print_cr("      available: KMF  Encrypted DEA-128");      break;
 559               case Cipher::_EncryptedDEA192:    tty->print_cr("      available: KMF  Encrypted DEA-192");      break;
 560               case Cipher::_AES128:             tty->print_cr("      available: KMF  AES-128");                break;
 561               case Cipher::_AES192:             tty->print_cr("      available: KMF  AES-192");                break;
 562               case Cipher::_AES256:             tty->print_cr("      available: KMF  AES-256");                break;
 563               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KMF  Encrypted-AES-128");      break;
 564               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KMF  Encrypted-AES-192");      break;
 565               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KMF  Encrypted-AES-256");      break;
 566               default: tty->print_cr("      available: unknown KMF code %d", i);      break;
 567             }
 568           }
 569         }
 570       }
 571 
 572       if (test_feature_bit(&_cipher_features_KMCTR[0], -1, (int)Cipher::_featureBits)) {
 573         tty->print_cr("    available Crypto Features of KMCTR (Cipher Message with Counter):");
 574         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 575           if (test_feature_bit(&_cipher_features_KMCTR[0], i, (int)Cipher::_featureBits)) {
 576             switch (i) {
 577               case Cipher::_Query:              tty->print_cr("      available: KMCTR  Query");                break;
 578               case Cipher::_DEA:                tty->print_cr("      available: KMCTR  DEA");                  break;
 579               case Cipher::_TDEA128:            tty->print_cr("      available: KMCTR  TDEA-128");             break;
 580               case Cipher::_TDEA192:            tty->print_cr("      available: KMCTR  TDEA-192");             break;
 581               case Cipher::_EncryptedDEA:       tty->print_cr("      available: KMCTR  Encrypted DEA");        break;
 582               case Cipher::_EncryptedDEA128:    tty->print_cr("      available: KMCTR  Encrypted DEA-128");    break;
 583               case Cipher::_EncryptedDEA192:    tty->print_cr("      available: KMCTR  Encrypted DEA-192");    break;
 584               case Cipher::_AES128:             tty->print_cr("      available: KMCTR  AES-128");              break;
 585               case Cipher::_AES192:             tty->print_cr("      available: KMCTR  AES-192");              break;
 586               case Cipher::_AES256:             tty->print_cr("      available: KMCTR  AES-256");              break;
 587               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KMCTR  Encrypted-AES-128");    break;
 588               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KMCTR  Encrypted-AES-192");    break;
 589               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KMCTR  Encrypted-AES-256");    break;
 590               default: tty->print_cr("      available: unknown KMCTR code %d", i);      break;
 591             }
 592           }
 593         }
 594       }
 595 
 596       if (test_feature_bit(&_cipher_features_KMO[0], -1, (int)Cipher::_featureBits)) {
 597         tty->print_cr("    available Crypto Features of KMO (Cipher Message with Output Feedback):");
 598         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 599           if (test_feature_bit(&_cipher_features_KMO[0], i, (int)Cipher::_featureBits)) {
 600             switch (i) {
 601               case Cipher::_Query:              tty->print_cr("      available: KMO  Query");                  break;
 602               case Cipher::_DEA:                tty->print_cr("      available: KMO  DEA");                    break;
 603               case Cipher::_TDEA128:            tty->print_cr("      available: KMO  TDEA-128");               break;
 604               case Cipher::_TDEA192:            tty->print_cr("      available: KMO  TDEA-192");               break;
 605               case Cipher::_EncryptedDEA:       tty->print_cr("      available: KMO  Encrypted DEA");          break;
 606               case Cipher::_EncryptedDEA128:    tty->print_cr("      available: KMO  Encrypted DEA-128");      break;
 607               case Cipher::_EncryptedDEA192:    tty->print_cr("      available: KMO  Encrypted DEA-192");      break;
 608               case Cipher::_AES128:             tty->print_cr("      available: KMO  AES-128");                break;
 609               case Cipher::_AES192:             tty->print_cr("      available: KMO  AES-192");                break;
 610               case Cipher::_AES256:             tty->print_cr("      available: KMO  AES-256");                break;
 611               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KMO  Encrypted-AES-128");      break;
 612               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KMO  Encrypted-AES-192");      break;
 613               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KMO  Encrypted-AES-256");      break;
 614               default: tty->print_cr("      available: unknown KMO code %d", i);      break;
 615             }
 616           }
 617         }
 618       }
 619     }
 620 
 621     if (has_CryptoExt8()) {
 622       if (test_feature_bit(&_cipher_features_KMA[0], -1, (int)Cipher::_featureBits)) {
 623         tty->print_cr("    available Crypto Features of KMA (Cipher Message with Authentication):");
 624         for (unsigned int i = 0; i < Cipher::_featureBits; i++) {
 625           if (test_feature_bit(&_cipher_features_KMA[0], i, (int)Cipher::_featureBits)) {
 626             switch (i) {
 627               case Cipher::_Query:              tty->print_cr("      available: KMA      Query");              break;
 628               case Cipher::_AES128:             tty->print_cr("      available: KMA-GCM  AES-128");            break;
 629               case Cipher::_AES192:             tty->print_cr("      available: KMA-GCM  AES-192");            break;
 630               case Cipher::_AES256:             tty->print_cr("      available: KMA-GCM  AES-256");            break;
 631               case Cipher::_EnccryptedAES128:   tty->print_cr("      available: KMA-GCM  Encrypted-AES-128");  break;
 632               case Cipher::_EnccryptedAES192:   tty->print_cr("      available: KMA-GCM  Encrypted-AES-192");  break;
 633               case Cipher::_EnccryptedAES256:   tty->print_cr("      available: KMA-GCM  Encrypted-AES-256");  break;
 634               default: tty->print_cr("      available: unknown KMA code %d", i);      break;
 635             }
 636           }
 637         }
 638       }
 639     }
 640 
 641     if (has_Crypto()) {
 642       if (test_feature_bit(&_msgdigest_features[0], -1, 2*MsgDigest::_featureBits)) {
 643         tty->cr();
 644         tty->print_cr("  available: %s", "Message Digest Functions for SHA");
 645       }
 646 
 647       if (test_feature_bit(&_msgdigest_features[0], -1, (int)MsgDigest::_featureBits)) {
 648         tty->print_cr("    available Features of KIMD (Msg Digest):");
 649         for (unsigned int i = 0; i < MsgDigest::_featureBits; i++) {
 650           if (test_feature_bit(&_msgdigest_features[0], i, (int)MsgDigest::_featureBits)) {
 651             switch (i) {
 652               case MsgDigest::_Query:     tty->print_cr("      available: KIMD Query");   break;
 653               case MsgDigest::_SHA1:      tty->print_cr("      available: KIMD SHA-1");   break;
 654               case MsgDigest::_SHA256:    tty->print_cr("      available: KIMD SHA-256"); break;
 655               case MsgDigest::_SHA512:    tty->print_cr("      available: KIMD SHA-512"); break;
 656               case MsgDigest::_SHA3_224:  tty->print_cr("      available: KIMD SHA3-224");  break;
 657               case MsgDigest::_SHA3_256:  tty->print_cr("      available: KIMD SHA3-256");  break;
 658               case MsgDigest::_SHA3_384:  tty->print_cr("      available: KIMD SHA3-384");  break;
 659               case MsgDigest::_SHA3_512:  tty->print_cr("      available: KIMD SHA3-512");  break;
 660               case MsgDigest::_SHAKE_128: tty->print_cr("      available: KIMD SHAKE-128"); break;
 661               case MsgDigest::_SHAKE_256: tty->print_cr("      available: KIMD SHAKE-256"); break;
 662               case MsgDigest::_GHASH:     tty->print_cr("      available: KIMD GHASH");   break;
 663               default: tty->print_cr("      available: unknown code %d", i);  break;
 664             }
 665           }
 666         }
 667       }
 668 
 669       if (test_feature_bit(&_msgdigest_features[2], -1, (int)MsgDigest::_featureBits)) {
 670         tty->print_cr("    available Features of KLMD (Msg Digest):");
 671         for (unsigned int i = 0; i < MsgDigest::_featureBits; i++) {
 672           if (test_feature_bit(&_msgdigest_features[2], i, (int)MsgDigest::_featureBits)) {
 673             switch (i) {
 674               case MsgDigest::_Query:     tty->print_cr("      available: KLMD Query");   break;
 675               case MsgDigest::_SHA1:      tty->print_cr("      available: KLMD SHA-1");   break;
 676               case MsgDigest::_SHA256:    tty->print_cr("      available: KLMD SHA-256"); break;
 677               case MsgDigest::_SHA512:    tty->print_cr("      available: KLMD SHA-512"); break;
 678               case MsgDigest::_SHA3_224:  tty->print_cr("      available: KLMD SHA3-224");  break;
 679               case MsgDigest::_SHA3_256:  tty->print_cr("      available: KLMD SHA3-256");  break;
 680               case MsgDigest::_SHA3_384:  tty->print_cr("      available: KLMD SHA3-384");  break;
 681               case MsgDigest::_SHA3_512:  tty->print_cr("      available: KLMD SHA3-512");  break;
 682               case MsgDigest::_SHAKE_128: tty->print_cr("      available: KLMD SHAKE-128"); break;
 683               case MsgDigest::_SHAKE_256: tty->print_cr("      available: KLMD SHAKE-256"); break;
 684               default: tty->print_cr("      available: unknown code %d", i);  break;
 685             }
 686           }
 687         }
 688       }
 689     }
 690     if (ContendedPaddingWidth > 0) {
 691       tty->cr();
 692       tty->print_cr("ContendedPaddingWidth " INTX_FORMAT, ContendedPaddingWidth);
 693     }
 694   }
 695 }
 696 
 697 void VM_Version::print_platform_virtualization_info(outputStream* st) {
 698   // /proc/sysinfo contains interesting information about
 699   // - LPAR
 700   // - whole "Box" (CPUs )
 701   // - z/VM / KVM (VM<nn>); this is not available in an LPAR-only setup
 702   const char* kw[] = { "LPAR", "CPUs", "VM", NULL };
 703   const char* info_file = "/proc/sysinfo";
 704 
 705   if (!print_matching_lines_from_file(info_file, st, kw)) {
 706     st->print_cr("  <%s Not Available>", info_file);
 707   }
 708 }
 709 
 710 void VM_Version::print_features() {
 711   print_features_internal("Version:");
 712 }
 713 
 714 void VM_Version::reset_features(bool reset) {
 715   if (reset) {
 716     for (unsigned int i = 0; i < _features_buffer_len; i++) {
 717       VM_Version::_features[i] = 0;
 718     }
 719   }
 720 }
 721 
 722 void VM_Version::set_features_z900(bool reset) {
 723   reset_features(reset);
 724 
 725   set_has_long_displacement();
 726   set_has_ETF2();
 727 }
 728 
 729 void VM_Version::set_features_z990(bool reset) {
 730   reset_features(reset);
 731 
 732   set_features_z900(false);
 733   set_has_ETF3();
 734   set_has_long_displacement_fast();
 735   set_has_HFPMultiplyAndAdd();
 736 }
 737 
 738 void VM_Version::set_features_z9(bool reset) {
 739   reset_features(reset);
 740 
 741   set_features_z990(false);
 742   set_has_StoreFacilityListExtended();
 743   // set_has_Crypto();   // Do not set, crypto features must be retrieved separately.
 744   set_has_ETF2Enhancements();
 745   set_has_ETF3Enhancements();
 746   set_has_extended_immediate();
 747   set_has_StoreClockFast();
 748   set_has_HFPUnnormalized();
 749 }
 750 
 751 void VM_Version::set_features_z10(bool reset) {
 752   reset_features(reset);
 753 
 754   set_features_z9(false);
 755   set_has_CompareSwapStore();
 756   set_has_RelativeLoadStore();
 757   set_has_CompareBranch();
 758   set_has_CompareTrap();
 759   set_has_MultiplySingleImm32();
 760   set_has_Prefetch();
 761   set_has_MoveImmToMem();
 762   set_has_MemWithImmALUOps();
 763   set_has_ExecuteExtensions();
 764   set_has_FPSupportEnhancements();
 765   set_has_DecimalFloatingPoint();
 766   set_has_ExtractCPUtime();
 767   set_has_CryptoExt3();
 768 }
 769 
 770 void VM_Version::set_features_z196(bool reset) {
 771   reset_features(reset);
 772 
 773   set_features_z10(false);
 774   set_has_InterlockedAccessV1();
 775   set_has_PopCount();
 776   set_has_LoadStoreConditional();
 777   set_has_HighWordInstr();
 778   set_has_FastSync();
 779   set_has_FPExtensions();
 780   set_has_DistinctOpnds();
 781   set_has_CryptoExt4();
 782 }
 783 
 784 void VM_Version::set_features_ec12(bool reset) {
 785   reset_features(reset);
 786 
 787   set_features_z196(false);
 788   set_has_MiscInstrExt();
 789   set_has_InterlockedAccessV2();
 790   set_has_LoadAndALUAtomicV2();
 791   set_has_TxMem();
 792 }
 793 
 794 void VM_Version::set_features_z13(bool reset) {
 795   reset_features(reset);
 796 
 797   set_features_ec12(false);
 798   set_has_LoadStoreConditional2();
 799   set_has_CryptoExt5();
 800   set_has_VectorFacility();
 801 }
 802 
 803 void VM_Version::set_features_z14(bool reset) {
 804   reset_features(reset);
 805 
 806   set_features_z13(false);
 807   set_has_MiscInstrExt2();
 808   set_has_VectorEnhancements1();
 809   has_VectorPackedDecimal();
 810   set_has_CryptoExt8();
 811 }
 812 
 813 void VM_Version::set_features_z15(bool reset) {
 814   reset_features(reset);
 815 
 816   set_features_z14(false);
 817   set_has_MiscInstrExt3();
 818   set_has_VectorEnhancements2();
 819   has_VectorPackedDecimalEnh();
 820   set_has_CryptoExt9();
 821 }
 822 
 823 void VM_Version::set_features_from(const char* march) {
 824   bool err = false;
 825   bool prt = false;
 826 
 827   if ((march != NULL) && (march[0] != '\0')) {
 828     const int buf_len = 16;
 829     const int hdr_len =  5;
 830     char buf[buf_len];
 831     if (strlen(march) >= hdr_len) {
 832       memcpy(buf, march, hdr_len);
 833       buf[hdr_len] = '\00';
 834     } else {
 835       buf[0]       = '\00';
 836     }
 837 
 838     if (!strcmp(march, "z900")) {
 839       set_features_z900();
 840     } else if (!strcmp(march, "z990")) {
 841         set_features_z990();
 842     } else if (!strcmp(march, "z9")) {
 843         set_features_z9();
 844     } else if (!strcmp(march, "z10")) {
 845         set_features_z10();
 846     } else if (!strcmp(march, "z196")) {
 847         set_features_z196();
 848     } else if (!strcmp(march, "ec12")) {
 849         set_features_ec12();
 850     } else if (!strcmp(march, "z13")) {
 851         set_features_z13();
 852     } else if (!strcmp(march, "z14")) {
 853         set_features_z14();
 854     } else if (!strcmp(march, "z15")) {
 855         set_features_z15();
 856     } else {
 857       err = true;
 858     }
 859     if (!err) {
 860       set_features_string();
 861       if (prt || PrintAssembly) {
 862         print_features_internal("CPU Version as set by cmdline option:", prt);
 863       }
 864     } else {
 865       tty->print_cr("***Warning: Unsupported ProcessorArchitecture: %s, internal settings left undisturbed.", march);
 866     }
 867   }
 868 
 869 }
 870 
 871 // getFeatures call interface
 872 // Z_ARG1 (R2) - feature bit buffer address.
 873 //               Must be DW aligned.
 874 // Z_ARG2 (R3) -  > 0 feature bit buffer length (#DWs).
 875 //                    Implies request to store cpu feature list via STFLE.
 876 //                = 0 invalid
 877 //                < 0 function code (which feature information to retrieve)
 878 //                    Implies that a buffer of at least two DWs is passed in.
 879 //                =-1 - retrieve cache topology
 880 //                =-2 - basic cipher instruction capabilities
 881 //                =-3 - msg digest (secure hash) instruction capabilities
 882 //                =-4 - vector instruction OS support availability
 883 //               =-17 - cipher (KMF) support
 884 //               =-18 - cipher (KMCTR) support
 885 //               =-19 - cipher (KMO) support
 886 //               =-20 - cipher (KMA) support
 887 // Z_ARG3 (R4) - feature code for ECAG instruction
 888 //
 889 // Z_RET (R2)  - return value
 890 //                >  0: success: number of retrieved feature bit string words.
 891 //                <  0: failure: required number of feature bit string words (buffer too small).
 892 //                == 0: failure: operation aborted.
 893 //
 894 static long (*getFeatures)(unsigned long*, int, int) = NULL;
 895 
 896 void VM_Version::set_getFeatures(address entryPoint) {
 897   if (getFeatures == NULL) {
 898     getFeatures = (long(*)(unsigned long*, int, int))entryPoint;
 899   }
 900 }
 901 
 902 long VM_Version::call_getFeatures(unsigned long* buffer, int buflen, int functionCode) {
 903   VM_Version::_is_determine_features_test_running = true;
 904   long functionResult = (*getFeatures)(buffer, buflen, functionCode);
 905   VM_Version::_is_determine_features_test_running = false;
 906   return functionResult;
 907 }
 908 
 909 // Helper function for "extract cache attribute" instruction.
 910 int VM_Version::calculate_ECAG_functionCode(unsigned int attributeIndication,
 911                                             unsigned int levelIndication,
 912                                             unsigned int typeIndication) {
 913   return (attributeIndication<<4) | (levelIndication<<1) | typeIndication;
 914 }
 915 
 916 void VM_Version::clear_buffer(unsigned long* buffer, unsigned int len) {
 917   memset(buffer, 0, sizeof(buffer[0])*len);
 918 }
 919 
 920 void VM_Version::copy_buffer(unsigned long* to, unsigned long* from, unsigned int len) {
 921   memcpy(to, from, sizeof(to[0])*len);
 922 }
 923 
 924 void VM_Version::determine_features() {
 925 
 926   const int      cbuf_size = _code_buffer_len;
 927   const int      buf_len   = _features_buffer_len;
 928 
 929   // Allocate code buffer space for the detection code.
 930   ResourceMark    rm;
 931   CodeBuffer      cbuf("determine CPU features", cbuf_size, 0);
 932   MacroAssembler* a = new MacroAssembler(&cbuf);
 933 
 934   // Emit code.
 935   set_getFeatures(a->pc());
 936   address   code = a->pc();
 937 
 938   // Try STFLE. Possible INVOP will cause defaults to be used.
 939   Label    getFEATURES;
 940   Label    getCPUFEATURES;                   // fcode = -1 (cache)
 941   Label    getCIPHERFEATURES_KM;             // fcode = -2 (cipher)
 942   Label    getCIPHERFEATURES_KMA;            // fcode = -20 (cipher)
 943   Label    getCIPHERFEATURES_KMF;            // fcode = -17 (cipher)
 944   Label    getCIPHERFEATURES_KMCTR;          // fcode = -18 (cipher)
 945   Label    getCIPHERFEATURES_KMO;            // fcode = -19 (cipher)
 946   Label    getMSGDIGESTFEATURES;             // fcode = -3 (SHA)
 947   Label    getVECTORFEATURES;                // fcode = -4 (OS support for vector instructions)
 948   Label    errRTN;
 949   a->z_ltgfr(Z_R0, Z_ARG2);                  // buf_len/fcode to r0 and test.
 950   a->z_brl(getFEATURES);                     // negative -> Get machine features or instruction-specific features
 951   a->z_lghi(Z_R1,0);
 952   a->z_brz(errRTN);                          // zero -> Function code currently not used, indicate "aborted".
 953 
 954   //---<  store feature list  >---
 955   // We have three possible outcomes here:
 956   // success:    cc = 0 and first DW of feature bit array != 0
 957   //             Z_R0 contains index of last stored DW (used_len - 1)
 958   // incomplete: cc = 3 and first DW of feature bit array != 0
 959   //             Z_R0 contains index of last DW that would have been stored (required_len - 1)
 960   a->z_aghi(Z_R0, -1);                       // STFLE needs last index, not length, of feature bit array.
 961   a->z_stfle(0, Z_ARG1);
 962   a->z_lg(Z_R1, Address(Z_ARG1, (intptr_t)0)); // Get first DW of facility list.
 963   a->z_lgr(Z_RET, Z_R0);                     // Calculate used/required len
 964   a->z_la(Z_RET, 1, Z_RET);                  // don't destroy cc from stfle!
 965   a->z_brnz(errRTN);                         // Instr failed if non-zero CC.
 966   a->z_ltgr(Z_R1, Z_R1);                     // Check if first DW of facility list was filled.
 967   a->z_bcr(Assembler::bcondNotZero, Z_R14);  // Successful return.
 968 
 969   //---<  error exit  >---
 970   a->bind(errRTN);
 971   a->z_lngr(Z_RET, Z_RET);                   // negative return value to indicate "buffer too small"
 972   a->z_ltgr(Z_R1, Z_R1);                     // Check if first DW of facility list was filled.
 973   a->z_bcr(Assembler::bcondNotZero, Z_R14);  // Return "buffer too small".
 974   a->z_xgr(Z_RET, Z_RET);
 975   a->z_br(Z_R14);                            // Return "operation aborted".
 976 
 977   a->bind(getFEATURES);
 978   a->z_cghi(Z_R0, -1);                       // -1: Extract CPU attributes, currently: cache layout only.
 979   a->z_bre(getCPUFEATURES);
 980   a->z_cghi(Z_R0, -2);                       // -2: Extract detailed crypto capabilities (cipher instructions).
 981   a->z_bre(getCIPHERFEATURES_KM);
 982   a->z_cghi(Z_R0, -3);                       // -3: Extract detailed crypto capabilities (msg digest instructions).
 983   a->z_bre(getMSGDIGESTFEATURES);
 984   a->z_cghi(Z_R0, -4);                       // -4: Verify vector instruction availability (OS support).
 985   a->z_bre(getVECTORFEATURES);
 986 
 987   a->z_cghi(Z_R0, -17);                      // -17: Extract detailed crypto capabilities (cipher instructions).
 988   a->z_bre(getCIPHERFEATURES_KMF);
 989   a->z_cghi(Z_R0, -18);                      // -18: Extract detailed crypto capabilities (cipher instructions).
 990   a->z_bre(getCIPHERFEATURES_KMCTR);
 991   a->z_cghi(Z_R0, -19);                      // -19: Extract detailed crypto capabilities (cipher instructions).
 992   a->z_bre(getCIPHERFEATURES_KMO);
 993   a->z_cghi(Z_R0, -20);                      // -20: Extract detailed crypto capabilities (cipher instructions).
 994   a->z_bre(getCIPHERFEATURES_KMA);
 995 
 996   a->z_xgr(Z_RET, Z_RET);                    // Not a valid function code.
 997   a->z_br(Z_R14);                            // Return "operation aborted".
 998 
 999   // Try KIMD/KLMD query function to get details about msg digest (secure hash, SHA) instructions.
1000   a->bind(getMSGDIGESTFEATURES);
1001   a->z_lghi(Z_R0,(int)MsgDigest::_Query);    // query function code
1002   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size
1003   a->z_kimd(Z_R2,Z_R2);                      // Get available KIMD functions (bit pattern in param blk). Must use even regs.
1004   a->z_la(Z_R1,16,Z_R1);                     // next param block addr
1005   a->z_klmd(Z_R2,Z_R4);                      // Get available KLMD functions (bit pattern in param blk). Must use distinct even regs.
1006   a->z_lghi(Z_RET,4);                        // #used words in output buffer
1007   a->z_br(Z_R14);
1008 
1009   // Try KM/KMC query function to get details about crypto instructions.
1010   a->bind(getCIPHERFEATURES_KM);
1011   a->z_lghi(Z_R0,(int)Cipher::_Query);       // query function code
1012   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size (KIMD/KLMD output)
1013   a->z_km(Z_R2,Z_R2);                        // get available KM functions. Must use even regs.
1014   a->z_la(Z_R1,16,Z_R1);                     // next param block addr
1015   a->z_kmc(Z_R2,Z_R2);                       // get available KMC functions
1016   a->z_lghi(Z_RET,4);                        // #used words in output buffer
1017   a->z_br(Z_R14);
1018 
1019   // Try KMA query function to get details about crypto instructions.
1020   a->bind(getCIPHERFEATURES_KMA);
1021   a->z_lghi(Z_R0,(int)Cipher::_Query);       // query function code
1022   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size (KIMD/KLMD output)
1023   a->z_kma(Z_R2,Z_R4,Z_R6);                  // get available KMA functions. Must use distinct even regs.
1024   a->z_lghi(Z_RET,2);                        // #used words in output buffer
1025   a->z_br(Z_R14);
1026 
1027   // Try KMF query function to get details about crypto instructions.
1028   a->bind(getCIPHERFEATURES_KMF);
1029   a->z_lghi(Z_R0,(int)Cipher::_Query);       // query function code
1030   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size (KIMD/KLMD output)
1031   a->z_kmf(Z_R2,Z_R2);                       // get available KMA functions. Must use even regs.
1032   a->z_lghi(Z_RET,2);                        // #used words in output buffer
1033   a->z_br(Z_R14);
1034 
1035   // Try KMCTR query function to get details about crypto instructions.
1036   a->bind(getCIPHERFEATURES_KMCTR);
1037   a->z_lghi(Z_R0,(int)Cipher::_Query);       // query function code
1038   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size (KIMD/KLMD output)
1039   a->z_kmctr(Z_R2,Z_R2,Z_R2);                     // get available KMCTR functions. Must use even regs.
1040   a->z_lghi(Z_RET,2);                        // #used words in output buffer
1041   a->z_br(Z_R14);
1042 
1043   // Try KMO query function to get details about crypto instructions.
1044   a->bind(getCIPHERFEATURES_KMO);
1045   a->z_lghi(Z_R0,(int)Cipher::_Query);       // query function code
1046   a->z_lgr(Z_R1,Z_R2);                       // param block addr, 2*16 bytes min size (KIMD/KLMD output)
1047   a->z_kmo(Z_R2,Z_R2);                       // get available KMO functions. Must use even regs.
1048   a->z_lghi(Z_RET,2);                        // #used words in output buffer
1049   a->z_br(Z_R14);
1050 
1051   // Use EXTRACT CPU ATTRIBUTE instruction to get information about cache layout.
1052   a->bind(getCPUFEATURES);
1053   a->z_xgr(Z_R0,Z_R0);                       // as recommended in instruction documentation
1054   a->z_ecag(Z_RET,Z_R0,0,Z_ARG3);            // Extract information as requested by Z_ARG1 contents.
1055   a->z_br(Z_R14);
1056 
1057   // Use a vector instruction to verify OS support. Will fail with SIGFPE if OS support is missing.
1058   a->bind(getVECTORFEATURES);
1059   a->z_vtm(Z_V0,Z_V0);                       // non-destructive vector instruction. Will cause SIGFPE if not supported.
1060   a->z_br(Z_R14);
1061 
1062   address code_end = a->pc();
1063   a->flush();
1064 
1065   // Print the detection code.
1066   bool printVerbose = Verbose || PrintAssembly || PrintStubCode;
1067   if (printVerbose) {
1068     ttyLocker ttyl;
1069     tty->print_cr("Decoding CPU feature detection stub at " INTPTR_FORMAT " before execution:", p2i(code));
1070     tty->print_cr("Stub length is %ld bytes, codebuffer reserves %d bytes, %ld bytes spare.",
1071                   code_end-code, cbuf_size, cbuf_size-(code_end-code));
1072 
1073     // Use existing decode function. This enables the [Code] format which is needed to DecodeErrorFile.
1074     Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
1075   }
1076 
1077   // prepare work buffer
1078   unsigned long  buffer[buf_len];
1079   clear_buffer(buffer, buf_len);
1080 
1081   // execute code
1082   // Illegal instructions will be replaced by 0 in signal handler.
1083   // In case of problems, call_getFeatures will return a not-positive result.
1084   long used_len = call_getFeatures(buffer, buf_len, 0);
1085 
1086   bool ok;
1087   if ((used_len > 0) && (used_len <= buf_len)) {
1088     ok = true;
1089     if (printVerbose) {
1090       bool compact = Verbose;
1091       tty->print_cr("Note: feature list uses %ld array elements.", used_len);
1092       if (compact) {
1093         tty->print("non-zero feature list elements:");
1094         for (unsigned int k = 0; k < used_len; k++) {
1095           if (buffer[k] != 0) {
1096             tty->print("  [%d]: 0x%16.16lx", k, buffer[k]);
1097           }
1098         }
1099         tty->cr();
1100       } else {
1101         for (unsigned int k = 0; k < used_len; k++) {
1102           tty->print_cr("non-zero feature list[%d]: 0x%16.16lx", k, buffer[k]);
1103         }
1104       }
1105 
1106       if (compact) {
1107         tty->print_cr("Active features (compact view):");
1108         for (unsigned int k = 0; k < used_len; k++) {
1109           tty->print_cr("  buffer[%d]:", k);
1110           for (unsigned int j = k*sizeof(long); j < (k+1)*sizeof(long); j++) {
1111             bool line = false;
1112             for (unsigned int i = j*8; i < (j+1)*8; i++) {
1113               bool bit  = test_feature_bit(buffer, i, used_len*sizeof(long)*8);
1114               if (bit) {
1115                 if (!line) {
1116                   tty->print("    byte[%d]:", j);
1117                   tty->fill_to(13);
1118                   line = true;
1119                 }
1120                 tty->print("  [%3.3d]", i);
1121               }
1122             }
1123             if (line) {
1124               tty->cr();
1125             }
1126           }
1127         }
1128       } else {
1129         tty->print_cr("Active features (full view):");
1130         for (unsigned int k = 0; k < used_len; k++) {
1131           tty->print_cr("  buffer[%d]:", k);
1132           for (unsigned int j = k*sizeof(long); j < (k+1)*sizeof(long); j++) {
1133             tty->print("    byte[%d]:", j);
1134             tty->fill_to(13);
1135             for (unsigned int i = j*8; i < (j+1)*8; i++) {
1136               bool bit  = test_feature_bit(buffer, i, used_len*sizeof(long)*8);
1137               if (bit) {
1138                 tty->print("  [%3.3d]", i);
1139               } else {
1140                 tty->print("       ");
1141               }
1142             }
1143             tty->cr();
1144           }
1145         }
1146       }
1147     }
1148   } else {  // No features retrieved if we reach here. Buffer too short or instr not available.
1149     ok = false;
1150     if (used_len < 0) {
1151       if (printVerbose) {
1152         tty->print_cr("feature list buffer[%d] too short, required: buffer[%ld]", buf_len, -used_len);
1153       }
1154     } else {
1155       if (printVerbose) {
1156         tty->print_cr("feature list could not be retrieved. Bad function code? Running on z900 or z990?");
1157       }
1158     }
1159   }
1160 
1161   if (ok) {
1162     // Copy detected features to features buffer.
1163     copy_buffer(_features, buffer, buf_len);
1164     _nfeatures = used_len;
1165   } else {
1166     // Something went wrong with feature detection. Disable everything.
1167     clear_buffer(_features, buf_len);
1168     _nfeatures = 0;
1169   }
1170 
1171   if (has_VectorFacility()) {
1172     // Verify that feature can actually be used. OS support required.
1173     // We will get a signal if not. Signal handler will disable vector facility
1174     call_getFeatures(buffer, -4, 0);
1175     if (printVerbose) {
1176       ttyLocker ttyl;
1177       if (has_VectorFacility()) {
1178         tty->print_cr("  Vector Facility has been verified to be supported by OS");
1179       } else {
1180         tty->print_cr("  Vector Facility has been disabled - not supported by OS");
1181       }
1182     }
1183   }
1184 
1185   // Clear all Cipher feature buffers and the work buffer.
1186   clear_buffer(_cipher_features_KM, buf_len);
1187   clear_buffer(_cipher_features_KMA, buf_len);
1188   clear_buffer(_cipher_features_KMF, buf_len);
1189   clear_buffer(_cipher_features_KMCTR, buf_len);
1190   clear_buffer(_cipher_features_KMO, buf_len);
1191   clear_buffer(_msgdigest_features, buf_len);
1192   _ncipher_features_KM    = 0;
1193   _ncipher_features_KMA   = 0;
1194   _ncipher_features_KMF   = 0;
1195   _ncipher_features_KMCTR = 0;
1196   _ncipher_features_KMO   = 0;
1197   _nmsgdigest_features    = 0;
1198 
1199   //---------------------------------------
1200   //--  Extract Crypto Facility details  --
1201   //---------------------------------------
1202 
1203   if (has_Crypto()) {
1204     // Get features of KM/KMC cipher instructions
1205     clear_buffer(buffer, buf_len);
1206     used_len = call_getFeatures(buffer, -2, 0);
1207     copy_buffer(_cipher_features_KM, buffer, buf_len);
1208     _ncipher_features_KM = used_len;
1209 
1210     // Get msg digest features.
1211     clear_buffer(buffer, buf_len);
1212     used_len = call_getFeatures(buffer, -3, 0);
1213     copy_buffer(_msgdigest_features, buffer, buf_len);
1214     _nmsgdigest_features = used_len;
1215   }
1216 
1217   if (has_CryptoExt4()) {
1218     // Get features of KMF cipher instruction
1219     clear_buffer(buffer, buf_len);
1220     used_len = call_getFeatures(buffer, -17, 0);
1221     copy_buffer(_cipher_features_KMF, buffer, buf_len);
1222     _ncipher_features_KMF = used_len;
1223 
1224     // Get features of KMCTR cipher instruction
1225     clear_buffer(buffer, buf_len);
1226     used_len = call_getFeatures(buffer, -18, 0);
1227     copy_buffer(_cipher_features_KMCTR, buffer, buf_len);
1228     _ncipher_features_KMCTR = used_len;
1229 
1230     // Get features of KMO cipher instruction
1231     clear_buffer(buffer, buf_len);
1232     used_len = call_getFeatures(buffer, -19, 0);
1233     copy_buffer(_cipher_features_KMO, buffer, buf_len);
1234     _ncipher_features_KMO = used_len;
1235   }
1236 
1237   if (has_CryptoExt8()) {
1238     // Get features of KMA cipher instruction
1239     clear_buffer(buffer, buf_len);
1240     used_len = call_getFeatures(buffer, -20, 0);
1241     copy_buffer(_cipher_features_KMA, buffer, buf_len);
1242     _ncipher_features_KMA = used_len;
1243   }
1244   if (printVerbose) {
1245     tty->print_cr("  Crypto capabilities retrieved.");
1246   }
1247 
1248   static int   levelProperties[_max_cache_levels];     // All property indications per level.
1249   static int   levelScope[_max_cache_levels];          // private/shared
1250   static const char* levelScopeText[4] = {"No cache   ",
1251                                           "CPU private",
1252                                           "shared     ",
1253                                           "reserved   "};
1254 
1255   static int   levelType[_max_cache_levels];           // D/I/mixed
1256   static const char* levelTypeText[4]  = {"separate D and I caches",
1257                                           "I cache only           ",
1258                                           "D-cache only           ",
1259                                           "combined D/I cache     "};
1260 
1261   static unsigned int levelReserved[_max_cache_levels];    // reserved property bits
1262   static unsigned int levelLineSize[_max_cache_levels];
1263   static unsigned int levelTotalSize[_max_cache_levels];
1264   static unsigned int levelAssociativity[_max_cache_levels];
1265 
1266 
1267   // Extract Cache Layout details.
1268   if (has_ExtractCPUAttributes() && printVerbose) { // For information only, as of now.
1269     bool         lineSize_mismatch;
1270     bool         print_something;
1271     long         functionResult;
1272     unsigned int attributeIndication = 0; // 0..15
1273     unsigned int levelIndication     = 0; // 0..8
1274     unsigned int typeIndication      = 0; // 0..1 (D-Cache, I-Cache)
1275     int          functionCode        = calculate_ECAG_functionCode(attributeIndication, levelIndication, typeIndication);
1276 
1277     // Get cache topology.
1278     functionResult = call_getFeatures(buffer, -1, functionCode);
1279 
1280     for (unsigned int i = 0; i < _max_cache_levels; i++) {
1281       if (functionResult > 0) {
1282         int shiftVal          = 8*(_max_cache_levels-(i+1));
1283         levelProperties[i]    = (functionResult & (0xffUL<<shiftVal)) >> shiftVal;
1284         levelReserved[i]      = (levelProperties[i] & 0xf0) >> 4;
1285         levelScope[i]         = (levelProperties[i] & 0x0c) >> 2;
1286         levelType[i]          = (levelProperties[i] & 0x03);
1287       } else {
1288         levelProperties[i]    = 0;
1289         levelReserved[i]      = 0;
1290         levelScope[i]         = 0;
1291         levelType[i]          = 0;
1292       }
1293       levelLineSize[i]      = 0;
1294       levelTotalSize[i]     = 0;
1295       levelAssociativity[i] = 0;
1296     }
1297 
1298     tty->cr();
1299     tty->print_cr("------------------------------------");
1300     tty->print_cr("---  Cache Topology Information  ---");
1301     tty->print_cr("------------------------------------");
1302     for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1303       tty->print_cr("  Cache Level %d: <scope>  %s | <type>  %s",
1304                     i+1, levelScopeText[levelScope[i]], levelTypeText[levelType[i]]);
1305     }
1306 
1307     // Get D-cache details per level.
1308     _Dcache_lineSize   = 0;
1309     lineSize_mismatch  = false;
1310     print_something    = false;
1311     typeIndication     = 0; // 0..1 (D-Cache, I-Cache)
1312     for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1313       if ((levelType[i] == 0) || (levelType[i] == 2)) {
1314         print_something     = true;
1315 
1316         // Get cache line size of level i.
1317         attributeIndication   = 1;
1318         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1319         levelLineSize[i]      = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1320 
1321         // Get cache total size of level i.
1322         attributeIndication   = 2;
1323         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1324         levelTotalSize[i]     = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1325 
1326         // Get cache associativity of level i.
1327         attributeIndication   = 3;
1328         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1329         levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1330 
1331         _Dcache_lineSize      = _Dcache_lineSize == 0 ? levelLineSize[i] : _Dcache_lineSize;
1332         lineSize_mismatch     = lineSize_mismatch || (_Dcache_lineSize != levelLineSize[i]);
1333       } else {
1334         levelLineSize[i]      = 0;
1335       }
1336     }
1337 
1338     if (print_something) {
1339       tty->cr();
1340       tty->print_cr("------------------------------------");
1341       tty->print_cr("---  D-Cache Detail Information  ---");
1342       tty->print_cr("------------------------------------");
1343       if (lineSize_mismatch) {
1344         tty->print_cr("WARNING: D-Cache line size mismatch!");
1345       }
1346       for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1347         if (levelLineSize[i] > 0) {
1348           tty->print_cr("  D-Cache Level %d: line size = %4d,  total size = %6dKB,  associativity = %2d",
1349                         i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]);
1350         }
1351       }
1352     }
1353 
1354     // Get I-cache details per level.
1355     _Icache_lineSize   = 0;
1356     lineSize_mismatch  = false;
1357     print_something    = false;
1358     typeIndication     = 1; // 0..1 (D-Cache, I-Cache)
1359     for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1360       if ((levelType[i] == 0) || (levelType[i] == 1)) {
1361         print_something     = true;
1362 
1363         // Get cache line size of level i.
1364         attributeIndication   = 1;
1365         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1366         levelLineSize[i]      = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1367 
1368         // Get cache total size of level i.
1369         attributeIndication   = 2;
1370         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1371         levelTotalSize[i]     = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1372 
1373         // Get cache associativity of level i.
1374         attributeIndication   = 3;
1375         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1376         levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1377 
1378         _Icache_lineSize      = _Icache_lineSize == 0 ? levelLineSize[i] : _Icache_lineSize;
1379         lineSize_mismatch     = lineSize_mismatch || (_Icache_lineSize != levelLineSize[i]);
1380       } else {
1381         levelLineSize[i]      = 0;
1382       }
1383     }
1384 
1385     if (print_something) {
1386       tty->cr();
1387       tty->print_cr("------------------------------------");
1388       tty->print_cr("---  I-Cache Detail Information  ---");
1389       tty->print_cr("------------------------------------");
1390       if (lineSize_mismatch) {
1391         tty->print_cr("WARNING: I-Cache line size mismatch!");
1392       }
1393       for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1394         if (levelLineSize[i] > 0) {
1395           tty->print_cr("  I-Cache Level %d: line size = %4d,  total size = %6dKB,  associativity = %2d",
1396                         i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]);
1397         }
1398       }
1399     }
1400 
1401     // Get D/I-cache details per level.
1402     lineSize_mismatch  = false;
1403     print_something    = false;
1404     typeIndication     = 0; // 0..1 (D-Cache, I-Cache)
1405     for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1406       if (levelType[i] == 3) {
1407         print_something     = true;
1408 
1409         // Get cache line size of level i.
1410         attributeIndication   = 1;
1411         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1412         levelLineSize[i]      = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1413 
1414         // Get cache total size of level i.
1415         attributeIndication   = 2;
1416         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1417         levelTotalSize[i]     = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1418 
1419         // Get cache associativity of level i.
1420         attributeIndication   = 3;
1421         functionCode          = calculate_ECAG_functionCode(attributeIndication, i, typeIndication);
1422         levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode);
1423 
1424         _Dcache_lineSize      = _Dcache_lineSize == 0 ? levelLineSize[i] : _Dcache_lineSize;
1425         _Icache_lineSize      = _Icache_lineSize == 0 ? levelLineSize[i] : _Icache_lineSize;
1426         lineSize_mismatch     = lineSize_mismatch || (_Dcache_lineSize != levelLineSize[i])
1427                                                   || (_Icache_lineSize != levelLineSize[i]);
1428       } else {
1429         levelLineSize[i]      = 0;
1430       }
1431     }
1432 
1433     if (print_something) {
1434       tty->cr();
1435       tty->print_cr("--------------------------------------");
1436       tty->print_cr("---  D/I-Cache Detail Information  ---");
1437       tty->print_cr("--------------------------------------");
1438       if (lineSize_mismatch) {
1439         tty->print_cr("WARNING: D/I-Cache line size mismatch!");
1440       }
1441       for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) {
1442         if (levelLineSize[i] > 0) {
1443           tty->print_cr("  D/I-Cache Level %d: line size = %4d,  total size = %6dKB,  associativity = %2d",
1444                         i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]);
1445         }
1446       }
1447     }
1448     tty->cr();
1449   }
1450   return;
1451 }
1452 
1453 unsigned long VM_Version::z_SIGILL() {
1454   unsigned long   ZeroBuffer = 0;
1455   unsigned long   work;
1456   asm(
1457     "     LA      %[work],%[buffer]  \n\t"   // Load address of buffer.
1458     "     LARL    14,+6              \n\t"   // Load address of faulting instruction.
1459     "     BCR     15,%[work]         \n\t"   // Branch into buffer, execute whatever is in there.
1460     : [buffer]  "+Q"  (ZeroBuffer)   /* outputs   */
1461     , [work]   "=&a"  (work)         /* outputs   */
1462     :                                /* inputs    */
1463     : "cc"                           /* clobbered */
1464  );
1465   return ZeroBuffer;
1466 }
1467 
1468 unsigned long VM_Version::z_SIGSEGV() {
1469   unsigned long   ZeroBuffer = 0;
1470   unsigned long   work;
1471   asm(
1472     "     LG      %[work],%[buffer]  \n\t"   // Load zero address.
1473     "     STG     %[work],0(,%[work])\n\t"   // Store to address zero.
1474     : [buffer]  "+Q"  (ZeroBuffer)   /* outputs   */
1475     , [work]   "=&a"  (work)         /* outputs   */
1476     :                                /* inputs    */
1477     : "cc"                           /* clobbered */
1478  );
1479   return ZeroBuffer;
1480 }