Skip to content

Instantly share code, notes, and snippets.

@luhenry
Created September 8, 2020 18:50
Show Gist options
  • Save luhenry/d981f5fe7e9f1a1ad8cd3292b5e75cc4 to your computer and use it in GitHub Desktop.
Save luhenry/d981f5fe7e9f1a1ad8cd3292b5e75cc4 to your computer and use it in GitHub Desktop.
diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp
index a2f5b4b6f53..1f175f2098d 100644
--- a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp
@@ -26,41 +26,20 @@
#include "precompiled.hpp"
#include "asm/macroAssembler.hpp"
#include "asm/macroAssembler.inline.hpp"
+#include "logging/log.hpp"
#include "memory/resourceArea.hpp"
-#include "runtime/arguments.hpp"
#include "runtime/java.hpp"
#include "runtime/os.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "runtime/vm_version.hpp"
#include "utilities/macros.hpp"
+#include "vm_version_aarch64.hpp"
#include OS_HEADER_INLINE(os)
+#ifndef _WIN64
#include <sys/auxv.h>
#include <asm/hwcap.h>
-
-#ifndef HWCAP_AES
-#define HWCAP_AES (1<<3)
-#endif
-
-#ifndef HWCAP_PMULL
-#define HWCAP_PMULL (1<<4)
-#endif
-
-#ifndef HWCAP_SHA1
-#define HWCAP_SHA1 (1<<5)
-#endif
-
-#ifndef HWCAP_SHA2
-#define HWCAP_SHA2 (1<<6)
-#endif
-
-#ifndef HWCAP_CRC32
-#define HWCAP_CRC32 (1<<7)
-#endif
-
-#ifndef HWCAP_ATOMICS
-#define HWCAP_ATOMICS (1<<8)
#endif
#ifndef HWCAP_SHA512
@@ -104,8 +83,10 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
__ get_dczid_el0(rscratch1);
__ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::dczid_el0_offset())));
+#ifndef _WIN64
__ get_ctr_el0(rscratch1);
__ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::ctr_el0_offset())));
+#endif
__ leave();
__ ret(lr);
@@ -166,13 +147,19 @@ void VM_Version::get_processor_features() {
SoftwarePrefetchHintDistance &= ~7;
}
- uint64_t auxv = getauxval(AT_HWCAP);
+#ifndef _WIN64
+ _features = getauxval(AT_HWCAP);
+#else
+ if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) _features |= CPU_CRC32;
+ if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) _features |= CPU_AES | CPU_SHA1 | CPU_SHA2;
+ if (IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE)) _features |= CPU_ASIMD;
+ // No check for CPU_PMULL
+#endif // _WIN64
char buf[512];
- _features = auxv;
-
int cpu_lines = 0;
+#ifndef _WIN64
if (FILE *f = fopen("/proc/cpuinfo", "r")) {
// need a large buffer as the flags line may include lots of text
char buf[1024], *p;
@@ -198,6 +185,28 @@ void VM_Version::get_processor_features() {
}
fclose(f);
}
+#else
+ {
+ char* buf = ::getenv("PROCESSOR_IDENTIFIER");
+ if (buf && strstr(buf, "Ampere(TM)") != NULL) {
+ _cpu = CPU_AMCC;
+ cpu_lines++;
+ } else if (buf && strstr(buf, "Cavium Inc.") != NULL) {
+ _cpu = CPU_CAVIUM;
+ cpu_lines++;
+ } else {
+ log_info(os)("VM_Version: unknown CPU model");
+ }
+
+ if (_cpu) {
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ _model = si.wProcessorLevel;
+ _variant = si.wProcessorRevision / 0xFF;
+ _revision = si.wProcessorRevision & 0xFF;
+ }
+ }
+#endif // _WIN64
if (os::supports_map_sync()) {
// if dcpop is available publish data cache line flush size via
@@ -285,21 +294,21 @@ void VM_Version::get_processor_features() {
sprintf(buf, "0x%02x:0x%x:0x%03x:%d", _cpu, _variant, _model, _revision);
if (_model2) sprintf(buf+strlen(buf), "(0x%03x)", _model2);
- if (auxv & HWCAP_ASIMD) strcat(buf, ", simd");
- if (auxv & HWCAP_CRC32) strcat(buf, ", crc");
- if (auxv & HWCAP_AES) strcat(buf, ", aes");
- if (auxv & HWCAP_SHA1) strcat(buf, ", sha1");
- if (auxv & HWCAP_SHA2) strcat(buf, ", sha256");
- if (auxv & HWCAP_SHA512) strcat(buf, ", sha512");
- if (auxv & HWCAP_ATOMICS) strcat(buf, ", lse");
+ if (_features & CPU_ASIMD) strcat(buf, ", simd");
+ if (_features & CPU_CRC32) strcat(buf, ", crc");
+ if (_features & CPU_AES) strcat(buf, ", aes");
+ if (_features & CPU_SHA1) strcat(buf, ", sha1");
+ if (_features & CPU_SHA2) strcat(buf, ", sha256");
+ if (_features & CPU_SHA512) strcat(buf, ", sha512");
+ if (_features & CPU_LSE) strcat(buf, ", lse");
_features_string = os::strdup(buf);
if (FLAG_IS_DEFAULT(UseCRC32)) {
- UseCRC32 = (auxv & HWCAP_CRC32) != 0;
+ UseCRC32 = (_features & CPU_CRC32) != 0;
}
- if (UseCRC32 && (auxv & HWCAP_CRC32) == 0) {
+ if (UseCRC32 && (_features & CPU_CRC32) == 0) {
warning("UseCRC32 specified, but not supported on this CPU");
FLAG_SET_DEFAULT(UseCRC32, false);
}
@@ -313,7 +322,7 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false);
}
- if (auxv & HWCAP_ATOMICS) {
+ if (_features & CPU_LSE) {
if (FLAG_IS_DEFAULT(UseLSE))
FLAG_SET_DEFAULT(UseLSE, true);
} else {
@@ -323,7 +332,7 @@ void VM_Version::get_processor_features() {
}
}
- if (auxv & HWCAP_AES) {
+ if (_features & CPU_AES) {
UseAES = UseAES || FLAG_IS_DEFAULT(UseAES);
UseAESIntrinsics =
UseAESIntrinsics || (UseAES && FLAG_IS_DEFAULT(UseAESIntrinsics));
@@ -351,7 +360,7 @@ void VM_Version::get_processor_features() {
UseCRC32Intrinsics = true;
}
- if (auxv & HWCAP_CRC32) {
+ if (_features & CPU_CRC32) {
if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) {
FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true);
}
@@ -369,7 +378,7 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseMD5Intrinsics, false);
}
- if (auxv & (HWCAP_SHA1 | HWCAP_SHA2)) {
+ if (_features & (CPU_SHA1 | CPU_SHA2)) {
if (FLAG_IS_DEFAULT(UseSHA)) {
FLAG_SET_DEFAULT(UseSHA, true);
}
@@ -378,7 +387,7 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseSHA, false);
}
- if (UseSHA && (auxv & HWCAP_SHA1)) {
+ if (UseSHA && (_features & CPU_SHA1)) {
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
}
@@ -387,7 +396,7 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
}
- if (UseSHA && (auxv & HWCAP_SHA2)) {
+ if (UseSHA && (_features & CPU_SHA2)) {
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
}
@@ -410,7 +419,7 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseSHA, false);
}
- if (auxv & HWCAP_PMULL) {
+ if (_features & CPU_PMULL) {
if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) {
FLAG_SET_DEFAULT(UseGHASHIntrinsics, true);
}
diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp
index 91bba66fa34..78ba27479a3 100644
--- a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp
+++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp
@@ -29,6 +29,7 @@
#include "runtime/abstract_vm_version.hpp"
#include "runtime/globals_extension.hpp"
#include "utilities/sizes.hpp"
+#include "runtime/java.hpp"
class VM_Version : public Abstract_VM_Version {
friend class JVMCIVMStructs;
@@ -43,7 +44,12 @@ protected:
static bool _dcpop;
struct PsrInfo {
uint32_t dczid_el0;
+#ifndef _WIN64
+ // On Windows-aarch64, this register is not accessible. We then need to
+ // access the cache line size in a different way. Instead, we get the cache
+ // line size in os::win32::get_cacheline_size.
uint32_t ctr_el0;
+#endif
};
static PsrInfo _psr_info;
static void get_processor_features();
@@ -96,6 +102,7 @@ public:
CPU_SHA2 = (1<<6),
CPU_CRC32 = (1<<7),
CPU_LSE = (1<<8),
+ CPU_SHA512 = (1<<21),
CPU_STXR_PREFETCH= (1 << 29),
CPU_A53MAC = (1 << 30),
};
@@ -106,8 +113,11 @@ public:
static int cpu_variant() { return _variant; }
static int cpu_revision() { return _revision; }
static bool supports_dcpop() { return _dcpop; }
+
static ByteSize dczid_el0_offset() { return byte_offset_of(PsrInfo, dczid_el0); }
+#ifndef _WIN64
static ByteSize ctr_el0_offset() { return byte_offset_of(PsrInfo, ctr_el0); }
+#endif
static bool is_zva_enabled() {
// Check the DZP bit (bit 4) of dczid_el0 is zero
// and block size (bit 0~3) is not zero.
@@ -119,10 +129,18 @@ public:
return 4 << (_psr_info.dczid_el0 & 0xf);
}
static int icache_line_size() {
+#ifndef _WIN64
return (1 << (_psr_info.ctr_el0 & 0x0f)) * 4;
+#else
+ return os::win32::get_cacheline_size();
+#endif
}
static int dcache_line_size() {
+#ifndef _WIN64
return (1 << ((_psr_info.ctr_el0 >> 16) & 0x0f)) * 4;
+#else
+ return os::win32::get_cacheline_size();
+#endif
}
static bool supports_fast_class_init_checks() { return true; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment