1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
   4  * Copyright (c) 2015, Linaro Ltd. All rights reserved.
   5  * Copyright (c) 2015-2018, Azul Systems, Inc. All rights reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23  * or visit www.oracle.com if you need additional information or have any
  24  * questions.
  25  *
  26  */
  27 
  28 #ifndef CPU_AARCH32_VM_FRAME_AARCH32_HPP
  29 #define CPU_AARCH32_VM_FRAME_AARCH32_HPP
  30 
  31 #include "runtime/synchronizer.hpp"
  32 
  33 // A frame represents a physical stack frame (an activation).  Frames can be
  34 // C or Java frames, and the Java frames can be interpreted or compiled.
  35 // In contrast, vframes represent source-level activations, so that one physical frame
  36 // can correspond to multiple source level frames because of inlining.
  37 // A frame is comprised of {pc, fp, sp}
  38 // ------------------------------ Asm interpreter ----------------------------------------
  39 // Layout of asm interpreter frame:
  40 //    [expression stack      ] * <- sp
  41 
  42 //    [monitors[0]           ]   \
  43 //     ...                        | monitor block size = k
  44 //    [monitors[k-1]         ]   /
  45 //    [frame initial esp     ] ( == &monitors[0], initially here)       initial_sp_offset
  46 //    [byte code index/pointr]                   = bcx()                bcx_offset
  47 
  48 //    [pointer to locals     ]                   = locals()             locals_offset
  49 //    [constant pool cache   ]                   = cache()              cache_offset
  50 
  51 //    [klass of method       ]                   = mirror()             mirror_offset
  52 //    [padding               ]
  53 
  54 //    [methodData            ]                   = mdp()                mdx_offset
  55 //    [methodOop             ]                   = method()             method_offset
  56 
  57 //    [last esp              ]                   = last_sp()            last_sp_offset
  58 //    [old stack pointer     ]                     (sender_sp)          sender_sp_offset
  59 
  60 //    [old frame pointer     ]                   = link()
  61 //    [return pc             ]   <- fp
  62 
  63 //    [last sp               ]
  64 //    [oop temp              ]                     (only for native calls)
  65 
  66 //    [locals and parameters ]
  67 //                               <- sender sp
  68 // ------------------------------ Asm interpreter ----------------------------------------
  69 
  70  public:
  71   enum {
  72     pc_return_offset                                 =  0,
  73     // All frames
  74     sender_sp_offset                                 =  1,
  75 
  76     // we don't need a save area
  77     arg_reg_save_area_bytes                          =  0,
  78 
  79     // Interpreter frames
  80     interpreter_frame_oop_temp_offset                = 2, // for native calls only
  81 
  82     interpreter_frame_sender_sp_offset               = 0,
  83     // outgoing sp before a call to an invoked method
  84     interpreter_frame_last_sp_offset                 = interpreter_frame_sender_sp_offset - 1,
  85     interpreter_frame_method_offset                  = interpreter_frame_last_sp_offset - 1,
  86     interpreter_frame_mdp_offset                     = interpreter_frame_method_offset - 1,
  87     interpreter_frame_padding_offset                 = interpreter_frame_mdp_offset - 1,
  88     interpreter_frame_mirror_offset                  = interpreter_frame_padding_offset - 1,
  89     interpreter_frame_cache_offset                   = interpreter_frame_mirror_offset - 1,
  90     interpreter_frame_locals_offset                  = interpreter_frame_cache_offset - 1,
  91     interpreter_frame_bcp_offset                     = interpreter_frame_locals_offset - 1,
  92     interpreter_frame_initial_sp_offset              = interpreter_frame_bcp_offset - 1,
  93 
  94     interpreter_frame_monitor_block_top_offset       = interpreter_frame_initial_sp_offset,
  95     interpreter_frame_monitor_block_bottom_offset    = interpreter_frame_initial_sp_offset,
  96   };
  97 
  98   static int get_frame_size(bool apcs = FrameAPCS) {
  99     return apcs ? 4 : 2;
 100   }
 101 
 102   static int get_link_offset(bool apcs = FrameAPCS) {
 103     return apcs ? -3 : -1;
 104   }
 105 
 106   static int get_return_addr_offset(bool apcs = FrameAPCS) {
 107     return apcs ? -1 : 0;
 108   }
 109 
 110   // Entry frames
 111   // n.b. these values are determined by the layout defined in
 112   // stubGenerator for the Java call stub
 113   static int get_entry_frame_after_call_words()                  { return (get_frame_size(VMFrameAPCS) + 10) + (StackAlignmentInBytes/BytesPerWord); }
 114   static int get_entry_frame_call_wrapper_offset()               { return -(get_frame_size(VMFrameAPCS) + 10); }
 115 
 116   static int get_offset_from_rfp_bytes()                         { return wordSize * (get_frame_size(VMFrameAPCS) - 1); }
 117   static int get_interpreter_frame_oop_temp_offset()             { return interpreter_frame_oop_temp_offset; }
 118   static int get_interpreter_frame_sender_sp_offset()            { return -get_frame_size() + interpreter_frame_sender_sp_offset; }
 119   static int get_interpreter_frame_last_sp_offset()              { return -get_frame_size() + interpreter_frame_last_sp_offset; }
 120   static int get_interpreter_frame_method_offset()               { return -get_frame_size() + interpreter_frame_method_offset; }
 121   static int get_interpreter_frame_mdp_offset()                  { return -get_frame_size() + interpreter_frame_mdp_offset; }
 122   static int get_interpreter_frame_padding_offset()              { return -get_frame_size() + interpreter_frame_padding_offset; }
 123   static int get_interpreter_frame_mirror_offset()               { return -get_frame_size() + interpreter_frame_mirror_offset; }
 124   static int get_interpreter_frame_cache_offset()                { return -get_frame_size() + interpreter_frame_cache_offset; }
 125   static int get_interpreter_frame_locals_offset()               { return -get_frame_size() + interpreter_frame_locals_offset; }
 126   static int get_interpreter_frame_bcp_offset()                  { return -get_frame_size() + interpreter_frame_bcp_offset; }
 127   static int get_interpreter_frame_initial_sp_offset()           { return -get_frame_size() + interpreter_frame_initial_sp_offset; }
 128   static int get_interpreter_frame_monitor_block_top_offset()    { return -get_frame_size() + interpreter_frame_monitor_block_top_offset; }
 129   static int get_interpreter_frame_monitor_block_bottom_offset() { return -get_frame_size() + interpreter_frame_monitor_block_bottom_offset; }
 130 
 131   intptr_t ptr_at(int offset) const {
 132     return *ptr_at_addr(offset);
 133   }
 134 
 135   void ptr_at_put(int offset, intptr_t value) {
 136     *ptr_at_addr(offset) = value;
 137   }
 138 
 139  private:
 140   // an additional field beyond _sp and _pc:
 141   intptr_t*   _fp; // frame pointer
 142   // The interpreter and adapters will extend the frame of the caller.
 143   // Since oopMaps are based on the sp of the caller before extension
 144   // we need to know that value. However in order to compute the address
 145   // of the return address we need the real "raw" sp. Since sparc already
 146   // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's
 147   // original sp we use that convention.
 148 
 149   intptr_t*     _unextended_sp;
 150   void adjust_unextended_sp();
 151 
 152   intptr_t* ptr_at_addr(int offset) const {
 153     return (intptr_t*) addr_at(offset);
 154   }
 155 
 156 #ifdef ASSERT
 157   // Used in frame::sender_for_{interpreter,compiled}_frame
 158   static void verify_deopt_original_pc(   CompiledMethod* nm, intptr_t* unextended_sp);
 159 #endif
 160 
 161  public:
 162   // Constructors
 163 
 164   frame(intptr_t* sp, intptr_t* fp, address pc);
 165 
 166   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
 167 
 168   frame(intptr_t* sp, intptr_t* fp);
 169 
 170   void init(intptr_t* sp, intptr_t* fp, address pc);
 171 
 172   // accessors for the instance variables
 173   // Note: not necessarily the real 'frame pointer' (see real_fp)
 174   intptr_t*   fp() const { return _fp; }
 175 
 176   inline address* sender_pc_addr() const;
 177 
 178   // expression stack tos if we are nested in a java call
 179   intptr_t* interpreter_frame_last_sp() const;
 180 
 181   // helper to update a map with callee-saved RBP
 182   static void update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr);
 183 
 184   // deoptimization support
 185   void interpreter_frame_set_last_sp(intptr_t* sp);
 186 
 187   static jint interpreter_frame_expression_stack_direction() { return -1; }
 188 
 189 #endif // CPU_AARCH32_VM_FRAME_AARCH32_HPP