diff --git a/src/hotspot/cpu/ppc/vm_version_ppc.cpp b/src/hotspot/cpu/ppc/vm_version_ppc.cpp index 447c93f3ea..90504ad13b 100644 --- a/src/hotspot/cpu/ppc/vm_version_ppc.cpp +++ b/src/hotspot/cpu/ppc/vm_version_ppc.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2018, SAP SE. All rights reserved. + * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -382,6 +382,50 @@ void VM_Version::initialize() { if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) { FLAG_SET_DEFAULT(UseUnalignedAccesses, true); } + + check_virtualizations(); +} + +void VM_Version::check_virtualizations() { +#if defined(_AIX) + int rc = 0; + perfstat_partition_total_t pinfo; + rc = perfstat_partition_total(NULL, &pinfo, sizeof(perfstat_partition_total_t), 1); + if (rc == 1) { + Abstract_VM_Version::_detected_virtualization = PowerVM; + } +#else + const char* info_file = "/proc/ppc64/lparcfg"; + // system_type=...qemu indicates PowerKVM + // e.g. system_type=IBM pSeries (emulated by qemu) + char line[500]; + FILE* fp = fopen(info_file, "r"); + if (fp == NULL) { + return; + } + const char* system_type="system_type="; // in case this line contains qemu, it is KVM + const char* num_lpars="NumLpars="; // in case of non-KVM : if this line is found it is PowerVM + bool num_lpars_found = false; + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strncmp(line, system_type, strlen(system_type)) == 0) { + if (strstr(line, "qemu") != 0) { + Abstract_VM_Version::_detected_virtualization = PowerKVM; + fclose(fp); + return; + } + } + if (strncmp(line, num_lpars, strlen(num_lpars)) == 0) { + num_lpars_found = true; + } + } + if (num_lpars_found) { + Abstract_VM_Version::_detected_virtualization = PowerVM; + } else { + Abstract_VM_Version::_detected_virtualization = PowerFullPartitionMode; + } + fclose(fp); +#endif } void VM_Version::print_platform_virtualization_info(outputStream* st) { diff --git a/src/hotspot/cpu/ppc/vm_version_ppc.hpp b/src/hotspot/cpu/ppc/vm_version_ppc.hpp index 5d4a7cea65..787e147438 100644 --- a/src/hotspot/cpu/ppc/vm_version_ppc.hpp +++ b/src/hotspot/cpu/ppc/vm_version_ppc.hpp @@ -1,6 +1,6 @@ /* * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2018 SAP SE. All rights reserved. + * Copyright (c) 2012, 2019 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -87,6 +87,7 @@ protected: public: // Initialization static void initialize(); + static void check_virtualizations(); // Override Abstract_VM_Version implementation static void print_platform_virtualization_info(outputStream*); diff --git a/src/hotspot/share/jfr/metadata/metadata.xml b/src/hotspot/share/jfr/metadata/metadata.xml index 208b0db906..63323c8373 100644 --- a/src/hotspot/share/jfr/metadata/metadata.xml +++ b/src/hotspot/share/jfr/metadata/metadata.xml @@ -615,6 +615,10 @@ + + + + diff --git a/src/hotspot/share/jfr/periodic/jfrOSInterface.cpp b/src/hotspot/share/jfr/periodic/jfrOSInterface.cpp index 331b249a73..52337f121c 100644 --- a/src/hotspot/share/jfr/periodic/jfrOSInterface.cpp +++ b/src/hotspot/share/jfr/periodic/jfrOSInterface.cpp @@ -215,6 +215,27 @@ int JfrOSInterface::os_version(char** os_version) { return instance()._impl->os_version(os_version); } +const char* JfrOSInterface::virtualization_name() { + VirtualizationType vrt = VM_Version::get_detected_virtualization(); + if (vrt == XenHVM) { + return "Xen hardware-assisted virtualization"; + } else if (vrt == KVM) { + return "KVM virtualization"; + } else if (vrt == VMWare) { + return "VMWare virtualization"; + } else if (vrt == HyperV) { + return "HyperV virtualization"; + } else if (vrt == PowerVM) { + return "PowerVM virtualization"; + } else if (vrt == PowerKVM) { + return "Power KVM virtualization"; + } else if (vrt == PowerFullPartitionMode) { + return "Power full partition"; + } + + return "No virtualization detected"; +} + int JfrOSInterface::generate_initial_environment_variable_events() { if (environ == NULL) { return OS_ERR; diff --git a/src/hotspot/share/jfr/periodic/jfrOSInterface.hpp b/src/hotspot/share/jfr/periodic/jfrOSInterface.hpp index 43e8a894a5..141e7505ef 100644 --- a/src/hotspot/share/jfr/periodic/jfrOSInterface.hpp +++ b/src/hotspot/share/jfr/periodic/jfrOSInterface.hpp @@ -52,6 +52,7 @@ class JfrOSInterface: public JfrCHeapObj { static int cpu_load_total_process(double* cpu_load); static int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad); static int os_version(char** os_version); + static const char* virtualization_name(); static int generate_initial_environment_variable_events(); static int system_processes(SystemProcess** system_processes, int* no_of_sys_processes); static int network_utilization(NetworkInterface** network_interfaces); diff --git a/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp b/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp index ef2b79d459..87a1a57550 100644 --- a/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp +++ b/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp @@ -95,6 +95,12 @@ TRACE_REQUEST_FUNC(OSInformation) { event.commit(); } +TRACE_REQUEST_FUNC(VirtualizationInformation) { + EventVirtualizationInformation event; + event.set_name(JfrOSInterface::virtualization_name()); + event.commit(); +} + TRACE_REQUEST_FUNC(ModuleRequire) { JfrModuleEvent::generate_module_dependency_events(); } diff --git a/src/hotspot/share/runtime/vm_version.hpp b/src/hotspot/share/runtime/vm_version.hpp index 2d5633ef63..67552b28bd 100644 --- a/src/hotspot/share/runtime/vm_version.hpp +++ b/src/hotspot/share/runtime/vm_version.hpp @@ -34,7 +34,10 @@ typedef enum { XenHVM, KVM, VMWare, - HyperV + HyperV, + PowerVM, // on AIX or Linux ppc64(le) + PowerFullPartitionMode, // on Linux ppc64(le) + PowerKVM } VirtualizationType; // VM_Version provides information about the VM. diff --git a/src/jdk.jfr/share/conf/jfr/default.jfc b/src/jdk.jfr/share/conf/jfr/default.jfc index d37c3dba2e..7bc5ebd9fe 100644 --- a/src/jdk.jfr/share/conf/jfr/default.jfc +++ b/src/jdk.jfr/share/conf/jfr/default.jfc @@ -513,6 +513,11 @@ beginChunk + + true + beginChunk + + true beginChunk diff --git a/src/jdk.jfr/share/conf/jfr/profile.jfc b/src/jdk.jfr/share/conf/jfr/profile.jfc index d1c8dcf2d8..21612bb2fe 100644 --- a/src/jdk.jfr/share/conf/jfr/profile.jfc +++ b/src/jdk.jfr/share/conf/jfr/profile.jfc @@ -513,6 +513,11 @@ beginChunk + + true + beginChunk + + true beginChunk diff --git a/test/jdk/jdk/jfr/event/os/TestVirtualizationInfo.java b/test/jdk/jdk/jfr/event/os/TestVirtualizationInfo.java new file mode 100644 index 0000000000..b3a0919187 --- /dev/null +++ b/test/jdk/jdk/jfr/event/os/TestVirtualizationInfo.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.jfr.event.os; + +import java.util.List; + +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordedEvent; +import jdk.test.lib.jfr.EventNames; +import jdk.test.lib.jfr.Events; + +/** + * @test + * @key jfr + * @requires vm.hasJFR + * @library /test/lib + * @run main/othervm jdk.jfr.event.os.TestVirtualizationInfo + */ +public class TestVirtualizationInfo { + private final static String EVENT_NAME = EventNames.VirtualizationInformation; + + public static void main(String[] args) throws Throwable { + Recording recording = new Recording(); + recording.enable(EVENT_NAME); + recording.start(); + recording.stop(); + List events = Events.fromRecording(recording); + Events.hasEvents(events); + for (RecordedEvent event : events) { + System.out.println("Event: " + event); + Events.assertField(event, "name").notEmpty(); + } + } +} diff --git a/test/lib/jdk/test/lib/jfr/EventNames.java b/test/lib/jdk/test/lib/jfr/EventNames.java index fb89ab566c..9b1d20f616 100644 --- a/test/lib/jdk/test/lib/jfr/EventNames.java +++ b/test/lib/jdk/test/lib/jfr/EventNames.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -154,6 +154,7 @@ public class EventNames { // OS public final static String OSInformation = PREFIX + "OSInformation"; + public final static String VirtualizationInformation = PREFIX + "VirtualizationInformation"; public final static String CPUInformation = PREFIX + "CPUInformation"; public final static String CPULoad = PREFIX + "CPULoad"; public final static String ThreadCPULoad = PREFIX + "ThreadCPULoad";