hotspot/src/os/posix/vm/os_posix.cpp
author nloodin
Thu, 10 May 2012 15:44:19 +0200
changeset 12735 3e2e491f4f69
parent 11418 66ca80da30e2
child 13195 be27e1b6a4b9
permissions -rw-r--r--
7165755: OS Information much longer on linux than other platforms Reviewed-by: sla, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     1
/*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     2
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     4
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     7
* published by the Free Software Foundation.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     8
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    13
* accompanied this code).
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    14
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    18
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    21
* questions.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    22
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    23
*/
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    24
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    25
#include "prims/jvm.h"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    26
#include "runtime/os.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    27
#include "utilities/vmError.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    28
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    29
#include <unistd.h>
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    30
#include <sys/resource.h>
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    31
#include <sys/utsname.h>
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    32
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    33
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    34
// Check core dump limit and report possible place where core can be found
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    35
void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    36
  struct rlimit rlim;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    37
  static char cwd[O_BUFLEN];
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    38
  bool success;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    39
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    40
  get_current_directory(cwd, sizeof(cwd));
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    41
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    42
  if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    43
    jio_snprintf(buffer, bufferSize, "%s/core or core.%d (may not exist)", cwd, current_process_id());
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    44
    success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    45
  } else {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    46
    switch(rlim.rlim_cur) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    47
      case RLIM_INFINITY:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    48
        jio_snprintf(buffer, bufferSize, "%s/core or core.%d", cwd, current_process_id());
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    49
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    50
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    51
      case 0:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    52
        jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    53
        success = false;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    54
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    55
      default:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    56
        jio_snprintf(buffer, bufferSize, "%s/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", cwd, current_process_id(), (unsigned long)(rlim.rlim_cur >> 10));
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    57
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    58
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    59
    }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    60
  }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    61
  VMError::report_coredump_status(buffer, success);
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    62
}
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    63
11418
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    64
int os::get_last_error() {
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    65
  return errno;
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    66
}
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    67
8476
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    68
bool os::is_debugger_attached() {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    69
  // not implemented
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    70
  return false;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    71
}
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    72
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    73
void os::wait_for_keypress_at_exit(void) {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    74
  // don't do anything on posix platforms
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    75
  return;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    76
}
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    77
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    78
void os::Posix::print_load_average(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    79
  st->print("load average:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    80
  double loadavg[3];
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    81
  os::loadavg(loadavg, 3);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    82
  st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    83
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    84
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    85
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    86
void os::Posix::print_rlimit_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    87
  st->print("rlimit:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    88
  struct rlimit rlim;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    89
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    90
  st->print(" STACK ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    91
  getrlimit(RLIMIT_STACK, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    92
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    93
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    94
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    95
  st->print(", CORE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    96
  getrlimit(RLIMIT_CORE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    97
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    98
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    99
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   100
  //Isn't there on solaris
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   101
#ifndef TARGET_OS_FAMILY_solaris
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   102
  st->print(", NPROC ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   103
  getrlimit(RLIMIT_NPROC, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   104
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   105
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   106
#endif
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   107
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   108
  st->print(", NOFILE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   109
  getrlimit(RLIMIT_NOFILE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   110
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   111
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   112
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   113
  st->print(", AS ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   114
  getrlimit(RLIMIT_AS, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   115
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   116
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   117
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   118
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   119
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   120
void os::Posix::print_uname_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   121
  // kernel
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   122
  st->print("uname:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   123
  struct utsname name;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   124
  uname(&name);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   125
  st->print(name.sysname); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   126
  st->print(name.release); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   127
  st->print(name.version); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   128
  st->print(name.machine);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   129
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   130
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   131
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   132