1 /*
  2  * Copyright (c) 2022, 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_CONTINUATIONHELPER_PPC_INLINE_HPP
 26 #define CPU_PPC_CONTINUATIONHELPER_PPC_INLINE_HPP
 27 
 28 #include "runtime/continuationHelper.hpp"
 29 
 30 template<typename FKind>
 31 static inline intptr_t** link_address(const frame& f) {
 32   Unimplemented();
 33   return nullptr;
 34 }
 35 




 36 inline int ContinuationHelper::frame_align_words(int size) {
 37   return size & 1;
 38 }
 39 
 40 inline intptr_t* ContinuationHelper::frame_align_pointer(intptr_t* p) {
 41   return align_down(p, frame::frame_alignment);
 42 }
 43 
 44 template<typename FKind>
 45 inline void ContinuationHelper::update_register_map(const frame& f, RegisterMap* map) {
 46   // Currently all registers are considered to be volatile and saved in the caller (java) frame if needed
 47 }
 48 
 49 inline void ContinuationHelper::update_register_map_with_callee(const frame& f, RegisterMap* map) {
 50   // Currently all registers are considered to be volatile and saved in the caller (java) frame if needed
 51 }
 52 
 53 inline void ContinuationHelper::push_pd(const frame& f) {
 54   f.own_abi()->callers_sp = (uint64_t)f.fp();
 55 }
 56 
 57 
 58 inline void ContinuationHelper::set_anchor_to_entry_pd(JavaFrameAnchor* anchor, ContinuationEntry* cont) {
 59   // nothing to do
 60 }
 61 
 62 #ifdef ASSERT
 63 inline void ContinuationHelper::set_anchor_pd(JavaFrameAnchor* anchor, intptr_t* sp) {
 64   // nothing to do
 65 }
 66 

 67 inline bool ContinuationHelper::Frame::assert_frame_laid_out(frame f) {
 68   intptr_t* sp = f.sp();
 69   address pc = *(address*)(sp - frame::sender_sp_ret_address_offset());
 70   intptr_t* fp = (intptr_t*)f.own_abi()->callers_sp;
 71   assert(f.raw_pc() == pc, "f.ra_pc: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.raw_pc()), p2i(pc));
 72   assert(f.fp() == fp, "f.fp: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.fp()), p2i(fp));
 73   return f.raw_pc() == pc && f.fp() == fp;
 74 }
 75 #endif
 76 
 77 inline intptr_t** ContinuationHelper::Frame::callee_link_address(const frame& f) {
 78   return (intptr_t**)&f.own_abi()->callers_sp;
 79 }
 80 
 81 inline address* ContinuationHelper::InterpretedFrame::return_pc_address(const frame& f) {
 82   return (address*)&f.callers_abi()->lr;
 83 }
 84 
 85 inline void ContinuationHelper::InterpretedFrame::patch_sender_sp(frame& f, const frame& caller) {
 86   intptr_t* sp = caller.unextended_sp();
 87   if (!f.is_heap_frame() && caller.is_interpreted_frame()) {
 88     // See diagram "Interpreter Calling Procedure on PPC" at the end of continuationFreezeThaw_ppc.inline.hpp
 89     sp = (intptr_t*)caller.at_relative(ijava_idx(top_frame_sp));
 90   }
 91   assert(f.is_interpreted_frame(), "");
 92   assert(f.is_heap_frame() || is_aligned(sp, frame::alignment_in_bytes), "");
 93   intptr_t* la = f.addr_at(ijava_idx(sender_sp));
 94   *la = f.is_heap_frame() ? (intptr_t)(sp - f.fp()) : (intptr_t)sp;
 95 }
 96 
 97 inline address* ContinuationHelper::Frame::return_pc_address(const frame& f) {
 98   return (address*)&f.callers_abi()->lr;
 99 }
100 
101 inline address ContinuationHelper::Frame::real_pc(const frame& f) {
102   return (address)f.own_abi()->lr;
103 }
104 
105 inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
106   f.own_abi()->lr = (uint64_t)pc;
107 }
108 
109 //                     | Minimal ABI          |
110 //                     | (frame::java_abi)    |
111 //                     | 4 words              |
112 //                     | Caller's SP          |<- FP of f's caller
113 //                     |======================|
114 //                     |                      |                                 Frame of f's caller
115 //                     |                      |
116 // frame_bottom of f ->|                      |
117 //                     |----------------------|
118 //                     | L0 aka P0            |
119 //                     | :                    |
120 //                     | :      Pn            |
121 //                     | :                    |
122 //                     | Lm                   |
123 //                     |----------------------|
124 //                     | SP alignment (opt.)  |
125 //                     |----------------------|
126 //                     | Minimal ABI          |
127 //                     | (frame::java_abi)    |
128 //                     | 4 words              |
129 //                     | Caller's SP          |<- SP of f's caller / FP of f
130 //                     |======================|
131 //                     |ijava_state (metadata)|                                 Frame of f
132 //                     |                      |
133 //                     |                      |
134 //                     |----------------------|
135 //                     | Expression stack     |
136 //                     |                      |
137 //    frame_top of f ->|                      |
138 //   if callee interp. |......................|
139 //                     | L0 aka P0            |<- ijava_state.esp + callee_argsize
140 //                     | :                    |
141 //    frame_top of f ->| :      Pn            |
142 //  + metadata_words   | :                    |<- ijava_state.esp (1 slot below Pn)
143 //    if callee comp.  | Lm                   |
144 //                     |----------------------|
145 //                     | SP alignment (opt.)  |
146 //                     |----------------------|
147 //                     | Minimal ABI          |
148 //                     | (frame::java_abi)    |
149 //                     | 4 words              |
150 //                     | Caller's SP          |<- SP of f / FP of f's callee
151 //                     |======================|
152 //                     |ijava_state (metadata)|                                 Frame of f's callee
153 //                     |                      |
154 //
155 //                           |  Growth  |
156 //                           v          v
157 //
158 // See also diagram at the end of continuation_ppc.inline.hpp
159 //
160 inline intptr_t* ContinuationHelper::InterpretedFrame::frame_top(const frame& f, InterpreterOopMap* mask) { // inclusive; this will be copied with the frame
161   int expression_stack_sz = expression_stack_size(f, mask);
162   intptr_t* res = (intptr_t*)f.interpreter_frame_monitor_end() - expression_stack_sz;
163   assert(res <= (intptr_t*)f.get_ijava_state() - expression_stack_sz,
164          "res=" PTR_FORMAT " f.get_ijava_state()=" PTR_FORMAT " expression_stack_sz=%d",
165          p2i(res), p2i(f.get_ijava_state()), expression_stack_sz);
166   assert(res >= f.unextended_sp(),
167          "res: " INTPTR_FORMAT " ijava_state: " INTPTR_FORMAT " esp: " INTPTR_FORMAT " unextended_sp: " INTPTR_FORMAT " expression_stack_size: %d",
168          p2i(res), p2i(f.get_ijava_state()), f.get_ijava_state()->esp, p2i(f.unextended_sp()), expression_stack_sz);
169   return res;
170 }
171 
172 inline intptr_t* ContinuationHelper::InterpretedFrame::frame_bottom(const frame& f) {
173   return (intptr_t*)f.at_relative(ijava_idx(locals)) + 1; // exclusive (will not be copied), so we add 1 word
174 }
175 
176 inline intptr_t* ContinuationHelper::InterpretedFrame::frame_top(const frame& f, int callee_argsize_incl_metadata, bool callee_interpreted) {
177   intptr_t* pseudo_unextended_sp = f.interpreter_frame_esp() + 1 - frame::metadata_words_at_top;
178   return pseudo_unextended_sp + (callee_interpreted ? callee_argsize_incl_metadata : 0);
179 }
180 
181 inline intptr_t* ContinuationHelper::InterpretedFrame::callers_sp(const frame& f) {
182   return f.fp();
183 }
184 
185 #endif // CPU_PPC_CONTINUATIONFRAMEHELPERS_PPC_INLINE_HPP
--- EOF ---