1 /*
  2  * Copyright (c) 2019, 2023, Oracle and/or its affiliates. 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 #ifndef CPU_PPC_CONTINUATION_PPC_INLINE_HPP
 26 #define CPU_PPC_CONTINUATION_PPC_INLINE_HPP
 27 
 28 #include "oops/stackChunkOop.inline.hpp"
 29 #include "runtime/frame.hpp"
 30 #include "runtime/frame.inline.hpp"
 31 
 32 inline void patch_callee_link(const frame& f, intptr_t* fp) {
 33   *ContinuationHelper::Frame::callee_link_address(f) = fp;
 34 }
 35 
 36 inline void patch_callee_link_relative(const frame& f, intptr_t* fp) {
 37   intptr_t* la = (intptr_t*)ContinuationHelper::Frame::callee_link_address(f);
 38   intptr_t new_value = fp - la;
 39   *la = new_value;
 40 }
 41 
 42 ////// Freeze
 43 
 44 // Fast path
 45 
 46 inline void FreezeBase::patch_stack_pd(intptr_t* frame_sp, intptr_t* heap_sp) {
 47   // Nothing to do. The backchain is reconstructed when thawing (see Thaw<ConfigT>::patch_caller_links())
 48 }
 49 
 50 // Slow path
 51 
 52 template<typename FKind>
 53 inline frame FreezeBase::sender(const frame& f) {
 54   assert(FKind::is_instance(f), "");
 55   if (FKind::interpreted) {
 56     return frame(f.sender_sp(), f.sender_pc(), f.interpreter_frame_sender_sp());
 57   }
 58 
 59   intptr_t* sender_sp = f.sender_sp();
 60   address sender_pc = f.sender_pc();
 61   assert(sender_sp != f.sp(), "must have changed");
 62 
 63   int slot = 0;
 64   CodeBlob* sender_cb = CodeCache::find_blob_and_oopmap(sender_pc, slot);
 65   return sender_cb != nullptr
 66     ? frame(sender_sp, sender_sp, nullptr, sender_pc, sender_cb, slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc))
 67     : frame(sender_sp, sender_pc, sender_sp);
 68 }
 69 
 70 void FreezeBase::adjust_interpreted_frame_unextended_sp(frame& f) {
 71   // nothing to do
 72 }
 73 
 74 inline void FreezeBase::prepare_freeze_interpreted_top_frame(const frame& f) {
 75   Unimplemented();
 76 }
 77 
 78 inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, const frame& hf) {
 79   intptr_t* vfp = f.fp();
 80   intptr_t* hfp = hf.fp();
 81   assert(f.fp() > (intptr_t*)f.interpreter_frame_esp(), "");
 82 
 83   // There is alignment padding between vfp and f's locals array in the original
 84   // frame, because we freeze the padding (see recurse_freeze_interpreted_frame)
 85   // in order to keep the same relativized locals pointer, we don't need to change it here.
 86 
 87   // Make sure that monitors is already relativized.
 88   assert(hf.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
 89 
 90   // Make sure that esp is already relativized.
 91   assert(hf.at_absolute(ijava_idx(esp)) <= hf.at_absolute(ijava_idx(monitors)), "");
 92 
 93   // top_frame_sp is already relativized
 94 
 95   // hfp == hf.sp() + (f.fp() - f.sp()) is not true on ppc because the stack frame has room for
 96   // the maximal expression stack and the expression stack in the heap frame is trimmed.
 97   assert(hf.fp() == hf.interpreter_frame_esp() + (f.fp() - f.interpreter_frame_esp()), "");
 98   assert(hf.fp()                 <= (intptr_t*)hf.at(ijava_idx(locals)), "");
 99 }
100 
101 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
102   stackChunkOop chunk = _cont.tail();
103   assert(chunk->is_in_chunk(hf.sp()), "hf.sp()=" PTR_FORMAT, p2i(hf.sp()));
104 
105   hf.own_abi()->lr = (uint64_t)hf.pc();
106   if (hf.is_interpreted_frame()) {
107     patch_callee_link_relative(hf, hf.fp());
108   }
109 #ifdef ASSERT
110   else {
111     // See also FreezeBase::patch_pd()
112     patch_callee_link(hf, (intptr_t*)badAddress);
113   }
114 #endif
115 }
116 
117 //
118 // Heap frames differ from stack frames in the following aspects
119 //
120 // - they are just word aligned
121 // - the unextended sp of interpreted frames is set such that
122 //   unextended sp + frame::metadata_words_at_top + 1 points to the last call parameter
123 //   (the comment at the file end explains the unextended sp for interpreted frames on the stack)
124 //
125 // The difference in respect to the unextended sp is required to comply with shared code.
126 // Furthermore fast frozen and compiled frames have invalid back links (see
127 // Thaw<ConfigT>::patch_caller_links() and FreezeBase::patch_pd())
128 //
129 // === New Interpreted Frame ==========================================================================================
130 //
131 // ### Interpreted Caller: Overlap new frame with Caller
132 //
133 //     Caller on entry                                     New frame with resized Caller
134 //
135 //     | frame::java_abi        |                          |                        |
136 //     |                        |<- FP of caller           | Caller's SP            |<- FP of caller
137 //     ==========================                          ==========================
138 //     | ijava_state            |                          | ijava_state            |
139 //     |                        |                          |                        |
140 //     |------------------------|                  -----   |------------------------|
141 //     | P0                     |                    ^     | L0 aka P0              |
142 //     | :                      |                    |     | :      :               |
143 //     | Pn                     |<- unext. SP        |     | :      Pn              |<- unext. SP
144 //     |------------------------|   + metadata     overlap | :                      |   + metadata
145 //     | frame::java_abi        |                    |     | Lm                     |
146 //     | (metadata_words_at_top)|<- SP == unext. SP  v     |------------------------|<- unextended SP of caller (1)
147 //     ==========================   of caller      -----   | frame::java_abi        |
148 //                                                         | (metadata_words_at_top)|<- new SP of caller / FP of new frame
149 //      overlap = stack_argsize(f)                         ==========================       ^
150 //                + frame::metadata_words_at_top           | ijava_state            |       |
151 //                                                         |                        |       |
152 //      Where f is the frame to be relocated on the heap.  |------------------------|       |
153 //      See also StackChunkFrameStream::frame_size().      | Expressions            |   FP - esp of f
154 //                                                         | P0                     |       |
155 //                                                         | :                      |       |
156 //                            |  Growth  |                 | Pi                     |       v
157 //                            v          v                 |------------------------|      ---
158 //                                                         | frame::java_abi        |
159 //                                                         | (metadata_words_at_top)|<- unextended SP /
160 //                                                         ==========================   SP of new frame
161 // ### Compiled Caller: No Overlap
162 //
163 //     The caller is resized to accomodate the callee's locals and abi but there is _no_ overlap with
164 //     the original caller frame.
165 //
166 //     Caller on entry                                     New frame with resized Caller
167 //
168 //     | frame::java_abi        |                          |                        |
169 //     | (metadata_words_at_top)|<- FP of caller           | Caller's SP            |<- FP of caller
170 //     ==========================                          ==========================
171 //     |                        |                          |                        |
172 //     |                        |                          |                        |
173 //     |------------------------|                          |------------------------|
174 //     | frame::java_abi        |                          | frame::java_abi        |
175 //     | (metadata_words_at_top)|<- SP == unext. SP        | (metadata_words_at_top)|<- unext. SP of caller
176 //     ==========================   of caller              |------------------------|
177 //                                                         | L0 aka P0              |
178 //                                                         | :      :               |
179 //                                                         | :      Pn              |
180 //      overlap = 0                                        | Lm                     |
181 //                                                         |------------------------|
182 //      f is the frame to be relocated on the heap         | frame::java_abi        |
183 //                                                         | (metadata_words_at_top)|<- new SP of caller / FP of new frame
184 //                                                         ==========================       ^
185 //                                                         | ijava_state            |       |
186 //                             |  Growth  |                |                        |       |
187 //                             v          v                |------------------------|       |
188 //                                                         | Expressions            |   FP - esp of f
189 //                                                         | P0                     |       |
190 //                                                         | :                      |       |
191 //                                                         | Pi                     |       v
192 //                                                         |------------------------|      ---
193 //                                                         | frame::java_abi        |
194 //                                                         | (metadata_words_at_top)|<- unextended SP /
195 //                                                         ==========================   SP of new frame
196 //
197 // (1) Caller's unextended SP is preserved in callee's frame::ijava_state::sender_sp
198 //     (See ContinuationHelper::InterpretedFrame::patch_sender_sp). This is required
199 //     by StackChunkFrameStream<frame_kind>::next_for_interpreter_frame().
200 //
201 // === New Compiled Frame =============================================================================================
202 //
203 // ### Interpreted Caller: No Overlap
204 //
205 //     The caller is resized to accomodate the callee's stack arguments and abi but there is _no_ overlap with
206 //     the original caller frame.
207 //
208 //     Note: a new ABI is added to the caller even if there are no stackargs.
209 //     This is necessary to comply with shared code.
210 //
211 //     Caller on entry                                     New frame with resized Caller
212 //
213 //     | frame::java_abi        |                          | frame::java_abi        |
214 //     | (metadata_words_at_top)|<- FP of caller           | (metadata_words_at_top)|<- FP of caller
215 //     ==========================                          ==========================
216 //     | ijava_state            |                          | ijava_state            |
217 //     |                        |                          |                        |
218 //     |------------------------|                          |------------------------|
219 //     | P0                     |                          | P0                     |
220 //     | :                      |                          | :                      |
221 //     | Pn                     |<- unext. SP              | Pn                     |<- unext. SP
222 //     |------------------------|   + metadata             |------------------------|   + metadata
223 //     | frame::java_abi        |                          | frame::java_abi        |
224 //     | (metadata_words_at_top)|<- SP == unext. SP        | (metadata_words_at_top)|<- unextended SP of caller (1)
225 //     ==========================   of caller              |------------------------|
226 //                                                         | Stack Args             |
227 //      overlap = 0                                        | (if any)               |
228 //                                                         |------------------------|
229 //      f is the frame to be relocated on the heap         | frame::java_abi        |
230 //                                                         | (metadata_words_at_top)|<- new SP of caller / FP of new frame
231 //                                                         ==========================
232 //                                                         |                        |
233 //                             |  Growth  |                |                        |
234 //                             v          v                |------------------------|
235 //                                                         | frame::java_abi        |
236 //                                                         | (metadata_words_at_top)|<- SP == unext. SP of new frame
237 //                                                         ==========================
238 //
239 // ### Compiled Caller: Stackargs + ABI Overlap
240 //
241 //     Caller on entry                                     New frame with resized Caller
242 //
243 //     | frame::java_abi        |                          | frame::java_abi        |
244 //     | (metadata_words_at_top)|<- FP of caller           | (metadata_words_at_top)|<- FP of caller
245 //     ==========================                          ==========================
246 //     |                        |                          |                        |
247 //     |                        |                          |                        |
248 //     |------------------------|                   -----  |------------------------|
249 //     | Stack Args             |                     ^    | Stack Args             |
250 //     | (if any)               |                     |    | (if any)               |
251 //     |------------------------|                  overlap |------------------------|
252 //     | frame::java_abi        |                     |    | frame::java_abi        |
253 //     | (metadata_words_at_top)|<- SP == unext. SP   v    | (metadata_words_at_top)|<- SP == unext. SP of caller
254 //     ==========================   of caller       -----  ==========================   / FP of new frame
255 //                                                         |                        |
256 //      overlap = stack_argsize(f)                         |                        |
257 //                + frame::metadata_words_at_top           |------------------------|
258 //                                                         | frame::java_abi        |
259 //      Where f is the frame to be relocated on the heap.  | (metadata_words_at_top)|<- SP == unext. SP of new frame
260 //      See also StackChunkFrameStream::frame_size().      ==========================
261 //
262 template<typename FKind>
263 frame FreezeBase::new_heap_frame(frame& f, frame& caller) {
264   assert(FKind::is_instance(f), "");
265 
266   intptr_t *sp, *fp;
267   if (FKind::interpreted) {
268     intptr_t locals_offset = *f.addr_at(ijava_idx(locals));
269     // If the caller.is_empty(), i.e. we're freezing into an empty chunk, then we set
270     // the chunk's argsize in finalize_freeze and make room for it above the unextended_sp
271     // See also comment on StackChunkFrameStream<frame_kind>::interpreter_frame_size()
272     int overlap =
273         (caller.is_interpreted_frame() || caller.is_empty())
274         ? ContinuationHelper::InterpretedFrame::stack_argsize(f) + frame::metadata_words_at_top
275         : 0;
276     fp = caller.unextended_sp() - 1 - locals_offset + overlap;
277     // esp points one slot below the last argument
278     intptr_t* x86_64_like_unextended_sp = f.interpreter_frame_esp() + 1 - frame::metadata_words_at_top;
279     sp = fp - (f.fp() - x86_64_like_unextended_sp);
280 
281     assert (sp <= fp && (fp <= caller.unextended_sp() || caller.is_interpreted_frame()),
282             "sp=" PTR_FORMAT " fp=" PTR_FORMAT " caller.unextended_sp()=" PTR_FORMAT " caller.is_interpreted_frame()=%d",
283             p2i(sp), p2i(fp), p2i(caller.unextended_sp()), caller.is_interpreted_frame());
284     caller.set_sp(fp);
285 
286     assert(_cont.tail()->is_in_chunk(sp), "");
287 
288     frame hf(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
289     // frame_top() and frame_bottom() read these before relativize_interpreted_frame_metadata() is called
290     *hf.addr_at(ijava_idx(locals)) = locals_offset;
291     *hf.addr_at(ijava_idx(esp))    = f.interpreter_frame_esp() - f.fp();
292     return hf;
293   } else {
294     int fsize = FKind::size(f);
295     sp = caller.unextended_sp() - fsize;
296     if (caller.is_interpreted_frame()) {
297       // If the caller is interpreted, our stackargs are not supposed to overlap with it
298       // so we make more room by moving sp down by argsize
299       int argsize = FKind::stack_argsize(f);
300       sp -= argsize + frame::metadata_words_at_top;
301     }
302     fp = sp + fsize;
303     caller.set_sp(fp);
304 
305     assert(_cont.tail()->is_in_chunk(sp), "");
306 
307     return frame(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
308   }
309 }
310 
311 inline void FreezeBase::patch_pd(frame& hf, const frame& caller) {
312   if (caller.is_interpreted_frame()) {
313     assert(!caller.is_empty(), "");
314     patch_callee_link_relative(caller, caller.fp());
315   }
316 #ifdef ASSERT
317   else {
318     // For compiled frames the back link is actually redundant. It gets computed
319     // as unextended_sp + frame_size.
320 
321     // Note the difference on x86_64: the link is not made relative if the caller
322     // is a compiled frame because there rbp is used as a non-volatile register by
323     // c1/c2 so it could be a computed value local to the caller.
324 
325     // See also:
326     // - FreezeBase::set_top_frame_metadata_pd
327     // - StackChunkFrameStream<frame_kind>::fp()
328     // - UseContinuationFastPath: compiled frames are copied in a batch w/o patching the back link.
329     //   The backlinks are restored when thawing (see Thaw<ConfigT>::patch_caller_links())
330     patch_callee_link(hf, (intptr_t*)badAddress);
331   }
332 #endif
333 }
334 
335 //////// Thaw
336 
337 // Fast path
338 
339 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
340   size <<= LogBytesPerWord;
341   Prefetch::read(start, size);
342   Prefetch::read(start, size - 64);
343 }
344 
345 // Set back chain links of fast thawed frames such that *sp == callers_sp.
346 // See https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#STACK
347 template <typename ConfigT>
348 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
349   for (intptr_t* callers_sp; sp < bottom; sp = callers_sp) {
350     address pc = (address)((frame::java_abi*) sp)->lr;
351     assert(pc != nullptr, "");
352     // see ThawBase::patch_return() which gets called just before
353     bool is_entry_frame = pc == StubRoutines::cont_returnBarrier() || pc == _cont.entryPC();
354     if (is_entry_frame) {
355       callers_sp = _cont.entryFP();
356     } else {
357       CodeBlob* cb = CodeCache::find_blob_fast(pc);
358       callers_sp = sp + cb->frame_size();
359     }
360     // set the back link
361     ((frame::java_abi*) sp)->callers_sp = (intptr_t) callers_sp;
362   }
363 }
364 
365 // Slow path
366 
367 inline frame ThawBase::new_entry_frame() {
368   intptr_t* sp = _cont.entrySP();
369   return frame(sp, _cont.entryPC(), sp, _cont.entryFP());
370 }
371 
372 // === New Interpreted Frame ================================================================================================================
373 //
374 // ### Non-Interpreted Caller (compiled, enterSpecial): No Overlap
375 //
376 //     Heap Frame `hf`                                   `hf` gets copied to stack _without_ overlapping the caller
377 //
378 //     |                      |                            Non-Interpreted |                      |
379 //     |                      |<- bottom                   Caller          |----------------------|
380 //     |----------------------|    ^                                       | frame::java_abi      |<- unextended SP
381 //     | L0 aka P0            |    |                                   --- ========================
382 //     | :      :             |    |                                    ^  | L0 aka P0            |
383 //     | :      Pn            |    |                                    |  | :      :             | Parameters do
384 //     | :                    |    |                                    |  | :      Pn            | not overlap with
385 //     | Lm                   |    |                                    |  | :                    | caller!
386 //     |----------------------| `fsize`                                 |  | :                    |
387 //     | frame::java_abi      |    |                                       | :                    |
388 //     ========================    |                     `fsize` + padding | Lm                   |
389 //     |                      |    |                                       |----------------------|
390 //     | ijava_state          |    |                                    |  | Opt. Align. Padding  |
391 //     |                      |    |                                    |  |----------------------|
392 //     |----------------------|    |                                    |  | frame::java_abi      |<- new SP of caller
393 //     | L0 aka P0            |    |                                    |  ========================   / FP of new frame
394 //     | :      :             |    |                                    |  |                      |   (aligned)
395 //     | :      Pn            |<- unext. SP + metadata                  |  | ijava_state          |
396 //     | :                    |    |                                    |  |                      |
397 //     | Lm                   |    |                                    |  |----------------------|
398 //     |----------------------|    v                                    |  | P0                   |
399 //     | frame::java_abi      |<- SP / unextended SP                    |  | :                    |
400 //     ========================                                         |  | Pi                   |<- unextended SP + metadata
401 //                                                                      |  |----------------------|
402 //                                           | Growth |                 v  | frame::java_abi      |<- unextended SP / SP of new frame
403 //                                           v        v                --- ========================   (not yet aligned(1))
404 //
405 //
406 // ### Interpreted Caller: Overlap with Caller
407 //
408 //     Caller                                                              New frame with resized/aligned Caller
409 //
410 //     |                      |                                            |                      |
411 //     | ijava_state          |                                            | ijava_state          |
412 //     |----------------------|                                            |----------------------|
413 //     | non param. expr.     |                                     bottom | non param. expr.     |
414 //     | - - - - - - - - - -  |                           ---           ^  | - - - - - - - - - -  |
415 //     | P0                   |                            ^            |  | L0 aka P0            |
416 //     | :                    |                            |            |  | :      :             |
417 //     | Pn                   |<- unextended SP           overlap       |  | :      Pn            |<- unextended SP
418 //     |----------------------|   + metadata_words_at_top  |            |  | :                    |   + metadata_words_at_top
419 //     | frame::java_abi      |<- unextended SP            v            |  | :                    |   (unaligned)
420 //     ========================   / SP of new frame       ---           |  | :                    |   of caller
421 //                                (not yet aligned(1))                  |  | Lm                   |
422 //                                                                `fsize`  |----------------------|
423 //       overlap = stack_argsize(hf)                              + padding| Opt. Align. Padding  |
424 //                 + frame::metadata_words_at_top                       |  |----------------------|
425 //                                                                      |  | frame::java_abi      |<- new SP of caller
426 //                                                                      |  ========================   / FP of new frame
427 //                                                                      |  |                      |   (aligned)
428 //                                  | Growth |                          |  | ijava_state          |
429 //                                  v        v                          |  |                      |
430 //                                                                      |  |----------------------|
431 //                                                                      |  | P0                   |
432 //                                                                      |  | :                    |
433 //                                                                      |  | Pi                   |<- unextended SP
434 //                                                                      |  |----------------------|    + metadata_words_at_top
435 //                                                                      v  | frame::java_abi      |<- unextended SP / SP of new frame
436 //                                                                     --- ========================   (not yet aligned(1))
437 //
438 //
439 //  (1) The SP / unextended SP of the new interpreted frame is not aligned. It
440 //      gets aligned when its callee is pushed on stack or in finish_thaw() if
441 //      it is the top frame. This allows addressing parameters: unextended SP + metadata_words_at_top
442 //
443 //  (2) If caller is interpreted then its ijava_state::top_frame_sp will be used as sender sp
444 //      of the new frame (see ContinuationHelper::InterpretedFrame::patch_sender_sp() and diagram at the end of this file)
445 //
446 //  (3) The size of alignment padding required when thawing frames is accounted for
447 //      in FreezeBase::_align_size.
448 //
449 // === New Compiled Frame ===================================================================================================================
450 //
451 //        Compiled Caller                              Interpreted Caller
452 //
453 //        - stackargs+abi overlap with caller          - gets resized for stackargs
454 //        - no alignment padding                       - SP gets aligned
455 //                                                     - no overlap with orig.
456 //                                                       caller
457 //   O C
458 //   r a  |                      |                     |                      |
459 //   i l  |                      |                     |                      |
460 //   g l  |----------------------|                     |                      |
461 //   i e  | Stack Args           |                     |                      |
462 //   n r  | (if any)             |                     |----------------------|
463 //   a    |----------------------|                     | frame::java_abi      |
464 //   l    | frame::java_abi      |<- unext. SP / SP    | (unused)             |<- unal.unext.SP
465 //  - - - ======================== - - - - - - - - - - |----------------------|- - - - - - - - - - - - - - - - - - - - - - - - - - - -
466 //    N   |                      |                     | Opt. Align. Padding  |
467 //    e   |                      |                     |----------------------|
468 //    w   |----------------------|                     | Stack Args           |
469 //        | frame::java_abi      |<- unext. SP / SP    | (if any)             |
470 //    F   ========================                     |----------------------|
471 //    r                                                | frame::java_abi      |<- caller's SP
472 //    a                                                ======================== / new frame's FP
473 //    m                                                |                      |   (aligned)
474 //    e                                                |                      |
475 //                                                     |----------------------|
476 //                                                     | frame::java_abi      |<- unext. SP / SP
477 //                                                     ========================
478 //
479 //  If the new frame is at the bottom just above the ContinuationEntry frame then the stackargs
480 //  don't overlap the caller either even though it is compiled because the size is not
481 //  limited/known. In contrast to the interpreted caller case the abi overlaps with the caller
482 //  if there are no stackargs. This is to comply with shared code (see e.g. StackChunkFrameStream::frame_size())
483 //
484 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
485   assert(FKind::is_instance(hf), "");
486 
487   assert(is_aligned(caller.fp(), frame::frame_alignment), "");
488   assert(is_aligned(caller.sp(), frame::frame_alignment), "");
489   if (FKind::interpreted) {
490     // Note: we have to overlap with the caller, at least if it is interpreted, to match the
491     // max_thawing_size calculation during freeze. See also comment above.
492     intptr_t* heap_sp = hf.unextended_sp();
493     const int fsize = ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp();
494     const int overlap = !caller.is_interpreted_frame() ? 0
495                         : ContinuationHelper::InterpretedFrame::stack_argsize(hf) + frame::metadata_words_at_top;
496     intptr_t* frame_sp = caller.unextended_sp() + overlap - fsize;
497     intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
498     // align fp
499     int padding = fp - align_down(fp, frame::frame_alignment);
500     fp -= padding;
501     // alignment of sp is done by callee or in finish_thaw()
502     frame_sp -= padding;
503 
504     // On ppc esp points to the next free slot on the expression stack and sp + metadata points to the last parameter
505     DEBUG_ONLY(intptr_t* esp = fp + *hf.addr_at(ijava_idx(esp));)
506     assert(frame_sp + frame::metadata_words_at_top == esp+1, " frame_sp=" PTR_FORMAT " esp=" PTR_FORMAT, p2i(frame_sp), p2i(esp));
507     caller.set_sp(fp);
508     frame f(frame_sp, hf.pc(), frame_sp, fp);
509     // we need to set the locals so that the caller of new_stack_frame() can call
510     // ContinuationHelper::InterpretedFrame::frame_bottom
511     // copy relativized locals from the heap frame
512     *f.addr_at(ijava_idx(locals)) = *hf.addr_at(ijava_idx(locals));
513 
514     return f;
515   } else {
516     int fsize = FKind::size(hf);
517     int argsize = hf.compiled_frame_stack_argsize();
518     intptr_t* frame_sp = caller.sp() - fsize;
519 
520     if ((bottom && argsize > 0) || caller.is_interpreted_frame()) {
521       frame_sp -= argsize + frame::metadata_words_at_top;
522       frame_sp = align_down(frame_sp, frame::alignment_in_bytes);
523       caller.set_sp(frame_sp + fsize);
524     }
525 
526     assert(hf.cb() != nullptr, "");
527     assert(hf.oop_map() != nullptr, "");
528     intptr_t* fp = frame_sp + fsize;
529     return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false);
530   }
531 }
532 
533 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
534   // Unused. Alignment is done directly in new_stack_frame() / finish_thaw().
535   return nullptr;
536 }
537 
538 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
539   intptr_t* vfp = f.fp();
540 
541   // Make sure that monitors is still relativized.
542   assert(f.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
543 
544   // Make sure that esp is still relativized.
545   assert(f.at_absolute(ijava_idx(esp)) <= f.at_absolute(ijava_idx(monitors)), "");
546 
547   // Keep top_frame_sp relativized.
548 }
549 
550 inline intptr_t* ThawBase::push_preempt_rerun_adapter(frame top, bool is_interpreted_frame) {
551   Unimplemented();
552   return nullptr;
553 }
554 
555 inline intptr_t* ThawBase::push_preempt_monitorenter_redo(stackChunkOop chunk) {
556   Unimplemented();
557   return nullptr;
558 }
559 
560 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
561   patch_callee_link(caller, caller.fp());
562   // Prevent assertion if f gets deoptimized right away before it's fully initialized
563   f.mark_not_fully_initialized();
564 }
565 
566 inline void ThawBase::patch_pd(frame& f, intptr_t* caller_sp) {
567   Unimplemented();
568 }
569 
570 //
571 // Interpreter Calling Procedure on PPC
572 //
573 // Caller                                   Resized Caller before the Call                New Callee Frame
574 //
575 //   - SP/FP are 16 byte aligned.           - The unused part of the expression stack     - The caller's original SP is passed as
576 //     Padding is added as necessary.         is removed                                    sender SP (in R21_sender_SP) also by
577 //   - SP is _not_ used as esp              - Slots for the callee's nonparameter locals    compiled callers. It is saved in the
578 //     (expression stack pointer)             are added.                                    ijava_state::sender_sp slot and
579 //   - Has reserved slots for the           - The large ABI is replaced with a minimal      restored when returning.
580 //     maximal expression stack               ABI.                                          This removes a c2i extension if there
581 //   - Has a larger ABI section on          - The original SP was saved in                  is one.
582 //     top that is required to call           ijava_state::top_frame_sp slot.             - ijava_state::sender_sp will be set
583 //     C++ code                               From there it is restored as SP _after_       as the caller's unextended sp when
584 //                                            returning from a call. This reverts the       iterating stack frames
585 //                                            resizing described above. It is also          (see frame::unextended_sp() and
586 //                                            required to undo potential i2c extensions     frame::sender_for_interpreter_frame())
587 //                                            if the calle should be compiled.
588 //                                          - Note that unextended SP < SP
589 //                                            is possible on ppc.
590 //
591 // |                      |                 |                      |                      |                      |
592 // | (frame::java_abi)    |                 | (frame::java_abi)    |                      | (frame::java_abi)    |
593 // | 4 words              |                 | 4 words              |                      | 4 words              |
594 // | Caller's SP          |<- FP of caller  | Caller's SP          |<- FP of caller       | Caller's SP          |<- FP of caller
595 // ========================   (aligned)     ========================                      ========================
596 // | frame::              |                 | frame::              |                      | frame::              |
597 // | ijava_state          |                 | ijava_state          |                      | ijava_state          |
598 // |                      |                 |                      |                      |                      |
599 // |----------------------|                 |----------------------|                      |----------------------|
600 // | P0                   |                 | L0 aka P0            |                      | L0 aka P0            |
601 // |                      |                 | :                    |                      | :                    |
602 // | Pn                   |                 | :      Pn            |                      | :      Pn            |
603 // |----------------------|                 | :                    |                      | :                    |
604 // |                      |                 | Lm                   |                      | Lm                   |
605 // | Reserved Expr. Stack |                 |----------------------|                      |----------------------|
606 // |                      |                 | Opt. Alignm. Padding |                      | Opt. Alignm. Padding |
607 // |                      |<- ConstMethod   |----------------------|                      |----------------------|
608 // |----------------------|   ::_max_stack  |                      |                      |                      |
609 // | Opt. Alignm. Padding |                 | (frame::java_abi)    |                      | (frame::java_abi)    |
610 // |----------------------|                 | 4 words              |                      | 4 words              |
611 // | Large ABI            |                 | Caller's SP          |<- new SP of caller   | Caller's SP          |<- SP of caller /
612 // | for C++ calls        |                 ========================   (aligned)          ========================   FP of callee
613 // | (frame::             |                                                               | frame::              |   (aligned)
614 // |  native_abi_reg_args)|                                                               | ijava_state          |
615 // |                      |                                                               |                      |
616 // |                      |                                                               |----------------------|
617 // |                      |                                                               |                      |
618 // | Caller's SP          |<- SP of caller                          <- unextended SP      | Reserved Expr. Stack |<- unextended SP
619 // ========================   (aligned)                                of caller          |                      |   of caller
620 //                                                                     (aligned)          |                      |
621 //                                                                                        |                      |
622 //                                                                                        |                      |
623 //                                                                                        |                      |
624 //                                                                                        |                      |<- ConstMethod
625 //                                                                                        |----------------------|   ::_max_stack
626 //                         Resize Caller                    Push new Callee Frame         | Opt. Alignm. Padding |
627 //                     -------------------->              ------------------------>       |----------------------|
628 //                     (ABI, expressions, locals)                                         | Large ABI            |
629 //                                                                                        | for C++ calls        |
630 //                                                                                        | (frame::             |
631 //                                                                                        |  native_abi_reg_args)|
632 //                                                |  Growth  |                            |                      |
633 //                                                v          v                            |                      |
634 //                                                                                        |                      |
635 //                                                                                        | Caller's SP          |<- SP of callee
636 //                                                                                        ========================   (aligned)
637 //
638 //
639 #endif // CPU_PPC_CONTINUATION_PPC_INLINE_HPP
--- EOF ---