Skip to content

Commit 11804b2

Browse files
committed
8301050: Detect Xen Virtualization on Linux aarch64
Reviewed-by: dholmes, clanger
1 parent b504c94 commit 11804b2

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/hotspot/cpu/aarch64/vm_version_aarch64.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,26 +564,40 @@ void VM_Version::initialize() {
564564
check_virtualizations();
565565
}
566566

567-
void VM_Version::check_virtualizations() {
568567
#if defined(LINUX)
569-
const char* info_file = "/sys/devices/virtual/dmi/id/product_name";
570-
// check for various strings in the dmi data indicating virtualizations
568+
static bool check_info_file(const char* fpath,
569+
const char* virt1, VirtualizationType vt1,
570+
const char* virt2, VirtualizationType vt2) {
571571
char line[500];
572-
FILE* fp = os::fopen(info_file, "r");
572+
FILE* fp = os::fopen(fpath, "r");
573573
if (fp == nullptr) {
574-
return;
574+
return false;
575575
}
576576
while (fgets(line, sizeof(line), fp) != nullptr) {
577-
if (strcasestr(line, "KVM") != 0) {
578-
Abstract_VM_Version::_detected_virtualization = KVM;
579-
break;
577+
if (strcasestr(line, virt1) != 0) {
578+
Abstract_VM_Version::_detected_virtualization = vt1;
579+
fclose(fp);
580+
return true;
580581
}
581-
if (strcasestr(line, "VMware") != 0) {
582-
Abstract_VM_Version::_detected_virtualization = VMWare;
583-
break;
582+
if (virt2 != NULL && strcasestr(line, virt2) != 0) {
583+
Abstract_VM_Version::_detected_virtualization = vt2;
584+
fclose(fp);
585+
return true;
584586
}
585587
}
586588
fclose(fp);
589+
return false;
590+
}
591+
#endif
592+
593+
void VM_Version::check_virtualizations() {
594+
#if defined(LINUX)
595+
const char* pname_file = "/sys/devices/virtual/dmi/id/product_name";
596+
const char* tname_file = "/sys/hypervisor/type";
597+
if (check_info_file(pname_file, "KVM", KVM, "VMWare", VMWare)) {
598+
return;
599+
}
600+
check_info_file(tname_file, "Xen", XenHVM, NULL, NoDetectedVirtualization);
587601
#endif
588602
}
589603

src/hotspot/share/runtime/abstract_vm_version.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -71,9 +71,10 @@ class Abstract_VM_Version: AllStatic {
7171
static int _vm_build_number;
7272
static unsigned int _data_cache_line_flush_size;
7373

74+
public:
75+
7476
static VirtualizationType _detected_virtualization;
7577

76-
public:
7778
// Called as part of the runtime services initialization which is
7879
// called from the management module initialization (via init_globals())
7980
// after argument parsing and attaching of the main thread has

0 commit comments

Comments
 (0)