1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/frame_x86.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,193 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A frame represents a physical stack frame (an activation). Frames can be 1.29 +// C or Java frames, and the Java frames can be interpreted or compiled. 1.30 +// In contrast, vframes represent source-level activations, so that one physical frame 1.31 +// can correspond to multiple source level frames because of inlining. 1.32 +// A frame is comprised of {pc, fp, sp} 1.33 +// ------------------------------ Asm interpreter ---------------------------------------- 1.34 +// Layout of asm interpreter frame: 1.35 +// [expression stack ] * <- sp 1.36 +// [monitors ] \ 1.37 +// ... | monitor block size 1.38 +// [monitors ] / 1.39 +// [monitor block size ] 1.40 +// [byte code index/pointr] = bcx() bcx_offset 1.41 +// [pointer to locals ] = locals() locals_offset 1.42 +// [constant pool cache ] = cache() cache_offset 1.43 +// [methodData ] = mdp() mdx_offset 1.44 +// [methodOop ] = method() method_offset 1.45 +// [last sp ] = last_sp() last_sp_offset 1.46 +// [old stack pointer ] (sender_sp) sender_sp_offset 1.47 +// [old frame pointer ] <- fp = link() 1.48 +// [return pc ] 1.49 +// [oop temp ] (only for native calls) 1.50 +// [locals and parameters ] 1.51 +// <- sender sp 1.52 +// ------------------------------ Asm interpreter ---------------------------------------- 1.53 + 1.54 +// ------------------------------ C++ interpreter ---------------------------------------- 1.55 +// 1.56 +// Layout of C++ interpreter frame: (While executing in BytecodeInterpreter::run) 1.57 +// 1.58 +// <- SP (current esp/rsp) 1.59 +// [local variables ] BytecodeInterpreter::run local variables 1.60 +// ... BytecodeInterpreter::run local variables 1.61 +// [local variables ] BytecodeInterpreter::run local variables 1.62 +// [old frame pointer ] fp [ BytecodeInterpreter::run's ebp/rbp ] 1.63 +// [return pc ] (return to frame manager) 1.64 +// [interpreter_state* ] (arg to BytecodeInterpreter::run) -------------- 1.65 +// [expression stack ] <- last_Java_sp | 1.66 +// [... ] * <- interpreter_state.stack | 1.67 +// [expression stack ] * <- interpreter_state.stack_base | 1.68 +// [monitors ] \ | 1.69 +// ... | monitor block size | 1.70 +// [monitors ] / <- interpreter_state.monitor_base | 1.71 +// [struct interpretState ] <-----------------------------------------| 1.72 +// [return pc ] (return to callee of frame manager [1] 1.73 +// [locals and parameters ] 1.74 +// <- sender sp 1.75 + 1.76 +// [1] When the c++ interpreter calls a new method it returns to the frame 1.77 +// manager which allocates a new frame on the stack. In that case there 1.78 +// is no real callee of this newly allocated frame. The frame manager is 1.79 +// aware of the additional frame(s) and will pop them as nested calls 1.80 +// complete. Howevers tTo make it look good in the debugger the frame 1.81 +// manager actually installs a dummy pc pointing to RecursiveInterpreterActivation 1.82 +// with a fake interpreter_state* parameter to make it easy to debug 1.83 +// nested calls. 1.84 + 1.85 +// Note that contrary to the layout for the assembly interpreter the 1.86 +// expression stack allocated for the C++ interpreter is full sized. 1.87 +// However this is not as bad as it seems as the interpreter frame_manager 1.88 +// will truncate the unused space on succesive method calls. 1.89 +// 1.90 +// ------------------------------ C++ interpreter ---------------------------------------- 1.91 + 1.92 + public: 1.93 + enum { 1.94 + pc_return_offset = 0, 1.95 + // All frames 1.96 + link_offset = 0, 1.97 + return_addr_offset = 1, 1.98 + // non-interpreter frames 1.99 + sender_sp_offset = 2, 1.100 + 1.101 +#ifndef CC_INTERP 1.102 + 1.103 + // Interpreter frames 1.104 + interpreter_frame_result_handler_offset = 3, // for native calls only 1.105 + interpreter_frame_oop_temp_offset = 2, // for native calls only 1.106 + 1.107 + interpreter_frame_sender_sp_offset = -1, 1.108 + // outgoing sp before a call to an invoked method 1.109 + interpreter_frame_last_sp_offset = interpreter_frame_sender_sp_offset - 1, 1.110 + interpreter_frame_method_offset = interpreter_frame_last_sp_offset - 1, 1.111 + interpreter_frame_mdx_offset = interpreter_frame_method_offset - 1, 1.112 + interpreter_frame_cache_offset = interpreter_frame_mdx_offset - 1, 1.113 + interpreter_frame_locals_offset = interpreter_frame_cache_offset - 1, 1.114 + interpreter_frame_bcx_offset = interpreter_frame_locals_offset - 1, 1.115 + interpreter_frame_initial_sp_offset = interpreter_frame_bcx_offset - 1, 1.116 + 1.117 + interpreter_frame_monitor_block_top_offset = interpreter_frame_initial_sp_offset, 1.118 + interpreter_frame_monitor_block_bottom_offset = interpreter_frame_initial_sp_offset, 1.119 + 1.120 +#endif // CC_INTERP 1.121 + 1.122 + // Entry frames 1.123 +#ifdef AMD64 1.124 +#ifdef _WIN64 1.125 + entry_frame_after_call_words = 8, 1.126 + entry_frame_call_wrapper_offset = 2, 1.127 + 1.128 + arg_reg_save_area_bytes = 32, // Register argument save area 1.129 +#else 1.130 + entry_frame_after_call_words = 13, 1.131 + entry_frame_call_wrapper_offset = -6, 1.132 + 1.133 + arg_reg_save_area_bytes = 0, 1.134 +#endif // _WIN64 1.135 +#else 1.136 + entry_frame_call_wrapper_offset = 2, 1.137 +#endif // AMD64 1.138 + 1.139 + // Native frames 1.140 + 1.141 + native_frame_initial_param_offset = 2 1.142 + 1.143 + }; 1.144 + 1.145 + intptr_t ptr_at(int offset) const { 1.146 + return *ptr_at_addr(offset); 1.147 + } 1.148 + 1.149 + void ptr_at_put(int offset, intptr_t value) { 1.150 + *ptr_at_addr(offset) = value; 1.151 + } 1.152 + 1.153 + private: 1.154 + // an additional field beyond _sp and _pc: 1.155 + intptr_t* _fp; // frame pointer 1.156 + // The interpreter and adapters will extend the frame of the caller. 1.157 + // Since oopMaps are based on the sp of the caller before extension 1.158 + // we need to know that value. However in order to compute the address 1.159 + // of the return address we need the real "raw" sp. Since sparc already 1.160 + // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's 1.161 + // original sp we use that convention. 1.162 + 1.163 + intptr_t* _unextended_sp; 1.164 + 1.165 + intptr_t* ptr_at_addr(int offset) const { 1.166 + return (intptr_t*) addr_at(offset); 1.167 + } 1.168 + 1.169 + public: 1.170 + // Constructors 1.171 + 1.172 + frame(intptr_t* sp, intptr_t* fp, address pc); 1.173 + 1.174 + frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc); 1.175 + 1.176 + frame(intptr_t* sp, intptr_t* fp); 1.177 + 1.178 + // accessors for the instance variables 1.179 + intptr_t* fp() const { return _fp; } 1.180 + 1.181 + inline address* sender_pc_addr() const; 1.182 + 1.183 + // return address of param, zero origin index. 1.184 + inline address* native_param_addr(int idx) const; 1.185 + 1.186 + // expression stack tos if we are nested in a java call 1.187 + intptr_t* interpreter_frame_last_sp() const; 1.188 + 1.189 +#ifndef CC_INTERP 1.190 + // deoptimization support 1.191 + void interpreter_frame_set_last_sp(intptr_t* sp); 1.192 +#endif // CC_INTERP 1.193 + 1.194 +#ifdef CC_INTERP 1.195 + inline interpreterState get_interpreterState() const; 1.196 +#endif // CC_INTERP