1 /* 2 * Copyright (c) 2013, Red Hat Inc. 3 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 4 * All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 * 25 */ 26 27 #ifndef CPU_AARCH64_VM_FRAME_AARCH64_HPP 28 #define CPU_AARCH64_VM_FRAME_AARCH64_HPP 29 30 #include "runtime/synchronizer.hpp" 31 #include "utilities/top.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 // [methodData ] = mdp() mdx_offset 52 // [methodOop ] = method() method_offset 53 54 // [last esp ] = last_sp() last_sp_offset 55 // [old stack pointer ] (sender_sp) sender_sp_offset 56 57 // [old frame pointer ] <- fp = link() 58 // [return pc ] 59 60 // [last sp ] 61 // [oop temp ] (only for native calls) 62 63 // [locals and parameters ] 64 // <- sender sp 65 // ------------------------------ Asm interpreter ---------------------------------------- 66 67 // ------------------------------ C++ interpreter ---------------------------------------- 68 // 69 // Layout of C++ interpreter frame: (While executing in BytecodeInterpreter::run) 70 // 71 // <- SP (current esp/rsp) 72 // [local variables ] BytecodeInterpreter::run local variables 73 // ... BytecodeInterpreter::run local variables 74 // [local variables ] BytecodeInterpreter::run local variables 75 // [old frame pointer ] fp [ BytecodeInterpreter::run's ebp/rbp ] 76 // [return pc ] (return to frame manager) 77 // [interpreter_state* ] (arg to BytecodeInterpreter::run) -------------- 78 // [expression stack ] <- last_Java_sp | 79 // [... ] * <- interpreter_state.stack | 80 // [expression stack ] * <- interpreter_state.stack_base | 81 // [monitors ] \ | 82 // ... | monitor block size | 83 // [monitors ] / <- interpreter_state.monitor_base | 84 // [struct interpretState ] <-----------------------------------------| 85 // [return pc ] (return to callee of frame manager [1] 86 // [locals and parameters ] 87 // <- sender sp 88 89 // [1] When the c++ interpreter calls a new method it returns to the frame 90 // manager which allocates a new frame on the stack. In that case there 91 // is no real callee of this newly allocated frame. The frame manager is 92 // aware of the additional frame(s) and will pop them as nested calls 93 // complete. Howevers tTo make it look good in the debugger the frame 94 // manager actually installs a dummy pc pointing to RecursiveInterpreterActivation 95 // with a fake interpreter_state* parameter to make it easy to debug 96 // nested calls. 97 98 // Note that contrary to the layout for the assembly interpreter the 99 // expression stack allocated for the C++ interpreter is full sized. 100 // However this is not as bad as it seems as the interpreter frame_manager 101 // will truncate the unused space on succesive method calls. 102 // 103 // ------------------------------ C++ interpreter ---------------------------------------- 104 105 public: 106 enum { 107 pc_return_offset = 0, 108 // All frames 109 link_offset = 0, 110 return_addr_offset = 1, 111 sender_sp_offset = 2, 112 113 #ifndef CC_INTERP 114 115 // Interpreter frames 116 interpreter_frame_oop_temp_offset = 3, // for native calls only 117 118 interpreter_frame_sender_sp_offset = -1, 119 // outgoing sp before a call to an invoked method 120 interpreter_frame_last_sp_offset = interpreter_frame_sender_sp_offset - 1, 121 interpreter_frame_method_offset = interpreter_frame_last_sp_offset - 1, 122 interpreter_frame_mdx_offset = interpreter_frame_method_offset - 1, 123 interpreter_frame_cache_offset = interpreter_frame_mdx_offset - 1, 124 interpreter_frame_locals_offset = interpreter_frame_cache_offset - 1, 125 interpreter_frame_bcx_offset = interpreter_frame_locals_offset - 1, 126 interpreter_frame_initial_sp_offset = interpreter_frame_bcx_offset - 1, 127 128 interpreter_frame_monitor_block_top_offset = interpreter_frame_initial_sp_offset, 129 interpreter_frame_monitor_block_bottom_offset = interpreter_frame_initial_sp_offset, 130 131 #endif // CC_INTERP 132 133 // Entry frames 134 // n.b. these values are determined by the layout defined in 135 // stubGenerator for the Java call stub 136 entry_frame_after_call_words = 27, 137 entry_frame_call_wrapper_offset = -8, 138 139 // we don't need a save area 140 arg_reg_save_area_bytes = 0, 141 142 // TODO - check that this is still correct 143 // Native frames 144 145 native_frame_initial_param_offset = 2 146 147 }; 148 ptr_at(int offset) const149 intptr_t ptr_at(int offset) const { 150 return *ptr_at_addr(offset); 151 } 152 ptr_at_put(int offset,intptr_t value)153 void ptr_at_put(int offset, intptr_t value) { 154 *ptr_at_addr(offset) = value; 155 } 156 157 private: 158 // an additional field beyond _sp and _pc: 159 intptr_t* _fp; // frame pointer 160 // The interpreter and adapters will extend the frame of the caller. 161 // Since oopMaps are based on the sp of the caller before extension 162 // we need to know that value. However in order to compute the address 163 // of the return address we need the real "raw" sp. Since sparc already 164 // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's 165 // original sp we use that convention. 166 167 intptr_t* _unextended_sp; 168 void adjust_unextended_sp(); 169 ptr_at_addr(int offset) const170 intptr_t* ptr_at_addr(int offset) const { 171 return (intptr_t*) addr_at(offset); 172 } 173 174 #ifdef ASSERT 175 // Used in frame::sender_for_{interpreter,compiled}_frame 176 static void verify_deopt_original_pc( nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return = false); verify_deopt_mh_original_pc(nmethod * nm,intptr_t * unextended_sp)177 static void verify_deopt_mh_original_pc(nmethod* nm, intptr_t* unextended_sp) { 178 verify_deopt_original_pc(nm, unextended_sp, true); 179 } 180 #endif 181 182 public: 183 // Constructors 184 185 frame(intptr_t* sp, intptr_t* fp, address pc); 186 187 frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc); 188 189 frame(intptr_t* sp, intptr_t* fp); 190 191 void init(intptr_t* sp, intptr_t* fp, address pc); 192 193 // accessors for the instance variables 194 // Note: not necessarily the real 'frame pointer' (see real_fp) fp() const195 intptr_t* fp() const { return _fp; } 196 197 inline address* sender_pc_addr() const; 198 199 // return address of param, zero origin index. 200 inline address* native_param_addr(int idx) const; 201 202 // expression stack tos if we are nested in a java call 203 intptr_t* interpreter_frame_last_sp() const; 204 205 // helper to update a map with callee-saved RBP 206 static void update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr); 207 208 #ifndef CC_INTERP 209 // deoptimization support 210 void interpreter_frame_set_last_sp(intptr_t* sp); 211 #endif // CC_INTERP 212 213 #ifdef CC_INTERP 214 inline interpreterState get_interpreterState() const; 215 #endif // CC_INTERP 216 217 #endif // CPU_AARCH64_VM_FRAME_AARCH64_HPP 218