1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/frame_x86.inline.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,315 @@ 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_INLINE_HPP 1.29 +#define CPU_X86_VM_FRAME_X86_INLINE_HPP 1.30 + 1.31 +#include "code/codeCache.hpp" 1.32 + 1.33 +// Inline functions for Intel frames: 1.34 + 1.35 +// Constructors: 1.36 + 1.37 +inline frame::frame() { 1.38 + _pc = NULL; 1.39 + _sp = NULL; 1.40 + _unextended_sp = NULL; 1.41 + _fp = NULL; 1.42 + _cb = NULL; 1.43 + _deopt_state = unknown; 1.44 +} 1.45 + 1.46 +inline frame::frame(intptr_t* sp, intptr_t* fp, address pc) { 1.47 + _sp = sp; 1.48 + _unextended_sp = sp; 1.49 + _fp = fp; 1.50 + _pc = pc; 1.51 + assert(pc != NULL, "no pc?"); 1.52 + _cb = CodeCache::find_blob(pc); 1.53 + adjust_unextended_sp(); 1.54 + 1.55 + address original_pc = nmethod::get_deopt_original_pc(this); 1.56 + if (original_pc != NULL) { 1.57 + _pc = original_pc; 1.58 + _deopt_state = is_deoptimized; 1.59 + } else { 1.60 + _deopt_state = not_deoptimized; 1.61 + } 1.62 +} 1.63 + 1.64 +inline frame::frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc) { 1.65 + _sp = sp; 1.66 + _unextended_sp = unextended_sp; 1.67 + _fp = fp; 1.68 + _pc = pc; 1.69 + assert(pc != NULL, "no pc?"); 1.70 + _cb = CodeCache::find_blob(pc); 1.71 + adjust_unextended_sp(); 1.72 + 1.73 + address original_pc = nmethod::get_deopt_original_pc(this); 1.74 + if (original_pc != NULL) { 1.75 + _pc = original_pc; 1.76 + assert(((nmethod*)_cb)->insts_contains(_pc), "original PC must be in nmethod"); 1.77 + _deopt_state = is_deoptimized; 1.78 + } else { 1.79 + _deopt_state = not_deoptimized; 1.80 + } 1.81 +} 1.82 + 1.83 +inline frame::frame(intptr_t* sp, intptr_t* fp) { 1.84 + _sp = sp; 1.85 + _unextended_sp = sp; 1.86 + _fp = fp; 1.87 + _pc = (address)(sp[-1]); 1.88 + 1.89 + // Here's a sticky one. This constructor can be called via AsyncGetCallTrace 1.90 + // when last_Java_sp is non-null but the pc fetched is junk. If we are truly 1.91 + // unlucky the junk value could be to a zombied method and we'll die on the 1.92 + // find_blob call. This is also why we can have no asserts on the validity 1.93 + // of the pc we find here. AsyncGetCallTrace -> pd_get_top_frame_for_signal_handler 1.94 + // -> pd_last_frame should use a specialized version of pd_last_frame which could 1.95 + // call a specilaized frame constructor instead of this one. 1.96 + // Then we could use the assert below. However this assert is of somewhat dubious 1.97 + // value. 1.98 + // assert(_pc != NULL, "no pc?"); 1.99 + 1.100 + _cb = CodeCache::find_blob(_pc); 1.101 + adjust_unextended_sp(); 1.102 + 1.103 + address original_pc = nmethod::get_deopt_original_pc(this); 1.104 + if (original_pc != NULL) { 1.105 + _pc = original_pc; 1.106 + _deopt_state = is_deoptimized; 1.107 + } else { 1.108 + _deopt_state = not_deoptimized; 1.109 + } 1.110 +} 1.111 + 1.112 +// Accessors 1.113 + 1.114 +inline bool frame::equal(frame other) const { 1.115 + bool ret = sp() == other.sp() 1.116 + && unextended_sp() == other.unextended_sp() 1.117 + && fp() == other.fp() 1.118 + && pc() == other.pc(); 1.119 + assert(!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state, "inconsistent construction"); 1.120 + return ret; 1.121 +} 1.122 + 1.123 +// Return unique id for this frame. The id must have a value where we can distinguish 1.124 +// identity and younger/older relationship. NULL represents an invalid (incomparable) 1.125 +// frame. 1.126 +inline intptr_t* frame::id(void) const { return unextended_sp(); } 1.127 + 1.128 +// Relationals on frames based 1.129 +// Return true if the frame is younger (more recent activation) than the frame represented by id 1.130 +inline bool frame::is_younger(intptr_t* id) const { assert(this->id() != NULL && id != NULL, "NULL frame id"); 1.131 + return this->id() < id ; } 1.132 + 1.133 +// Return true if the frame is older (less recent activation) than the frame represented by id 1.134 +inline bool frame::is_older(intptr_t* id) const { assert(this->id() != NULL && id != NULL, "NULL frame id"); 1.135 + return this->id() > id ; } 1.136 + 1.137 + 1.138 + 1.139 +inline intptr_t* frame::link() const { return (intptr_t*) *(intptr_t **)addr_at(link_offset); } 1.140 +inline void frame::set_link(intptr_t* addr) { *(intptr_t **)addr_at(link_offset) = addr; } 1.141 + 1.142 + 1.143 +inline intptr_t* frame::unextended_sp() const { return _unextended_sp; } 1.144 + 1.145 +// Return address: 1.146 + 1.147 +inline address* frame::sender_pc_addr() const { return (address*) addr_at( return_addr_offset); } 1.148 +inline address frame::sender_pc() const { return *sender_pc_addr(); } 1.149 + 1.150 +// return address of param, zero origin index. 1.151 +inline address* frame::native_param_addr(int idx) const { return (address*) addr_at( native_frame_initial_param_offset+idx); } 1.152 + 1.153 +#ifdef CC_INTERP 1.154 + 1.155 +inline interpreterState frame::get_interpreterState() const { 1.156 + return ((interpreterState)addr_at( -((int)sizeof(BytecodeInterpreter))/wordSize )); 1.157 +} 1.158 + 1.159 +inline intptr_t* frame::sender_sp() const { 1.160 + // Hmm this seems awfully expensive QQQ, is this really called with interpreted frames? 1.161 + if (is_interpreted_frame()) { 1.162 + assert(false, "should never happen"); 1.163 + return get_interpreterState()->sender_sp(); 1.164 + } else { 1.165 + return addr_at(sender_sp_offset); 1.166 + } 1.167 +} 1.168 + 1.169 +inline intptr_t** frame::interpreter_frame_locals_addr() const { 1.170 + assert(is_interpreted_frame(), "must be interpreted"); 1.171 + return &(get_interpreterState()->_locals); 1.172 +} 1.173 + 1.174 +inline intptr_t* frame::interpreter_frame_bcx_addr() const { 1.175 + assert(is_interpreted_frame(), "must be interpreted"); 1.176 + return (intptr_t*) &(get_interpreterState()->_bcp); 1.177 +} 1.178 + 1.179 + 1.180 +// Constant pool cache 1.181 + 1.182 +inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const { 1.183 + assert(is_interpreted_frame(), "must be interpreted"); 1.184 + return &(get_interpreterState()->_constants); 1.185 +} 1.186 + 1.187 +// Method 1.188 + 1.189 +inline Method** frame::interpreter_frame_method_addr() const { 1.190 + assert(is_interpreted_frame(), "must be interpreted"); 1.191 + return &(get_interpreterState()->_method); 1.192 +} 1.193 + 1.194 +inline intptr_t* frame::interpreter_frame_mdx_addr() const { 1.195 + assert(is_interpreted_frame(), "must be interpreted"); 1.196 + return (intptr_t*) &(get_interpreterState()->_mdx); 1.197 +} 1.198 + 1.199 +// top of expression stack 1.200 +inline intptr_t* frame::interpreter_frame_tos_address() const { 1.201 + assert(is_interpreted_frame(), "wrong frame type"); 1.202 + return get_interpreterState()->_stack + 1; 1.203 +} 1.204 + 1.205 +#else /* asm interpreter */ 1.206 +inline intptr_t* frame::sender_sp() const { return addr_at( sender_sp_offset); } 1.207 + 1.208 +inline intptr_t** frame::interpreter_frame_locals_addr() const { 1.209 + return (intptr_t**)addr_at(interpreter_frame_locals_offset); 1.210 +} 1.211 + 1.212 +inline intptr_t* frame::interpreter_frame_last_sp() const { 1.213 + return *(intptr_t**)addr_at(interpreter_frame_last_sp_offset); 1.214 +} 1.215 + 1.216 +inline intptr_t* frame::interpreter_frame_bcx_addr() const { 1.217 + return (intptr_t*)addr_at(interpreter_frame_bcx_offset); 1.218 +} 1.219 + 1.220 + 1.221 +inline intptr_t* frame::interpreter_frame_mdx_addr() const { 1.222 + return (intptr_t*)addr_at(interpreter_frame_mdx_offset); 1.223 +} 1.224 + 1.225 + 1.226 + 1.227 +// Constant pool cache 1.228 + 1.229 +inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const { 1.230 + return (ConstantPoolCache**)addr_at(interpreter_frame_cache_offset); 1.231 +} 1.232 + 1.233 +// Method 1.234 + 1.235 +inline Method** frame::interpreter_frame_method_addr() const { 1.236 + return (Method**)addr_at(interpreter_frame_method_offset); 1.237 +} 1.238 + 1.239 +// top of expression stack 1.240 +inline intptr_t* frame::interpreter_frame_tos_address() const { 1.241 + intptr_t* last_sp = interpreter_frame_last_sp(); 1.242 + if (last_sp == NULL) { 1.243 + return sp(); 1.244 + } else { 1.245 + // sp() may have been extended or shrunk by an adapter. At least 1.246 + // check that we don't fall behind the legal region. 1.247 + // For top deoptimized frame last_sp == interpreter_frame_monitor_end. 1.248 + assert(last_sp <= (intptr_t*) interpreter_frame_monitor_end(), "bad tos"); 1.249 + return last_sp; 1.250 + } 1.251 +} 1.252 + 1.253 +inline oop* frame::interpreter_frame_temp_oop_addr() const { 1.254 + return (oop *)(fp() + interpreter_frame_oop_temp_offset); 1.255 +} 1.256 + 1.257 +#endif /* CC_INTERP */ 1.258 + 1.259 +inline int frame::pd_oop_map_offset_adjustment() const { 1.260 + return 0; 1.261 +} 1.262 + 1.263 +inline int frame::interpreter_frame_monitor_size() { 1.264 + return BasicObjectLock::size(); 1.265 +} 1.266 + 1.267 + 1.268 +// expression stack 1.269 +// (the max_stack arguments are used by the GC; see class FrameClosure) 1.270 + 1.271 +inline intptr_t* frame::interpreter_frame_expression_stack() const { 1.272 + intptr_t* monitor_end = (intptr_t*) interpreter_frame_monitor_end(); 1.273 + return monitor_end-1; 1.274 +} 1.275 + 1.276 + 1.277 +inline jint frame::interpreter_frame_expression_stack_direction() { return -1; } 1.278 + 1.279 + 1.280 +// Entry frames 1.281 + 1.282 +inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const { 1.283 + return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset); 1.284 +} 1.285 + 1.286 +// Compiled frames 1.287 + 1.288 +inline int frame::local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) { 1.289 + return (nof_args - local_index + (local_index < nof_args ? 1: -1)); 1.290 +} 1.291 + 1.292 +inline int frame::monitor_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) { 1.293 + return local_offset_for_compiler(local_index, nof_args, max_nof_locals, max_nof_monitors); 1.294 +} 1.295 + 1.296 +inline int frame::min_local_offset_for_compiler(int nof_args, int max_nof_locals, int max_nof_monitors) { 1.297 + return (nof_args - (max_nof_locals + max_nof_monitors*2) - 1); 1.298 +} 1.299 + 1.300 +inline bool frame::volatile_across_calls(Register reg) { 1.301 + return true; 1.302 +} 1.303 + 1.304 +inline oop frame::saved_oop_result(RegisterMap* map) const { 1.305 + oop* result_adr = (oop *)map->location(rax->as_VMReg()); 1.306 + guarantee(result_adr != NULL, "bad register save location"); 1.307 + 1.308 + return (*result_adr); 1.309 +} 1.310 + 1.311 +inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) { 1.312 + oop* result_adr = (oop *)map->location(rax->as_VMReg()); 1.313 + guarantee(result_adr != NULL, "bad register save location"); 1.314 + 1.315 + *result_adr = obj; 1.316 +} 1.317 + 1.318 +#endif // CPU_X86_VM_FRAME_X86_INLINE_HPP