question about JDK-8172231: SPARC CPU features detection

David Buck david.buck at oracle.com
Wed Apr 28 05:07:09 UTC 2021


Hi Goetz!

Our fix looked something like below. Note the following diff also includes JDK-8263407 [1].

===
diff --git a/src/hotspot/cpu/sparc/vm_version_sparc.cpp b/src/hotspot/cpu/sparc/vm_version_sparc.cpp
--- a/src/hotspot/cpu/sparc/vm_version_sparc.cpp
+++ b/src/hotspot/cpu/sparc/vm_version_sparc.cpp
@@ -160,7 +160,8 @@ void VM_Version::initialize() {
 
   // Use compare and branch instructions if available.
   if (has_cbcond()) {
-    if (FLAG_IS_DEFAULT(UseCBCond)) {
+    // cbcond suspected to cause issues on Athena CPUs
+    if (FLAG_IS_DEFAULT(UseCBCond) && !is_athena()) {
       FLAG_SET_DEFAULT(UseCBCond, true);
     }
   } else if (UseCBCond) {
@@ -218,7 +219,7 @@ void VM_Version::initialize() {
 
   char buf[512];
   jio_snprintf(buf, sizeof(buf),
-               "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
+               "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
                "%s%s%s%s%s%s%s%s%s" "%s%s%s%s%s%s%s%s%s"
                "%s%s%s%s%s%s%s",
                (has_v9()          ? "v9" : ""),
@@ -228,6 +229,7 @@ void VM_Version::initialize() {
                (has_blk_init()    ? ", blk_init" : ""),
                (has_fmaf()        ? ", fmaf" : ""),
                (has_hpc()         ? ", hpc" : ""),
+               (has_athena()      ? ", athena" : ""),
                (has_ima()         ? ", ima" : ""),
                (has_aes()         ? ", aes" : ""),
                (has_des()         ? ", des" : ""),
diff --git a/src/hotspot/cpu/sparc/vm_version_sparc.hpp b/src/hotspot/cpu/sparc/vm_version_sparc.hpp
--- a/src/hotspot/cpu/sparc/vm_version_sparc.hpp
+++ b/src/hotspot/cpu/sparc/vm_version_sparc.hpp
@@ -42,6 +42,7 @@ protected:
     ISA_FMAF,
     ISA_VIS3,
     ISA_HPC,
+    ISA_FJATHHPC,
     ISA_IMA,
     ISA_AES,
     ISA_DES,
@@ -104,6 +105,7 @@ private:
     ISA_fmaf_msk        = UINT64_C(1) << ISA_FMAF,
     ISA_vis3_msk        = UINT64_C(1) << ISA_VIS3,
     ISA_hpc_msk         = UINT64_C(1) << ISA_HPC,
+    ISA_fjathhpc_msk    = UINT64_C(1) << ISA_FJATHHPC,
     ISA_ima_msk         = UINT64_C(1) << ISA_IMA,
     ISA_aes_msk         = UINT64_C(1) << ISA_AES,
     ISA_des_msk         = UINT64_C(1) << ISA_DES,
@@ -253,6 +255,7 @@ public:
   static bool has_fmaf()         { return (_features & ISA_fmaf_msk) != 0; }
   static bool has_vis3()         { return (_features & ISA_vis3_msk) != 0; }
   static bool has_hpc()          { return (_features & ISA_hpc_msk) != 0; }
+  static bool has_athena()       { return (_features & ISA_fjathhpc_msk) != 0; }
   static bool has_ima()          { return (_features & ISA_ima_msk) != 0; }
   static bool has_aes()          { return (_features & ISA_aes_msk) != 0; }
   static bool has_des()          { return (_features & ISA_des_msk) != 0; }
@@ -306,6 +309,10 @@ public:
     return (_features & niagara2_msk) == niagara2_msk;
   }
 
+  static bool is_athena() {
+    return has_athena() || has_athena_plus() || has_athena_plus2();
+  }
+
   // Default prefetch block size on SPARC.
   static uint prefetch_data_size() { return L2_data_cache_line_size(); }
 
diff --git a/src/hotspot/os_cpu/solaris_sparc/vm_version_solaris_sparc.cpp b/src/hotspot/os_cpu/solaris_sparc/vm_version_solaris_sparc.cpp
--- a/src/hotspot/os_cpu/solaris_sparc/vm_version_solaris_sparc.cpp
+++ b/src/hotspot/os_cpu/solaris_sparc/vm_version_solaris_sparc.cpp
@@ -355,12 +355,17 @@ void VM_Version::platform_features() {
 
 #ifndef AV_SPARC_FMAF
 #define AV_SPARC_FMAF         0x00000100 // Fused Multiply-Add
+#endif
+
+#ifndef AV_SPARC_FJATHHPC
+#define AV_SPARC_FJATHHPC     0x00001000 // Fujitsu HPC (Athena) instrs
 #endif
 
   if (av & AV_SPARC_ASI_BLK_INIT) features |= ISA_blk_init_msk;
   if (av & AV_SPARC_FMAF)         features |= ISA_fmaf_msk;
   if (av & AV_SPARC_VIS3)         features |= ISA_vis3_msk;
   if (av & AV_SPARC_HPC)          features |= ISA_hpc_msk;
+  if (av & AV_SPARC_FJATHHPC)     features |= ISA_fjathhpc_msk;
   if (av & AV_SPARC_IMA)          features |= ISA_ima_msk;
   if (av & AV_SPARC_AES)          features |= ISA_aes_msk;
   if (av & AV_SPARC_DES)          features |= ISA_des_msk;
@@ -460,14 +465,13 @@ void VM_Version::platform_features() {
 
   Sysinfo machine(SI_MACHINE);
 
-  bool is_sun4v = machine.match("sun4v");   // All Oracle SPARC + Fujitsu Athena+/++
+  bool is_sun4v = machine.match("sun4v");   // All Oracle SPARC + Fujitsu Athena(+/++)
   bool is_sun4u = machine.match("sun4u");   // All other Fujitsu
 
-  // Handle Athena+/++ conservatively (simply because we are lacking info.).
+  // Handle Athena(+/++) conservatively (simply because we are lacking info.).
 
-  bool an_athena = has_athena_plus() || has_athena_plus2();
-  bool do_sun4v  = is_sun4v && !an_athena;
-  bool do_sun4u  = is_sun4u ||  an_athena;
+  bool do_sun4v  = is_sun4v && !is_athena();
+  bool do_sun4u  = is_sun4u ||  is_athena();
 
   uint64_t synthetic = 0;
===

Cheers,
-Buck

[1] https://bugs.openjdk.java.net/browse/JDK-8263407

-----Original Message-----
From: Lindenmaier, Goetz <goetz.lindenmaier at sap.com> 
Sent: Tuesday, April 20, 2021 3:43 PM
To: David Buck <david.buck at oracle.com>; Ilarion Nakonechnyy <ilarion at azul.com>; jdk-updates-dev at openjdk.java.net
Subject: [External] : RE: question about JDK-8172231: SPARC CPU features detection

Hi David, 

do you mind sharing the patch?
As the change was made in OracleJDK, we can not reach the changeset from JBS.

Thanks!
  Goetz

> -----Original Message-----
> From: jdk-updates-dev <jdk-updates-dev-retn at openjdk.java.net> On 
> Behalf Of David Buck
> Sent: Tuesday, April 20, 2021 4:26 AM
> To: Ilarion Nakonechnyy <ilarion at azul.com>; jdk-updates- 
> dev at openjdk.java.net
> Subject: RE: question about JDK-8172231: SPARC CPU features detection
> 
> Hi Ilarion!
> 
> The OpenJDK community may want to consider a fix similar to what we 
> did in Oracle JDK 11 [0].
> 
> Cheers,
> -Buck
> 
> [0] https://bugs.openjdk.java.net/browse/JDK-8263407
> 
> -----Original Message-----
> From: jdk-updates-dev <jdk-updates-dev-retn at openjdk.java.net> On 
> Behalf Of Ilarion Nakonechnyy
> Sent: Tuesday, April 20, 2021 4:21 AM
> To: jdk-updates-dev at openjdk.java.net
> Subject: FW: question about JDK-8172231: SPARC CPU features detection
> 
> Dear sirs, good day.
> My name is Ilarion, I’m new contributor for OpenJDK project.
> 
> I have some questions about implementation of fix for bug JDK-8172231:
> SPARC CPU features detection, probably somebody may shed some lights 
> on it.
> 
> I’m doing my exercises on JDK 11 and noticed that on exact SPARC CPU 
> block zeroing detection feature determines wrong.
> Having system with SPARC64-X CPU, java fails with segmentation 
> violation error, on the very beginning of the java run.
> My investigations lead me to MacroAssembler::bis_zeroing() routine.  
> Where begin and end of memory area is cleared by stx instruction, and 
> the rest – via stxa(G0, to, G0, Assembler::ASI_ST_BLKINIT_PRIMARY), 
> that supposed to zeroing memory, but it doesn’t.
> Turning off block zeroing feature via flag -XX:-UseBlockZeroing helps 
> to avoid the crash.
> 
> 
> 
> 
> Decision if CPU has the CPU_blk_zeroing_msk feature based on 
> determining another cpu flag,  ISA_ima_msk
> 
> +    // Niagara Core S3 supports fast RDPC and block zeroing.
> 
> +    if (has_ima()) {
> 
> +      synthetic |= (CPU_fast_rdpc_msk | CPU_blk_zeroing_msk);
> 
> +    }
> 
> But there is also mentioned special flag, that corresponds to Block 
> initialization feature: ISA_blk_init_msk. That actually isn’t checked at all.
> ( Other than in reporting ) I looked in JDK 8, and  figured out, that 
> block zeroing capacity there was decided not  only by ISA flags, but 
> with referring on CPU model also:
> 
> -  // On T4 and newer Sparc BIS to the beginning of cache line always zeros it.
> 
> -  static bool has_block_zeroing()       { return has_blk_init() && is_T4(); }
> 
> 
> JDK 8 works well for my case, because BIS instruction isn’t used 
> Despite ISA flags that is returned by getisax reports that block 
> initialization is supported ( AV_SPARC_ASI_BLK_INIT 0x0080 )
> 
> [0.172s][info][os,cpu  ] getisax(2) returned 1 words:
> 
> [0.172s][info][os,cpu  ]     word 0: 0xc001b1f0
> 
> So, as I can see, the CPU version ( “cpu brand”  in jdk 8 ) has main 
> role in detecting CPU block zeroing feature.
> Do you have some more information, probably any doc, where noted why 
> CPU version plays such a role in feature detecting for JVM? In CPU 
> specifications I didn’t found any clues about this.
> Thank you in advance.


More information about the jdk-updates-dev mailing list