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