src/cpu/x86/vm/frame_x86.inline.hpp

Fri, 29 May 2015 10:58:45 +0200

author
zmajo
date
Fri, 29 May 2015 10:58:45 +0200
changeset 7854
e8260b6328fb
parent 7553
f43fad8786fc
child 7994
04ff2f6cd0eb
child 8877
f04097176542
permissions
-rw-r--r--

8068945: Use RBP register as proper frame pointer in JIT compiled code on x86
Summary: Introduce the PreserveFramePointer flag to control if RBP is used as the frame pointer or as a general purpose register.
Reviewed-by: kvn, roland, dlong, enevill, shade

duke@435 1 /*
mikael@6198 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef CPU_X86_VM_FRAME_X86_INLINE_HPP
stefank@2314 26 #define CPU_X86_VM_FRAME_X86_INLINE_HPP
stefank@2314 27
twisti@4318 28 #include "code/codeCache.hpp"
twisti@4318 29
duke@435 30 // Inline functions for Intel frames:
duke@435 31
duke@435 32 // Constructors:
duke@435 33
duke@435 34 inline frame::frame() {
duke@435 35 _pc = NULL;
duke@435 36 _sp = NULL;
duke@435 37 _unextended_sp = NULL;
duke@435 38 _fp = NULL;
duke@435 39 _cb = NULL;
duke@435 40 _deopt_state = unknown;
duke@435 41 }
duke@435 42
simonis@7553 43 inline void frame::init(intptr_t* sp, intptr_t* fp, address pc) {
duke@435 44 _sp = sp;
duke@435 45 _unextended_sp = sp;
duke@435 46 _fp = fp;
duke@435 47 _pc = pc;
duke@435 48 assert(pc != NULL, "no pc?");
duke@435 49 _cb = CodeCache::find_blob(pc);
jrose@2952 50 adjust_unextended_sp();
twisti@1639 51
twisti@1639 52 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1639 53 if (original_pc != NULL) {
twisti@1639 54 _pc = original_pc;
duke@435 55 _deopt_state = is_deoptimized;
duke@435 56 } else {
duke@435 57 _deopt_state = not_deoptimized;
duke@435 58 }
duke@435 59 }
duke@435 60
simonis@7553 61 inline frame::frame(intptr_t* sp, intptr_t* fp, address pc) {
simonis@7553 62 init(sp, fp, pc);
simonis@7553 63 }
simonis@7553 64
twisti@1639 65 inline frame::frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc) {
duke@435 66 _sp = sp;
duke@435 67 _unextended_sp = unextended_sp;
duke@435 68 _fp = fp;
duke@435 69 _pc = pc;
duke@435 70 assert(pc != NULL, "no pc?");
duke@435 71 _cb = CodeCache::find_blob(pc);
never@2895 72 adjust_unextended_sp();
twisti@1639 73
twisti@1639 74 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1639 75 if (original_pc != NULL) {
twisti@1639 76 _pc = original_pc;
twisti@2103 77 assert(((nmethod*)_cb)->insts_contains(_pc), "original PC must be in nmethod");
duke@435 78 _deopt_state = is_deoptimized;
duke@435 79 } else {
duke@435 80 _deopt_state = not_deoptimized;
duke@435 81 }
duke@435 82 }
duke@435 83
duke@435 84 inline frame::frame(intptr_t* sp, intptr_t* fp) {
duke@435 85 _sp = sp;
duke@435 86 _unextended_sp = sp;
duke@435 87 _fp = fp;
duke@435 88 _pc = (address)(sp[-1]);
sgoldman@542 89
sgoldman@542 90 // Here's a sticky one. This constructor can be called via AsyncGetCallTrace
sgoldman@542 91 // when last_Java_sp is non-null but the pc fetched is junk. If we are truly
sgoldman@542 92 // unlucky the junk value could be to a zombied method and we'll die on the
sgoldman@542 93 // find_blob call. This is also why we can have no asserts on the validity
sgoldman@542 94 // of the pc we find here. AsyncGetCallTrace -> pd_get_top_frame_for_signal_handler
sgoldman@542 95 // -> pd_last_frame should use a specialized version of pd_last_frame which could
zmajo@7854 96 // call a specialized frame constructor instead of this one.
sgoldman@542 97 // Then we could use the assert below. However this assert is of somewhat dubious
sgoldman@542 98 // value.
sgoldman@542 99 // assert(_pc != NULL, "no pc?");
sgoldman@542 100
duke@435 101 _cb = CodeCache::find_blob(_pc);
jrose@2952 102 adjust_unextended_sp();
duke@435 103
twisti@1639 104 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1639 105 if (original_pc != NULL) {
twisti@1639 106 _pc = original_pc;
duke@435 107 _deopt_state = is_deoptimized;
duke@435 108 } else {
duke@435 109 _deopt_state = not_deoptimized;
duke@435 110 }
duke@435 111 }
duke@435 112
duke@435 113 // Accessors
duke@435 114
duke@435 115 inline bool frame::equal(frame other) const {
duke@435 116 bool ret = sp() == other.sp()
duke@435 117 && unextended_sp() == other.unextended_sp()
duke@435 118 && fp() == other.fp()
duke@435 119 && pc() == other.pc();
duke@435 120 assert(!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state, "inconsistent construction");
duke@435 121 return ret;
duke@435 122 }
duke@435 123
duke@435 124 // Return unique id for this frame. The id must have a value where we can distinguish
duke@435 125 // identity and younger/older relationship. NULL represents an invalid (incomparable)
duke@435 126 // frame.
duke@435 127 inline intptr_t* frame::id(void) const { return unextended_sp(); }
duke@435 128
duke@435 129 // Relationals on frames based
duke@435 130 // Return true if the frame is younger (more recent activation) than the frame represented by id
duke@435 131 inline bool frame::is_younger(intptr_t* id) const { assert(this->id() != NULL && id != NULL, "NULL frame id");
duke@435 132 return this->id() < id ; }
duke@435 133
duke@435 134 // Return true if the frame is older (less recent activation) than the frame represented by id
duke@435 135 inline bool frame::is_older(intptr_t* id) const { assert(this->id() != NULL && id != NULL, "NULL frame id");
duke@435 136 return this->id() > id ; }
duke@435 137
duke@435 138
duke@435 139
duke@435 140 inline intptr_t* frame::link() const { return (intptr_t*) *(intptr_t **)addr_at(link_offset); }
duke@435 141 inline void frame::set_link(intptr_t* addr) { *(intptr_t **)addr_at(link_offset) = addr; }
duke@435 142
duke@435 143
duke@435 144 inline intptr_t* frame::unextended_sp() const { return _unextended_sp; }
duke@435 145
duke@435 146 // Return address:
duke@435 147
duke@435 148 inline address* frame::sender_pc_addr() const { return (address*) addr_at( return_addr_offset); }
duke@435 149 inline address frame::sender_pc() const { return *sender_pc_addr(); }
duke@435 150
duke@435 151 // return address of param, zero origin index.
duke@435 152 inline address* frame::native_param_addr(int idx) const { return (address*) addr_at( native_frame_initial_param_offset+idx); }
duke@435 153
duke@435 154 #ifdef CC_INTERP
duke@435 155
duke@435 156 inline interpreterState frame::get_interpreterState() const {
coleenp@955 157 return ((interpreterState)addr_at( -((int)sizeof(BytecodeInterpreter))/wordSize ));
duke@435 158 }
duke@435 159
duke@435 160 inline intptr_t* frame::sender_sp() const {
duke@435 161 // Hmm this seems awfully expensive QQQ, is this really called with interpreted frames?
duke@435 162 if (is_interpreted_frame()) {
duke@435 163 assert(false, "should never happen");
duke@435 164 return get_interpreterState()->sender_sp();
duke@435 165 } else {
duke@435 166 return addr_at(sender_sp_offset);
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170 inline intptr_t** frame::interpreter_frame_locals_addr() const {
duke@435 171 assert(is_interpreted_frame(), "must be interpreted");
duke@435 172 return &(get_interpreterState()->_locals);
duke@435 173 }
duke@435 174
duke@435 175 inline intptr_t* frame::interpreter_frame_bcx_addr() const {
duke@435 176 assert(is_interpreted_frame(), "must be interpreted");
never@739 177 return (intptr_t*) &(get_interpreterState()->_bcp);
duke@435 178 }
duke@435 179
duke@435 180
duke@435 181 // Constant pool cache
duke@435 182
coleenp@4037 183 inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const {
duke@435 184 assert(is_interpreted_frame(), "must be interpreted");
duke@435 185 return &(get_interpreterState()->_constants);
duke@435 186 }
duke@435 187
duke@435 188 // Method
duke@435 189
coleenp@4037 190 inline Method** frame::interpreter_frame_method_addr() const {
duke@435 191 assert(is_interpreted_frame(), "must be interpreted");
duke@435 192 return &(get_interpreterState()->_method);
duke@435 193 }
duke@435 194
duke@435 195 inline intptr_t* frame::interpreter_frame_mdx_addr() const {
duke@435 196 assert(is_interpreted_frame(), "must be interpreted");
never@739 197 return (intptr_t*) &(get_interpreterState()->_mdx);
duke@435 198 }
duke@435 199
duke@435 200 // top of expression stack
duke@435 201 inline intptr_t* frame::interpreter_frame_tos_address() const {
duke@435 202 assert(is_interpreted_frame(), "wrong frame type");
duke@435 203 return get_interpreterState()->_stack + 1;
duke@435 204 }
duke@435 205
duke@435 206 #else /* asm interpreter */
duke@435 207 inline intptr_t* frame::sender_sp() const { return addr_at( sender_sp_offset); }
duke@435 208
duke@435 209 inline intptr_t** frame::interpreter_frame_locals_addr() const {
duke@435 210 return (intptr_t**)addr_at(interpreter_frame_locals_offset);
duke@435 211 }
duke@435 212
duke@435 213 inline intptr_t* frame::interpreter_frame_last_sp() const {
duke@435 214 return *(intptr_t**)addr_at(interpreter_frame_last_sp_offset);
duke@435 215 }
duke@435 216
duke@435 217 inline intptr_t* frame::interpreter_frame_bcx_addr() const {
duke@435 218 return (intptr_t*)addr_at(interpreter_frame_bcx_offset);
duke@435 219 }
duke@435 220
duke@435 221
duke@435 222 inline intptr_t* frame::interpreter_frame_mdx_addr() const {
duke@435 223 return (intptr_t*)addr_at(interpreter_frame_mdx_offset);
duke@435 224 }
duke@435 225
duke@435 226
duke@435 227
duke@435 228 // Constant pool cache
duke@435 229
coleenp@4037 230 inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const {
coleenp@4037 231 return (ConstantPoolCache**)addr_at(interpreter_frame_cache_offset);
duke@435 232 }
duke@435 233
duke@435 234 // Method
duke@435 235
coleenp@4037 236 inline Method** frame::interpreter_frame_method_addr() const {
coleenp@4037 237 return (Method**)addr_at(interpreter_frame_method_offset);
duke@435 238 }
duke@435 239
duke@435 240 // top of expression stack
duke@435 241 inline intptr_t* frame::interpreter_frame_tos_address() const {
duke@435 242 intptr_t* last_sp = interpreter_frame_last_sp();
twisti@1572 243 if (last_sp == NULL) {
duke@435 244 return sp();
duke@435 245 } else {
twisti@1572 246 // sp() may have been extended or shrunk by an adapter. At least
twisti@1572 247 // check that we don't fall behind the legal region.
kvn@1690 248 // For top deoptimized frame last_sp == interpreter_frame_monitor_end.
kvn@1690 249 assert(last_sp <= (intptr_t*) interpreter_frame_monitor_end(), "bad tos");
duke@435 250 return last_sp;
duke@435 251 }
duke@435 252 }
duke@435 253
goetz@6521 254 inline oop* frame::interpreter_frame_temp_oop_addr() const {
goetz@6521 255 return (oop *)(fp() + interpreter_frame_oop_temp_offset);
goetz@6521 256 }
goetz@6521 257
duke@435 258 #endif /* CC_INTERP */
duke@435 259
duke@435 260 inline int frame::pd_oop_map_offset_adjustment() const {
duke@435 261 return 0;
duke@435 262 }
duke@435 263
duke@435 264 inline int frame::interpreter_frame_monitor_size() {
duke@435 265 return BasicObjectLock::size();
duke@435 266 }
duke@435 267
duke@435 268
duke@435 269 // expression stack
duke@435 270 // (the max_stack arguments are used by the GC; see class FrameClosure)
duke@435 271
duke@435 272 inline intptr_t* frame::interpreter_frame_expression_stack() const {
duke@435 273 intptr_t* monitor_end = (intptr_t*) interpreter_frame_monitor_end();
duke@435 274 return monitor_end-1;
duke@435 275 }
duke@435 276
duke@435 277
duke@435 278 inline jint frame::interpreter_frame_expression_stack_direction() { return -1; }
duke@435 279
duke@435 280
duke@435 281 // Entry frames
duke@435 282
rbackman@5419 283 inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const {
rbackman@5419 284 return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset);
duke@435 285 }
duke@435 286
duke@435 287 // Compiled frames
duke@435 288
duke@435 289 inline int frame::local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) {
duke@435 290 return (nof_args - local_index + (local_index < nof_args ? 1: -1));
duke@435 291 }
duke@435 292
duke@435 293 inline int frame::monitor_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) {
duke@435 294 return local_offset_for_compiler(local_index, nof_args, max_nof_locals, max_nof_monitors);
duke@435 295 }
duke@435 296
duke@435 297 inline int frame::min_local_offset_for_compiler(int nof_args, int max_nof_locals, int max_nof_monitors) {
duke@435 298 return (nof_args - (max_nof_locals + max_nof_monitors*2) - 1);
duke@435 299 }
duke@435 300
duke@435 301 inline bool frame::volatile_across_calls(Register reg) {
duke@435 302 return true;
duke@435 303 }
duke@435 304
morris@4762 305 inline oop frame::saved_oop_result(RegisterMap* map) const {
morris@4762 306 oop* result_adr = (oop *)map->location(rax->as_VMReg());
morris@4762 307 guarantee(result_adr != NULL, "bad register save location");
duke@435 308
morris@4762 309 return (*result_adr);
duke@435 310 }
duke@435 311
duke@435 312 inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) {
morris@4762 313 oop* result_adr = (oop *)map->location(rax->as_VMReg());
morris@4762 314 guarantee(result_adr != NULL, "bad register save location");
morris@4762 315
morris@4762 316 *result_adr = obj;
duke@435 317 }
stefank@2314 318
stefank@2314 319 #endif // CPU_X86_VM_FRAME_X86_INLINE_HPP

mercurial