Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os_cpu/windows_aarch64/os_windows_aarch64.cpp
40930 views
1
/*
2
* Copyright (c) 2020, Microsoft Corporation. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "jvm.h"
27
#include "asm/macroAssembler.hpp"
28
#include "classfile/vmSymbols.hpp"
29
#include "code/codeCache.hpp"
30
#include "code/icBuffer.hpp"
31
#include "code/vtableStubs.hpp"
32
#include "code/nativeInst.hpp"
33
#include "interpreter/interpreter.hpp"
34
#include "memory/allocation.inline.hpp"
35
#include "prims/jniFastGetField.hpp"
36
#include "prims/jvm_misc.hpp"
37
#include "runtime/arguments.hpp"
38
#include "runtime/frame.inline.hpp"
39
#include "runtime/interfaceSupport.inline.hpp"
40
#include "runtime/java.hpp"
41
#include "runtime/javaCalls.hpp"
42
#include "runtime/mutexLocker.hpp"
43
#include "runtime/osThread.hpp"
44
#include "runtime/sharedRuntime.hpp"
45
#include "runtime/stubRoutines.hpp"
46
#include "runtime/thread.inline.hpp"
47
#include "runtime/timer.hpp"
48
#include "unwind_windows_aarch64.hpp"
49
#include "utilities/debug.hpp"
50
#include "utilities/events.hpp"
51
#include "utilities/vmError.hpp"
52
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
62
void os::os_exception_wrapper(java_call_t f, JavaValue* value, const methodHandle& method, JavaCallArguments* args, JavaThread* thread) {
63
f(value, method, args, thread);
64
}
65
66
PRAGMA_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.
70
address os::current_stack_pointer() {
71
int dummy;
72
address sp = (address)&dummy;
73
return sp;
74
}
75
76
address os::fetch_frame_from_context(const void* ucVoid,
77
intptr_t** ret_sp, intptr_t** ret_fp) {
78
address epc;
79
CONTEXT* uc = (CONTEXT*)ucVoid;
80
81
if (uc != NULL) {
82
epc = (address)uc->Pc;
83
if (ret_sp) *ret_sp = (intptr_t*)uc->Sp;
84
if (ret_fp) *ret_fp = (intptr_t*)uc->Fp;
85
} else {
86
// construct empty ExtendedPC for return value checking
87
epc = NULL;
88
if (ret_sp) *ret_sp = (intptr_t *)NULL;
89
if (ret_fp) *ret_fp = (intptr_t *)NULL;
90
}
91
return epc;
92
}
93
94
frame os::fetch_frame_from_context(const void* ucVoid) {
95
intptr_t* sp;
96
intptr_t* fp;
97
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
98
return frame(sp, fp, epc);
99
}
100
101
bool os::win32::get_frame_at_stack_banging_point(JavaThread* thread,
102
struct _EXCEPTION_POINTERS* exceptionInfo, address pc, frame* fr) {
103
PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
104
address addr = (address) exceptionRecord->ExceptionInformation[1];
105
if (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);
111
if (!fr->is_first_java_frame()) {
112
assert(fr->safe_for_sender(thread), "Safety check");
113
*fr = fr->java_sender();
114
}
115
} else {
116
// more complex code with compiled code
117
assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
118
CodeBlob* cb = CodeCache::find_blob(pc);
119
if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
120
// Not sure where the pc points to, fallback to default
121
// stack overflow handling
122
return 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.
127
intptr_t* fp = (intptr_t*)exceptionInfo->ContextRecord->Fp;
128
intptr_t* sp = (intptr_t*)exceptionInfo->ContextRecord->Sp;
129
address pc = (address)(exceptionInfo->ContextRecord->Lr
130
- NativeInstruction::instruction_size);
131
*fr = frame(sp, fp, pc);
132
if (!fr->is_java_frame()) {
133
assert(fr->safe_for_sender(thread), "Safety check");
134
assert(!fr->is_first_frame(), "Safety check");
135
*fr = fr->java_sender();
136
}
137
}
138
}
139
assert(fr->is_java_frame(), "Safety check");
140
return true;
141
}
142
143
frame os::get_sender_for_C_frame(frame* fr) {
144
ShouldNotReachHere();
145
return frame();
146
}
147
148
frame os::current_frame() {
149
return 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
162
void os::print_context(outputStream *st, const void *context) {
163
if (context == NULL) return;
164
165
const CONTEXT* uc = (const CONTEXT*)context;
166
167
st->print_cr("Registers:");
168
169
st->print( "X0 =" INTPTR_FORMAT, uc->X0);
170
st->print(", X1 =" INTPTR_FORMAT, uc->X1);
171
st->print(", X2 =" INTPTR_FORMAT, uc->X2);
172
st->print(", X3 =" INTPTR_FORMAT, uc->X3);
173
st->cr();
174
st->print( "X4 =" INTPTR_FORMAT, uc->X4);
175
st->print(", X5 =" INTPTR_FORMAT, uc->X5);
176
st->print(", X6 =" INTPTR_FORMAT, uc->X6);
177
st->print(", X7 =" INTPTR_FORMAT, uc->X7);
178
st->cr();
179
st->print( "X8 =" INTPTR_FORMAT, uc->X8);
180
st->print(", X9 =" INTPTR_FORMAT, uc->X9);
181
st->print(", X10=" INTPTR_FORMAT, uc->X10);
182
st->print(", X11=" INTPTR_FORMAT, uc->X11);
183
st->cr();
184
st->print( "X12=" INTPTR_FORMAT, uc->X12);
185
st->print(", X13=" INTPTR_FORMAT, uc->X13);
186
st->print(", X14=" INTPTR_FORMAT, uc->X14);
187
st->print(", X15=" INTPTR_FORMAT, uc->X15);
188
st->cr();
189
st->print( "X16=" INTPTR_FORMAT, uc->X16);
190
st->print(", X17=" INTPTR_FORMAT, uc->X17);
191
st->print(", X18=" INTPTR_FORMAT, uc->X18);
192
st->print(", X19=" INTPTR_FORMAT, uc->X19);
193
st->cr();
194
st->print(", X20=" INTPTR_FORMAT, uc->X20);
195
st->print(", X21=" INTPTR_FORMAT, uc->X21);
196
st->print(", X22=" INTPTR_FORMAT, uc->X22);
197
st->print(", X23=" INTPTR_FORMAT, uc->X23);
198
st->cr();
199
st->print(", X24=" INTPTR_FORMAT, uc->X24);
200
st->print(", X25=" INTPTR_FORMAT, uc->X25);
201
st->print(", X26=" INTPTR_FORMAT, uc->X26);
202
st->print(", X27=" INTPTR_FORMAT, uc->X27);
203
st->print(", X28=" INTPTR_FORMAT, uc->X28);
204
st->cr();
205
st->cr();
206
207
intptr_t *sp = (intptr_t *)uc->Sp;
208
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
209
print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
210
st->cr();
211
212
// Note: it may be unsafe to inspect memory near pc. For example, pc may
213
// point to garbage if entry point in an nmethod is corrupted. Leave
214
// this at the end, and hope for the best.
215
address pc = (address)uc->Pc;
216
st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
217
print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
218
st->cr();
219
220
}
221
222
void os::print_register_info(outputStream *st, const void *context) {
223
if (context == NULL) return;
224
225
const CONTEXT* uc = (const CONTEXT*)context;
226
227
st->print_cr("Register to memory mapping:");
228
st->cr();
229
// this is only for the "general purpose" registers
230
st->print(" X0="); print_location(st, uc->X0);
231
st->print(" X1="); print_location(st, uc->X1);
232
st->print(" X2="); print_location(st, uc->X2);
233
st->print(" X3="); print_location(st, uc->X3);
234
st->cr();
235
st->print(" X4="); print_location(st, uc->X4);
236
st->print(" X5="); print_location(st, uc->X5);
237
st->print(" X6="); print_location(st, uc->X6);
238
st->print(" X7="); print_location(st, uc->X7);
239
st->cr();
240
st->print(" X8="); print_location(st, uc->X8);
241
st->print(" X9="); print_location(st, uc->X9);
242
st->print("X10="); print_location(st, uc->X10);
243
st->print("X11="); print_location(st, uc->X11);
244
st->cr();
245
st->print("X12="); print_location(st, uc->X12);
246
st->print("X13="); print_location(st, uc->X13);
247
st->print("X14="); print_location(st, uc->X14);
248
st->print("X15="); print_location(st, uc->X15);
249
st->cr();
250
st->print("X16="); print_location(st, uc->X16);
251
st->print("X17="); print_location(st, uc->X17);
252
st->print("X18="); print_location(st, uc->X18);
253
st->print("X19="); print_location(st, uc->X19);
254
st->cr();
255
st->print("X20="); print_location(st, uc->X20);
256
st->print("X21="); print_location(st, uc->X21);
257
st->print("X22="); print_location(st, uc->X22);
258
st->print("X23="); print_location(st, uc->X23);
259
st->cr();
260
st->print("X24="); print_location(st, uc->X24);
261
st->print("X25="); print_location(st, uc->X25);
262
st->print("X26="); print_location(st, uc->X26);
263
st->print("X27="); print_location(st, uc->X27);
264
st->print("X28="); print_location(st, uc->X28);
265
266
st->cr();
267
}
268
269
void os::setup_fpu() {
270
}
271
272
bool os::supports_sse() {
273
return true;
274
}
275
276
#ifndef PRODUCT
277
void os::verify_stack_alignment() {
278
assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
279
}
280
#endif
281
282
int os::extra_bang_size_in_bytes() {
283
// AArch64 does not require the additional stack bang.
284
return 0;
285
}
286
287
extern "C" {
288
int SpinPause() {
289
return 0;
290
}
291
};
292
293