1 /*
  2  * Copyright (c) 2008, 2025, 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_ARM_FRAME_ARM_HPP
 26 #define CPU_ARM_FRAME_ARM_HPP
 27 
 28  public:
 29   enum {
 30     pc_return_offset                                 =  0,
 31     // All frames
 32     link_offset                                      =  0,
 33     return_addr_offset                               =  1,
 34     // non-interpreter frames
 35     sender_sp_offset                                 =  2,
 36 
 37     // Interpreter frames
 38     interpreter_frame_oop_temp_offset                =  2, // for native calls only
 39 
 40     interpreter_frame_sender_sp_offset               = -1,
 41     // outgoing sp before a call to an invoked method
 42     interpreter_frame_last_sp_offset                 = interpreter_frame_sender_sp_offset - 1,
 43     interpreter_frame_method_offset                  = interpreter_frame_last_sp_offset - 1,
 44     interpreter_frame_mirror_offset                  = interpreter_frame_method_offset - 1,
 45     interpreter_frame_mdp_offset                     = interpreter_frame_mirror_offset - 1,
 46     interpreter_frame_cache_offset                   = interpreter_frame_mdp_offset - 1,
 47     interpreter_frame_locals_offset                  = interpreter_frame_cache_offset - 1,
 48     interpreter_frame_bcp_offset                     = interpreter_frame_locals_offset - 1,
 49     interpreter_frame_initial_sp_offset              = interpreter_frame_bcp_offset - 1,
 50 
 51     interpreter_frame_monitor_block_top_offset       = interpreter_frame_initial_sp_offset,
 52     interpreter_frame_monitor_block_bottom_offset    = interpreter_frame_initial_sp_offset,
 53 
 54     // Entry frames
 55     entry_frame_call_wrapper_offset                  =  0,
 56     metadata_words                                   = sender_sp_offset,
 57     // size, in words, of metadata at frame bottom, i.e. it is not part of the
 58     // caller/callee overlap
 59     metadata_words_at_bottom                         = metadata_words,
 60     // size, in words, of frame metadata at the frame top, i.e. it is located
 61     // between a callee frame and its stack arguments, where it is part
 62     // of the caller/callee overlap
 63     metadata_words_at_top                            = 0,
 64     frame_alignment                                  = 16,
 65     // size, in words, of maximum shift in frame position due to alignment
 66     align_wiggle                                     =  1
 67   };
 68 
 69   intptr_t ptr_at(int offset) const {
 70     return *ptr_at_addr(offset);
 71   }
 72 
 73   void ptr_at_put(int offset, intptr_t value) {
 74     *ptr_at_addr(offset) = value;
 75   }
 76 
 77  private:
 78   // an additional field beyond _sp and _pc:
 79   intptr_t* _fp; // frame pointer
 80   // The interpreter and adapters will extend the frame of the caller.
 81   // Since oopMaps are based on the sp of the caller before extension
 82   // we need to know that value. However in order to compute the address
 83   // of the return address we need the real "raw" sp. By convention we
 84   // use sp() to mean "raw" sp and unextended_sp() to mean the caller's
 85   // original sp.
 86 
 87   intptr_t* _unextended_sp;
 88 
 89   intptr_t* ptr_at_addr(int offset) const {
 90     return (intptr_t*) addr_at(offset);
 91   }
 92 
 93  public:
 94   // Constructors
 95 
 96   frame(intptr_t* sp, intptr_t* fp, address pc);
 97 
 98   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
 99 
100   frame(intptr_t* sp, intptr_t* fp);
101 
102   frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc, CodeBlob* cb, bool allow_cb_null = false);
103 
104   void setup(address pc);
105   void init(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
106 
107   // accessors for the instance variables
108   // Note: not necessarily the real 'frame pointer' (see real_fp)
109   intptr_t* fp() const { return _fp; }
110 
111   inline address* sender_pc_addr() const;
112 
113   // expression stack tos if we are nested in a java call
114   intptr_t* interpreter_frame_last_sp() const;
115 
116   template <typename RegisterMapT>
117   static void update_map_with_saved_link(RegisterMapT* map, intptr_t** link_addr);
118 
119   // deoptimization support
120   void interpreter_frame_set_last_sp(intptr_t* sp);
121 
122   // helper to update a map with callee-saved FP
123   static void update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr);
124 
125   static jint interpreter_frame_expression_stack_direction() { return -1; }
126 
127 #endif // CPU_ARM_FRAME_ARM_HPP