annotate src/os/posix/vm/os_posix.cpp @ 4703:73863f836e34

8014611: reserve_and_align() assumptions are invalid on windows Summary: also reviewed by ron.durbin@oracle.com, thomas.schatzl@oracle.com Reviewed-by: dcubed, brutisso
author jcoomes
date Thu, 23 May 2013 03:08:19 -0700
parents e629a7d0b760
children 63085fd28f10
rev   line source
ctornqvi@2085 1 /*
ctornqvi@2085 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
ctornqvi@2085 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ctornqvi@2085 4 *
ctornqvi@2085 5 * This code is free software; you can redistribute it and/or modify it
ctornqvi@2085 6 * under the terms of the GNU General Public License version 2 only, as
ctornqvi@2085 7 * published by the Free Software Foundation.
ctornqvi@2085 8 *
ctornqvi@2085 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ctornqvi@2085 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ctornqvi@2085 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ctornqvi@2085 12 * version 2 for more details (a copy is included in the LICENSE file that
ctornqvi@2085 13 * accompanied this code).
ctornqvi@2085 14 *
ctornqvi@2085 15 * You should have received a copy of the GNU General Public License version
ctornqvi@2085 16 * 2 along with this work; if not, write to the Free Software Foundation,
ctornqvi@2085 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ctornqvi@2085 18 *
ctornqvi@2085 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ctornqvi@2085 20 * or visit www.oracle.com if you need additional information or have any
ctornqvi@2085 21 * questions.
ctornqvi@2085 22 *
ctornqvi@2085 23 */
ctornqvi@2085 24
ctornqvi@2085 25 #include "prims/jvm.h"
ctornqvi@2085 26 #include "runtime/os.hpp"
ctornqvi@2085 27 #include "utilities/vmError.hpp"
ctornqvi@2085 28
ctornqvi@2085 29 #include <unistd.h>
ctornqvi@2085 30 #include <sys/resource.h>
nloodin@3380 31 #include <sys/utsname.h>
nloodin@3380 32
ctornqvi@2085 33
ctornqvi@2085 34 // Check core dump limit and report possible place where core can be found
ctornqvi@2085 35 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
ctornqvi@2085 36 struct rlimit rlim;
ctornqvi@2085 37 static char cwd[O_BUFLEN];
ctornqvi@2085 38 bool success;
ctornqvi@2085 39
ctornqvi@2085 40 get_current_directory(cwd, sizeof(cwd));
ctornqvi@2085 41
ctornqvi@2085 42 if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
ctornqvi@2085 43 jio_snprintf(buffer, bufferSize, "%s/core or core.%d (may not exist)", cwd, current_process_id());
ctornqvi@2085 44 success = true;
ctornqvi@2085 45 } else {
ctornqvi@2085 46 switch(rlim.rlim_cur) {
ctornqvi@2085 47 case RLIM_INFINITY:
ctornqvi@2085 48 jio_snprintf(buffer, bufferSize, "%s/core or core.%d", cwd, current_process_id());
ctornqvi@2085 49 success = true;
ctornqvi@2085 50 break;
ctornqvi@2085 51 case 0:
ctornqvi@2085 52 jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
ctornqvi@2085 53 success = false;
ctornqvi@2085 54 break;
ctornqvi@2085 55 default:
ctornqvi@2085 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));
ctornqvi@2085 57 success = true;
ctornqvi@2085 58 break;
ctornqvi@2085 59 }
ctornqvi@2085 60 }
ctornqvi@2085 61 VMError::report_coredump_status(buffer, success);
ctornqvi@2085 62 }
ctornqvi@2085 63
phh@3030 64 int os::get_last_error() {
phh@3030 65 return errno;
phh@3030 66 }
phh@3030 67
sla@2149 68 bool os::is_debugger_attached() {
sla@2149 69 // not implemented
sla@2149 70 return false;
sla@2149 71 }
sla@2149 72
sla@2149 73 void os::wait_for_keypress_at_exit(void) {
sla@2149 74 // don't do anything on posix platforms
sla@2149 75 return;
sla@2149 76 }
nloodin@3380 77
brutisso@4373 78 // Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
brutisso@4373 79 // so on posix, unmap the section at the start and at the end of the chunk that we mapped
brutisso@4373 80 // rather than unmapping and remapping the whole chunk to get requested alignment.
brutisso@4373 81 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
brutisso@4373 82 assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
brutisso@4373 83 "Alignment must be a multiple of allocation granularity (page size)");
brutisso@4373 84 assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
brutisso@4373 85
brutisso@4373 86 size_t extra_size = size + alignment;
brutisso@4373 87 assert(extra_size >= size, "overflow, size is too large to allow alignment");
brutisso@4373 88
brutisso@4373 89 char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
brutisso@4373 90
brutisso@4373 91 if (extra_base == NULL) {
brutisso@4373 92 return NULL;
brutisso@4373 93 }
brutisso@4373 94
brutisso@4373 95 // Do manual alignment
brutisso@4373 96 char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
brutisso@4373 97
brutisso@4373 98 // [ | | ]
brutisso@4373 99 // ^ extra_base
brutisso@4373 100 // ^ extra_base + begin_offset == aligned_base
brutisso@4373 101 // extra_base + begin_offset + size ^
brutisso@4373 102 // extra_base + extra_size ^
brutisso@4373 103 // |<>| == begin_offset
brutisso@4373 104 // end_offset == |<>|
brutisso@4373 105 size_t begin_offset = aligned_base - extra_base;
brutisso@4373 106 size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
brutisso@4373 107
brutisso@4373 108 if (begin_offset > 0) {
brutisso@4373 109 os::release_memory(extra_base, begin_offset);
brutisso@4373 110 }
brutisso@4373 111
brutisso@4373 112 if (end_offset > 0) {
brutisso@4373 113 os::release_memory(extra_base + begin_offset + size, end_offset);
brutisso@4373 114 }
brutisso@4373 115
brutisso@4373 116 return aligned_base;
brutisso@4373 117 }
brutisso@4373 118
jcoomes@4703 119 bool os::can_release_partial_region() {
jcoomes@4703 120 return true;
jcoomes@4703 121 }
jcoomes@4703 122
nloodin@3380 123 void os::Posix::print_load_average(outputStream* st) {
nloodin@3380 124 st->print("load average:");
nloodin@3380 125 double loadavg[3];
nloodin@3380 126 os::loadavg(loadavg, 3);
nloodin@3380 127 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
nloodin@3380 128 st->cr();
nloodin@3380 129 }
nloodin@3380 130
nloodin@3380 131 void os::Posix::print_rlimit_info(outputStream* st) {
nloodin@3380 132 st->print("rlimit:");
nloodin@3380 133 struct rlimit rlim;
nloodin@3380 134
nloodin@3380 135 st->print(" STACK ");
nloodin@3380 136 getrlimit(RLIMIT_STACK, &rlim);
nloodin@3380 137 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3380 138 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3380 139
nloodin@3380 140 st->print(", CORE ");
nloodin@3380 141 getrlimit(RLIMIT_CORE, &rlim);
nloodin@3380 142 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3380 143 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3380 144
nloodin@3380 145 //Isn't there on solaris
nloodin@3380 146 #ifndef TARGET_OS_FAMILY_solaris
nloodin@3380 147 st->print(", NPROC ");
nloodin@3380 148 getrlimit(RLIMIT_NPROC, &rlim);
nloodin@3380 149 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3380 150 else st->print("%d", rlim.rlim_cur);
nloodin@3380 151 #endif
nloodin@3380 152
nloodin@3380 153 st->print(", NOFILE ");
nloodin@3380 154 getrlimit(RLIMIT_NOFILE, &rlim);
nloodin@3380 155 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3380 156 else st->print("%d", rlim.rlim_cur);
nloodin@3380 157
nloodin@3380 158 st->print(", AS ");
nloodin@3380 159 getrlimit(RLIMIT_AS, &rlim);
nloodin@3380 160 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3380 161 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3380 162 st->cr();
nloodin@3380 163 }
nloodin@3380 164
nloodin@3380 165 void os::Posix::print_uname_info(outputStream* st) {
nloodin@3380 166 // kernel
nloodin@3380 167 st->print("uname:");
nloodin@3380 168 struct utsname name;
nloodin@3380 169 uname(&name);
nloodin@3380 170 st->print(name.sysname); st->print(" ");
nloodin@3380 171 st->print(name.release); st->print(" ");
nloodin@3380 172 st->print(name.version); st->print(" ");
nloodin@3380 173 st->print(name.machine);
nloodin@3380 174 st->cr();
nloodin@3380 175 }
nloodin@3380 176
nloodin@3380 177