jdk
293 строки · 10.1 Кб
1/*
2* Copyright (c) 2020, Microsoft Corporation. All rights reserved.
3* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5*
6* This code is free software; you can redistribute it and/or modify it
7* under the terms of the GNU General Public License version 2 only, as
8* published by the Free Software Foundation.
9*
10* This code is distributed in the hope that it will be useful, but WITHOUT
11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13* version 2 for more details (a copy is included in the LICENSE file that
14* accompanied this code).
15*
16* You should have received a copy of the GNU General Public License version
17* 2 along with this work; if not, write to the Free Software Foundation,
18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19*
20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21* or visit www.oracle.com if you need additional information or have any
22* questions.
23*
24*/
25
26#include "precompiled.hpp"
27#include "asm/macroAssembler.hpp"
28#include "classfile/vmSymbols.hpp"
29#include "code/codeCache.hpp"
30#include "code/vtableStubs.hpp"
31#include "code/nativeInst.hpp"
32#include "interpreter/interpreter.hpp"
33#include "jvm.h"
34#include "memory/allocation.inline.hpp"
35#include "os_windows.hpp"
36#include "prims/jniFastGetField.hpp"
37#include "prims/jvm_misc.hpp"
38#include "runtime/arguments.hpp"
39#include "runtime/frame.inline.hpp"
40#include "runtime/interfaceSupport.inline.hpp"
41#include "runtime/java.hpp"
42#include "runtime/javaCalls.hpp"
43#include "runtime/javaThread.hpp"
44#include "runtime/mutexLocker.hpp"
45#include "runtime/osThread.hpp"
46#include "runtime/sharedRuntime.hpp"
47#include "runtime/stubRoutines.hpp"
48#include "runtime/timer.hpp"
49#include "unwind_windows_aarch64.hpp"
50#include "utilities/debug.hpp"
51#include "utilities/events.hpp"
52#include "utilities/vmError.hpp"
53
54// put OS-includes here
55# include <sys/types.h>
56# include <signal.h>
57# include <errno.h>
58# include <stdlib.h>
59# include <stdio.h>
60# include <intrin.h>
61
62void os::os_exception_wrapper(java_call_t f, JavaValue* value, const methodHandle& method, JavaCallArguments* args, JavaThread* thread) {
63f(value, method, args, thread);
64}
65
66PRAGMA_DISABLE_MSVC_WARNING(4172)
67// Returns an estimate of the current stack pointer. Result must be guaranteed
68// to point into the calling threads stack, and be no lower than the current
69// stack pointer.
70address os::current_stack_pointer() {
71int dummy;
72address sp = (address)&dummy;
73return sp;
74}
75
76address os::fetch_frame_from_context(const void* ucVoid,
77intptr_t** ret_sp, intptr_t** ret_fp) {
78address epc;
79CONTEXT* uc = (CONTEXT*)ucVoid;
80
81if (uc != nullptr) {
82epc = (address)uc->Pc;
83if (ret_sp) *ret_sp = (intptr_t*)uc->Sp;
84if (ret_fp) *ret_fp = (intptr_t*)uc->Fp;
85} else {
86// construct empty ExtendedPC for return value checking
87epc = nullptr;
88if (ret_sp) *ret_sp = (intptr_t *)nullptr;
89if (ret_fp) *ret_fp = (intptr_t *)nullptr;
90}
91return epc;
92}
93
94frame os::fetch_frame_from_context(const void* ucVoid) {
95intptr_t* sp;
96intptr_t* fp;
97address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
98return frame(sp, fp, epc);
99}
100
101bool os::win32::get_frame_at_stack_banging_point(JavaThread* thread,
102struct _EXCEPTION_POINTERS* exceptionInfo, address pc, frame* fr) {
103PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
104address addr = (address) exceptionRecord->ExceptionInformation[1];
105if (Interpreter::contains(pc)) {
106// interpreter performs stack banging after the fixed frame header has
107// been generated while the compilers perform it before. To maintain
108// semantic consistency between interpreted and compiled frames, the
109// method returns the Java sender of the current frame.
110*fr = os::fetch_frame_from_context((void*)exceptionInfo->ContextRecord);
111if (!fr->is_first_java_frame()) {
112assert(fr->safe_for_sender(thread), "Safety check");
113*fr = fr->java_sender();
114}
115} else {
116// more complex code with compiled code
117assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
118CodeBlob* cb = CodeCache::find_blob(pc);
119if (cb == nullptr || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
120// Not sure where the pc points to, fallback to default
121// stack overflow handling
122return false;
123} else {
124// In compiled code, the stack banging is performed before LR
125// has been saved in the frame. LR is live, and SP and FP
126// belong to the caller.
127intptr_t* fp = (intptr_t*)exceptionInfo->ContextRecord->Fp;
128intptr_t* sp = (intptr_t*)exceptionInfo->ContextRecord->Sp;
129address pc = (address)(exceptionInfo->ContextRecord->Lr
130- NativeInstruction::instruction_size);
131*fr = frame(sp, fp, pc);
132if (!fr->is_java_frame()) {
133assert(fr->safe_for_sender(thread), "Safety check");
134assert(!fr->is_first_frame(), "Safety check");
135*fr = fr->java_sender();
136}
137}
138}
139assert(fr->is_java_frame(), "Safety check");
140return true;
141}
142
143frame os::get_sender_for_C_frame(frame* fr) {
144ShouldNotReachHere();
145return frame();
146}
147
148frame os::current_frame() {
149return frame(); // cannot walk Windows frames this way. See os::get_native_stack
150// and os::platform_print_native_stack
151}
152
153////////////////////////////////////////////////////////////////////////////////
154// thread stack
155
156// Minimum usable stack sizes required to get to user code. Space for
157// HotSpot guard pages is added later.
158
159/////////////////////////////////////////////////////////////////////////////
160// helper functions for fatal error handler
161
162void os::print_context(outputStream *st, const void *context) {
163if (context == nullptr) return;
164
165const CONTEXT* uc = (const CONTEXT*)context;
166
167st->print_cr("Registers:");
168
169st->print( "X0 =" INTPTR_FORMAT, uc->X0);
170st->print(", X1 =" INTPTR_FORMAT, uc->X1);
171st->print(", X2 =" INTPTR_FORMAT, uc->X2);
172st->print(", X3 =" INTPTR_FORMAT, uc->X3);
173st->cr();
174st->print( "X4 =" INTPTR_FORMAT, uc->X4);
175st->print(", X5 =" INTPTR_FORMAT, uc->X5);
176st->print(", X6 =" INTPTR_FORMAT, uc->X6);
177st->print(", X7 =" INTPTR_FORMAT, uc->X7);
178st->cr();
179st->print( "X8 =" INTPTR_FORMAT, uc->X8);
180st->print(", X9 =" INTPTR_FORMAT, uc->X9);
181st->print(", X10=" INTPTR_FORMAT, uc->X10);
182st->print(", X11=" INTPTR_FORMAT, uc->X11);
183st->cr();
184st->print( "X12=" INTPTR_FORMAT, uc->X12);
185st->print(", X13=" INTPTR_FORMAT, uc->X13);
186st->print(", X14=" INTPTR_FORMAT, uc->X14);
187st->print(", X15=" INTPTR_FORMAT, uc->X15);
188st->cr();
189st->print( "X16=" INTPTR_FORMAT, uc->X16);
190st->print(", X17=" INTPTR_FORMAT, uc->X17);
191st->print(", X18=" INTPTR_FORMAT, uc->X18);
192st->print(", X19=" INTPTR_FORMAT, uc->X19);
193st->cr();
194st->print(", X20=" INTPTR_FORMAT, uc->X20);
195st->print(", X21=" INTPTR_FORMAT, uc->X21);
196st->print(", X22=" INTPTR_FORMAT, uc->X22);
197st->print(", X23=" INTPTR_FORMAT, uc->X23);
198st->cr();
199st->print(", X24=" INTPTR_FORMAT, uc->X24);
200st->print(", X25=" INTPTR_FORMAT, uc->X25);
201st->print(", X26=" INTPTR_FORMAT, uc->X26);
202st->print(", X27=" INTPTR_FORMAT, uc->X27);
203st->print(", X28=" INTPTR_FORMAT, uc->X28);
204st->cr();
205st->cr();
206}
207
208void os::print_tos_pc(outputStream *st, const void *context) {
209if (context == nullptr) return;
210
211const CONTEXT* uc = (const CONTEXT*)context;
212
213address sp = (address)uc->Sp;
214print_tos(st, sp);
215st->cr();
216
217// Note: it may be unsafe to inspect memory near pc. For example, pc may
218// point to garbage if entry point in an nmethod is corrupted. Leave
219// this at the end, and hope for the best.
220address pc = (address)uc->Pc;
221st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
222print_hex_dump(st, pc - 32, pc + 32, sizeof(char), /* print_ascii=*/false);
223st->cr();
224}
225
226void os::print_register_info(outputStream *st, const void *context, int& continuation) {
227const int register_count = 29 /* X0-X28 */;
228int n = continuation;
229assert(n >= 0 && n <= register_count, "Invalid continuation value");
230if (context == nullptr || n == register_count) {
231return;
232}
233
234const CONTEXT* uc = (const CONTEXT*)context;
235while (n < register_count) {
236// Update continuation with next index before printing location
237continuation = n + 1;
238# define CASE_PRINT_REG(n, str, id) case n: st->print(str); print_location(st, uc->id);
239switch (n) {
240CASE_PRINT_REG( 0, " X0=", X0); break;
241CASE_PRINT_REG( 1, " X1=", X1); break;
242CASE_PRINT_REG( 2, " X2=", X2); break;
243CASE_PRINT_REG( 3, " X3=", X3); break;
244CASE_PRINT_REG( 4, " X4=", X4); break;
245CASE_PRINT_REG( 5, " X5=", X5); break;
246CASE_PRINT_REG( 6, " X6=", X6); break;
247CASE_PRINT_REG( 7, " X7=", X7); break;
248CASE_PRINT_REG( 8, " X8=", X8); break;
249CASE_PRINT_REG( 9, " X9=", X9); break;
250CASE_PRINT_REG(10, "X10=", X10); break;
251CASE_PRINT_REG(11, "X11=", X11); break;
252CASE_PRINT_REG(12, "X12=", X12); break;
253CASE_PRINT_REG(13, "X13=", X13); break;
254CASE_PRINT_REG(14, "X14=", X14); break;
255CASE_PRINT_REG(15, "X15=", X15); break;
256CASE_PRINT_REG(16, "X16=", X16); break;
257CASE_PRINT_REG(17, "X17=", X17); break;
258CASE_PRINT_REG(18, "X18=", X18); break;
259CASE_PRINT_REG(19, "X19=", X19); break;
260CASE_PRINT_REG(20, "X20=", X20); break;
261CASE_PRINT_REG(21, "X21=", X21); break;
262CASE_PRINT_REG(22, "X22=", X22); break;
263CASE_PRINT_REG(23, "X23=", X23); break;
264CASE_PRINT_REG(24, "X24=", X24); break;
265CASE_PRINT_REG(25, "X25=", X25); break;
266CASE_PRINT_REG(26, "X26=", X26); break;
267CASE_PRINT_REG(27, "X27=", X27); break;
268CASE_PRINT_REG(28, "X28=", X28); break;
269}
270# undef CASE_PRINT_REG
271++n;
272}
273}
274
275void os::setup_fpu() {
276}
277
278#ifndef PRODUCT
279void os::verify_stack_alignment() {
280assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
281}
282#endif
283
284int os::extra_bang_size_in_bytes() {
285// AArch64 does not require the additional stack bang.
286return 0;
287}
288
289extern "C" {
290int SpinPause() {
291return 0;
292}
293};
294