1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/frame_x86.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,214 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef CPU_X86_VM_FRAME_X86_HPP 1.29 +#define CPU_X86_VM_FRAME_X86_HPP 1.30 + 1.31 +#include "runtime/synchronizer.hpp" 1.32 +#include "utilities/top.hpp" 1.33 + 1.34 +// A frame represents a physical stack frame (an activation). Frames can be 1.35 +// C or Java frames, and the Java frames can be interpreted or compiled. 1.36 +// In contrast, vframes represent source-level activations, so that one physical frame 1.37 +// can correspond to multiple source level frames because of inlining. 1.38 +// A frame is comprised of {pc, fp, sp} 1.39 +// ------------------------------ Asm interpreter ---------------------------------------- 1.40 +// Layout of asm interpreter frame: 1.41 +// [expression stack ] * <- sp 1.42 +// [monitors ] \ 1.43 +// ... | monitor block size 1.44 +// [monitors ] / 1.45 +// [monitor block size ] 1.46 +// [byte code index/pointr] = bcx() bcx_offset 1.47 +// [pointer to locals ] = locals() locals_offset 1.48 +// [constant pool cache ] = cache() cache_offset 1.49 +// [methodData ] = mdp() mdx_offset 1.50 +// [Method* ] = method() method_offset 1.51 +// [last sp ] = last_sp() last_sp_offset 1.52 +// [old stack pointer ] (sender_sp) sender_sp_offset 1.53 +// [old frame pointer ] <- fp = link() 1.54 +// [return pc ] 1.55 +// [oop temp ] (only for native calls) 1.56 +// [locals and parameters ] 1.57 +// <- sender sp 1.58 +// ------------------------------ Asm interpreter ---------------------------------------- 1.59 + 1.60 +// ------------------------------ C++ interpreter ---------------------------------------- 1.61 +// 1.62 +// Layout of C++ interpreter frame: (While executing in BytecodeInterpreter::run) 1.63 +// 1.64 +// <- SP (current esp/rsp) 1.65 +// [local variables ] BytecodeInterpreter::run local variables 1.66 +// ... BytecodeInterpreter::run local variables 1.67 +// [local variables ] BytecodeInterpreter::run local variables 1.68 +// [old frame pointer ] fp [ BytecodeInterpreter::run's ebp/rbp ] 1.69 +// [return pc ] (return to frame manager) 1.70 +// [interpreter_state* ] (arg to BytecodeInterpreter::run) -------------- 1.71 +// [expression stack ] <- last_Java_sp | 1.72 +// [... ] * <- interpreter_state.stack | 1.73 +// [expression stack ] * <- interpreter_state.stack_base | 1.74 +// [monitors ] \ | 1.75 +// ... | monitor block size | 1.76 +// [monitors ] / <- interpreter_state.monitor_base | 1.77 +// [struct interpretState ] <-----------------------------------------| 1.78 +// [return pc ] (return to callee of frame manager [1] 1.79 +// [locals and parameters ] 1.80 +// <- sender sp 1.81 + 1.82 +// [1] When the c++ interpreter calls a new method it returns to the frame 1.83 +// manager which allocates a new frame on the stack. In that case there 1.84 +// is no real callee of this newly allocated frame. The frame manager is 1.85 +// aware of the additional frame(s) and will pop them as nested calls 1.86 +// complete. Howevers tTo make it look good in the debugger the frame 1.87 +// manager actually installs a dummy pc pointing to RecursiveInterpreterActivation 1.88 +// with a fake interpreter_state* parameter to make it easy to debug 1.89 +// nested calls. 1.90 + 1.91 +// Note that contrary to the layout for the assembly interpreter the 1.92 +// expression stack allocated for the C++ interpreter is full sized. 1.93 +// However this is not as bad as it seems as the interpreter frame_manager 1.94 +// will truncate the unused space on succesive method calls. 1.95 +// 1.96 +// ------------------------------ C++ interpreter ---------------------------------------- 1.97 + 1.98 + public: 1.99 + enum { 1.100 + pc_return_offset = 0, 1.101 + // All frames 1.102 + link_offset = 0, 1.103 + return_addr_offset = 1, 1.104 + // non-interpreter frames 1.105 + sender_sp_offset = 2, 1.106 + 1.107 +#ifndef CC_INTERP 1.108 + 1.109 + // Interpreter frames 1.110 + interpreter_frame_result_handler_offset = 3, // for native calls only 1.111 + interpreter_frame_oop_temp_offset = 2, // for native calls only 1.112 + 1.113 + interpreter_frame_sender_sp_offset = -1, 1.114 + // outgoing sp before a call to an invoked method 1.115 + interpreter_frame_last_sp_offset = interpreter_frame_sender_sp_offset - 1, 1.116 + interpreter_frame_method_offset = interpreter_frame_last_sp_offset - 1, 1.117 + interpreter_frame_mdx_offset = interpreter_frame_method_offset - 1, 1.118 + interpreter_frame_cache_offset = interpreter_frame_mdx_offset - 1, 1.119 + interpreter_frame_locals_offset = interpreter_frame_cache_offset - 1, 1.120 + interpreter_frame_bcx_offset = interpreter_frame_locals_offset - 1, 1.121 + interpreter_frame_initial_sp_offset = interpreter_frame_bcx_offset - 1, 1.122 + 1.123 + interpreter_frame_monitor_block_top_offset = interpreter_frame_initial_sp_offset, 1.124 + interpreter_frame_monitor_block_bottom_offset = interpreter_frame_initial_sp_offset, 1.125 + 1.126 +#endif // CC_INTERP 1.127 + 1.128 + // Entry frames 1.129 +#ifdef AMD64 1.130 +#ifdef _WIN64 1.131 + entry_frame_after_call_words = 28, 1.132 + entry_frame_call_wrapper_offset = 2, 1.133 + 1.134 + arg_reg_save_area_bytes = 32, // Register argument save area 1.135 +#else 1.136 + entry_frame_after_call_words = 13, 1.137 + entry_frame_call_wrapper_offset = -6, 1.138 + 1.139 + arg_reg_save_area_bytes = 0, 1.140 +#endif // _WIN64 1.141 +#else 1.142 + entry_frame_call_wrapper_offset = 2, 1.143 +#endif // AMD64 1.144 + 1.145 + // Native frames 1.146 + 1.147 + native_frame_initial_param_offset = 2 1.148 + 1.149 + }; 1.150 + 1.151 + intptr_t ptr_at(int offset) const { 1.152 + return *ptr_at_addr(offset); 1.153 + } 1.154 + 1.155 + void ptr_at_put(int offset, intptr_t value) { 1.156 + *ptr_at_addr(offset) = value; 1.157 + } 1.158 + 1.159 + private: 1.160 + // an additional field beyond _sp and _pc: 1.161 + intptr_t* _fp; // frame pointer 1.162 + // The interpreter and adapters will extend the frame of the caller. 1.163 + // Since oopMaps are based on the sp of the caller before extension 1.164 + // we need to know that value. However in order to compute the address 1.165 + // of the return address we need the real "raw" sp. Since sparc already 1.166 + // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's 1.167 + // original sp we use that convention. 1.168 + 1.169 + intptr_t* _unextended_sp; 1.170 + void adjust_unextended_sp(); 1.171 + 1.172 + intptr_t* ptr_at_addr(int offset) const { 1.173 + return (intptr_t*) addr_at(offset); 1.174 + } 1.175 + 1.176 +#ifdef ASSERT 1.177 + // Used in frame::sender_for_{interpreter,compiled}_frame 1.178 + static void verify_deopt_original_pc( nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return = false); 1.179 + static void verify_deopt_mh_original_pc(nmethod* nm, intptr_t* unextended_sp) { 1.180 + verify_deopt_original_pc(nm, unextended_sp, true); 1.181 + } 1.182 +#endif 1.183 + 1.184 + public: 1.185 + // Constructors 1.186 + 1.187 + frame(intptr_t* sp, intptr_t* fp, address pc); 1.188 + 1.189 + frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc); 1.190 + 1.191 + frame(intptr_t* sp, intptr_t* fp); 1.192 + 1.193 + // accessors for the instance variables 1.194 + // Note: not necessarily the real 'frame pointer' (see real_fp) 1.195 + intptr_t* fp() const { return _fp; } 1.196 + 1.197 + inline address* sender_pc_addr() const; 1.198 + 1.199 + // return address of param, zero origin index. 1.200 + inline address* native_param_addr(int idx) const; 1.201 + 1.202 + // expression stack tos if we are nested in a java call 1.203 + intptr_t* interpreter_frame_last_sp() const; 1.204 + 1.205 + // helper to update a map with callee-saved RBP 1.206 + static void update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr); 1.207 + 1.208 +#ifndef CC_INTERP 1.209 + // deoptimization support 1.210 + void interpreter_frame_set_last_sp(intptr_t* sp); 1.211 +#endif // CC_INTERP 1.212 + 1.213 +#ifdef CC_INTERP 1.214 + inline interpreterState get_interpreterState() const; 1.215 +#endif // CC_INTERP 1.216 + 1.217 +#endif // CPU_X86_VM_FRAME_X86_HPP