src/hotspot/share/utilities/virtualizationSupport.cpp
author mbaesken
Thu, 01 Aug 2019 09:37:24 +0200
changeset 57619 929f37a9c35d
parent 54910 361bd0fb9390
child 57875 427b38332f20
permissions -rw-r--r--
8228764: New library dependencies due to JDK-8222720 Reviewed-by: goetz, dholmes
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() {
57619
929f37a9c35d 8228764: New library dependencies due to JDK-8222720
mbaesken
parents: 54910
diff changeset
    43
  if (!ExtensiveErrorReports) return;
929f37a9c35d 8228764: New library dependencies due to JDK-8222720
mbaesken
parents: 54910
diff changeset
    44
54852
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    45
  // 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
    46
  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
    47
  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
    48
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    49
#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
    50
  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
    51
    // 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
    52
    // 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
    53
    // 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
    54
    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
    55
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    56
#endif
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    57
  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
    58
    return;
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    59
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    60
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    61
  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
    62
  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
    63
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    64
  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
    65
    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
    66
    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
    67
    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
    68
    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
    69
      has_resource_information = true;
54910
361bd0fb9390 8224033: os::snprintf should be used in virtualizationSupport.cpp
shade
parents: 54852
diff changeset
    70
      os::snprintf(extended_resource_info_at_startup, sizeof(extended_resource_info_at_startup), "%s", result_info);
54852
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    71
      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
    72
    }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    73
    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
    74
    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
    75
      has_host_information = true;
54910
361bd0fb9390 8224033: os::snprintf should be used in virtualizationSupport.cpp
shade
parents: 54852
diff changeset
    76
      os::snprintf(host_information, sizeof(host_information), "%s", result_info);
54852
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    77
      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
    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
}
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    81
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    82
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
    83
  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
    84
    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
    85
    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
    86
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    87
  // 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
    88
  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
    89
    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
    90
    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
    91
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    92
  // 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
    93
  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
    94
    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
    95
    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
    96
    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
    97
    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
    98
      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
    99
      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
   100
      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
   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
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
   103
}
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
   104