author | sangheki |
Mon, 07 Mar 2016 10:01:38 +0000 | |
changeset 36575 | a61a9898d623 |
parent 35201 | 996db89f378e |
child 37430 | fd743dadef12 |
permissions | -rw-r--r-- |
380 | 1 |
/* |
32080
9d2ace436482
8080298: Clean up os::...::supports_variable_stack_size()
dholmes
parents:
29573
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
380 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
21 |
* questions. |
380 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
// no precompiled headers |
14631
526804361522
8003250: SPARC: move MacroAssembler into separate file
twisti
parents:
13963
diff
changeset
|
26 |
#include "asm/macroAssembler.hpp" |
7397 | 27 |
#include "classfile/classLoader.hpp" |
28 |
#include "classfile/systemDictionary.hpp" |
|
29 |
#include "classfile/vmSymbols.hpp" |
|
34667 | 30 |
#include "code/codeCache.hpp" |
7397 | 31 |
#include "code/icBuffer.hpp" |
32 |
#include "code/vtableStubs.hpp" |
|
33 |
#include "interpreter/interpreter.hpp" |
|
34 |
#include "jvm_linux.h" |
|
35 |
#include "memory/allocation.inline.hpp" |
|
36 |
#include "mutex_linux.inline.hpp" |
|
37 |
#include "nativeInst_sparc.hpp" |
|
38 |
#include "os_share_linux.hpp" |
|
39 |
#include "prims/jniFastGetField.hpp" |
|
40 |
#include "prims/jvm.h" |
|
41 |
#include "prims/jvm_misc.hpp" |
|
42 |
#include "runtime/arguments.hpp" |
|
43 |
#include "runtime/extendedPC.hpp" |
|
44 |
#include "runtime/frame.inline.hpp" |
|
45 |
#include "runtime/interfaceSupport.hpp" |
|
46 |
#include "runtime/java.hpp" |
|
47 |
#include "runtime/javaCalls.hpp" |
|
48 |
#include "runtime/mutexLocker.hpp" |
|
49 |
#include "runtime/osThread.hpp" |
|
50 |
#include "runtime/sharedRuntime.hpp" |
|
51 |
#include "runtime/stubRoutines.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13963
diff
changeset
|
52 |
#include "runtime/thread.inline.hpp" |
7397 | 53 |
#include "runtime/timer.hpp" |
54 |
#include "utilities/events.hpp" |
|
55 |
#include "utilities/vmError.hpp" |
|
380 | 56 |
|
57 |
// Linux/Sparc has rather obscure naming of registers in sigcontext |
|
58 |
// different between 32 and 64 bits |
|
59 |
#ifdef _LP64 |
|
60 |
#define SIG_PC(x) ((x)->sigc_regs.tpc) |
|
61 |
#define SIG_NPC(x) ((x)->sigc_regs.tnpc) |
|
62 |
#define SIG_REGS(x) ((x)->sigc_regs) |
|
63 |
#else |
|
64 |
#define SIG_PC(x) ((x)->si_regs.pc) |
|
65 |
#define SIG_NPC(x) ((x)->si_regs.npc) |
|
66 |
#define SIG_REGS(x) ((x)->si_regs) |
|
67 |
#endif |
|
68 |
||
69 |
// those are to reference registers in sigcontext |
|
70 |
enum { |
|
71 |
CON_G0 = 0, |
|
72 |
CON_G1, |
|
73 |
CON_G2, |
|
74 |
CON_G3, |
|
75 |
CON_G4, |
|
76 |
CON_G5, |
|
77 |
CON_G6, |
|
78 |
CON_G7, |
|
79 |
CON_O0, |
|
80 |
CON_O1, |
|
81 |
CON_O2, |
|
82 |
CON_O3, |
|
83 |
CON_O4, |
|
84 |
CON_O5, |
|
85 |
CON_O6, |
|
86 |
CON_O7, |
|
87 |
}; |
|
88 |
||
89 |
// For Forte Analyzer AsyncGetCallTrace profiling support - thread is |
|
90 |
// currently interrupted by SIGPROF. |
|
91 |
// os::Solaris::fetch_frame_from_ucontext() tries to skip nested |
|
92 |
// signal frames. Currently we don't do that on Linux, so it's the |
|
93 |
// same as os::fetch_frame_from_context(). |
|
94 |
ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
95 |
const ucontext_t* uc, |
380 | 96 |
intptr_t** ret_sp, |
97 |
intptr_t** ret_fp) { |
|
98 |
assert(thread != NULL, "just checking"); |
|
99 |
assert(ret_sp != NULL, "just checking"); |
|
100 |
assert(ret_fp != NULL, "just checking"); |
|
101 |
||
102 |
return os::fetch_frame_from_context(uc, ret_sp, ret_fp); |
|
103 |
} |
|
104 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
105 |
ExtendedPC os::fetch_frame_from_context(const void* ucVoid, |
380 | 106 |
intptr_t** ret_sp, |
107 |
intptr_t** ret_fp) { |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
108 |
const ucontext_t* uc = (const ucontext_t*) ucVoid; |
380 | 109 |
ExtendedPC epc; |
110 |
||
111 |
if (uc != NULL) { |
|
112 |
epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); |
|
113 |
if (ret_sp) { |
|
114 |
*ret_sp = os::Linux::ucontext_get_sp(uc); |
|
115 |
} |
|
116 |
if (ret_fp) { |
|
25722
72f566374afc
8050167: linux-sparcv9: hs_err file does not show any stack information
zgu
parents:
24917
diff
changeset
|
117 |
*ret_fp = (intptr_t*)NULL; |
380 | 118 |
} |
119 |
} else { |
|
120 |
// construct empty ExtendedPC for return value checking |
|
121 |
epc = ExtendedPC(NULL); |
|
122 |
if (ret_sp) { |
|
123 |
*ret_sp = (intptr_t*) NULL; |
|
124 |
} |
|
125 |
if (ret_fp) { |
|
126 |
*ret_fp = (intptr_t*) NULL; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
return epc; |
|
131 |
} |
|
132 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
133 |
frame os::fetch_frame_from_context(const void* ucVoid) { |
380 | 134 |
intptr_t* sp; |
25722
72f566374afc
8050167: linux-sparcv9: hs_err file does not show any stack information
zgu
parents:
24917
diff
changeset
|
135 |
ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, NULL); |
72f566374afc
8050167: linux-sparcv9: hs_err file does not show any stack information
zgu
parents:
24917
diff
changeset
|
136 |
return frame(sp, frame::unpatchable, epc.pc()); |
380 | 137 |
} |
138 |
||
139 |
frame os::get_sender_for_C_frame(frame* fr) { |
|
25718
6281d7800e8d
8050165: linux-sparcv9: NMT detail causes assert((intptr_t*)younger_sp[FP->sp_offset_in_saved_window()] == (intptr_t*)((intptr_t)sp - STACK_BIAS)) failed: younger_sp must be valid
zgu
parents:
24917
diff
changeset
|
140 |
return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); |
380 | 141 |
} |
142 |
||
143 |
frame os::current_frame() { |
|
144 |
intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); |
|
145 |
frame myframe(sp, frame::unpatchable, |
|
146 |
CAST_FROM_FN_PTR(address, os::current_frame)); |
|
147 |
if (os::is_first_C_frame(&myframe)) { |
|
148 |
// stack is not walkable |
|
149 |
return frame(NULL, frame::unpatchable, NULL); |
|
150 |
} else { |
|
151 |
return os::get_sender_for_C_frame(&myframe); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
address os::current_stack_pointer() { |
|
156 |
register void *sp __asm__ ("sp"); |
|
157 |
return (address)sp; |
|
158 |
} |
|
159 |
||
160 |
static void current_stack_region(address* bottom, size_t* size) { |
|
161 |
if (os::Linux::is_initial_thread()) { |
|
162 |
// initial thread needs special handling because pthread_getattr_np() |
|
163 |
// may return bogus value. |
|
164 |
*bottom = os::Linux::initial_thread_stack_bottom(); |
|
165 |
*size = os::Linux::initial_thread_stack_size(); |
|
166 |
} else { |
|
167 |
pthread_attr_t attr; |
|
168 |
||
169 |
int rslt = pthread_getattr_np(pthread_self(), &attr); |
|
170 |
||
171 |
// JVM needs to know exact stack location, abort if it fails |
|
172 |
if (rslt != 0) { |
|
173 |
if (rslt == ENOMEM) { |
|
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
15926
diff
changeset
|
174 |
vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); |
380 | 175 |
} else { |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32080
diff
changeset
|
176 |
fatal("pthread_getattr_np failed with errno = %d", rslt); |
380 | 177 |
} |
178 |
} |
|
179 |
||
180 |
if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { |
|
181 |
fatal("Can not locate current stack attributes!"); |
|
182 |
} |
|
183 |
||
184 |
pthread_attr_destroy(&attr); |
|
185 |
} |
|
186 |
assert(os::current_stack_pointer() >= *bottom && |
|
187 |
os::current_stack_pointer() < *bottom + *size, "just checking"); |
|
188 |
} |
|
189 |
||
190 |
address os::current_stack_base() { |
|
191 |
address bottom; |
|
192 |
size_t size; |
|
193 |
current_stack_region(&bottom, &size); |
|
194 |
return bottom + size; |
|
195 |
} |
|
196 |
||
197 |
size_t os::current_stack_size() { |
|
198 |
// stack size includes normal stack and HotSpot guard pages |
|
199 |
address bottom; |
|
200 |
size_t size; |
|
201 |
current_stack_region(&bottom, &size); |
|
202 |
return size; |
|
203 |
} |
|
204 |
||
205 |
char* os::non_memory_address_word() { |
|
206 |
// Must never look like an address returned by reserve_memory, |
|
207 |
// even in its subfields (as defined by the CPU immediate fields, |
|
208 |
// if the CPU splits constants across multiple instructions). |
|
209 |
// On SPARC, 0 != %hi(any real address), because there is no |
|
210 |
// allocation in the first 1Kb of the virtual address space. |
|
211 |
return (char*) 0; |
|
212 |
} |
|
213 |
||
13859
7fe4578493fc
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
11961
diff
changeset
|
214 |
void os::initialize_thread(Thread* thr) {} |
380 | 215 |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
216 |
void os::print_context(outputStream *st, const void *context) { |
380 | 217 |
if (context == NULL) return; |
218 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
219 |
const ucontext_t* uc = (const ucontext_t*)context; |
380 | 220 |
sigcontext* sc = (sigcontext*)context; |
221 |
st->print_cr("Registers:"); |
|
222 |
||
7108 | 223 |
st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT |
224 |
" G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, |
|
225 |
SIG_REGS(sc).u_regs[CON_G1], |
|
226 |
SIG_REGS(sc).u_regs[CON_G2], |
|
227 |
SIG_REGS(sc).u_regs[CON_G3], |
|
228 |
SIG_REGS(sc).u_regs[CON_G4]); |
|
229 |
st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT |
|
24917 | 230 |
" G7=" INTPTR_FORMAT " Y=0x%x", |
7108 | 231 |
SIG_REGS(sc).u_regs[CON_G5], |
232 |
SIG_REGS(sc).u_regs[CON_G6], |
|
233 |
SIG_REGS(sc).u_regs[CON_G7], |
|
234 |
SIG_REGS(sc).y); |
|
380 | 235 |
st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT |
236 |
" O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, |
|
237 |
SIG_REGS(sc).u_regs[CON_O0], |
|
238 |
SIG_REGS(sc).u_regs[CON_O1], |
|
239 |
SIG_REGS(sc).u_regs[CON_O2], |
|
240 |
SIG_REGS(sc).u_regs[CON_O3]); |
|
241 |
st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT |
|
242 |
" O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, |
|
243 |
SIG_REGS(sc).u_regs[CON_O4], |
|
244 |
SIG_REGS(sc).u_regs[CON_O5], |
|
245 |
SIG_REGS(sc).u_regs[CON_O6], |
|
246 |
SIG_REGS(sc).u_regs[CON_O7]); |
|
247 |
||
7108 | 248 |
|
249 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); |
|
250 |
st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT |
|
251 |
" L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, |
|
252 |
sp[L0->sp_offset_in_saved_window()], |
|
253 |
sp[L1->sp_offset_in_saved_window()], |
|
254 |
sp[L2->sp_offset_in_saved_window()], |
|
255 |
sp[L3->sp_offset_in_saved_window()]); |
|
256 |
st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT |
|
257 |
" L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, |
|
258 |
sp[L4->sp_offset_in_saved_window()], |
|
259 |
sp[L5->sp_offset_in_saved_window()], |
|
260 |
sp[L6->sp_offset_in_saved_window()], |
|
261 |
sp[L7->sp_offset_in_saved_window()]); |
|
262 |
st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT |
|
263 |
" I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, |
|
264 |
sp[I0->sp_offset_in_saved_window()], |
|
265 |
sp[I1->sp_offset_in_saved_window()], |
|
266 |
sp[I2->sp_offset_in_saved_window()], |
|
267 |
sp[I3->sp_offset_in_saved_window()]); |
|
268 |
st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT |
|
269 |
" I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, |
|
270 |
sp[I4->sp_offset_in_saved_window()], |
|
271 |
sp[I5->sp_offset_in_saved_window()], |
|
272 |
sp[I6->sp_offset_in_saved_window()], |
|
273 |
sp[I7->sp_offset_in_saved_window()]); |
|
380 | 274 |
|
275 |
st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, |
|
276 |
SIG_PC(sc), |
|
277 |
SIG_NPC(sc)); |
|
278 |
st->cr(); |
|
279 |
st->cr(); |
|
280 |
||
24917 | 281 |
st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", p2i(sp)); |
380 | 282 |
print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); |
283 |
st->cr(); |
|
284 |
||
285 |
// Note: it may be unsafe to inspect memory near pc. For example, pc may |
|
286 |
// point to garbage if entry point in an nmethod is corrupted. Leave |
|
287 |
// this at the end, and hope for the best. |
|
288 |
address pc = os::Linux::ucontext_get_pc(uc); |
|
24917 | 289 |
st->print_cr("Instructions: (pc=" INTPTR_FORMAT ")", p2i(pc)); |
7108 | 290 |
print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); |
291 |
} |
|
292 |
||
293 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
294 |
void os::print_register_info(outputStream *st, const void *context) { |
7108 | 295 |
if (context == NULL) return; |
296 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
297 |
const ucontext_t *uc = (const ucontext_t*)context; |
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
298 |
const sigcontext* sc = (const sigcontext*)context; |
7108 | 299 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); |
300 |
||
301 |
st->print_cr("Register to memory mapping:"); |
|
302 |
st->cr(); |
|
303 |
||
304 |
// this is only for the "general purpose" registers |
|
24327 | 305 |
st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); |
306 |
st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); |
|
307 |
st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); |
|
308 |
st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); |
|
309 |
st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); |
|
310 |
st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); |
|
311 |
st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); |
|
7108 | 312 |
st->cr(); |
313 |
||
24327 | 314 |
st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); |
315 |
st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); |
|
316 |
st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); |
|
317 |
st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); |
|
318 |
st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); |
|
319 |
st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); |
|
320 |
st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); |
|
321 |
st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); |
|
7108 | 322 |
st->cr(); |
323 |
||
324 |
st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); |
|
325 |
st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); |
|
326 |
st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); |
|
327 |
st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); |
|
328 |
st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); |
|
329 |
st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); |
|
330 |
st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); |
|
331 |
st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); |
|
332 |
st->cr(); |
|
333 |
||
334 |
st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); |
|
335 |
st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); |
|
336 |
st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); |
|
337 |
st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); |
|
338 |
st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); |
|
339 |
st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); |
|
340 |
st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); |
|
341 |
st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); |
|
342 |
st->cr(); |
|
380 | 343 |
} |
344 |
||
345 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
346 |
address os::Linux::ucontext_get_pc(const ucontext_t* uc) { |
380 | 347 |
return (address) SIG_PC((sigcontext*)uc); |
348 |
} |
|
349 |
||
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
350 |
void os::Linux::ucontext_set_pc(ucontext_t* uc, address pc) { |
34667 | 351 |
sigcontext* ctx = (sigcontext*) uc; |
352 |
SIG_PC(ctx) = (intptr_t)pc; |
|
353 |
SIG_NPC(ctx) = (intptr_t)(pc+4); |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
354 |
} |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
355 |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
356 |
intptr_t* os::Linux::ucontext_get_sp(const ucontext_t *uc) { |
380 | 357 |
return (intptr_t*) |
358 |
((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); |
|
359 |
} |
|
360 |
||
361 |
// not used on Sparc |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
362 |
intptr_t* os::Linux::ucontext_get_fp(const ucontext_t *uc) { |
380 | 363 |
ShouldNotReachHere(); |
364 |
return NULL; |
|
365 |
} |
|
366 |
||
367 |
// Utility functions |
|
368 |
||
369 |
inline static bool checkPrefetch(sigcontext* uc, address pc) { |
|
18740 | 370 |
if (StubRoutines::is_safefetch_fault(pc)) { |
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
371 |
os::Linux::ucontext_set_pc((ucontext_t*)uc, StubRoutines::continuation_for_safefetch_fault(pc)); |
380 | 372 |
return true; |
373 |
} |
|
374 |
return false; |
|
375 |
} |
|
376 |
||
377 |
inline static bool checkOverflow(sigcontext* uc, |
|
378 |
address pc, |
|
379 |
address addr, |
|
380 |
JavaThread* thread, |
|
381 |
address* stub) { |
|
382 |
// check if fault address is within thread stack |
|
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
383 |
if (thread->on_local_stack(addr)) { |
380 | 384 |
// stack overflow |
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
385 |
if (thread->in_stack_yellow_reserved_zone(addr)) { |
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
386 |
thread->disable_stack_yellow_reserved_zone(); |
380 | 387 |
if (thread->thread_state() == _thread_in_Java) { |
388 |
// Throw a stack overflow exception. Guard pages will be reenabled |
|
389 |
// while unwinding the stack. |
|
390 |
*stub = |
|
391 |
SharedRuntime::continuation_for_implicit_exception(thread, |
|
392 |
pc, |
|
393 |
SharedRuntime::STACK_OVERFLOW); |
|
394 |
} else { |
|
395 |
// Thread was in the vm or native code. Return and try to finish. |
|
396 |
return true; |
|
397 |
} |
|
398 |
} else if (thread->in_stack_red_zone(addr)) { |
|
399 |
// Fatal red zone violation. Disable the guard pages and fall through |
|
400 |
// to handle_unexpected_exception way down below. |
|
401 |
thread->disable_stack_red_zone(); |
|
402 |
tty->print_raw_cr("An irrecoverable stack overflow has occurred."); |
|
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
403 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
404 |
// This is a likely cause, but hard to verify. Let's just print |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
405 |
// it as a hint. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
406 |
tty->print_raw_cr("Please check if any of your loaded .so files has " |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
407 |
"enabled executable stack (see man page execstack(8))"); |
380 | 408 |
} else { |
409 |
// Accessing stack address below sp may cause SEGV if current |
|
410 |
// thread has MAP_GROWSDOWN stack. This should only happen when |
|
411 |
// current thread was created by user code with MAP_GROWSDOWN flag |
|
412 |
// and then attached to VM. See notes in os_linux.cpp. |
|
413 |
if (thread->osthread()->expanding_stack() == 0) { |
|
414 |
thread->osthread()->set_expanding_stack(); |
|
415 |
if (os::Linux::manually_expand_stack(thread, addr)) { |
|
416 |
thread->osthread()->clear_expanding_stack(); |
|
417 |
return true; |
|
418 |
} |
|
419 |
thread->osthread()->clear_expanding_stack(); |
|
420 |
} else { |
|
421 |
fatal("recursive segv. expanding stack."); |
|
422 |
} |
|
423 |
} |
|
424 |
} |
|
425 |
return false; |
|
426 |
} |
|
427 |
||
428 |
inline static bool checkPollingPage(address pc, address fault, address* stub) { |
|
429 |
if (fault == os::get_polling_page()) { |
|
430 |
*stub = SharedRuntime::get_poll_stub(pc); |
|
431 |
return true; |
|
432 |
} |
|
433 |
return false; |
|
434 |
} |
|
435 |
||
436 |
inline static bool checkByteBuffer(address pc, address* stub) { |
|
437 |
// BugId 4454115: A read from a MappedByteBuffer can fault |
|
438 |
// here if the underlying file has been truncated. |
|
439 |
// Do not crash the VM in such a case. |
|
440 |
CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
|
441 |
nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; |
|
442 |
if (nm != NULL && nm->has_unsafe_access()) { |
|
443 |
*stub = StubRoutines::handler_for_unsafe_access(); |
|
444 |
return true; |
|
445 |
} |
|
446 |
return false; |
|
447 |
} |
|
448 |
||
449 |
inline static bool checkVerifyOops(address pc, address fault, address* stub) { |
|
450 |
if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] |
|
451 |
&& pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { |
|
452 |
*stub = MacroAssembler::_verify_oop_implicit_branch[2]; |
|
453 |
warning("fixed up memory fault in +VerifyOops at address " |
|
24917 | 454 |
INTPTR_FORMAT, p2i(fault)); |
380 | 455 |
return true; |
456 |
} |
|
457 |
return false; |
|
458 |
} |
|
459 |
||
460 |
inline static bool checkFPFault(address pc, int code, |
|
461 |
JavaThread* thread, address* stub) { |
|
462 |
if (code == FPE_INTDIV || code == FPE_FLTDIV) { |
|
463 |
*stub = |
|
464 |
SharedRuntime:: |
|
465 |
continuation_for_implicit_exception(thread, |
|
466 |
pc, |
|
467 |
SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); |
|
468 |
return true; |
|
469 |
} |
|
470 |
return false; |
|
471 |
} |
|
472 |
||
473 |
inline static bool checkNullPointer(address pc, intptr_t fault, |
|
474 |
JavaThread* thread, address* stub) { |
|
475 |
if (!MacroAssembler::needs_explicit_null_check(fault)) { |
|
476 |
// Determination of interpreter/vtable stub/compiled code null |
|
477 |
// exception |
|
478 |
*stub = |
|
479 |
SharedRuntime:: |
|
480 |
continuation_for_implicit_exception(thread, pc, |
|
481 |
SharedRuntime::IMPLICIT_NULL); |
|
482 |
return true; |
|
483 |
} |
|
484 |
return false; |
|
485 |
} |
|
486 |
||
487 |
inline static bool checkFastJNIAccess(address pc, address* stub) { |
|
488 |
address addr = JNI_FastGetField::find_slowcase_pc(pc); |
|
489 |
if (addr != (address)-1) { |
|
490 |
*stub = addr; |
|
491 |
return true; |
|
492 |
} |
|
493 |
return false; |
|
494 |
} |
|
495 |
||
496 |
inline static bool checkSerializePage(JavaThread* thread, address addr) { |
|
497 |
return os::is_memory_serialize_page(thread, addr); |
|
498 |
} |
|
499 |
||
500 |
inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { |
|
501 |
if (nativeInstruction_at(*pc)->is_zombie()) { |
|
502 |
// zombie method (ld [%g0],%o7 instruction) |
|
503 |
*stub = SharedRuntime::get_handle_wrong_method_stub(); |
|
504 |
||
505 |
// At the stub it needs to look like a call from the caller of this |
|
506 |
// method (not a call from the segv site). |
|
507 |
*pc = (address)SIG_REGS(uc).u_regs[CON_O7]; |
|
508 |
return true; |
|
509 |
} |
|
510 |
return false; |
|
511 |
} |
|
512 |
||
513 |
inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { |
|
514 |
#ifdef COMPILER2 |
|
515 |
if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { |
|
516 |
#ifdef ASSERT |
|
517 |
#ifdef TIERED |
|
24327 | 518 |
CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); |
380 | 519 |
assert(cb->is_compiled_by_c2(), "Wrong compiler"); |
520 |
#endif // TIERED |
|
521 |
#endif // ASSERT |
|
522 |
// Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. |
|
523 |
*stub = SharedRuntime::get_ic_miss_stub(); |
|
524 |
// At the stub it needs to look like a call from the caller of this |
|
525 |
// method (not a call from the segv site). |
|
526 |
*pc = (address)SIG_REGS(uc).u_regs[CON_O7]; |
|
527 |
return true; |
|
528 |
} |
|
529 |
#endif // COMPILER2 |
|
530 |
return false; |
|
531 |
} |
|
532 |
||
8106 | 533 |
extern "C" JNIEXPORT int |
380 | 534 |
JVM_handle_linux_signal(int sig, |
535 |
siginfo_t* info, |
|
536 |
void* ucVoid, |
|
537 |
int abort_if_unrecognized) { |
|
538 |
// in fact this isn't ucontext_t* at all, but struct sigcontext* |
|
539 |
// but Linux porting layer uses ucontext_t, so to minimize code change |
|
540 |
// we cast as needed |
|
541 |
ucontext_t* ucFake = (ucontext_t*) ucVoid; |
|
542 |
sigcontext* uc = (sigcontext*)ucVoid; |
|
543 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33105
diff
changeset
|
544 |
Thread* t = Thread::current_or_null_safe(); |
380 | 545 |
|
18943 | 546 |
// Must do this before SignalHandlerMark, if crash protection installed we will longjmp away |
547 |
// (no destructors can be run) |
|
548 |
os::WatcherThreadCrashProtection::check_crash_protection(sig, t); |
|
549 |
||
380 | 550 |
SignalHandlerMark shm(t); |
551 |
||
552 |
// Note: it's not uncommon that JNI code uses signal/sigset to install |
|
553 |
// then restore certain signal handler (e.g. to temporarily block SIGPIPE, |
|
554 |
// or have a SIGILL handler when detecting CPU type). When that happens, |
|
555 |
// JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To |
|
556 |
// avoid unnecessary crash when libjsig is not preloaded, try handle signals |
|
557 |
// that do not require siginfo/ucontext first. |
|
558 |
||
559 |
if (sig == SIGPIPE || sig == SIGXFSZ) { |
|
560 |
// allow chained handler to go first |
|
561 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
562 |
return true; |
|
563 |
} else { |
|
564 |
if (PrintMiscellaneous && (WizardMode || Verbose)) { |
|
565 |
char buf[64]; |
|
566 |
warning("Ignoring %s - see bugs 4229104 or 646499219", |
|
567 |
os::exception_name(sig, buf, sizeof(buf))); |
|
568 |
} |
|
569 |
return true; |
|
570 |
} |
|
571 |
} |
|
572 |
||
573 |
JavaThread* thread = NULL; |
|
574 |
VMThread* vmthread = NULL; |
|
575 |
if (os::Linux::signal_handlers_are_installed) { |
|
576 |
if (t != NULL ){ |
|
577 |
if(t->is_Java_thread()) { |
|
578 |
thread = (JavaThread*)t; |
|
579 |
} |
|
580 |
else if(t->is_VM_thread()){ |
|
581 |
vmthread = (VMThread *)t; |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
585 |
||
586 |
// decide if this trap can be handled by a stub |
|
587 |
address stub = NULL; |
|
588 |
address pc = NULL; |
|
589 |
address npc = NULL; |
|
590 |
||
591 |
//%note os_trap_1 |
|
592 |
if (info != NULL && uc != NULL && thread != NULL) { |
|
593 |
pc = address(SIG_PC(uc)); |
|
594 |
npc = address(SIG_NPC(uc)); |
|
595 |
||
596 |
// Check to see if we caught the safepoint code in the |
|
597 |
// process of write protecting the memory serialization page. |
|
598 |
// It write enables the page immediately after protecting it |
|
599 |
// so we can just return to retry the write. |
|
600 |
if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { |
|
601 |
// Block current thread until the memory serialize page permission restored. |
|
602 |
os::block_on_serialize_page_trap(); |
|
603 |
return 1; |
|
604 |
} |
|
605 |
||
606 |
if (checkPrefetch(uc, pc)) { |
|
607 |
return 1; |
|
608 |
} |
|
609 |
||
610 |
// Handle ALL stack overflow variations here |
|
611 |
if (sig == SIGSEGV) { |
|
612 |
if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { |
|
613 |
return 1; |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
if (sig == SIGBUS && |
|
618 |
thread->thread_state() == _thread_in_vm && |
|
619 |
thread->doing_unsafe_access()) { |
|
620 |
stub = StubRoutines::handler_for_unsafe_access(); |
|
621 |
} |
|
622 |
||
623 |
if (thread->thread_state() == _thread_in_Java) { |
|
624 |
do { |
|
625 |
// Java thread running in Java code => find exception handler if any |
|
626 |
// a fault inside compiled code, the interpreter, or a stub |
|
627 |
||
628 |
if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { |
|
629 |
break; |
|
630 |
} |
|
631 |
||
632 |
if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { |
|
633 |
break; |
|
634 |
} |
|
635 |
||
636 |
if ((sig == SIGSEGV || sig == SIGBUS) && |
|
637 |
checkVerifyOops(pc, (address)info->si_addr, &stub)) { |
|
638 |
break; |
|
639 |
} |
|
640 |
||
641 |
if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { |
|
642 |
break; |
|
643 |
} |
|
644 |
||
645 |
if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { |
|
646 |
break; |
|
647 |
} |
|
648 |
||
649 |
if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { |
|
650 |
break; |
|
651 |
} |
|
652 |
||
653 |
if ((sig == SIGSEGV) && |
|
654 |
checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { |
|
655 |
break; |
|
656 |
} |
|
657 |
} while (0); |
|
658 |
||
659 |
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in |
|
660 |
// and the heap gets shrunk before the field access. |
|
661 |
if ((sig == SIGSEGV) || (sig == SIGBUS)) { |
|
662 |
checkFastJNIAccess(pc, &stub); |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
if (stub != NULL) { |
|
667 |
// save all thread context in case we need to restore it |
|
668 |
thread->set_saved_exception_pc(pc); |
|
669 |
thread->set_saved_exception_npc(npc); |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
670 |
os::Linux::ucontext_set_pc((ucontext_t*)uc, stub); |
380 | 671 |
return true; |
672 |
} |
|
673 |
} |
|
674 |
||
675 |
// signal-chaining |
|
676 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
677 |
return true; |
|
678 |
} |
|
679 |
||
680 |
if (!abort_if_unrecognized) { |
|
681 |
// caller wants another chance, so give it to him |
|
682 |
return false; |
|
683 |
} |
|
684 |
||
685 |
if (pc == NULL && uc != NULL) { |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
686 |
pc = os::Linux::ucontext_get_pc((const ucontext_t*)uc); |
380 | 687 |
} |
688 |
||
689 |
// unmask current signal |
|
690 |
sigset_t newset; |
|
691 |
sigemptyset(&newset); |
|
692 |
sigaddset(&newset, sig); |
|
693 |
sigprocmask(SIG_UNBLOCK, &newset, NULL); |
|
694 |
||
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32080
diff
changeset
|
695 |
VMError::report_and_die(t, sig, pc, info, ucVoid); |
380 | 696 |
|
697 |
ShouldNotReachHere(); |
|
34667 | 698 |
return false; |
380 | 699 |
} |
700 |
||
701 |
void os::Linux::init_thread_fpu_state(void) { |
|
702 |
// Nothing to do |
|
703 |
} |
|
704 |
||
705 |
int os::Linux::get_fpu_control_word() { |
|
706 |
return 0; |
|
707 |
} |
|
708 |
||
709 |
void os::Linux::set_fpu_control_word(int fpu) { |
|
710 |
// nothing |
|
711 |
} |
|
712 |
||
713 |
bool os::is_allocatable(size_t bytes) { |
|
714 |
#ifdef _LP64 |
|
715 |
return true; |
|
716 |
#else |
|
717 |
if (bytes < 2 * G) { |
|
718 |
return true; |
|
719 |
} |
|
720 |
||
721 |
char* addr = reserve_memory(bytes, NULL); |
|
722 |
||
723 |
if (addr != NULL) { |
|
724 |
release_memory(addr, bytes); |
|
725 |
} |
|
726 |
||
727 |
return addr != NULL; |
|
728 |
#endif // _LP64 |
|
729 |
} |
|
730 |
||
731 |
/////////////////////////////////////////////////////////////////////////////// |
|
732 |
// thread stack |
|
733 |
||
734 |
size_t os::Linux::min_stack_allowed = 128 * K; |
|
735 |
||
736 |
// return default stack size for thr_type |
|
737 |
size_t os::Linux::default_stack_size(os::ThreadType thr_type) { |
|
738 |
// default stack size (compiler thread needs larger stack) |
|
739 |
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); |
|
740 |
return s; |
|
741 |
} |
|
742 |
||
743 |
size_t os::Linux::default_guard_size(os::ThreadType thr_type) { |
|
744 |
// Creating guard page is very expensive. Java thread has HotSpot |
|
745 |
// guard page, only enable glibc guard page for non-Java threads. |
|
746 |
return (thr_type == java_thread ? 0 : page_size()); |
|
747 |
} |
|
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
748 |
|
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
749 |
#ifndef PRODUCT |
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
750 |
void os::verify_stack_alignment() { |
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
751 |
} |
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
752 |
#endif |
26576
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
753 |
|
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
754 |
int os::extra_bang_size_in_bytes() { |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
755 |
// SPARC does not require the additional stack bang. |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
756 |
return 0; |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
757 |
} |