Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/cpu/ppc/frame_ppc.cpp
64440 views
1
/*
2
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2012, 2022 SAP SE. 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 "compiler/oopMap.hpp"
28
#include "interpreter/interpreter.hpp"
29
#include "memory/resourceArea.hpp"
30
#include "memory/universe.hpp"
31
#include "oops/markWord.hpp"
32
#include "oops/method.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "runtime/frame.inline.hpp"
35
#include "runtime/handles.inline.hpp"
36
#include "runtime/javaCalls.hpp"
37
#include "runtime/jniHandles.inline.hpp"
38
#include "runtime/monitorChunk.hpp"
39
#include "runtime/os.inline.hpp"
40
#include "runtime/signature.hpp"
41
#include "runtime/stackWatermarkSet.hpp"
42
#include "runtime/stubCodeGenerator.hpp"
43
#include "runtime/stubRoutines.hpp"
44
#ifdef COMPILER1
45
#include "c1/c1_Runtime1.hpp"
46
#include "runtime/vframeArray.hpp"
47
#endif
48
49
#ifdef ASSERT
50
void RegisterMap::check_location_valid() {
51
}
52
#endif // ASSERT
53
54
bool frame::safe_for_sender(JavaThread *thread) {
55
address sp = (address)_sp;
56
address fp = (address)_fp;
57
address unextended_sp = (address)_unextended_sp;
58
59
// consider stack guards when trying to determine "safe" stack pointers
60
// sp must be within the usable part of the stack (not in guards)
61
if (!thread->is_in_usable_stack(sp)) {
62
return false;
63
}
64
65
// Unextended sp must be within the stack
66
if (!thread->is_in_full_stack_checked(unextended_sp)) {
67
return false;
68
}
69
70
// An fp must be within the stack and above (but not equal) sp.
71
bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
72
// An interpreter fp must be fp_safe.
73
// Moreover, it must be at a distance at least the size of the ijava_state structure.
74
bool fp_interp_safe = fp_safe && ((fp - sp) >= ijava_state_size);
75
76
// We know sp/unextended_sp are safe, only fp is questionable here
77
78
// If the current frame is known to the code cache then we can attempt to
79
// construct the sender and do some validation of it. This goes a long way
80
// toward eliminating issues when we get in frame construction code
81
82
if (_cb != NULL ){
83
84
// First check if the frame is complete and the test is reliable.
85
// Unfortunately we can only check frame completeness for runtime stubs
86
// and nmethods. Other generic buffer blobs are more problematic
87
// so we just assume they are OK.
88
// Adapter blobs never have a complete frame and are never OK
89
if (!_cb->is_frame_complete_at(_pc)) {
90
if (_cb->is_compiled() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
91
return false;
92
}
93
}
94
95
// Could just be some random pointer within the codeBlob.
96
if (!_cb->code_contains(_pc)) {
97
return false;
98
}
99
100
// Entry frame checks
101
if (is_entry_frame()) {
102
// An entry frame must have a valid fp.
103
return fp_safe && is_entry_frame_valid(thread);
104
}
105
106
if (is_interpreted_frame() && !fp_interp_safe) {
107
return false;
108
}
109
110
// At this point, there still is a chance that fp_safe is false.
111
// In particular, (fp == NULL) might be true. So let's check and
112
// bail out before we actually dereference from fp.
113
if (!fp_safe) {
114
return false;
115
}
116
117
abi_minframe* sender_abi = (abi_minframe*) fp;
118
intptr_t* sender_sp = (intptr_t*) fp;
119
address sender_pc = (address) sender_abi->lr;;
120
121
// We must always be able to find a recognizable pc.
122
CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
123
if (sender_blob == NULL) {
124
return false;
125
}
126
127
// Could be a zombie method
128
if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
129
return false;
130
}
131
132
// It should be safe to construct the sender though it might not be valid.
133
134
frame sender(sender_sp, sender_pc);
135
136
// Do we have a valid fp?
137
address sender_fp = (address) sender.fp();
138
139
// sender_fp must be within the stack and above (but not
140
// equal) current frame's fp.
141
if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
142
return false;
143
}
144
145
// If the potential sender is the interpreter then we can do some more checking.
146
if (Interpreter::contains(sender_pc)) {
147
return sender.is_interpreted_frame_valid(thread);
148
}
149
150
// Could just be some random pointer within the codeBlob.
151
if (!sender.cb()->code_contains(sender_pc)) {
152
return false;
153
}
154
155
// We should never be able to see an adapter if the current frame is something from code cache.
156
if (sender_blob->is_adapter_blob()) {
157
return false;
158
}
159
160
if (sender.is_entry_frame()) {
161
return sender.is_entry_frame_valid(thread);
162
}
163
164
// Frame size is always greater than zero. If the sender frame size is zero or less,
165
// something is really weird and we better give up.
166
if (sender_blob->frame_size() <= 0) {
167
return false;
168
}
169
170
return true;
171
}
172
173
// Must be native-compiled frame. Since sender will try and use fp to find
174
// linkages it must be safe
175
176
if (!fp_safe) {
177
return false;
178
}
179
180
return true;
181
}
182
183
bool frame::is_interpreted_frame() const {
184
return Interpreter::contains(pc());
185
}
186
187
frame frame::sender_for_entry_frame(RegisterMap *map) const {
188
assert(map != NULL, "map must be set");
189
// Java frame called from C; skip all C frames and return top C
190
// frame of that chunk as the sender.
191
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
192
assert(!entry_frame_is_first(), "next Java fp must be non zero");
193
assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
194
map->clear();
195
assert(map->include_argument_oops(), "should be set by clear");
196
197
if (jfa->last_Java_pc() != NULL) {
198
frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());
199
return fr;
200
}
201
// Last_java_pc is not set, if we come here from compiled code. The
202
// constructor retrieves the PC from the stack.
203
frame fr(jfa->last_Java_sp());
204
return fr;
205
}
206
207
OptimizedEntryBlob::FrameData* OptimizedEntryBlob::frame_data_for_frame(const frame& frame) const {
208
ShouldNotCallThis();
209
return nullptr;
210
}
211
212
bool frame::optimized_entry_frame_is_first() const {
213
ShouldNotCallThis();
214
return false;
215
}
216
217
frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
218
// Pass callers initial_caller_sp as unextended_sp.
219
return frame(sender_sp(), sender_pc(), (intptr_t*)get_ijava_state()->sender_sp);
220
}
221
222
frame frame::sender_for_compiled_frame(RegisterMap *map) const {
223
assert(map != NULL, "map must be set");
224
225
// Frame owned by compiler.
226
address pc = *compiled_sender_pc_addr(_cb);
227
frame caller(compiled_sender_sp(_cb), pc);
228
229
// Now adjust the map.
230
231
// Get the rest.
232
if (map->update_map()) {
233
// Tell GC to use argument oopmaps for some runtime stubs that need it.
234
map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
235
if (_cb->oop_maps() != NULL) {
236
OopMapSet::update_register_map(this, map);
237
}
238
}
239
240
return caller;
241
}
242
243
intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {
244
return sender_sp();
245
}
246
247
address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {
248
return sender_pc_addr();
249
}
250
251
frame frame::sender_raw(RegisterMap* map) const {
252
// Default is we do have to follow them. The sender_for_xxx will
253
// update it accordingly.
254
map->set_include_argument_oops(false);
255
256
if (is_entry_frame()) return sender_for_entry_frame(map);
257
if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
258
assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
259
260
if (_cb != NULL) {
261
return sender_for_compiled_frame(map);
262
}
263
// Must be native-compiled frame, i.e. the marshaling code for native
264
// methods that exists in the core system.
265
return frame(sender_sp(), sender_pc());
266
}
267
268
frame frame::sender(RegisterMap* map) const {
269
frame result = sender_raw(map);
270
271
if (map->process_frames()) {
272
StackWatermarkSet::on_iteration(map->thread(), result);
273
}
274
275
return result;
276
}
277
278
void frame::patch_pc(Thread* thread, address pc) {
279
assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
280
if (TracePcPatching) {
281
tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "]",
282
p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));
283
}
284
own_abi()->lr = (uint64_t)pc;
285
if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
286
address orig = (((nmethod*)_cb)->get_original_pc(this));
287
assert(orig == _pc, "expected original to be stored before patching");
288
_deopt_state = is_deoptimized;
289
// Leave _pc as is.
290
} else {
291
_deopt_state = not_deoptimized;
292
_pc = pc;
293
}
294
}
295
296
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
297
assert(is_interpreted_frame(), "Not an interpreted frame");
298
// These are reasonable sanity checks
299
if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
300
return false;
301
}
302
if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
303
return false;
304
}
305
int min_frame_slots = (abi_minframe_size + ijava_state_size) / sizeof(intptr_t);
306
if (fp() - min_frame_slots < sp()) {
307
return false;
308
}
309
// These are hacks to keep us out of trouble.
310
// The problem with these is that they mask other problems
311
if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
312
return false;
313
}
314
315
// do some validation of frame elements
316
317
// first the method
318
319
Method* m = *interpreter_frame_method_addr();
320
321
// validate the method we'd find in this potential sender
322
if (!Method::is_valid_method(m)) return false;
323
324
// stack frames shouldn't be much larger than max_stack elements
325
// this test requires the use of unextended_sp which is the sp as seen by
326
// the current frame, and not sp which is the "raw" pc which could point
327
// further because of local variables of the callee method inserted after
328
// method arguments
329
if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
330
return false;
331
}
332
333
// validate bci/bcx
334
335
address bcp = interpreter_frame_bcp();
336
if (m->validate_bci_from_bcp(bcp) < 0) {
337
return false;
338
}
339
340
// validate constantPoolCache*
341
ConstantPoolCache* cp = *interpreter_frame_cache_addr();
342
if (MetaspaceObj::is_valid(cp) == false) return false;
343
344
// validate locals
345
346
address locals = (address) *interpreter_frame_locals_addr();
347
return thread->is_in_stack_range_incl(locals, (address)fp());
348
}
349
350
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
351
assert(is_interpreted_frame(), "interpreted frame expected");
352
Method* method = interpreter_frame_method();
353
BasicType type = method->result_type();
354
355
if (method->is_native()) {
356
// Prior to calling into the runtime to notify the method exit the possible
357
// result value is saved into the interpreter frame.
358
address lresult = (address)&(get_ijava_state()->lresult);
359
address fresult = (address)&(get_ijava_state()->fresult);
360
361
switch (method->result_type()) {
362
case T_OBJECT:
363
case T_ARRAY: {
364
*oop_result = JNIHandles::resolve(*(jobject*)lresult);
365
break;
366
}
367
// We use std/stfd to store the values.
368
case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;
369
case T_INT : value_result->i = (jint) *(long*)lresult; break;
370
case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;
371
case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;
372
case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;
373
case T_LONG : value_result->j = (jlong) *(long*)lresult; break;
374
case T_FLOAT : value_result->f = (jfloat) *(double*)fresult; break;
375
case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;
376
case T_VOID : /* Nothing to do */ break;
377
default : ShouldNotReachHere();
378
}
379
} else {
380
intptr_t* tos_addr = interpreter_frame_tos_address();
381
switch (method->result_type()) {
382
case T_OBJECT:
383
case T_ARRAY: {
384
oop obj = *(oop*)tos_addr;
385
assert(Universe::is_in_heap_or_null(obj), "sanity check");
386
*oop_result = obj;
387
}
388
case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;
389
case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;
390
case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;
391
case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;
392
case T_INT : value_result->i = *(jint*)tos_addr; break;
393
case T_LONG : value_result->j = *(jlong*)tos_addr; break;
394
case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
395
case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
396
case T_VOID : /* Nothing to do */ break;
397
default : ShouldNotReachHere();
398
}
399
}
400
return type;
401
}
402
403
#ifndef PRODUCT
404
405
void frame::describe_pd(FrameValues& values, int frame_no) {
406
if (is_interpreted_frame()) {
407
#define DESCRIBE_ADDRESS(name) \
408
values.describe(frame_no, (intptr_t*)&(get_ijava_state()->name), #name);
409
410
DESCRIBE_ADDRESS(method);
411
DESCRIBE_ADDRESS(mirror);
412
DESCRIBE_ADDRESS(locals);
413
DESCRIBE_ADDRESS(monitors);
414
DESCRIBE_ADDRESS(cpoolCache);
415
DESCRIBE_ADDRESS(bcp);
416
DESCRIBE_ADDRESS(esp);
417
DESCRIBE_ADDRESS(mdx);
418
DESCRIBE_ADDRESS(top_frame_sp);
419
DESCRIBE_ADDRESS(sender_sp);
420
DESCRIBE_ADDRESS(oop_tmp);
421
DESCRIBE_ADDRESS(lresult);
422
DESCRIBE_ADDRESS(fresult);
423
}
424
}
425
#endif
426
427
intptr_t *frame::initial_deoptimization_info() {
428
// unused... but returns fp() to minimize changes introduced by 7087445
429
return fp();
430
}
431
432
#ifndef PRODUCT
433
// This is a generic constructor which is only used by pns() in debug.cpp.
434
frame::frame(void* sp, void* fp, void* pc) : _sp((intptr_t*)sp), _unextended_sp((intptr_t*)sp) {
435
find_codeblob_and_set_pc_and_deopt_state((address)pc); // also sets _fp and adjusts _unextended_sp
436
}
437
438
void frame::pd_ps() {}
439
#endif
440
441