26
#include "precompiled.hpp"
27
#include "runtime/globals.hpp"
28
#include "runtime/os.hpp"
29
#include "utilities/virtualizationSupport.hpp"
31
static void *dlHandle = nullptr;
33
static GuestLib_StatGet_t GuestLib_StatGet = nullptr;
34
static GuestLib_StatFree_t GuestLib_StatFree = nullptr;
36
static bool has_host_information = false;
37
static bool has_resource_information = false;
40
static char host_information[300];
41
static char extended_resource_info_at_startup[600];
43
void VirtualizationSupport::initialize() {
44
if (!ExtensiveErrorReports) return;
48
dlHandle = os::dll_load("vmGuestLib", ebuf, sizeof ebuf);
51
if (dlHandle == nullptr) {
55
dlHandle = os::dll_load("/usr/lib64/libguestlib.so.0", ebuf, sizeof ebuf);
58
if (dlHandle == nullptr) {
62
GuestLib_StatGet = CAST_TO_FN_PTR(GuestLib_StatGet_t, os::dll_lookup(dlHandle, "VMGuestLib_StatGet"));
63
GuestLib_StatFree = CAST_TO_FN_PTR(GuestLib_StatFree_t, os::dll_lookup(dlHandle, "VMGuestLib_StatFree"));
65
if (GuestLib_StatGet != nullptr && GuestLib_StatFree != nullptr) {
66
char* result_info = nullptr;
67
size_t result_size = 0;
68
VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
69
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
70
has_resource_information = true;
71
os::snprintf(extended_resource_info_at_startup, sizeof(extended_resource_info_at_startup), "%s", result_info);
72
GuestLib_StatFree(result_info, result_size);
74
sg_error = GuestLib_StatGet("text", "host", &result_info, &result_size);
75
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
76
has_host_information = true;
77
os::snprintf(host_information, sizeof(host_information), "%s", result_info);
78
GuestLib_StatFree(result_info, result_size);
83
void VirtualizationSupport::print_virtualization_info(outputStream* st) {
84
if (has_host_information) {
85
st->print_cr("vSphere host information:");
86
st->print_cr("%s", host_information);
89
if (has_resource_information) {
90
st->print_cr("vSphere resource information collected at VM startup:");
91
st->print_cr("%s", extended_resource_info_at_startup);
94
if (GuestLib_StatGet != nullptr && GuestLib_StatFree != nullptr) {
95
char* result_info = nullptr;
96
size_t result_size = 0;
97
VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
98
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
99
st->print_cr("vSphere resource information available now:");
100
st->print_cr("%s", result_info);
101
GuestLib_StatFree(result_info, result_size);