annotate src/os/posix/vm/os_posix.cpp @ 17684:d1621038becf

8031968: Mac OS X: VM starts the agent by calling both Agent_OnAttach and Agent_OnAttach_L functions if its agent library is dynamically linked. Summary: Make sure we only look for statically linked agents in the main process image Reviewed-by: dsamersoff, bpittore, dcubed
author sla
date Thu, 23 Jan 2014 09:06:21 +0100
parents c636758ea616
children 8a9bb7821e28 6c9332549827
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
1 /*
12141
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
4 *
63d374c54045 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
63d374c54045 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
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
7 * published by the Free Software Foundation.
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
8 *
63d374c54045 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
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63d374c54045 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
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
13 * accompanied this code).
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
14 *
63d374c54045 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
63d374c54045 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,
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
18 *
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
63d374c54045 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
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
21 * questions.
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
22 *
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
23 */
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
24
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
25 #include "prims/jvm.h"
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
26 #include "runtime/frame.inline.hpp"
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
27 #include "runtime/os.hpp"
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
28 #include "utilities/vmError.hpp"
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
29
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
30 #include <unistd.h>
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
31 #include <sys/resource.h>
6080
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
32 #include <sys/utsname.h>
12141
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
33 #include <pthread.h>
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
34 #include <signal.h>
6080
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
35
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
36
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
37 // Check core dump limit and report possible place where core can be found
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
38 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
6200
65906dc96aa1 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 6197
diff changeset
39 int n;
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
40 struct rlimit rlim;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
41 bool success;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
42
6200
65906dc96aa1 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 6197
diff changeset
43 n = get_core_path(buffer, bufferSize);
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
44
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
45 if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
6200
65906dc96aa1 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 6197
diff changeset
46 jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id());
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
47 success = true;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
48 } else {
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
49 switch(rlim.rlim_cur) {
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
50 case RLIM_INFINITY:
6200
65906dc96aa1 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 6197
diff changeset
51 jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id());
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
52 success = true;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
53 break;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
54 case 0:
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
55 jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
56 success = false;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
57 break;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
58 default:
6200
65906dc96aa1 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 6197
diff changeset
59 jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", current_process_id(), (unsigned long)(rlim.rlim_cur >> 10));
2204
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
60 success = true;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
61 break;
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
62 }
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
63 }
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
64 VMError::report_coredump_status(buffer, success);
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
65 }
63d374c54045 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
66
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
67 address os::get_caller_pc(int n) {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
68 #ifdef _NMT_NOINLINE_
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
69 n ++;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
70 #endif
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
71 frame fr = os::current_frame();
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
72 while (n > 0 && fr.pc() &&
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
73 !os::is_first_C_frame(&fr) && fr.sender_pc()) {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
74 fr = os::get_sender_for_C_frame(&fr);
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
75 n --;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
76 }
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
77 if (n == 0) {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
78 return fr.pc();
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
79 } else {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
80 return NULL;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
81 }
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
82 }
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6080
diff changeset
83
4750
b16494a69d3d 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 2302
diff changeset
84 int os::get_last_error() {
b16494a69d3d 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 2302
diff changeset
85 return errno;
b16494a69d3d 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 2302
diff changeset
86 }
b16494a69d3d 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 2302
diff changeset
87
2302
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
88 bool os::is_debugger_attached() {
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
89 // not implemented
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
90 return false;
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
91 }
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
92
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
93 void os::wait_for_keypress_at_exit(void) {
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
94 // don't do anything on posix platforms
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
95 return;
da091bb67459 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 2204
diff changeset
96 }
6080
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
97
7433
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
98 // Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
99 // so on posix, unmap the section at the start and at the end of the chunk that we mapped
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
100 // rather than unmapping and remapping the whole chunk to get requested alignment.
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
101 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
102 assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
103 "Alignment must be a multiple of allocation granularity (page size)");
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
104 assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
105
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
106 size_t extra_size = size + alignment;
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
107 assert(extra_size >= size, "overflow, size is too large to allow alignment");
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
108
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
109 char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
110
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
111 if (extra_base == NULL) {
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
112 return NULL;
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
113 }
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
114
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
115 // Do manual alignment
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
116 char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
117
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
118 // [ | | ]
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
119 // ^ extra_base
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
120 // ^ extra_base + begin_offset == aligned_base
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
121 // extra_base + begin_offset + size ^
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
122 // extra_base + extra_size ^
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
123 // |<>| == begin_offset
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
124 // end_offset == |<>|
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
125 size_t begin_offset = aligned_base - extra_base;
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
126 size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
127
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
128 if (begin_offset > 0) {
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
129 os::release_memory(extra_base, begin_offset);
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
130 }
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
131
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
132 if (end_offset > 0) {
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
133 os::release_memory(extra_base + begin_offset + size, end_offset);
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
134 }
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
135
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
136 return aligned_base;
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
137 }
730cc4ddd550 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 6842
diff changeset
138
6080
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
139 void os::Posix::print_load_average(outputStream* st) {
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
140 st->print("load average:");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
141 double loadavg[3];
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
142 os::loadavg(loadavg, 3);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
143 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
144 st->cr();
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
145 }
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
146
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
147 void os::Posix::print_rlimit_info(outputStream* st) {
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
148 st->print("rlimit:");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
149 struct rlimit rlim;
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
150
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
151 st->print(" STACK ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
152 getrlimit(RLIMIT_STACK, &rlim);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
153 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
154 else st->print("%uk", rlim.rlim_cur >> 10);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
155
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
156 st->print(", CORE ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
157 getrlimit(RLIMIT_CORE, &rlim);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
158 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
159 else st->print("%uk", rlim.rlim_cur >> 10);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
160
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
161 //Isn't there on solaris
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
162 #ifndef TARGET_OS_FAMILY_solaris
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
163 st->print(", NPROC ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
164 getrlimit(RLIMIT_NPROC, &rlim);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
165 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
166 else st->print("%d", rlim.rlim_cur);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
167 #endif
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
168
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
169 st->print(", NOFILE ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
170 getrlimit(RLIMIT_NOFILE, &rlim);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
171 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
172 else st->print("%d", rlim.rlim_cur);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
173
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
174 st->print(", AS ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
175 getrlimit(RLIMIT_AS, &rlim);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
176 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
177 else st->print("%uk", rlim.rlim_cur >> 10);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
178 st->cr();
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
179 }
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
180
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
181 void os::Posix::print_uname_info(outputStream* st) {
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
182 // kernel
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
183 st->print("uname:");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
184 struct utsname name;
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
185 uname(&name);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
186 st->print(name.sysname); st->print(" ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
187 st->print(name.release); st->print(" ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
188 st->print(name.version); st->print(" ");
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
189 st->print(name.machine);
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
190 st->cr();
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
191 }
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
192
8854
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
193 bool os::has_allocatable_memory_limit(julong* limit) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
194 struct rlimit rlim;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
195 int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
196 // if there was an error when calling getrlimit, assume that there is no limitation
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
197 // on virtual memory.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
198 bool result;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
199 if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
200 result = false;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
201 } else {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
202 *limit = (julong)rlim.rlim_cur;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
203 result = true;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
204 }
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
205 #ifdef _LP64
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
206 return result;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
207 #else
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
208 // arbitrary virtual space limit for 32 bit Unices found by testing. If
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
209 // getrlimit above returned a limit, bound it with this limit. Otherwise
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
210 // directly use it.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
211 const julong max_virtual_limit = (julong)3800*M;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
212 if (result) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
213 *limit = MIN2(*limit, max_virtual_limit);
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
214 } else {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
215 *limit = max_virtual_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
216 }
6080
7432b9db36ff 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 4750
diff changeset
217
8854
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
218 // bound by actually allocatable memory. The algorithm uses two bounds, an
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
219 // upper and a lower limit. The upper limit is the current highest amount of
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
220 // memory that could not be allocated, the lower limit is the current highest
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
221 // amount of memory that could be allocated.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
222 // The algorithm iteratively refines the result by halving the difference
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
223 // between these limits, updating either the upper limit (if that value could
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
224 // not be allocated) or the lower limit (if the that value could be allocated)
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
225 // until the difference between these limits is "small".
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
226
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
227 // the minimum amount of memory we care about allocating.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
228 const julong min_allocation_size = M;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
229
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
230 julong upper_limit = *limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
231
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
232 // first check a few trivial cases
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
233 if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
234 *limit = upper_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
235 } else if (!is_allocatable(min_allocation_size)) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
236 // we found that not even min_allocation_size is allocatable. Return it
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
237 // anyway. There is no point to search for a better value any more.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
238 *limit = min_allocation_size;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
239 } else {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
240 // perform the binary search.
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
241 julong lower_limit = min_allocation_size;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
242 while ((upper_limit - lower_limit) > min_allocation_size) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
243 julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
244 temp_limit = align_size_down_(temp_limit, min_allocation_size);
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
245 if (is_allocatable(temp_limit)) {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
246 lower_limit = temp_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
247 } else {
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
248 upper_limit = temp_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
249 }
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
250 }
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
251 *limit = lower_limit;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
252 }
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
253 return true;
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
254 #endif
754c24457b20 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 7433
diff changeset
255 }
10195
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
256
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
257 const char* os::get_current_directory(char *buf, size_t buflen) {
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
258 return getcwd(buf, buflen);
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
259 }
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
260
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
261 FILE* os::open(int fd, const char* mode) {
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
262 return ::fdopen(fd, mode);
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8854
diff changeset
263 }
11151
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
264
12117
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
265 // Builds a platform dependent Agent_OnLoad_<lib_name> function name
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
266 // which is used to find statically linked in agents.
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
267 // Parameters:
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
268 // sym_name: Symbol in library we are looking for
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
269 // lib_name: Name of library to look in, NULL for shared libs.
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
270 // is_absolute_path == true if lib_name is absolute path to agent
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
271 // such as "/a/b/libL.so"
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
272 // == false if only the base name of the library is passed in
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
273 // such as "L"
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
274 char* os::build_agent_function_name(const char *sym_name, const char *lib_name,
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
275 bool is_absolute_path) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
276 char *agent_entry_name;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
277 size_t len;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
278 size_t name_len;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
279 size_t prefix_len = strlen(JNI_LIB_PREFIX);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
280 size_t suffix_len = strlen(JNI_LIB_SUFFIX);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
281 const char *start;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
282
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
283 if (lib_name != NULL) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
284 len = name_len = strlen(lib_name);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
285 if (is_absolute_path) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
286 // Need to strip path, prefix and suffix
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
287 if ((start = strrchr(lib_name, *os::file_separator())) != NULL) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
288 lib_name = ++start;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
289 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
290 if (len <= (prefix_len + suffix_len)) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
291 return NULL;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
292 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
293 lib_name += prefix_len;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
294 name_len = strlen(lib_name) - suffix_len;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
295 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
296 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
297 len = (lib_name != NULL ? name_len : 0) + strlen(sym_name) + 2;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
298 agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
299 if (agent_entry_name == NULL) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
300 return NULL;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
301 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
302 strcpy(agent_entry_name, sym_name);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
303 if (lib_name != NULL) {
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
304 strcat(agent_entry_name, "_");
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
305 strncat(agent_entry_name, lib_name, name_len);
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
306 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
307 return agent_entry_name;
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
308 }
f92b82d454fa 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 11151
diff changeset
309
11151
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
310 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
311 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
312 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
313
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
314 /*
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
315 * See the caveats for this class in os_posix.hpp
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
316 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
317 * method and returns false. If none of the signals are raised, returns true.
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
318 * The callback is supposed to provide the method that should be protected.
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
319 */
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
320 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
12141
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
321 sigset_t saved_sig_mask;
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
322
11151
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
323 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
324 assert(!WatcherThread::watcher_thread()->has_crash_protection(),
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
325 "crash_protection already set?");
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
326
12141
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
327 // we cannot rely on sigsetjmp/siglongjmp to save/restore the signal mask
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
328 // since on at least some systems (OS X) siglongjmp will restore the mask
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
329 // for the process, not the thread
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
330 pthread_sigmask(0, NULL, &saved_sig_mask);
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
331 if (sigsetjmp(_jmpbuf, 0) == 0) {
11151
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
332 // make sure we can see in the signal handler that we have crash protection
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
333 // installed
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
334 WatcherThread::watcher_thread()->set_crash_protection(this);
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
335 cb.call();
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
336 // and clear the crash protection
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
337 WatcherThread::watcher_thread()->set_crash_protection(NULL);
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
338 return true;
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
339 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
340 // this happens when we siglongjmp() back
12141
cc56f122f3f7 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 11151
diff changeset
341 pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
11151
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
342 WatcherThread::watcher_thread()->set_crash_protection(NULL);
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
343 return false;
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
344 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
345
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
346 void os::WatcherThreadCrashProtection::restore() {
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
347 assert(WatcherThread::watcher_thread()->has_crash_protection(),
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
348 "must have crash protection");
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
349
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
350 siglongjmp(_jmpbuf, 1);
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
351 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
352
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
353 void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
354 Thread* thread) {
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
355
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
356 if (thread != NULL &&
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
357 thread->is_Watcher_thread() &&
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
358 WatcherThread::watcher_thread()->has_crash_protection()) {
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
359
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
360 if (sig == SIGSEGV || sig == SIGBUS) {
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
361 WatcherThread::watcher_thread()->crash_protection()->restore();
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
362 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
363 }
5e3b6f79d280 8020701: Avoid crashes in WatcherThread
rbackman
parents: 10195
diff changeset
364 }