jdk

Форк
0
/
os_windows_aarch64.cpp 
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

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 != nullptr) {
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 = nullptr;
88
    if (ret_sp) *ret_sp = (intptr_t *)nullptr;
89
    if (ret_fp) *ret_fp = (intptr_t *)nullptr;
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 == 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
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 == nullptr) 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

208
void os::print_tos_pc(outputStream *st, const void *context) {
209
  if (context == nullptr) return;
210

211
  const CONTEXT* uc = (const CONTEXT*)context;
212

213
  address sp = (address)uc->Sp;
214
  print_tos(st, sp);
215
  st->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.
220
  address pc = (address)uc->Pc;
221
  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
222
  print_hex_dump(st, pc - 32, pc + 32, sizeof(char), /* print_ascii=*/false);
223
  st->cr();
224
}
225

226
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
227
  const int register_count = 29 /* X0-X28 */;
228
  int n = continuation;
229
  assert(n >= 0 && n <= register_count, "Invalid continuation value");
230
  if (context == nullptr || n == register_count) {
231
    return;
232
  }
233

234
  const CONTEXT* uc = (const CONTEXT*)context;
235
  while (n < register_count) {
236
    // Update continuation with next index before printing location
237
    continuation = n + 1;
238
# define CASE_PRINT_REG(n, str, id) case n: st->print(str); print_location(st, uc->id);
239
    switch (n) {
240
      CASE_PRINT_REG( 0, " X0=", X0); break;
241
      CASE_PRINT_REG( 1, " X1=", X1); break;
242
      CASE_PRINT_REG( 2, " X2=", X2); break;
243
      CASE_PRINT_REG( 3, " X3=", X3); break;
244
      CASE_PRINT_REG( 4, " X4=", X4); break;
245
      CASE_PRINT_REG( 5, " X5=", X5); break;
246
      CASE_PRINT_REG( 6, " X6=", X6); break;
247
      CASE_PRINT_REG( 7, " X7=", X7); break;
248
      CASE_PRINT_REG( 8, " X8=", X8); break;
249
      CASE_PRINT_REG( 9, " X9=", X9); break;
250
      CASE_PRINT_REG(10, "X10=", X10); break;
251
      CASE_PRINT_REG(11, "X11=", X11); break;
252
      CASE_PRINT_REG(12, "X12=", X12); break;
253
      CASE_PRINT_REG(13, "X13=", X13); break;
254
      CASE_PRINT_REG(14, "X14=", X14); break;
255
      CASE_PRINT_REG(15, "X15=", X15); break;
256
      CASE_PRINT_REG(16, "X16=", X16); break;
257
      CASE_PRINT_REG(17, "X17=", X17); break;
258
      CASE_PRINT_REG(18, "X18=", X18); break;
259
      CASE_PRINT_REG(19, "X19=", X19); break;
260
      CASE_PRINT_REG(20, "X20=", X20); break;
261
      CASE_PRINT_REG(21, "X21=", X21); break;
262
      CASE_PRINT_REG(22, "X22=", X22); break;
263
      CASE_PRINT_REG(23, "X23=", X23); break;
264
      CASE_PRINT_REG(24, "X24=", X24); break;
265
      CASE_PRINT_REG(25, "X25=", X25); break;
266
      CASE_PRINT_REG(26, "X26=", X26); break;
267
      CASE_PRINT_REG(27, "X27=", X27); break;
268
      CASE_PRINT_REG(28, "X28=", X28); break;
269
    }
270
# undef CASE_PRINT_REG
271
    ++n;
272
  }
273
}
274

275
void os::setup_fpu() {
276
}
277

278
#ifndef PRODUCT
279
void os::verify_stack_alignment() {
280
  assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
281
}
282
#endif
283

284
int os::extra_bang_size_in_bytes() {
285
  // AArch64 does not require the additional stack bang.
286
  return 0;
287
}
288

289
extern "C" {
290
  int SpinPause() {
291
    return 0;
292
  }
293
};
294

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.