src/hotspot/share/utilities/virtualizationSupport.cpp
author mbaesken
Fri, 10 May 2019 10:18:16 +0200
changeset 54852 ddb27517396c
child 54910 361bd0fb9390
permissions -rw-r--r--
8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64 Reviewed-by: dholmes, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54852
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     1
/*
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     3
 * Copyright (c) 2019 SAP SE. All rights reserved.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     5
 *
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     8
 * published by the Free Software Foundation.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
     9
 *
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    14
 * accompanied this code).
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    15
 *
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    19
 *
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    22
 * questions.
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    23
 *
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    24
 */
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    25
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    26
#include "precompiled.hpp"
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    27
#include "runtime/os.hpp"
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    28
#include "utilities/virtualizationSupport.hpp"
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    29
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    30
static void *dlHandle = NULL;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    31
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    32
static GuestLib_StatGet_t GuestLib_StatGet = NULL;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    33
static GuestLib_StatFree_t GuestLib_StatFree = NULL;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    34
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    35
static bool has_host_information = false;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    36
static bool has_resource_information = false;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    37
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    38
// host + resource information; avoid the session and other special info vectors
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    39
static char host_information[300];
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    40
static char extended_resource_info_at_startup[600];
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    41
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    42
void VirtualizationSupport::initialize() {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    43
  // open vmguestlib and bind SDK functions
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    44
  char ebuf[1024];
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    45
  dlHandle = os::dll_load("vmGuestLib", ebuf, sizeof ebuf);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    46
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    47
#ifdef LINUX
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    48
  if (dlHandle == NULL) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    49
    // the open-vm-tools have a different guest lib name
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    50
    // on some distros e.g. SLES12 the open-vm-tools are the default,
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    51
    // so use the different libname as a fallback
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    52
    dlHandle = os::dll_load("/usr/lib64/libguestlib.so.0", ebuf, sizeof ebuf);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    53
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    54
#endif
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    55
  if (dlHandle == NULL) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    56
    return;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    57
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    58
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    59
  GuestLib_StatGet = CAST_TO_FN_PTR(GuestLib_StatGet_t, os::dll_lookup(dlHandle, "VMGuestLib_StatGet"));
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    60
  GuestLib_StatFree = CAST_TO_FN_PTR(GuestLib_StatFree_t, os::dll_lookup(dlHandle, "VMGuestLib_StatFree"));
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    61
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    62
  if (GuestLib_StatGet != NULL && GuestLib_StatFree != NULL) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    63
    char* result_info = NULL;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    64
    size_t result_size = 0;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    65
    VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    66
    if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    67
      has_resource_information = true;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    68
      snprintf(extended_resource_info_at_startup, sizeof(extended_resource_info_at_startup), "%s", result_info);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    69
      GuestLib_StatFree(result_info, result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    70
    }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    71
    sg_error = GuestLib_StatGet("text", "host", &result_info, &result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    72
    if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    73
      has_host_information = true;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    74
      snprintf(host_information, sizeof(host_information), "%s", result_info);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    75
      GuestLib_StatFree(result_info, result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    76
    }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    77
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    78
}
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    79
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    80
void VirtualizationSupport::print_virtualization_info(outputStream* st) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    81
  if (has_host_information) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    82
    st->print_cr("vSphere host information:");
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    83
    st->print_cr("%s", host_information);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    84
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    85
  // resource info at startup
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    86
  if (has_resource_information) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    87
    st->print_cr("vSphere resource information collected at VM startup:");
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    88
    st->print_cr("%s", extended_resource_info_at_startup);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    89
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    90
  // current resource info
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    91
  if (GuestLib_StatGet != NULL && GuestLib_StatFree != NULL) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    92
    char* result_info = NULL;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    93
    size_t result_size = 0;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    94
    VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    95
    if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    96
      st->print_cr("vSphere resource information available now:");
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    97
      st->print_cr("%s", result_info);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    98
      GuestLib_StatFree(result_info, result_size);
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    99
    }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
   100
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
   101
}
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
   102