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

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