hotspot/src/os/posix/vm/os_posix.cpp
author phh
Tue, 03 Jan 2012 15:11:31 -0500
changeset 11418 66ca80da30e2
parent 8476 7e34c2d4cf9b
child 12735 3e2e491f4f69
permissions -rw-r--r--
7126185: Clean up lasterror handling, add os::get_last_error() Summary: Add os::get_last_error(), replace getLastErrorString() by os::lasterror() in os_windows.cpp. Reviewed-by: kamg, dholmes Contributed-by: erik.gahlin@oracle.com
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>
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    31
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    32
// 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
    33
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
    34
  struct rlimit rlim;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    35
  static char cwd[O_BUFLEN];
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    36
  bool success;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    37
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    38
  get_current_directory(cwd, sizeof(cwd));
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
  if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    41
    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
    42
    success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    43
  } else {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    44
    switch(rlim.rlim_cur) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    45
      case RLIM_INFINITY:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    46
        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
    47
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    48
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    49
      case 0:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    50
        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
    51
        success = false;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    52
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    53
      default:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    54
        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
    55
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    56
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    57
    }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    58
  }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    59
  VMError::report_coredump_status(buffer, success);
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
11418
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    62
int os::get_last_error() {
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    63
  return errno;
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    64
}
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    65
8476
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    66
bool os::is_debugger_attached() {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    67
  // not implemented
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    68
  return false;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    69
}
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    70
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    71
void os::wait_for_keypress_at_exit(void) {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    72
  // don't do anything on posix platforms
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    73
  return;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    74
}