src/cpu/x86/vm/frame_x86.cpp

Wed, 05 Dec 2007 09:00:00 -0800

author
dcubed
date
Wed, 05 Dec 2007 09:00:00 -0800
changeset 451
f8236e79048a
parent 435
a61af66fc99e
child 542
93b6525e3b82
permissions
-rw-r--r--

6664627: Merge changes made only in hotspot 11 forward to jdk 7
Reviewed-by: jcoomes

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_frame_x86.cpp.incl"
duke@435 27
duke@435 28 #ifdef ASSERT
duke@435 29 void RegisterMap::check_location_valid() {
duke@435 30 }
duke@435 31 #endif
duke@435 32
duke@435 33
duke@435 34 // Profiling/safepoint support
duke@435 35
duke@435 36 bool frame::safe_for_sender(JavaThread *thread) {
duke@435 37 address sp = (address)_sp;
duke@435 38 address fp = (address)_fp;
duke@435 39 address unextended_sp = (address)_unextended_sp;
duke@435 40 bool sp_safe = (sp != NULL &&
duke@435 41 (sp <= thread->stack_base()) &&
duke@435 42 (sp >= thread->stack_base() - thread->stack_size()));
duke@435 43 bool unextended_sp_safe = (unextended_sp != NULL &&
duke@435 44 (unextended_sp <= thread->stack_base()) &&
duke@435 45 (unextended_sp >= thread->stack_base() - thread->stack_size()));
duke@435 46 bool fp_safe = (fp != NULL &&
duke@435 47 (fp <= thread->stack_base()) &&
duke@435 48 (fp >= thread->stack_base() - thread->stack_size()));
duke@435 49 if (sp_safe && unextended_sp_safe && fp_safe) {
duke@435 50 // Unfortunately we can only check frame complete for runtime stubs and nmethod
duke@435 51 // other generic buffer blobs are more problematic so we just assume they are
duke@435 52 // ok. adapter blobs never have a frame complete and are never ok.
duke@435 53 if (_cb != NULL && !_cb->is_frame_complete_at(_pc)) {
duke@435 54 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
duke@435 55 return false;
duke@435 56 }
duke@435 57 }
duke@435 58 return true;
duke@435 59 }
duke@435 60 // Note: fp == NULL is not really a prerequisite for this to be safe to
duke@435 61 // walk for c2. However we've modified the code such that if we get
duke@435 62 // a failure with fp != NULL that we then try with FP == NULL.
duke@435 63 // This is basically to mimic what a last_frame would look like if
duke@435 64 // c2 had generated it.
duke@435 65 if (sp_safe && unextended_sp_safe && fp == NULL) {
duke@435 66 // frame must be complete if fp == NULL as fp == NULL is only sensible
duke@435 67 // if we are looking at a nmethod and frame complete assures us of that.
duke@435 68 if (_cb != NULL && _cb->is_frame_complete_at(_pc) && _cb->is_compiled_by_c2()) {
duke@435 69 return true;
duke@435 70 }
duke@435 71 }
duke@435 72 return false;
duke@435 73 }
duke@435 74
duke@435 75
duke@435 76 void frame::patch_pc(Thread* thread, address pc) {
duke@435 77 if (TracePcPatching) {
duke@435 78 tty->print_cr("patch_pc at address 0x%x [0x%x -> 0x%x] ", &((address *)sp())[-1], ((address *)sp())[-1], pc);
duke@435 79 }
duke@435 80 ((address *)sp())[-1] = pc;
duke@435 81 _cb = CodeCache::find_blob(pc);
duke@435 82 if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
duke@435 83 address orig = (((nmethod*)_cb)->get_original_pc(this));
duke@435 84 assert(orig == _pc, "expected original to be stored before patching");
duke@435 85 _deopt_state = is_deoptimized;
duke@435 86 // leave _pc as is
duke@435 87 } else {
duke@435 88 _deopt_state = not_deoptimized;
duke@435 89 _pc = pc;
duke@435 90 }
duke@435 91 }
duke@435 92
duke@435 93 bool frame::is_interpreted_frame() const {
duke@435 94 return Interpreter::contains(pc());
duke@435 95 }
duke@435 96
duke@435 97 int frame::frame_size() const {
duke@435 98 RegisterMap map(JavaThread::current(), false);
duke@435 99 frame sender = this->sender(&map);
duke@435 100 return sender.sp() - sp();
duke@435 101 }
duke@435 102
duke@435 103 intptr_t* frame::entry_frame_argument_at(int offset) const {
duke@435 104 // convert offset to index to deal with tsi
duke@435 105 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@435 106 // Entry frame's arguments are always in relation to unextended_sp()
duke@435 107 return &unextended_sp()[index];
duke@435 108 }
duke@435 109
duke@435 110 // sender_sp
duke@435 111 #ifdef CC_INTERP
duke@435 112 intptr_t* frame::interpreter_frame_sender_sp() const {
duke@435 113 assert(is_interpreted_frame(), "interpreted frame expected");
duke@435 114 // QQQ why does this specialize method exist if frame::sender_sp() does same thing?
duke@435 115 // seems odd and if we always know interpreted vs. non then sender_sp() is really
duke@435 116 // doing too much work.
duke@435 117 return get_interpreterState()->sender_sp();
duke@435 118 }
duke@435 119
duke@435 120 // monitor elements
duke@435 121
duke@435 122 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
duke@435 123 return get_interpreterState()->monitor_base();
duke@435 124 }
duke@435 125
duke@435 126 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
duke@435 127 return (BasicObjectLock*) get_interpreterState()->stack_base();
duke@435 128 }
duke@435 129
duke@435 130 #else // CC_INTERP
duke@435 131
duke@435 132 intptr_t* frame::interpreter_frame_sender_sp() const {
duke@435 133 assert(is_interpreted_frame(), "interpreted frame expected");
duke@435 134 return (intptr_t*) at(interpreter_frame_sender_sp_offset);
duke@435 135 }
duke@435 136
duke@435 137 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
duke@435 138 assert(is_interpreted_frame(), "interpreted frame expected");
duke@435 139 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
duke@435 140 }
duke@435 141
duke@435 142
duke@435 143 // monitor elements
duke@435 144
duke@435 145 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
duke@435 146 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
duke@435 147 }
duke@435 148
duke@435 149 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
duke@435 150 BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
duke@435 151 // make sure the pointer points inside the frame
duke@435 152 assert((intptr_t) fp() > (intptr_t) result, "result must < than frame pointer");
duke@435 153 assert((intptr_t) sp() <= (intptr_t) result, "result must >= than stack pointer");
duke@435 154 return result;
duke@435 155 }
duke@435 156
duke@435 157 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
duke@435 158 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
duke@435 159 }
duke@435 160
duke@435 161 // Used by template based interpreter deoptimization
duke@435 162 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
duke@435 163 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
duke@435 164 }
duke@435 165 #endif // CC_INTERP
duke@435 166
duke@435 167 frame frame::sender_for_entry_frame(RegisterMap* map) const {
duke@435 168 assert(map != NULL, "map must be set");
duke@435 169 // Java frame called from C; skip all C frames and return top C
duke@435 170 // frame of that chunk as the sender
duke@435 171 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
duke@435 172 assert(!entry_frame_is_first(), "next Java fp must be non zero");
duke@435 173 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
duke@435 174 map->clear();
duke@435 175 assert(map->include_argument_oops(), "should be set by clear");
duke@435 176 if (jfa->last_Java_pc() != NULL ) {
duke@435 177 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
duke@435 178 return fr;
duke@435 179 }
duke@435 180 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp());
duke@435 181 return fr;
duke@435 182 }
duke@435 183
duke@435 184 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
duke@435 185 // sp is the raw sp from the sender after adapter or interpreter extension
duke@435 186 intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset);
duke@435 187
duke@435 188 // This is the sp before any possible extension (adapter/locals).
duke@435 189 intptr_t* unextended_sp = interpreter_frame_sender_sp();
duke@435 190
duke@435 191 // The interpreter and compiler(s) always save EBP/RBP in a known
duke@435 192 // location on entry. We must record where that location is
duke@435 193 // so this if EBP/RBP was live on callout from c2 we can find
duke@435 194 // the saved copy no matter what it called.
duke@435 195
duke@435 196 // Since the interpreter always saves EBP/RBP if we record where it is then
duke@435 197 // we don't have to always save EBP/RBP on entry and exit to c2 compiled
duke@435 198 // code, on entry will be enough.
duke@435 199 #ifdef COMPILER2
duke@435 200 if (map->update_map()) {
duke@435 201 map->set_location(rbp->as_VMReg(), (address) addr_at(link_offset));
duke@435 202 #ifdef AMD64
duke@435 203 // this is weird "H" ought to be at a higher address however the
duke@435 204 // oopMaps seems to have the "H" regs at the same address and the
duke@435 205 // vanilla register.
duke@435 206 // XXXX make this go away
duke@435 207 if (true) {
duke@435 208 map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset));
duke@435 209 }
duke@435 210 #endif // AMD64
duke@435 211 }
duke@435 212 #endif /* COMPILER2 */
duke@435 213 return frame(sp, unextended_sp, link(), sender_pc());
duke@435 214 }
duke@435 215
duke@435 216
duke@435 217 //------------------------------sender_for_compiled_frame-----------------------
duke@435 218 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
duke@435 219 assert(map != NULL, "map must be set");
duke@435 220 const bool c1_compiled = _cb->is_compiled_by_c1();
duke@435 221
duke@435 222 // frame owned by optimizing compiler
duke@435 223 intptr_t* sender_sp = NULL;
duke@435 224
duke@435 225 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
duke@435 226 sender_sp = unextended_sp() + _cb->frame_size();
duke@435 227
duke@435 228 // On Intel the return_address is always the word on the stack
duke@435 229 address sender_pc = (address) *(sender_sp-1);
duke@435 230
duke@435 231 // This is the saved value of ebp which may or may not really be an fp.
duke@435 232 // it is only an fp if the sender is an interpreter frame (or c1?)
duke@435 233
duke@435 234 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
duke@435 235
duke@435 236 if (map->update_map()) {
duke@435 237 // Tell GC to use argument oopmaps for some runtime stubs that need it.
duke@435 238 // For C1, the runtime stub might not have oop maps, so set this flag
duke@435 239 // outside of update_register_map.
duke@435 240 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
duke@435 241 if (_cb->oop_maps() != NULL) {
duke@435 242 OopMapSet::update_register_map(this, map);
duke@435 243 }
duke@435 244 // Since the prolog does the save and restore of epb there is no oopmap
duke@435 245 // for it so we must fill in its location as if there was an oopmap entry
duke@435 246 // since if our caller was compiled code there could be live jvm state in it.
duke@435 247 map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset));
duke@435 248 #ifdef AMD64
duke@435 249 // this is weird "H" ought to be at a higher address however the
duke@435 250 // oopMaps seems to have the "H" regs at the same address and the
duke@435 251 // vanilla register.
duke@435 252 // XXXX make this go away
duke@435 253 if (true) {
duke@435 254 map->set_location(rbp->as_VMReg()->next(), (address) (sender_sp - frame::sender_sp_offset));
duke@435 255 }
duke@435 256 #endif // AMD64
duke@435 257 }
duke@435 258
duke@435 259 assert(sender_sp != sp(), "must have changed");
duke@435 260 return frame(sender_sp, saved_fp, sender_pc);
duke@435 261 }
duke@435 262
duke@435 263 frame frame::sender(RegisterMap* map) const {
duke@435 264 // Default is we done have to follow them. The sender_for_xxx will
duke@435 265 // update it accordingly
duke@435 266 map->set_include_argument_oops(false);
duke@435 267
duke@435 268 if (is_entry_frame()) return sender_for_entry_frame(map);
duke@435 269 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
duke@435 270 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
duke@435 271
duke@435 272 if (_cb != NULL) {
duke@435 273 return sender_for_compiled_frame(map);
duke@435 274 }
duke@435 275 // Must be native-compiled frame, i.e. the marshaling code for native
duke@435 276 // methods that exists in the core system.
duke@435 277 return frame(sender_sp(), link(), sender_pc());
duke@435 278 }
duke@435 279
duke@435 280
duke@435 281 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
duke@435 282 assert(is_interpreted_frame(), "must be interpreter frame");
duke@435 283 methodOop method = interpreter_frame_method();
duke@435 284 // When unpacking an optimized frame the frame pointer is
duke@435 285 // adjusted with:
duke@435 286 int diff = (method->max_locals() - method->size_of_parameters()) *
duke@435 287 Interpreter::stackElementWords();
duke@435 288 return _fp == (fp - diff);
duke@435 289 }
duke@435 290
duke@435 291 void frame::pd_gc_epilog() {
duke@435 292 // nothing done here now
duke@435 293 }
duke@435 294
duke@435 295 bool frame::is_interpreted_frame_valid() const {
duke@435 296 // QQQ
duke@435 297 #ifdef CC_INTERP
duke@435 298 #else
duke@435 299 assert(is_interpreted_frame(), "Not an interpreted frame");
duke@435 300 // These are reasonable sanity checks
duke@435 301 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
duke@435 302 return false;
duke@435 303 }
duke@435 304 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
duke@435 305 return false;
duke@435 306 }
duke@435 307 if (fp() + interpreter_frame_initial_sp_offset < sp()) {
duke@435 308 return false;
duke@435 309 }
duke@435 310 // These are hacks to keep us out of trouble.
duke@435 311 // The problem with these is that they mask other problems
duke@435 312 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
duke@435 313 return false;
duke@435 314 }
duke@435 315 if (fp() - sp() > 4096) { // stack frames shouldn't be large.
duke@435 316 return false;
duke@435 317 }
duke@435 318 #endif // CC_INTERP
duke@435 319 return true;
duke@435 320 }
duke@435 321
duke@435 322 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
duke@435 323 #ifdef CC_INTERP
duke@435 324 // Needed for JVMTI. The result should always be in the interpreterState object
duke@435 325 assert(false, "NYI");
duke@435 326 interpreterState istate = get_interpreterState();
duke@435 327 #endif // CC_INTERP
duke@435 328 assert(is_interpreted_frame(), "interpreted frame expected");
duke@435 329 methodOop method = interpreter_frame_method();
duke@435 330 BasicType type = method->result_type();
duke@435 331
duke@435 332 intptr_t* tos_addr;
duke@435 333 if (method->is_native()) {
duke@435 334 // Prior to calling into the runtime to report the method_exit the possible
duke@435 335 // return value is pushed to the native stack. If the result is a jfloat/jdouble
duke@435 336 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
duke@435 337 tos_addr = (intptr_t*)sp();
duke@435 338 if (type == T_FLOAT || type == T_DOUBLE) {
duke@435 339 // QQQ seems like this code is equivalent on the two platforms
duke@435 340 #ifdef AMD64
duke@435 341 // This is times two because we do a push(ltos) after pushing XMM0
duke@435 342 // and that takes two interpreter stack slots.
duke@435 343 tos_addr += 2 * Interpreter::stackElementWords();
duke@435 344 #else
duke@435 345 tos_addr += 2;
duke@435 346 #endif // AMD64
duke@435 347 }
duke@435 348 } else {
duke@435 349 tos_addr = (intptr_t*)interpreter_frame_tos_address();
duke@435 350 }
duke@435 351
duke@435 352 switch (type) {
duke@435 353 case T_OBJECT :
duke@435 354 case T_ARRAY : {
duke@435 355 oop obj;
duke@435 356 if (method->is_native()) {
duke@435 357 #ifdef CC_INTERP
duke@435 358 obj = istate->_oop_temp;
duke@435 359 #else
duke@435 360 obj = (oop) at(interpreter_frame_oop_temp_offset);
duke@435 361 #endif // CC_INTERP
duke@435 362 } else {
duke@435 363 oop* obj_p = (oop*)tos_addr;
duke@435 364 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
duke@435 365 }
duke@435 366 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
duke@435 367 *oop_result = obj;
duke@435 368 break;
duke@435 369 }
duke@435 370 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
duke@435 371 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
duke@435 372 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
duke@435 373 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
duke@435 374 case T_INT : value_result->i = *(jint*)tos_addr; break;
duke@435 375 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
duke@435 376 case T_FLOAT : {
duke@435 377 #ifdef AMD64
duke@435 378 value_result->f = *(jfloat*)tos_addr;
duke@435 379 #else
duke@435 380 if (method->is_native()) {
duke@435 381 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat
duke@435 382 value_result->f = (jfloat)d;
duke@435 383 } else {
duke@435 384 value_result->f = *(jfloat*)tos_addr;
duke@435 385 }
duke@435 386 #endif // AMD64
duke@435 387 break;
duke@435 388 }
duke@435 389 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
duke@435 390 case T_VOID : /* Nothing to do */ break;
duke@435 391 default : ShouldNotReachHere();
duke@435 392 }
duke@435 393
duke@435 394 return type;
duke@435 395 }
duke@435 396
duke@435 397
duke@435 398 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
duke@435 399 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@435 400 return &interpreter_frame_tos_address()[index];
duke@435 401 }

mercurial