author | vromero |
Mon, 08 Oct 2018 06:52:41 -0700 | |
changeset 52038 | 957de5be48bc |
parent 49813 | 97984a163b55 |
child 52302 | 912b79d983d9 |
permissions | -rw-r--r-- |
380 | 1 |
/* |
49653
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, 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 |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
26 |
#include "jvm.h" |
14631
526804361522
8003250: SPARC: move MacroAssembler into separate file
twisti
parents:
13963
diff
changeset
|
27 |
#include "asm/macroAssembler.hpp" |
7397 | 28 |
#include "classfile/classLoader.hpp" |
29 |
#include "classfile/systemDictionary.hpp" |
|
30 |
#include "classfile/vmSymbols.hpp" |
|
34667 | 31 |
#include "code/codeCache.hpp" |
7397 | 32 |
#include "code/icBuffer.hpp" |
33 |
#include "code/vtableStubs.hpp" |
|
34 |
#include "interpreter/interpreter.hpp" |
|
35 |
#include "memory/allocation.inline.hpp" |
|
36 |
#include "nativeInst_sparc.hpp" |
|
37 |
#include "os_share_linux.hpp" |
|
38 |
#include "prims/jniFastGetField.hpp" |
|
39 |
#include "prims/jvm_misc.hpp" |
|
40 |
#include "runtime/arguments.hpp" |
|
41 |
#include "runtime/extendedPC.hpp" |
|
42 |
#include "runtime/frame.inline.hpp" |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47765
diff
changeset
|
43 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 44 |
#include "runtime/java.hpp" |
45 |
#include "runtime/javaCalls.hpp" |
|
46 |
#include "runtime/mutexLocker.hpp" |
|
47 |
#include "runtime/osThread.hpp" |
|
48 |
#include "runtime/sharedRuntime.hpp" |
|
49 |
#include "runtime/stubRoutines.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13963
diff
changeset
|
50 |
#include "runtime/thread.inline.hpp" |
7397 | 51 |
#include "runtime/timer.hpp" |
49653
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
52 |
#include "utilities/debug.hpp" |
7397 | 53 |
#include "utilities/events.hpp" |
54 |
#include "utilities/vmError.hpp" |
|
380 | 55 |
|
56 |
// Linux/Sparc has rather obscure naming of registers in sigcontext |
|
57 |
// different between 32 and 64 bits |
|
58 |
#define SIG_PC(x) ((x)->sigc_regs.tpc) |
|
59 |
#define SIG_NPC(x) ((x)->sigc_regs.tnpc) |
|
60 |
#define SIG_REGS(x) ((x)->sigc_regs) |
|
61 |
||
62 |
// those are to reference registers in sigcontext |
|
63 |
enum { |
|
64 |
CON_G0 = 0, |
|
65 |
CON_G1, |
|
66 |
CON_G2, |
|
67 |
CON_G3, |
|
68 |
CON_G4, |
|
69 |
CON_G5, |
|
70 |
CON_G6, |
|
71 |
CON_G7, |
|
72 |
CON_O0, |
|
73 |
CON_O1, |
|
74 |
CON_O2, |
|
75 |
CON_O3, |
|
76 |
CON_O4, |
|
77 |
CON_O5, |
|
78 |
CON_O6, |
|
79 |
CON_O7, |
|
80 |
}; |
|
81 |
||
82 |
// For Forte Analyzer AsyncGetCallTrace profiling support - thread is |
|
83 |
// currently interrupted by SIGPROF. |
|
84 |
// os::Solaris::fetch_frame_from_ucontext() tries to skip nested |
|
85 |
// signal frames. Currently we don't do that on Linux, so it's the |
|
86 |
// same as os::fetch_frame_from_context(). |
|
87 |
ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
88 |
const ucontext_t* uc, |
380 | 89 |
intptr_t** ret_sp, |
90 |
intptr_t** ret_fp) { |
|
91 |
assert(thread != NULL, "just checking"); |
|
92 |
assert(ret_sp != NULL, "just checking"); |
|
93 |
assert(ret_fp != NULL, "just checking"); |
|
94 |
||
95 |
return os::fetch_frame_from_context(uc, ret_sp, ret_fp); |
|
96 |
} |
|
97 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
98 |
ExtendedPC os::fetch_frame_from_context(const void* ucVoid, |
380 | 99 |
intptr_t** ret_sp, |
100 |
intptr_t** ret_fp) { |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
101 |
const ucontext_t* uc = (const ucontext_t*) ucVoid; |
380 | 102 |
ExtendedPC epc; |
103 |
||
104 |
if (uc != NULL) { |
|
105 |
epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); |
|
106 |
if (ret_sp) { |
|
107 |
*ret_sp = os::Linux::ucontext_get_sp(uc); |
|
108 |
} |
|
109 |
if (ret_fp) { |
|
25722
72f566374afc
8050167: linux-sparcv9: hs_err file does not show any stack information
zgu
parents:
24917
diff
changeset
|
110 |
*ret_fp = (intptr_t*)NULL; |
380 | 111 |
} |
112 |
} else { |
|
113 |
// construct empty ExtendedPC for return value checking |
|
114 |
epc = ExtendedPC(NULL); |
|
115 |
if (ret_sp) { |
|
116 |
*ret_sp = (intptr_t*) NULL; |
|
117 |
} |
|
118 |
if (ret_fp) { |
|
119 |
*ret_fp = (intptr_t*) NULL; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
return epc; |
|
124 |
} |
|
125 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
126 |
frame os::fetch_frame_from_context(const void* ucVoid) { |
380 | 127 |
intptr_t* sp; |
25722
72f566374afc
8050167: linux-sparcv9: hs_err file does not show any stack information
zgu
parents:
24917
diff
changeset
|
128 |
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
|
129 |
return frame(sp, frame::unpatchable, epc.pc()); |
380 | 130 |
} |
131 |
||
132 |
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
|
133 |
return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); |
380 | 134 |
} |
135 |
||
136 |
frame os::current_frame() { |
|
137 |
intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); |
|
138 |
frame myframe(sp, frame::unpatchable, |
|
139 |
CAST_FROM_FN_PTR(address, os::current_frame)); |
|
140 |
if (os::is_first_C_frame(&myframe)) { |
|
141 |
// stack is not walkable |
|
142 |
return frame(NULL, frame::unpatchable, NULL); |
|
143 |
} else { |
|
144 |
return os::get_sender_for_C_frame(&myframe); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
address os::current_stack_pointer() { |
|
149 |
register void *sp __asm__ ("sp"); |
|
150 |
return (address)sp; |
|
151 |
} |
|
152 |
||
153 |
char* os::non_memory_address_word() { |
|
154 |
// Must never look like an address returned by reserve_memory, |
|
155 |
// even in its subfields (as defined by the CPU immediate fields, |
|
156 |
// if the CPU splits constants across multiple instructions). |
|
157 |
// On SPARC, 0 != %hi(any real address), because there is no |
|
158 |
// allocation in the first 1Kb of the virtual address space. |
|
159 |
return (char*) 0; |
|
160 |
} |
|
161 |
||
13859
7fe4578493fc
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
11961
diff
changeset
|
162 |
void os::initialize_thread(Thread* thr) {} |
380 | 163 |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
164 |
void os::print_context(outputStream *st, const void *context) { |
380 | 165 |
if (context == NULL) return; |
166 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
167 |
const ucontext_t* uc = (const ucontext_t*)context; |
380 | 168 |
sigcontext* sc = (sigcontext*)context; |
169 |
st->print_cr("Registers:"); |
|
170 |
||
7108 | 171 |
st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT |
172 |
" G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, |
|
173 |
SIG_REGS(sc).u_regs[CON_G1], |
|
174 |
SIG_REGS(sc).u_regs[CON_G2], |
|
175 |
SIG_REGS(sc).u_regs[CON_G3], |
|
176 |
SIG_REGS(sc).u_regs[CON_G4]); |
|
177 |
st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT |
|
24917 | 178 |
" G7=" INTPTR_FORMAT " Y=0x%x", |
7108 | 179 |
SIG_REGS(sc).u_regs[CON_G5], |
180 |
SIG_REGS(sc).u_regs[CON_G6], |
|
181 |
SIG_REGS(sc).u_regs[CON_G7], |
|
182 |
SIG_REGS(sc).y); |
|
380 | 183 |
st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT |
184 |
" O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, |
|
185 |
SIG_REGS(sc).u_regs[CON_O0], |
|
186 |
SIG_REGS(sc).u_regs[CON_O1], |
|
187 |
SIG_REGS(sc).u_regs[CON_O2], |
|
188 |
SIG_REGS(sc).u_regs[CON_O3]); |
|
189 |
st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT |
|
190 |
" O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, |
|
191 |
SIG_REGS(sc).u_regs[CON_O4], |
|
192 |
SIG_REGS(sc).u_regs[CON_O5], |
|
193 |
SIG_REGS(sc).u_regs[CON_O6], |
|
194 |
SIG_REGS(sc).u_regs[CON_O7]); |
|
195 |
||
7108 | 196 |
|
197 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); |
|
198 |
st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT |
|
199 |
" L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, |
|
200 |
sp[L0->sp_offset_in_saved_window()], |
|
201 |
sp[L1->sp_offset_in_saved_window()], |
|
202 |
sp[L2->sp_offset_in_saved_window()], |
|
203 |
sp[L3->sp_offset_in_saved_window()]); |
|
204 |
st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT |
|
205 |
" L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, |
|
206 |
sp[L4->sp_offset_in_saved_window()], |
|
207 |
sp[L5->sp_offset_in_saved_window()], |
|
208 |
sp[L6->sp_offset_in_saved_window()], |
|
209 |
sp[L7->sp_offset_in_saved_window()]); |
|
210 |
st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT |
|
211 |
" I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, |
|
212 |
sp[I0->sp_offset_in_saved_window()], |
|
213 |
sp[I1->sp_offset_in_saved_window()], |
|
214 |
sp[I2->sp_offset_in_saved_window()], |
|
215 |
sp[I3->sp_offset_in_saved_window()]); |
|
216 |
st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT |
|
217 |
" I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, |
|
218 |
sp[I4->sp_offset_in_saved_window()], |
|
219 |
sp[I5->sp_offset_in_saved_window()], |
|
220 |
sp[I6->sp_offset_in_saved_window()], |
|
221 |
sp[I7->sp_offset_in_saved_window()]); |
|
380 | 222 |
|
223 |
st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, |
|
224 |
SIG_PC(sc), |
|
225 |
SIG_NPC(sc)); |
|
226 |
st->cr(); |
|
227 |
st->cr(); |
|
228 |
||
24917 | 229 |
st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", p2i(sp)); |
380 | 230 |
print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); |
231 |
st->cr(); |
|
232 |
||
233 |
// Note: it may be unsafe to inspect memory near pc. For example, pc may |
|
234 |
// point to garbage if entry point in an nmethod is corrupted. Leave |
|
235 |
// this at the end, and hope for the best. |
|
236 |
address pc = os::Linux::ucontext_get_pc(uc); |
|
24917 | 237 |
st->print_cr("Instructions: (pc=" INTPTR_FORMAT ")", p2i(pc)); |
7108 | 238 |
print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); |
239 |
} |
|
240 |
||
241 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
242 |
void os::print_register_info(outputStream *st, const void *context) { |
7108 | 243 |
if (context == NULL) return; |
244 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
245 |
const ucontext_t *uc = (const ucontext_t*)context; |
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
246 |
const sigcontext* sc = (const sigcontext*)context; |
7108 | 247 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); |
248 |
||
249 |
st->print_cr("Register to memory mapping:"); |
|
250 |
st->cr(); |
|
251 |
||
252 |
// this is only for the "general purpose" registers |
|
24327 | 253 |
st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); |
254 |
st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); |
|
255 |
st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); |
|
256 |
st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); |
|
257 |
st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); |
|
258 |
st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); |
|
259 |
st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); |
|
7108 | 260 |
st->cr(); |
261 |
||
24327 | 262 |
st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); |
263 |
st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); |
|
264 |
st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); |
|
265 |
st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); |
|
266 |
st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); |
|
267 |
st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); |
|
268 |
st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); |
|
269 |
st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); |
|
7108 | 270 |
st->cr(); |
271 |
||
272 |
st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); |
|
273 |
st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); |
|
274 |
st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); |
|
275 |
st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); |
|
276 |
st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); |
|
277 |
st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); |
|
278 |
st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); |
|
279 |
st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); |
|
280 |
st->cr(); |
|
281 |
||
282 |
st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); |
|
283 |
st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); |
|
284 |
st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); |
|
285 |
st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); |
|
286 |
st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); |
|
287 |
st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); |
|
288 |
st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); |
|
289 |
st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); |
|
290 |
st->cr(); |
|
380 | 291 |
} |
292 |
||
293 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
294 |
address os::Linux::ucontext_get_pc(const ucontext_t* uc) { |
380 | 295 |
return (address) SIG_PC((sigcontext*)uc); |
296 |
} |
|
297 |
||
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
298 |
void os::Linux::ucontext_set_pc(ucontext_t* uc, address pc) { |
34667 | 299 |
sigcontext* ctx = (sigcontext*) uc; |
300 |
SIG_PC(ctx) = (intptr_t)pc; |
|
301 |
SIG_NPC(ctx) = (intptr_t)(pc+4); |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
302 |
} |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
303 |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
304 |
intptr_t* os::Linux::ucontext_get_sp(const ucontext_t *uc) { |
380 | 305 |
return (intptr_t*) |
306 |
((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); |
|
307 |
} |
|
308 |
||
309 |
// not used on Sparc |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
310 |
intptr_t* os::Linux::ucontext_get_fp(const ucontext_t *uc) { |
380 | 311 |
ShouldNotReachHere(); |
312 |
return NULL; |
|
313 |
} |
|
314 |
||
315 |
// Utility functions |
|
316 |
||
317 |
inline static bool checkPrefetch(sigcontext* uc, address pc) { |
|
18740 | 318 |
if (StubRoutines::is_safefetch_fault(pc)) { |
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
319 |
os::Linux::ucontext_set_pc((ucontext_t*)uc, StubRoutines::continuation_for_safefetch_fault(pc)); |
380 | 320 |
return true; |
321 |
} |
|
322 |
return false; |
|
323 |
} |
|
324 |
||
325 |
inline static bool checkOverflow(sigcontext* uc, |
|
326 |
address pc, |
|
327 |
address addr, |
|
328 |
JavaThread* thread, |
|
329 |
address* stub) { |
|
330 |
// check if fault address is within thread stack |
|
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
331 |
if (thread->on_local_stack(addr)) { |
380 | 332 |
// stack overflow |
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
333 |
if (thread->in_stack_yellow_reserved_zone(addr)) { |
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
334 |
thread->disable_stack_yellow_reserved_zone(); |
380 | 335 |
if (thread->thread_state() == _thread_in_Java) { |
336 |
// Throw a stack overflow exception. Guard pages will be reenabled |
|
337 |
// while unwinding the stack. |
|
338 |
*stub = |
|
339 |
SharedRuntime::continuation_for_implicit_exception(thread, |
|
340 |
pc, |
|
341 |
SharedRuntime::STACK_OVERFLOW); |
|
342 |
} else { |
|
343 |
// Thread was in the vm or native code. Return and try to finish. |
|
344 |
return true; |
|
345 |
} |
|
346 |
} else if (thread->in_stack_red_zone(addr)) { |
|
347 |
// Fatal red zone violation. Disable the guard pages and fall through |
|
348 |
// to handle_unexpected_exception way down below. |
|
349 |
thread->disable_stack_red_zone(); |
|
350 |
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
|
351 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
14633
diff
changeset
|
352 |
// 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
|
353 |
// 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
|
354 |
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
|
355 |
"enabled executable stack (see man page execstack(8))"); |
380 | 356 |
} else { |
357 |
// Accessing stack address below sp may cause SEGV if current |
|
358 |
// thread has MAP_GROWSDOWN stack. This should only happen when |
|
359 |
// current thread was created by user code with MAP_GROWSDOWN flag |
|
360 |
// and then attached to VM. See notes in os_linux.cpp. |
|
361 |
if (thread->osthread()->expanding_stack() == 0) { |
|
362 |
thread->osthread()->set_expanding_stack(); |
|
363 |
if (os::Linux::manually_expand_stack(thread, addr)) { |
|
364 |
thread->osthread()->clear_expanding_stack(); |
|
365 |
return true; |
|
366 |
} |
|
367 |
thread->osthread()->clear_expanding_stack(); |
|
368 |
} else { |
|
369 |
fatal("recursive segv. expanding stack."); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
return false; |
|
374 |
} |
|
375 |
||
376 |
inline static bool checkPollingPage(address pc, address fault, address* stub) { |
|
49813
97984a163b55
8201616: Hotspot crashes on linux-sparc after 8189941
glaubitz
parents:
49653
diff
changeset
|
377 |
if (os::is_poll_address(fault)) { |
380 | 378 |
*stub = SharedRuntime::get_poll_stub(pc); |
379 |
return true; |
|
380 |
} |
|
381 |
return false; |
|
382 |
} |
|
383 |
||
46667 | 384 |
inline static bool checkByteBuffer(address pc, address npc, JavaThread * thread, address* stub) { |
380 | 385 |
// BugId 4454115: A read from a MappedByteBuffer can fault |
386 |
// here if the underlying file has been truncated. |
|
387 |
// Do not crash the VM in such a case. |
|
388 |
CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
|
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
37430
diff
changeset
|
389 |
CompiledMethod* nm = cb->as_compiled_method_or_null(); |
380 | 390 |
if (nm != NULL && nm->has_unsafe_access()) { |
38209
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
391 |
*stub = SharedRuntime::handle_unsafe_access(thread, npc); |
380 | 392 |
return true; |
393 |
} |
|
394 |
return false; |
|
395 |
} |
|
396 |
||
397 |
inline static bool checkVerifyOops(address pc, address fault, address* stub) { |
|
398 |
if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] |
|
399 |
&& pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { |
|
400 |
*stub = MacroAssembler::_verify_oop_implicit_branch[2]; |
|
401 |
warning("fixed up memory fault in +VerifyOops at address " |
|
24917 | 402 |
INTPTR_FORMAT, p2i(fault)); |
380 | 403 |
return true; |
404 |
} |
|
405 |
return false; |
|
406 |
} |
|
407 |
||
408 |
inline static bool checkFPFault(address pc, int code, |
|
409 |
JavaThread* thread, address* stub) { |
|
410 |
if (code == FPE_INTDIV || code == FPE_FLTDIV) { |
|
411 |
*stub = |
|
412 |
SharedRuntime:: |
|
413 |
continuation_for_implicit_exception(thread, |
|
414 |
pc, |
|
415 |
SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); |
|
416 |
return true; |
|
417 |
} |
|
418 |
return false; |
|
419 |
} |
|
420 |
||
421 |
inline static bool checkNullPointer(address pc, intptr_t fault, |
|
422 |
JavaThread* thread, address* stub) { |
|
423 |
if (!MacroAssembler::needs_explicit_null_check(fault)) { |
|
424 |
// Determination of interpreter/vtable stub/compiled code null |
|
425 |
// exception |
|
426 |
*stub = |
|
427 |
SharedRuntime:: |
|
428 |
continuation_for_implicit_exception(thread, pc, |
|
429 |
SharedRuntime::IMPLICIT_NULL); |
|
430 |
return true; |
|
431 |
} |
|
432 |
return false; |
|
433 |
} |
|
434 |
||
435 |
inline static bool checkFastJNIAccess(address pc, address* stub) { |
|
436 |
address addr = JNI_FastGetField::find_slowcase_pc(pc); |
|
437 |
if (addr != (address)-1) { |
|
438 |
*stub = addr; |
|
439 |
return true; |
|
440 |
} |
|
441 |
return false; |
|
442 |
} |
|
443 |
||
444 |
inline static bool checkSerializePage(JavaThread* thread, address addr) { |
|
445 |
return os::is_memory_serialize_page(thread, addr); |
|
446 |
} |
|
447 |
||
448 |
inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { |
|
449 |
if (nativeInstruction_at(*pc)->is_zombie()) { |
|
450 |
// zombie method (ld [%g0],%o7 instruction) |
|
451 |
*stub = SharedRuntime::get_handle_wrong_method_stub(); |
|
452 |
||
453 |
// At the stub it needs to look like a call from the caller of this |
|
454 |
// method (not a call from the segv site). |
|
455 |
*pc = (address)SIG_REGS(uc).u_regs[CON_O7]; |
|
456 |
return true; |
|
457 |
} |
|
458 |
return false; |
|
459 |
} |
|
460 |
||
461 |
inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { |
|
462 |
#ifdef COMPILER2 |
|
463 |
if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { |
|
464 |
#ifdef ASSERT |
|
465 |
#ifdef TIERED |
|
24327 | 466 |
CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); |
380 | 467 |
assert(cb->is_compiled_by_c2(), "Wrong compiler"); |
468 |
#endif // TIERED |
|
469 |
#endif // ASSERT |
|
470 |
// Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. |
|
471 |
*stub = SharedRuntime::get_ic_miss_stub(); |
|
472 |
// At the stub it needs to look like a call from the caller of this |
|
473 |
// method (not a call from the segv site). |
|
474 |
*pc = (address)SIG_REGS(uc).u_regs[CON_O7]; |
|
475 |
return true; |
|
476 |
} |
|
477 |
#endif // COMPILER2 |
|
478 |
return false; |
|
479 |
} |
|
480 |
||
8106 | 481 |
extern "C" JNIEXPORT int |
380 | 482 |
JVM_handle_linux_signal(int sig, |
483 |
siginfo_t* info, |
|
484 |
void* ucVoid, |
|
485 |
int abort_if_unrecognized) { |
|
486 |
// in fact this isn't ucontext_t* at all, but struct sigcontext* |
|
487 |
// but Linux porting layer uses ucontext_t, so to minimize code change |
|
488 |
// we cast as needed |
|
489 |
ucontext_t* ucFake = (ucontext_t*) ucVoid; |
|
490 |
sigcontext* uc = (sigcontext*)ucVoid; |
|
491 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33105
diff
changeset
|
492 |
Thread* t = Thread::current_or_null_safe(); |
380 | 493 |
|
18943 | 494 |
// Must do this before SignalHandlerMark, if crash protection installed we will longjmp away |
495 |
// (no destructors can be run) |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46381
diff
changeset
|
496 |
os::ThreadCrashProtection::check_crash_protection(sig, t); |
18943 | 497 |
|
380 | 498 |
SignalHandlerMark shm(t); |
499 |
||
500 |
// Note: it's not uncommon that JNI code uses signal/sigset to install |
|
501 |
// then restore certain signal handler (e.g. to temporarily block SIGPIPE, |
|
502 |
// or have a SIGILL handler when detecting CPU type). When that happens, |
|
503 |
// JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To |
|
504 |
// avoid unnecessary crash when libjsig is not preloaded, try handle signals |
|
505 |
// that do not require siginfo/ucontext first. |
|
506 |
||
507 |
if (sig == SIGPIPE || sig == SIGXFSZ) { |
|
508 |
// allow chained handler to go first |
|
509 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
510 |
return true; |
|
511 |
} else { |
|
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
35201
diff
changeset
|
512 |
// Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219 |
380 | 513 |
return true; |
514 |
} |
|
515 |
} |
|
516 |
||
49653
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
517 |
#ifdef CAN_SHOW_REGISTERS_ON_ASSERT |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
518 |
if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
519 |
handle_assert_poison_fault(ucVoid, info->si_addr); |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
520 |
return 1; |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
521 |
} |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
522 |
#endif |
a569cb4425f3
8191101: Show register content in hs-err file on assert
stuefe
parents:
49449
diff
changeset
|
523 |
|
380 | 524 |
JavaThread* thread = NULL; |
525 |
VMThread* vmthread = NULL; |
|
526 |
if (os::Linux::signal_handlers_are_installed) { |
|
527 |
if (t != NULL ){ |
|
528 |
if(t->is_Java_thread()) { |
|
529 |
thread = (JavaThread*)t; |
|
530 |
} |
|
531 |
else if(t->is_VM_thread()){ |
|
532 |
vmthread = (VMThread *)t; |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
// decide if this trap can be handled by a stub |
|
538 |
address stub = NULL; |
|
539 |
address pc = NULL; |
|
540 |
address npc = NULL; |
|
541 |
||
542 |
//%note os_trap_1 |
|
543 |
if (info != NULL && uc != NULL && thread != NULL) { |
|
544 |
pc = address(SIG_PC(uc)); |
|
545 |
npc = address(SIG_NPC(uc)); |
|
546 |
||
547 |
// Check to see if we caught the safepoint code in the |
|
548 |
// process of write protecting the memory serialization page. |
|
549 |
// It write enables the page immediately after protecting it |
|
550 |
// so we can just return to retry the write. |
|
551 |
if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { |
|
552 |
// Block current thread until the memory serialize page permission restored. |
|
553 |
os::block_on_serialize_page_trap(); |
|
554 |
return 1; |
|
555 |
} |
|
556 |
||
557 |
if (checkPrefetch(uc, pc)) { |
|
558 |
return 1; |
|
559 |
} |
|
560 |
||
561 |
// Handle ALL stack overflow variations here |
|
562 |
if (sig == SIGSEGV) { |
|
563 |
if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { |
|
564 |
return 1; |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
if (sig == SIGBUS && |
|
569 |
thread->thread_state() == _thread_in_vm && |
|
570 |
thread->doing_unsafe_access()) { |
|
38209
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
571 |
stub = SharedRuntime::handle_unsafe_access(thread, npc); |
380 | 572 |
} |
573 |
||
574 |
if (thread->thread_state() == _thread_in_Java) { |
|
575 |
do { |
|
576 |
// Java thread running in Java code => find exception handler if any |
|
577 |
// a fault inside compiled code, the interpreter, or a stub |
|
578 |
||
579 |
if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { |
|
580 |
break; |
|
581 |
} |
|
582 |
||
46667 | 583 |
if ((sig == SIGBUS) && checkByteBuffer(pc, npc, thread, &stub)) { |
380 | 584 |
break; |
585 |
} |
|
586 |
||
587 |
if ((sig == SIGSEGV || sig == SIGBUS) && |
|
588 |
checkVerifyOops(pc, (address)info->si_addr, &stub)) { |
|
589 |
break; |
|
590 |
} |
|
591 |
||
592 |
if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { |
|
593 |
break; |
|
594 |
} |
|
595 |
||
596 |
if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { |
|
597 |
break; |
|
598 |
} |
|
599 |
||
600 |
if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { |
|
601 |
break; |
|
602 |
} |
|
603 |
||
604 |
if ((sig == SIGSEGV) && |
|
605 |
checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { |
|
606 |
break; |
|
607 |
} |
|
608 |
} while (0); |
|
609 |
||
610 |
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in |
|
611 |
// and the heap gets shrunk before the field access. |
|
612 |
if ((sig == SIGSEGV) || (sig == SIGBUS)) { |
|
613 |
checkFastJNIAccess(pc, &stub); |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
if (stub != NULL) { |
|
618 |
// save all thread context in case we need to restore it |
|
619 |
thread->set_saved_exception_pc(pc); |
|
620 |
thread->set_saved_exception_npc(npc); |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26576
diff
changeset
|
621 |
os::Linux::ucontext_set_pc((ucontext_t*)uc, stub); |
380 | 622 |
return true; |
623 |
} |
|
624 |
} |
|
625 |
||
626 |
// signal-chaining |
|
627 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
628 |
return true; |
|
629 |
} |
|
630 |
||
631 |
if (!abort_if_unrecognized) { |
|
632 |
// caller wants another chance, so give it to him |
|
633 |
return false; |
|
634 |
} |
|
635 |
||
636 |
if (pc == NULL && uc != NULL) { |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
637 |
pc = os::Linux::ucontext_get_pc((const ucontext_t*)uc); |
380 | 638 |
} |
639 |
||
640 |
// unmask current signal |
|
641 |
sigset_t newset; |
|
642 |
sigemptyset(&newset); |
|
643 |
sigaddset(&newset, sig); |
|
644 |
sigprocmask(SIG_UNBLOCK, &newset, NULL); |
|
645 |
||
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32080
diff
changeset
|
646 |
VMError::report_and_die(t, sig, pc, info, ucVoid); |
380 | 647 |
|
648 |
ShouldNotReachHere(); |
|
34667 | 649 |
return false; |
380 | 650 |
} |
651 |
||
652 |
void os::Linux::init_thread_fpu_state(void) { |
|
653 |
// Nothing to do |
|
654 |
} |
|
655 |
||
656 |
int os::Linux::get_fpu_control_word() { |
|
657 |
return 0; |
|
658 |
} |
|
659 |
||
660 |
void os::Linux::set_fpu_control_word(int fpu) { |
|
661 |
// nothing |
|
662 |
} |
|
663 |
||
664 |
bool os::is_allocatable(size_t bytes) { |
|
665 |
return true; |
|
666 |
} |
|
667 |
||
668 |
/////////////////////////////////////////////////////////////////////////////// |
|
669 |
// thread stack |
|
670 |
||
42906
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
671 |
// Minimum usable stack sizes required to get to user code. Space for |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
672 |
// HotSpot guard pages is added later. |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
673 |
size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K; |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
674 |
size_t os::Posix::_java_thread_min_stack_allowed = 64 * K; |
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
675 |
size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K; |
380 | 676 |
|
677 |
// return default stack size for thr_type |
|
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
678 |
size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
380 | 679 |
// default stack size (compiler thread needs larger stack) |
680 |
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); |
|
681 |
return s; |
|
682 |
} |
|
683 |
||
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
684 |
#ifndef PRODUCT |
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
685 |
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
|
686 |
} |
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
8921
diff
changeset
|
687 |
#endif |
26576
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
688 |
|
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
689 |
int os::extra_bang_size_in_bytes() { |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
690 |
// SPARC does not require the additional stack bang. |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
691 |
return 0; |
a9429d24d429
8050147: StoreLoad barrier interferes with stack usages
shade
parents:
25723
diff
changeset
|
692 |
} |