Wed, 15 Apr 2020 11:49:55 +0800
Merge
1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2014 SAP AG. 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 */
26 #ifndef CPU_PPC_VM_FRAME_PPC_HPP
27 #define CPU_PPC_VM_FRAME_PPC_HPP
29 #include "runtime/synchronizer.hpp"
30 #include "utilities/top.hpp"
32 // C frame layout on PPC-64.
33 //
34 // In this figure the stack grows upwards, while memory grows
35 // downwards. See "64-bit PowerPC ELF ABI Supplement Version 1.7",
36 // IBM Corp. (2003-10-29)
37 // (http://math-atlas.sourceforge.net/devel/assembly/PPC-elf64abi-1.7.pdf).
38 //
39 // Square brackets denote stack regions possibly larger
40 // than a single 64 bit slot.
41 //
42 // STACK:
43 // 0 [C_FRAME] <-- SP after prolog (mod 16 = 0)
44 // [C_FRAME] <-- SP before prolog
45 // ...
46 // [C_FRAME]
47 //
48 // C_FRAME:
49 // 0 [ABI_REG_ARGS]
50 // 112 CARG_9: outgoing arg 9 (arg_1 ... arg_8 via gpr_3 ... gpr_{10})
51 // ...
52 // 40+M*8 CARG_M: outgoing arg M (M is the maximum of outgoing args taken over all call sites in the procedure)
53 // local 1
54 // ...
55 // local N
56 // spill slot for vector reg (16 bytes aligned)
57 // ...
58 // spill slot for vector reg
59 // alignment (4 or 12 bytes)
60 // V SR_VRSAVE
61 // V+4 spill slot for GR
62 // ... ...
63 // spill slot for GR
64 // spill slot for FR
65 // ...
66 // spill slot for FR
67 //
68 // ABI_48:
69 // 0 caller's SP
70 // 8 space for condition register (CR) for next call
71 // 16 space for link register (LR) for next call
72 // 24 reserved
73 // 32 reserved
74 // 40 space for TOC (=R2) register for next call
75 //
76 // ABI_REG_ARGS:
77 // 0 [ABI_48]
78 // 48 CARG_1: spill slot for outgoing arg 1. used by next callee.
79 // ... ...
80 // 104 CARG_8: spill slot for outgoing arg 8. used by next callee.
81 //
83 public:
85 // C frame layout
87 enum {
88 // stack alignment
89 alignment_in_bytes = 16,
90 // log_2(16*8 bits) = 7.
91 log_2_of_alignment_in_bits = 7
92 };
94 // ABI_MINFRAME:
95 struct abi_minframe {
96 uint64_t callers_sp;
97 uint64_t cr; //_16
98 uint64_t lr;
99 #if !defined(ABI_ELFv2)
100 uint64_t reserved1; //_16
101 uint64_t reserved2;
102 #endif
103 uint64_t toc; //_16
104 // nothing to add here!
105 // aligned to frame::alignment_in_bytes (16)
106 };
108 enum {
109 abi_minframe_size = sizeof(abi_minframe)
110 };
112 struct abi_reg_args : abi_minframe {
113 uint64_t carg_1;
114 uint64_t carg_2; //_16
115 uint64_t carg_3;
116 uint64_t carg_4; //_16
117 uint64_t carg_5;
118 uint64_t carg_6; //_16
119 uint64_t carg_7;
120 uint64_t carg_8; //_16
121 // aligned to frame::alignment_in_bytes (16)
122 };
124 enum {
125 abi_reg_args_size = sizeof(abi_reg_args)
126 };
128 #define _abi(_component) \
129 (offset_of(frame::abi_reg_args, _component))
131 struct abi_reg_args_spill : abi_reg_args {
132 // additional spill slots
133 uint64_t spill_ret;
134 uint64_t spill_fret; //_16
135 // aligned to frame::alignment_in_bytes (16)
136 };
138 enum {
139 abi_reg_args_spill_size = sizeof(abi_reg_args_spill)
140 };
142 #define _abi_reg_args_spill(_component) \
143 (offset_of(frame::abi_reg_args_spill, _component))
145 // non-volatile GPRs:
147 struct spill_nonvolatiles {
148 uint64_t r14;
149 uint64_t r15; //_16
150 uint64_t r16;
151 uint64_t r17; //_16
152 uint64_t r18;
153 uint64_t r19; //_16
154 uint64_t r20;
155 uint64_t r21; //_16
156 uint64_t r22;
157 uint64_t r23; //_16
158 uint64_t r24;
159 uint64_t r25; //_16
160 uint64_t r26;
161 uint64_t r27; //_16
162 uint64_t r28;
163 uint64_t r29; //_16
164 uint64_t r30;
165 uint64_t r31; //_16
167 double f14;
168 double f15;
169 double f16;
170 double f17;
171 double f18;
172 double f19;
173 double f20;
174 double f21;
175 double f22;
176 double f23;
177 double f24;
178 double f25;
179 double f26;
180 double f27;
181 double f28;
182 double f29;
183 double f30;
184 double f31;
186 // aligned to frame::alignment_in_bytes (16)
187 };
189 enum {
190 spill_nonvolatiles_size = sizeof(spill_nonvolatiles)
191 };
193 #define _spill_nonvolatiles_neg(_component) \
194 (int)(-frame::spill_nonvolatiles_size + offset_of(frame::spill_nonvolatiles, _component))
198 #ifndef CC_INTERP
199 // Frame layout for the Java template interpreter on PPC64.
200 //
201 // Diffs to the CC_INTERP are marked with 'X'.
202 //
203 // TOP_IJAVA_FRAME:
204 //
205 // 0 [TOP_IJAVA_FRAME_ABI]
206 // alignment (optional)
207 // [operand stack]
208 // [monitors] (optional)
209 // X[IJAVA_STATE]
210 // note: own locals are located in the caller frame.
211 //
212 // PARENT_IJAVA_FRAME:
213 //
214 // 0 [PARENT_IJAVA_FRAME_ABI]
215 // alignment (optional)
216 // [callee's Java result]
217 // [callee's locals w/o arguments]
218 // [outgoing arguments]
219 // [used part of operand stack w/o arguments]
220 // [monitors] (optional)
221 // X[IJAVA_STATE]
222 //
224 struct parent_ijava_frame_abi : abi_minframe {
225 };
227 enum {
228 parent_ijava_frame_abi_size = sizeof(parent_ijava_frame_abi)
229 };
231 #define _parent_ijava_frame_abi(_component) \
232 (offset_of(frame::parent_ijava_frame_abi, _component))
234 struct top_ijava_frame_abi : abi_reg_args {
235 };
237 enum {
238 top_ijava_frame_abi_size = sizeof(top_ijava_frame_abi)
239 };
241 #define _top_ijava_frame_abi(_component) \
242 (offset_of(frame::top_ijava_frame_abi, _component))
244 struct ijava_state {
245 #ifdef ASSERT
246 uint64_t ijava_reserved; // Used for assertion.
247 uint64_t ijava_reserved2; // Inserted for alignment.
248 #endif
249 uint64_t method;
250 uint64_t locals;
251 uint64_t monitors;
252 uint64_t cpoolCache;
253 uint64_t bcp;
254 uint64_t esp;
255 uint64_t mdx;
256 uint64_t top_frame_sp; // Maybe define parent_frame_abi and move there.
257 uint64_t sender_sp;
258 // Slots only needed for native calls. Maybe better to move elsewhere.
259 uint64_t oop_tmp;
260 uint64_t lresult;
261 uint64_t fresult;
262 // Aligned to frame::alignment_in_bytes (16).
263 };
265 enum {
266 ijava_state_size = sizeof(ijava_state)
267 };
269 #define _ijava_state_neg(_component) \
270 (int) (-frame::ijava_state_size + offset_of(frame::ijava_state, _component))
272 #else // CC_INTERP:
274 // Frame layout for the Java C++ interpreter on PPC64.
275 //
276 // This frame layout provides a C-like frame for every Java frame.
277 //
278 // In these figures the stack grows upwards, while memory grows
279 // downwards. Square brackets denote regions possibly larger than
280 // single 64 bit slots.
281 //
282 // STACK (no JNI, no compiled code, no library calls,
283 // interpreter-loop is active):
284 // 0 [InterpretMethod]
285 // [TOP_IJAVA_FRAME]
286 // [PARENT_IJAVA_FRAME]
287 // ...
288 // [PARENT_IJAVA_FRAME]
289 // [ENTRY_FRAME]
290 // [C_FRAME]
291 // ...
292 // [C_FRAME]
293 //
294 // TOP_IJAVA_FRAME:
295 // 0 [TOP_IJAVA_FRAME_ABI]
296 // alignment (optional)
297 // [operand stack]
298 // [monitors] (optional)
299 // [cInterpreter object]
300 // result, locals, and arguments are in parent frame!
301 //
302 // PARENT_IJAVA_FRAME:
303 // 0 [PARENT_IJAVA_FRAME_ABI]
304 // alignment (optional)
305 // [callee's Java result]
306 // [callee's locals w/o arguments]
307 // [outgoing arguments]
308 // [used part of operand stack w/o arguments]
309 // [monitors] (optional)
310 // [cInterpreter object]
311 //
312 // ENTRY_FRAME:
313 // 0 [PARENT_IJAVA_FRAME_ABI]
314 // alignment (optional)
315 // [callee's Java result]
316 // [callee's locals w/o arguments]
317 // [outgoing arguments]
318 // [ENTRY_FRAME_LOCALS]
319 //
320 // PARENT_IJAVA_FRAME_ABI:
321 // 0 [ABI_MINFRAME]
322 // top_frame_sp
323 // initial_caller_sp
324 //
325 // TOP_IJAVA_FRAME_ABI:
326 // 0 [PARENT_IJAVA_FRAME_ABI]
327 // carg_3_unused
328 // carg_4_unused
329 // carg_5_unused
330 // carg_6_unused
331 // carg_7_unused
332 // frame_manager_lr
333 //
335 // PARENT_IJAVA_FRAME_ABI
337 struct parent_ijava_frame_abi : abi_minframe {
338 // SOE registers.
339 // C2i adapters spill their top-frame stack-pointer here.
340 uint64_t top_frame_sp; // carg_1
341 // Sp of calling compiled frame before it was resized by the c2i
342 // adapter or sp of call stub. Does not contain a valid value for
343 // non-initial frames.
344 uint64_t initial_caller_sp; // carg_2
345 // aligned to frame::alignment_in_bytes (16)
346 };
348 enum {
349 parent_ijava_frame_abi_size = sizeof(parent_ijava_frame_abi)
350 };
352 #define _parent_ijava_frame_abi(_component) \
353 (offset_of(frame::parent_ijava_frame_abi, _component))
355 // TOP_IJAVA_FRAME_ABI
357 struct top_ijava_frame_abi : parent_ijava_frame_abi {
358 uint64_t carg_3_unused; // carg_3
359 uint64_t card_4_unused; //_16 carg_4
360 uint64_t carg_5_unused; // carg_5
361 uint64_t carg_6_unused; //_16 carg_6
362 uint64_t carg_7_unused; // carg_7
363 // Use arg8 for storing frame_manager_lr. The size of
364 // top_ijava_frame_abi must match abi_reg_args.
365 uint64_t frame_manager_lr; //_16 carg_8
366 // nothing to add here!
367 // aligned to frame::alignment_in_bytes (16)
368 };
370 enum {
371 top_ijava_frame_abi_size = sizeof(top_ijava_frame_abi)
372 };
374 #define _top_ijava_frame_abi(_component) \
375 (offset_of(frame::top_ijava_frame_abi, _component))
377 #endif // CC_INTERP
379 // ENTRY_FRAME
381 struct entry_frame_locals {
382 uint64_t call_wrapper_address;
383 uint64_t result_address; //_16
384 uint64_t result_type;
385 uint64_t arguments_tos_address; //_16
386 // aligned to frame::alignment_in_bytes (16)
387 uint64_t r[spill_nonvolatiles_size/sizeof(uint64_t)];
388 };
390 enum {
391 entry_frame_locals_size = sizeof(entry_frame_locals)
392 };
394 #define _entry_frame_locals_neg(_component) \
395 (int)(-frame::entry_frame_locals_size + offset_of(frame::entry_frame_locals, _component))
398 // Frame layout for JIT generated methods
399 //
400 // In these figures the stack grows upwards, while memory grows
401 // downwards. Square brackets denote regions possibly larger than single
402 // 64 bit slots.
403 //
404 // STACK (interpreted Java calls JIT generated Java):
405 // [JIT_FRAME] <-- SP (mod 16 = 0)
406 // [TOP_IJAVA_FRAME]
407 // ...
408 //
409 // JIT_FRAME (is a C frame according to PPC-64 ABI):
410 // [out_preserve]
411 // [out_args]
412 // [spills]
413 // [pad_1]
414 // [monitor] (optional)
415 // ...
416 // [monitor] (optional)
417 // [pad_2]
418 // [in_preserve] added / removed by prolog / epilog
419 //
421 // JIT_ABI (TOP and PARENT)
423 struct jit_abi {
424 uint64_t callers_sp;
425 uint64_t cr;
426 uint64_t lr;
427 uint64_t toc;
428 // Nothing to add here!
429 // NOT ALIGNED to frame::alignment_in_bytes (16).
430 };
432 struct jit_out_preserve : jit_abi {
433 // Nothing to add here!
434 };
436 struct jit_in_preserve {
437 // Nothing to add here!
438 };
440 enum {
441 jit_out_preserve_size = sizeof(jit_out_preserve),
442 jit_in_preserve_size = sizeof(jit_in_preserve)
443 };
445 struct jit_monitor {
446 uint64_t monitor[1];
447 };
449 enum {
450 jit_monitor_size = sizeof(jit_monitor),
451 };
453 private:
455 // STACK:
456 // ...
457 // [THIS_FRAME] <-- this._sp (stack pointer for this frame)
458 // [CALLER_FRAME] <-- this.fp() (_sp of caller's frame)
459 // ...
460 //
462 // frame pointer for this frame
463 intptr_t* _fp;
465 // The frame's stack pointer before it has been extended by a c2i adapter;
466 // needed by deoptimization
467 intptr_t* _unextended_sp;
468 void adjust_unextended_sp();
470 public:
472 // Accessors for fields
473 intptr_t* fp() const { return _fp; }
475 // Accessors for ABIs
476 inline abi_minframe* own_abi() const { return (abi_minframe*) _sp; }
477 inline abi_minframe* callers_abi() const { return (abi_minframe*) _fp; }
479 private:
481 // Find codeblob and set deopt_state.
482 inline void find_codeblob_and_set_pc_and_deopt_state(address pc);
484 public:
486 // Constructors
487 inline frame(intptr_t* sp);
488 frame(intptr_t* sp, address pc);
489 inline frame(intptr_t* sp, address pc, intptr_t* unextended_sp);
491 private:
493 intptr_t* compiled_sender_sp(CodeBlob* cb) const;
494 address* compiled_sender_pc_addr(CodeBlob* cb) const;
495 address* sender_pc_addr(void) const;
497 public:
499 #ifdef CC_INTERP
500 // Additional interface for interpreter frames:
501 inline interpreterState get_interpreterState() const;
502 #else
503 inline ijava_state* get_ijava_state() const;
504 // Some convenient register frame setters/getters for deoptimization.
505 inline intptr_t* interpreter_frame_esp() const;
506 inline void interpreter_frame_set_cpcache(ConstantPoolCache* cp);
507 inline void interpreter_frame_set_esp(intptr_t* esp);
508 inline void interpreter_frame_set_top_frame_sp(intptr_t* top_frame_sp);
509 inline void interpreter_frame_set_sender_sp(intptr_t* sender_sp);
510 #endif // CC_INTERP
512 // Size of a monitor in bytes.
513 static int interpreter_frame_monitor_size_in_bytes();
515 // The size of a cInterpreter object.
516 static inline int interpreter_frame_cinterpreterstate_size_in_bytes();
518 private:
520 ConstantPoolCache** interpreter_frame_cpoolcache_addr() const;
522 public:
524 // Additional interface for entry frames:
525 inline entry_frame_locals* get_entry_frame_locals() const {
526 return (entry_frame_locals*) (((address) fp()) - entry_frame_locals_size);
527 }
529 enum {
530 // normal return address is 1 bundle past PC
531 pc_return_offset = 0
532 };
534 #endif // CPU_PPC_VM_FRAME_PPC_HPP