Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/ppc/frame_ppc.cpp
40930 views
1
/*
2
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2012, 2021 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
bool safe = false;
56
address sp = (address)_sp;
57
address fp = (address)_fp;
58
address unextended_sp = (address)_unextended_sp;
59
60
// consider stack guards when trying to determine "safe" stack pointers
61
// sp must be within the usable part of the stack (not in guards)
62
if (!thread->is_in_usable_stack(sp)) {
63
return false;
64
}
65
66
// Unextended sp must be within the stack
67
if (!thread->is_in_full_stack_checked(unextended_sp)) {
68
return false;
69
}
70
71
// An fp must be within the stack and above (but not equal) sp.
72
bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
73
// An interpreter fp must be within the stack and above (but not equal) sp.
74
// Moreover, it must be at least the size of the ijava_state structure.
75
bool fp_interp_safe = fp_safe && ((fp - sp) >= ijava_state_size);
76
77
// We know sp/unextended_sp are safe, only fp is questionable here
78
79
// If the current frame is known to the code cache then we can attempt to
80
// to construct the sender and do some validation of it. This goes a long way
81
// toward eliminating issues when we get in frame construction code
82
83
if (_cb != NULL ){
84
// Entry frame checks
85
if (is_entry_frame()) {
86
// An entry frame must have a valid fp.
87
return fp_safe && is_entry_frame_valid(thread);
88
}
89
90
// Now check if the frame is complete and the test is
91
// reliable. Unfortunately we can only check frame completeness for
92
// runtime stubs and nmethods. Other generic buffer blobs are more
93
// problematic so we just assume they are OK. Adapter blobs never have a
94
// complete frame and are never OK
95
if (!_cb->is_frame_complete_at(_pc)) {
96
if (_cb->is_compiled() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
97
return false;
98
}
99
}
100
101
// Could just be some random pointer within the codeBlob.
102
if (!_cb->code_contains(_pc)) {
103
return false;
104
}
105
106
if (is_interpreted_frame() && !fp_interp_safe) {
107
return false;
108
}
109
110
abi_minframe* sender_abi = (abi_minframe*) fp;
111
intptr_t* sender_sp = (intptr_t*) fp;
112
address sender_pc = (address) sender_abi->lr;;
113
114
// We must always be able to find a recognizable pc.
115
CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
116
if (sender_blob == NULL) {
117
return false;
118
}
119
120
// Could be a zombie method
121
if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
122
return false;
123
}
124
125
// It should be safe to construct the sender though it might not be valid.
126
127
frame sender(sender_sp, sender_pc);
128
129
// Do we have a valid fp?
130
address sender_fp = (address) sender.fp();
131
132
// sender_fp must be within the stack and above (but not
133
// equal) current frame's fp.
134
if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
135
return false;
136
}
137
138
// If the potential sender is the interpreter then we can do some more checking.
139
if (Interpreter::contains(sender_pc)) {
140
return sender.is_interpreted_frame_valid(thread);
141
}
142
143
// Could just be some random pointer within the codeBlob.
144
if (!sender.cb()->code_contains(sender_pc)) {
145
return false;
146
}
147
148
// We should never be able to see an adapter if the current frame is something from code cache.
149
if (sender_blob->is_adapter_blob()) {
150
return false;
151
}
152
153
if (sender.is_entry_frame()) {
154
return sender.is_entry_frame_valid(thread);
155
}
156
157
// Frame size is always greater than zero. If the sender frame size is zero or less,
158
// something is really weird and we better give up.
159
if (sender_blob->frame_size() <= 0) {
160
return false;
161
}
162
163
return true;
164
}
165
166
// Must be native-compiled frame. Since sender will try and use fp to find
167
// linkages it must be safe
168
169
if (!fp_safe) {
170
return false;
171
}
172
173
return true;
174
}
175
176
bool frame::is_interpreted_frame() const {
177
return Interpreter::contains(pc());
178
}
179
180
frame frame::sender_for_entry_frame(RegisterMap *map) const {
181
assert(map != NULL, "map must be set");
182
// Java frame called from C; skip all C frames and return top C
183
// frame of that chunk as the sender.
184
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
185
assert(!entry_frame_is_first(), "next Java fp must be non zero");
186
assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
187
map->clear();
188
assert(map->include_argument_oops(), "should be set by clear");
189
190
if (jfa->last_Java_pc() != NULL) {
191
frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());
192
return fr;
193
}
194
// Last_java_pc is not set, if we come here from compiled code. The
195
// constructor retrieves the PC from the stack.
196
frame fr(jfa->last_Java_sp());
197
return fr;
198
}
199
200
frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
201
// Pass callers initial_caller_sp as unextended_sp.
202
return frame(sender_sp(), sender_pc(), (intptr_t*)get_ijava_state()->sender_sp);
203
}
204
205
frame frame::sender_for_compiled_frame(RegisterMap *map) const {
206
assert(map != NULL, "map must be set");
207
208
// Frame owned by compiler.
209
address pc = *compiled_sender_pc_addr(_cb);
210
frame caller(compiled_sender_sp(_cb), pc);
211
212
// Now adjust the map.
213
214
// Get the rest.
215
if (map->update_map()) {
216
// Tell GC to use argument oopmaps for some runtime stubs that need it.
217
map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
218
if (_cb->oop_maps() != NULL) {
219
OopMapSet::update_register_map(this, map);
220
}
221
}
222
223
return caller;
224
}
225
226
intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {
227
return sender_sp();
228
}
229
230
address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {
231
return sender_pc_addr();
232
}
233
234
frame frame::sender_raw(RegisterMap* map) const {
235
// Default is we do have to follow them. The sender_for_xxx will
236
// update it accordingly.
237
map->set_include_argument_oops(false);
238
239
if (is_entry_frame()) return sender_for_entry_frame(map);
240
if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
241
assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
242
243
if (_cb != NULL) {
244
return sender_for_compiled_frame(map);
245
}
246
// Must be native-compiled frame, i.e. the marshaling code for native
247
// methods that exists in the core system.
248
return frame(sender_sp(), sender_pc());
249
}
250
251
frame frame::sender(RegisterMap* map) const {
252
frame result = sender_raw(map);
253
254
if (map->process_frames()) {
255
StackWatermarkSet::on_iteration(map->thread(), result);
256
}
257
258
return result;
259
}
260
261
void frame::patch_pc(Thread* thread, address pc) {
262
assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
263
if (TracePcPatching) {
264
tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "]",
265
p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));
266
}
267
own_abi()->lr = (uint64_t)pc;
268
if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
269
address orig = (((nmethod*)_cb)->get_original_pc(this));
270
assert(orig == _pc, "expected original to be stored before patching");
271
_deopt_state = is_deoptimized;
272
// Leave _pc as is.
273
} else {
274
_deopt_state = not_deoptimized;
275
_pc = pc;
276
}
277
}
278
279
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
280
// Is there anything to do?
281
assert(is_interpreted_frame(), "Not an interpreted frame");
282
return true;
283
}
284
285
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
286
assert(is_interpreted_frame(), "interpreted frame expected");
287
Method* method = interpreter_frame_method();
288
BasicType type = method->result_type();
289
290
if (method->is_native()) {
291
// Prior to calling into the runtime to notify the method exit the possible
292
// result value is saved into the interpreter frame.
293
address lresult = (address)&(get_ijava_state()->lresult);
294
address fresult = (address)&(get_ijava_state()->fresult);
295
296
switch (method->result_type()) {
297
case T_OBJECT:
298
case T_ARRAY: {
299
*oop_result = JNIHandles::resolve(*(jobject*)lresult);
300
break;
301
}
302
// We use std/stfd to store the values.
303
case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;
304
case T_INT : value_result->i = (jint) *(long*)lresult; break;
305
case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;
306
case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;
307
case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;
308
case T_LONG : value_result->j = (jlong) *(long*)lresult; break;
309
case T_FLOAT : value_result->f = (jfloat) *(double*)fresult; break;
310
case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;
311
case T_VOID : /* Nothing to do */ break;
312
default : ShouldNotReachHere();
313
}
314
} else {
315
intptr_t* tos_addr = interpreter_frame_tos_address();
316
switch (method->result_type()) {
317
case T_OBJECT:
318
case T_ARRAY: {
319
oop obj = *(oop*)tos_addr;
320
assert(Universe::is_in_heap_or_null(obj), "sanity check");
321
*oop_result = obj;
322
}
323
case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;
324
case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;
325
case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;
326
case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;
327
case T_INT : value_result->i = *(jint*)tos_addr; break;
328
case T_LONG : value_result->j = *(jlong*)tos_addr; break;
329
case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
330
case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
331
case T_VOID : /* Nothing to do */ break;
332
default : ShouldNotReachHere();
333
}
334
}
335
return type;
336
}
337
338
#ifndef PRODUCT
339
340
void frame::describe_pd(FrameValues& values, int frame_no) {
341
if (is_interpreted_frame()) {
342
#define DESCRIBE_ADDRESS(name) \
343
values.describe(frame_no, (intptr_t*)&(get_ijava_state()->name), #name);
344
345
DESCRIBE_ADDRESS(method);
346
DESCRIBE_ADDRESS(mirror);
347
DESCRIBE_ADDRESS(locals);
348
DESCRIBE_ADDRESS(monitors);
349
DESCRIBE_ADDRESS(cpoolCache);
350
DESCRIBE_ADDRESS(bcp);
351
DESCRIBE_ADDRESS(esp);
352
DESCRIBE_ADDRESS(mdx);
353
DESCRIBE_ADDRESS(top_frame_sp);
354
DESCRIBE_ADDRESS(sender_sp);
355
DESCRIBE_ADDRESS(oop_tmp);
356
DESCRIBE_ADDRESS(lresult);
357
DESCRIBE_ADDRESS(fresult);
358
}
359
}
360
#endif
361
362
intptr_t *frame::initial_deoptimization_info() {
363
// unused... but returns fp() to minimize changes introduced by 7087445
364
return fp();
365
}
366
367
#ifndef PRODUCT
368
// This is a generic constructor which is only used by pns() in debug.cpp.
369
frame::frame(void* sp, void* fp, void* pc) : _sp((intptr_t*)sp), _unextended_sp((intptr_t*)sp) {
370
find_codeblob_and_set_pc_and_deopt_state((address)pc); // also sets _fp and adjusts _unextended_sp
371
}
372
373
void frame::pd_ps() {}
374
#endif
375
376