src/hotspot/share/utilities/virtualizationSupport.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57875 427b38332f20
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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"
57875
427b38332f20 8229836: Remove include of globals.hpp from allocation.hpp
stefank
parents: 57619
diff changeset
    27
#include "runtime/globals.hpp"
54852
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 "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
    29
#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
    30
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    31
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
    32
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_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
    34
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
    35
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_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
    37
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
    38
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    39
// 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
    40
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
    41
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
    42
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    43
void VirtualizationSupport::initialize() {
57619
929f37a9c35d 8228764: New library dependencies due to JDK-8222720
mbaesken
parents: 54910
diff changeset
    44
  if (!ExtensiveErrorReports) return;
929f37a9c35d 8228764: New library dependencies due to JDK-8222720
mbaesken
parents: 54910
diff changeset
    45
54852
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    46
  // 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
    47
  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
    48
  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
    49
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    50
#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
    51
  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
    52
    // 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
    53
    // 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
    54
    // 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
    55
    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
    56
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    57
#endif
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    58
  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
    59
    return;
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
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_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
    63
  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
    64
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    65
  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
    66
    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
    67
    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
    68
    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
    69
    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
    70
      has_resource_information = true;
54910
361bd0fb9390 8224033: os::snprintf should be used in virtualizationSupport.cpp
shade
parents: 54852
diff changeset
    71
      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
    72
      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
    73
    }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    74
    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
    75
    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
    76
      has_host_information = true;
54910
361bd0fb9390 8224033: os::snprintf should be used in virtualizationSupport.cpp
shade
parents: 54852
diff changeset
    77
      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
    78
      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
    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
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    83
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
    84
  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
    85
    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
    86
    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
    87
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    88
  // 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
  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
    90
    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
    91
    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
    92
  }
ddb27517396c 8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
mbaesken
parents:
diff changeset
    93
  // 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
    94
  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
    95
    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
    96
    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
    97
    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
    98
    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
    99
      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
   100
      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
   101
      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
   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
}