1 /*
  2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, Red Hat Inc. 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 #ifndef CPU_AARCH64_FRAME_AARCH64_HPP
 27 #define CPU_AARCH64_FRAME_AARCH64_HPP
 28 
 29 // A frame represents a physical stack frame (an activation).  Frames can be
 30 // C or Java frames, and the Java frames can be interpreted or compiled.
 31 // In contrast, vframes represent source-level activations, so that one physical frame
 32 // can correspond to multiple source level frames because of inlining.
 33 // A frame is comprised of {pc, fp, sp}
 34 // ------------------------------ Asm interpreter ----------------------------------------
 35 // Layout of asm interpreter frame:
 36 //    [expression stack      ] * <- sp
 37 
 38 //    [monitors[0]           ]   \
 39 //     ...                        | monitor block size = k
 40 //    [monitors[k-1]         ]   /
 41 //    [frame initial esp     ] ( == &monitors[0], initially here)       initial_sp_offset
 42 //    [byte code index/pointr]                   = bcx()                bcx_offset
 43 
 44 //    [pointer to locals     ]                   = locals()             locals_offset
 45 //    [constant pool cache   ]                   = cache()              cache_offset
 46 
 47 //    [klass of method       ]                   = mirror()             mirror_offset
 48 //    [extended SP           ]                                          extended_sp offset
 49 
 50 //    [methodData            ]                   = mdp()                mdx_offset
 51 //    [Method                ]                   = method()             method_offset
 52 
 53 //    [last esp              ]                   = last_sp()            last_sp_offset
 54 //    [sender's SP           ]                     (sender_sp)          sender_sp_offset
 55 
 56 //    [old frame pointer     ]   <- fp           = link()
 57 //    [return pc             ]
 58 
 59 //    [last sp               ]
 60 //    [oop temp              ]                     (only for native calls)
 61 
 62 //    [padding               ]                     (to preserve machine SP alignment)
 63 //    [locals and parameters ]
 64 //                               <- sender sp
 65 // ------------------------------ Asm interpreter ----------------------------------------
 66 
 67  public:
 68   enum {
 69     pc_return_offset                                 =  0,
 70     // All frames
 71     link_offset                                      =  0,
 72     return_addr_offset                               =  1,
 73     sender_sp_offset                                 =  2,
 74 
 75     // Interpreter frames
 76     interpreter_frame_result_handler_offset          =  3, // for native calls only
 77     interpreter_frame_oop_temp_offset                =  2, // for native calls only
 78 
 79     interpreter_frame_sender_sp_offset               = -1,
 80     // outgoing sp before a call to an invoked method
 81     interpreter_frame_last_sp_offset                 = interpreter_frame_sender_sp_offset - 1,
 82     interpreter_frame_method_offset                  = interpreter_frame_last_sp_offset - 1,
 83     interpreter_frame_mdp_offset                     = interpreter_frame_method_offset - 1,
 84     interpreter_frame_extended_sp_offset             = interpreter_frame_mdp_offset - 1,
 85     interpreter_frame_mirror_offset                  = interpreter_frame_extended_sp_offset - 1,
 86     interpreter_frame_cache_offset                   = interpreter_frame_mirror_offset - 1,
 87     interpreter_frame_locals_offset                  = interpreter_frame_cache_offset - 1,
 88     interpreter_frame_bcp_offset                     = interpreter_frame_locals_offset - 1,
 89     interpreter_frame_initial_sp_offset              = interpreter_frame_bcp_offset - 1,
 90 
 91     interpreter_frame_monitor_block_top_offset       = interpreter_frame_initial_sp_offset,
 92     interpreter_frame_monitor_block_bottom_offset    = interpreter_frame_initial_sp_offset,
 93 
 94     // Entry frames
 95     // n.b. these values are determined by the layout defined in
 96     // stubGenerator for the Java call stub
 97     entry_frame_after_call_words                     = 29,
 98     entry_frame_call_wrapper_offset                  = -8,
 99 
100     // we don't need a save area
101     arg_reg_save_area_bytes                          =  0,
102 
103     // size, in words, of frame metadata (e.g. pc and link)
104     metadata_words                                   = sender_sp_offset,
105     // size, in words, of metadata at frame bottom, i.e. it is not part of the
106     // caller/callee overlap
107     metadata_words_at_bottom                         = metadata_words,
108     // size, in words, of frame metadata at the frame top, i.e. it is located
109     // between a callee frame and its stack arguments, where it is part
110     // of the caller/callee overlap
111     metadata_words_at_top                            = 0,
112     // in bytes
113     frame_alignment                                  = 16,
114     // size, in words, of maximum shift in frame position due to alignment
115     align_wiggle                                     =  1
116   };
117 
118   intptr_t ptr_at(int offset) const {
119     return *ptr_at_addr(offset);
120   }
121 
122   void ptr_at_put(int offset, intptr_t value) {
123     *ptr_at_addr(offset) = value;
124   }
125 
126  private:
127   // an additional field beyond _sp and _pc:
128   union {
129     intptr_t*  _fp; // frame pointer
130     int _offset_fp; // relative frame pointer for use in stack-chunk frames
131   };
132   // The interpreter and adapters will extend the frame of the caller.
133   // Since oopMaps are based on the sp of the caller before extension
134   // we need to know that value. However in order to compute the address
135   // of the return address we need the real "raw" sp. Since sparc already
136   // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's
137   // original sp we use that convention.
138 
139   union {
140     intptr_t* _unextended_sp;
141     int _offset_unextended_sp; // for use in stack-chunk frames
142   };
143 
144   void adjust_unextended_sp() NOT_DEBUG_RETURN;
145 
146   // true means _sp value is correct and we can use it to get the sender's sp
147   // of the compiled frame, otherwise, _sp value may be invalid and we can use
148   // _fp to get the sender's sp if PreserveFramePointer is enabled.
149   bool _sp_is_trusted;
150 
151   intptr_t* ptr_at_addr(int offset) const {
152     return (intptr_t*) addr_at(offset);
153   }
154 
155 #ifdef ASSERT
156   // Used in frame::sender_for_{interpreter,compiled}_frame
157   static void verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp);
158 #endif
159 
160  public:
161   // Constructors
162 
163   frame(intptr_t* sp, intptr_t* fp, address pc);
164 
165   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
166 
167   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc, CodeBlob* cb, bool allow_cb_null = false);
168   // used for fast frame construction by continuations
169   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc, CodeBlob* cb, const ImmutableOopMap* oop_map, bool on_heap);
170 
171   frame(intptr_t* sp, intptr_t* fp);
172 
173   void init(intptr_t* sp, intptr_t* fp, address pc);
174   void setup(address pc);
175 
176   // accessors for the instance variables
177   // Note: not necessarily the real 'frame pointer' (see real_fp)
178   intptr_t*   fp() const        { assert_absolute(); return _fp; }
179   void set_fp(intptr_t* newfp)  { _fp = newfp; }
180   int offset_fp() const         { assert_offset();  return _offset_fp; }
181   void set_offset_fp(int value) { assert_on_heap(); _offset_fp = value; }
182 
183   inline address* sender_pc_addr() const;
184   inline address  sender_pc_maybe_signed() const;
185 
186   // expression stack tos if we are nested in a java call
187   intptr_t* interpreter_frame_last_sp() const;
188 
189   void interpreter_frame_set_extended_sp(intptr_t* sp);
190 
191   template <typename RegisterMapT>
192   static void update_map_with_saved_link(RegisterMapT* map, intptr_t** link_addr);
193 
194   // deoptimization support
195   void interpreter_frame_set_last_sp(intptr_t* sp);
196 
197   static jint interpreter_frame_expression_stack_direction() { return -1; }
198 
199   // returns the sending frame, without applying any barriers
200   inline frame sender_raw(RegisterMap* map) const;
201 
202   void set_sp_is_trusted() { _sp_is_trusted = true; }
203 
204 #endif // CPU_AARCH64_FRAME_AARCH64_HPP
--- EOF ---