Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/hotspot/cpu/aarch64/vm_version_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ void VM_Version::initialize() {
_features &= ~CPU_SVE;
}

check_cpufeatures_vmoptions();

// Construct the "features" string
char buf[512];
int buf_used_len = os::snprintf_checked(buf, sizeof(buf), "0x%02x:0x%x:0x%03x:%d", _cpu, _variant, _model, _revision);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/vm_version_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class VM_Version : public Abstract_VM_Version {
static void initialize();
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }
static void check_virtualizations();

static void print_platform_virtualization_info(outputStream*);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/arm/vm_version_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class VM_Version: public Abstract_VM_Version {
static bool is_initialized() { return _is_initialized; }
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }


protected:
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/arm/vm_version_arm_32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ void VM_Version::initialize() {
FLAG_SET_DEFAULT(UseUnalignedAccesses, false);
}

check_cpufeatures_vmoptions();

_is_initialized = true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/ppc/vm_version_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ void VM_Version::initialize() {
}

check_virtualizations();

check_cpufeatures_vmoptions();
}

void VM_Version::check_virtualizations() {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/vm_version_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class VM_Version: public Abstract_VM_Version {
static void check_virtualizations();
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }

// Override Abstract_VM_Version implementation
static void print_platform_virtualization_info(outputStream*);
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/riscv/vm_version_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void VM_Version::initialize() {
#ifdef COMPILER2
c2_initialize();
#endif // COMPILER2

check_cpufeatures_vmoptions();
}

void VM_Version::common_initialize() {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/vm_version_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class VM_Version : public Abstract_VM_Version {
static void initialize_cpu_information();
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }

constexpr static bool supports_stack_watermark_barrier() { return true; }

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/s390/vm_version_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ void VM_Version::initialize() {
if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) {
FLAG_SET_DEFAULT(UseUnalignedAccesses, true);
}

check_cpufeatures_vmoptions();
}


Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/vm_version_s390.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class VM_Version: public Abstract_VM_Version {
static bool is_determine_features_test_running() { return _is_determine_features_test_running; }
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }

// Override Abstract_VM_Version implementation
static void print_platform_virtualization_info(outputStream*);
Expand Down
14 changes: 0 additions & 14 deletions src/hotspot/cpu/x86/globals_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,6 @@ define_pd_global(intx, InitArrayShortSize, 8*BytesPerLong);
"Turn off JVM mitigations related to Intel micro code " \
"mitigations for the Intel JCC erratum") \
\
product(ccstr, CPUFeatures, nullptr, "CPU feature set, " \
"use -XX:CPUFeatures=0xnumber with -XX:CRaCCheckpointTo when you "\
"get an error during -XX:CRaCRestoreFrom on a different machine; "\
"-XX:CPUFeatures=native is the default; " \
"-XX:CPUFeatures=ignore will disable the CPU features check; " \
"-XX:CPUFeatures=generic is compatible but not as slow as 0") \
\
product(bool, ShowCPUFeatures, false, "Show features of this CPU " \
"to be possibly used for the -XX:CPUFeatures=0xnumber option") \
\
product(bool, IgnoreCPUFeatures, false, RESTORE_SETTABLE | EXPERIMENTAL, \
"Do not refuse to run after -XX:CRaCRestoreFrom finds out some " \
"CPU features are missing") \
\
product(int, X86ICacheSync, -1, DIAGNOSTIC, \
"Select the X86 ICache sync mechanism: -1 = auto-select; " \
"0 = none (dangerous); 1 = CLFLUSH loop; 2 = CLFLUSHOPT loop; "\
Expand Down
13 changes: 10 additions & 3 deletions src/hotspot/cpu/x86/vm_version_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,7 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
VM_Version::VM_Features VM_Version::CPUFeatures_parse(const char *str) {
#ifndef LINUX
_ignore_glibc_not_using = true;
return _features;
#else
#endif // !LINUX
if (str == nullptr || strcmp(str, "native") == 0) {
return _features;
}
Expand All @@ -901,6 +900,9 @@ VM_Version::VM_Features VM_Version::CPUFeatures_parse(const char *str) {
return _features;
}
if (strcmp(str, "generic") == 0) {
#ifndef LINUX
return _features;
#else
// 32-bit x86 cannot rely on anything.
VM_Version::VM_Features retval;
#ifdef AMD64
Expand All @@ -917,7 +919,12 @@ VM_Version::VM_Features VM_Version::CPUFeatures_parse(const char *str) {
// CPU_LAHFSAHF is disabled in 'gcc -Q --help=target' and "Early Intel Pentium 4 CPUs with Intel 64 support ... lacked the LAHF and SAHF instructions"
#endif
return retval;
#endif // !LINUX
}
#ifndef LINUX
vm_exit_during_initialization("This OS does not support any arch-specific -XX:CPUFeatures options");
return {};
#else // LINUX
int count = VM_Version::VM_Features::features_bitmap_element_count();
VM_Version::VM_Features retval;
const char *str_orig = str;
Expand Down Expand Up @@ -946,7 +953,7 @@ VM_Version::VM_Features VM_Version::CPUFeatures_parse(const char *str) {
}
vm_exit_during_initialization(err_msg("VM option 'CPUFeatures=%s' must be of the form: %s", str_orig, buf + 1));
return {};
#endif // LINUX
#endif
}

bool VM_Version::_ignore_glibc_not_using = false;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/vm_version_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,11 @@ class VM_Version : public Abstract_VM_Version {
// Initialization
static void initialize();
static bool cpu_features_binary(VM_Features *data);
static bool ignore_cpu_features(bool is_checkpoint) {
static bool ignore_cpu_features() {
// This gets triggered by -XX:CPUFeatures=ignore, not writing the features & arch
// on checkpoint into the image at all, and skipping the check on restore.
// IgnoreCPUFeatures is ignored on checkpoint
return _ignore_glibc_not_using || (!is_checkpoint && IgnoreCPUFeatures);
return _ignore_glibc_not_using;
}
static void restore_check(const char* str, const char* msg_prefix);

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/zero/vm_version_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void VM_Version::initialize() {
// the support unconditionally.
_supports_cx8 = true;
#endif

check_cpufeatures_vmoptions();
}

void VM_Version::initialize_cpu_information(void) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/zero/vm_version_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class VM_Version : public Abstract_VM_Version {
static void initialize();
struct VM_Features: public Zero_Features {};
static bool cpu_features_binary(VM_Features *data) { return false; }
static bool ignore_cpu_features(bool is_checkpoint) { return true; }
static bool ignore_cpu_features() { return true; }

constexpr static bool supports_stack_watermark_barrier() { return true; }

Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/runtime/abstract_vm_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "compiler/compilerDefinitions.hpp"
#include "jvm_io.h"
#include "runtime/arguments.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/vm_version.hpp"
#include "utilities/globalDefinitions.hpp"

Expand Down Expand Up @@ -402,3 +403,14 @@ const char* Abstract_VM_Version::cpu_description(void) {
strncpy(tmp, _cpu_desc, CPU_DETAILED_DESC_BUF_SIZE);
return tmp;
}

void Abstract_VM_Version::check_cpufeatures_vmoptions() {
if (!FLAG_IS_DEFAULT(CPUFeatures)) {
if (strcmp(CPUFeatures, "native") && strcmp(CPUFeatures, "generic") && strcmp(CPUFeatures, "ignore")) {
vm_exit_during_initialization("This architecture does not support any arch-specific -XX:CPUFeatures options");
}
}
if (!FLAG_IS_DEFAULT(ShowCPUFeatures)) {
tty->print_cr("Do not use -XX:ShowCPUFeatures: this architecture does not support any arch-specific strings.");
}
}
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/abstract_vm_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class Abstract_VM_Version: AllStatic {
static char _cpu_name[CPU_TYPE_DESC_BUF_SIZE];
static char _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE];

// Default check for non-x86_64 architectures on VM options sanity
static void check_cpufeatures_vmoptions();

public:
static int number_of_threads(void);
static int number_of_cores(void);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/crac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ int crac::checkpoint_restore(int *shmid) {

// Setup CPU arch & features only during the first checkpoint; the feature set
// cannot change after initial boot (and we don't support switching the engine).
if (_generation == 1 && !VM_Version::ignore_cpu_features(true)) {
if (_generation == 1 && !VM_Version::ignore_cpu_features()) {
VM_Version::VM_Features data;
if (VM_Version::cpu_features_binary(&data)) {
switch (_engine->prepare_image_constraints_api()) {
Expand Down Expand Up @@ -795,7 +795,7 @@ void crac::restore(crac_restore_data& restore_data) {
// was printed out but continued even despite features not being satisfied.
// Since the check itself is delegated to the C/R Engine we will simply
// skip the check here.
if (!VM_Version::ignore_cpu_features(false)) {
if (!VM_Version::ignore_cpu_features() && !IgnoreCPUFeatures) {
switch (engine.prepare_image_constraints_api()) {
case CracEngine::ApiStatus::OK: {
VM_Version::VM_Features data;
Expand Down
16 changes: 16 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,22 @@ const int ObjectAlignmentInBytes = 8;
product(size_t, CRaCMaxHeapSizeBeforeCheckpoint, 0, "Maximum size " \
"of heap before checkpoint. By default equals to -Xmx.") \
\
product(ccstr, CPUFeatures, nullptr, "CPU feature set, " \
"Limit set of CPU features to make the CRaC image compatible " \
"for running on a machine with different CPU:" \
"native: use all available features (default), " \
"generic: compatible with most CPUs, " \
"ignore: do not store CPU features at all, " \
"<arch-specific>: use -XX:+ShowCPUFeatures to find a suitable " \
"architecture-specific string, e.g. 0xnumber,0xnumber on x86_64.")\
\
product(bool, ShowCPUFeatures, false, "Show features of this CPU " \
"to be possibly used for the -XX:CPUFeatures=0xnumber option") \
\
product(bool, IgnoreCPUFeatures, false, RESTORE_SETTABLE | EXPERIMENTAL, \
"Do not refuse to run after -XX:CRaCRestoreFrom finds out some " \
"CPU features are missing") \
\
product(int, LockingMode, LM_LIGHTWEIGHT, \
"(Deprecated) Select locking mode: " \
"0: (Deprecated) monitors only (LM_MONITOR), " \
Expand Down
23 changes: 18 additions & 5 deletions src/java.base/share/man/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -1881,11 +1881,24 @@ performed by the Java HotSpot VM.
compilation while values greater than 1.0 delay compilation. Setting
`CompileThresholdScaling` to 0 is equivalent to disabling compilation.

`-XX:CPUFeatures=`*0xnumber,0xnumber*
: CPU feature set, use `-XX:CPUFeatures=`*0xnumber,0xnumber* with
`-XX:CRaCCheckpointTo` when you get an error during `-XX:CRaCRestoreFrom`
on a different machine. `-XX:CPUFeatures=native` is the default.
`-XX:CPUFeatures=generic` is compatible with any CPU.
`-XX:CPUFeatures=`*features*
: Limit the set of CPU features to make the CRaC image compatible for running
on a machine with a different CPU:

`native`
: Use all available CPU features (default).

`generic`
: This option is compatible with most CPUs and faster than disabling
all optional features.

`ignore`
: Do not store CPU features at all.

*arch-specific*
: Architecture specific string, e.g. *0xnumber,0xnumber* on x86_64.
Use `-XX:+ShowCPUFeatures` to find a suitable architecture-specific
string.

`-XX:+DoEscapeAnalysis`
: Enables the use of escape analysis. This option is enabled by default. To
Expand Down
49 changes: 0 additions & 49 deletions test/jdk/jdk/crac/CPUFeatures/SimpleCPUFeatures.sh

This file was deleted.

Loading