Skip to content
Closed
36 changes: 17 additions & 19 deletions src/hotspot/cpu/x86/vm_version_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ address VM_Version::_cpuinfo_cont_addr = 0;
address VM_Version::_cpuinfo_segv_addr_apx = 0;
// Address of instruction after the one which causes APX specific SEGV
address VM_Version::_cpuinfo_cont_addr_apx = 0;
// Address of apx state restore error handler.
address VM_Version::_apx_state_restore_warning_handler = (address)VM_Version::report_apx_state_restore_warning;

static BufferBlob* stub_blob;
static const int stub_size = 2000;
Expand Down Expand Up @@ -452,19 +450,12 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
__ movl(rax, Address(rsi, 0));

VM_Version::set_cpuinfo_cont_addr_apx(__ pc());
// Validate the contents of r16 and r31
/* FIXME: Uncomment after integration of JDK-8329032
__ mov64(rax, VM_Version::egpr_test_value());
__ cmpq(rax, r16);
__ jccb(Assembler::notEqual, apx_save_restore_warning);
__ cmpq(rax, r31);
__ jccb(Assembler::equal, vector_save_restore);
__ lea(rsi, Address(rbp, in_bytes(VM_Version::apx_save_offset())));
__ movq(Address(rsi, 0), r16);
__ movq(Address(rsi, 8), r31);

UseAPX = save_apx;

__ bind(apx_save_restore_warning);
__ lea(rax, ExternalAddress(VM_Version::_apx_state_restore_warning_handler));
__ call(rax);
*/
#endif
__ bind(vector_save_restore);
Expand Down Expand Up @@ -878,11 +869,6 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
};
};

void VM_Version::report_apx_state_restore_warning() {
tty->print("warning: Unsuccessful EGPRs state restoration across signal handling, setting UseAPX to false.\n");
_cpuid_info.sefsl1_cpuid7_edx.bits.apx_f = 0;
}

void VM_Version::get_processor_features() {

_cpu = 4; // 486 by default
Expand Down Expand Up @@ -1055,11 +1041,12 @@ void VM_Version::get_processor_features() {
}

// Currently APX support is only enabled for targets supporting AVX512VL feature.
if (UseAPX && (!supports_apx_f() || !supports_avx512vl())) {
bool apx_supported = os_supports_apx_egprs() && supports_apx_f() && supports_avx512vl();
if (UseAPX && !apx_supported) {
warning("UseAPX is not supported on this CPU, setting it to false");
FLAG_SET_DEFAULT(UseAPX, false);
} else if (FLAG_IS_DEFAULT(UseAPX)) {
FLAG_SET_DEFAULT(UseAPX, (supports_apx_f() && supports_avx512vl()) ? true : false);
FLAG_SET_DEFAULT(UseAPX, apx_supported ? true : false);
}

if (UseAVX < 2) {
Expand Down Expand Up @@ -3241,6 +3228,17 @@ bool VM_Version::os_supports_avx_vectors() {
return retVal;
}

bool VM_Version::os_supports_apx_egprs() {
if (!supports_apx_f()) {
return false;
}
if (_cpuid_info.apx_save[0] != egpr_test_value() ||
_cpuid_info.apx_save[1] != egpr_test_value()) {
return false;
}
return true;
}

uint VM_Version::cores_per_cpu() {
uint result = 1;
if (is_intel()) {
Expand Down
11 changes: 7 additions & 4 deletions src/hotspot/cpu/x86/vm_version_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ class VM_Version : public Abstract_VM_Version {
// Space to save zmm registers after signal handle
int zmm_save[16*4]; // Save zmm0, zmm7, zmm8, zmm31

// Space to save apx registers after signal handle
jlong apx_save[2]; // Save r16 and r31

uint64_t feature_flags() const;

// Asserts
Expand Down Expand Up @@ -594,6 +597,7 @@ class VM_Version : public Abstract_VM_Version {
static bool compute_has_intel_jcc_erratum();

static bool os_supports_avx_vectors();
static bool os_supports_apx_egprs();
static void get_processor_features();

public:
Expand All @@ -614,11 +618,12 @@ class VM_Version : public Abstract_VM_Version {
static ByteSize xem_xcr0_offset() { return byte_offset_of(CpuidInfo, xem_xcr0_eax); }
static ByteSize ymm_save_offset() { return byte_offset_of(CpuidInfo, ymm_save); }
static ByteSize zmm_save_offset() { return byte_offset_of(CpuidInfo, zmm_save); }
static ByteSize apx_save_offset() { return byte_offset_of(CpuidInfo, apx_save); }

// The value used to check ymm register after signal handle
static int ymm_test_value() { return 0xCAFEBABE; }
static long long egpr_test_value() { return 0xCAFEBABECAFEBABEULL; }
static void report_apx_state_restore_warning();
static jlong egpr_test_value() { return 0xCAFEBABECAFEBABELL; }

static void get_cpu_info_wrapper();
static void set_cpuinfo_segv_addr(address pc) { _cpuinfo_segv_addr = pc; }
static bool is_cpuinfo_segv_addr(address pc) { return _cpuinfo_segv_addr == pc; }
Expand All @@ -629,8 +634,6 @@ class VM_Version : public Abstract_VM_Version {
static bool is_cpuinfo_segv_addr_apx(address pc) { return _cpuinfo_segv_addr_apx == pc; }
static void set_cpuinfo_cont_addr_apx(address pc) { _cpuinfo_cont_addr_apx = pc; }
static address cpuinfo_cont_addr_apx() { return _cpuinfo_cont_addr_apx; }
// address of apx state restore error handler.
static address _apx_state_restore_warning_handler;

static void clear_apx_test_state();

Expand Down