annotate src/cpu/sparc/vm/frame_sparc.cpp @ 6652:c283096252e3

8046611: Build errors with gcc on sparc/fastdebug Reviewed-by: dholmes, ctornqvi
author mikael
date Fri, 20 Jun 2014 11:19:22 -0700
parents cb5694166a39
children ecdcd96f051a 22b98ab2a69f
rev   line source
duke@0 1 /*
drchase@4507 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "interpreter/interpreter.hpp"
stefank@1879 27 #include "memory/resourceArea.hpp"
stefank@1879 28 #include "oops/markOop.hpp"
coleenp@3602 29 #include "oops/method.hpp"
stefank@1879 30 #include "oops/oop.inline.hpp"
iveresov@3060 31 #include "prims/methodHandles.hpp"
stefank@1879 32 #include "runtime/frame.inline.hpp"
stefank@1879 33 #include "runtime/handles.inline.hpp"
stefank@1879 34 #include "runtime/javaCalls.hpp"
stefank@1879 35 #include "runtime/monitorChunk.hpp"
stefank@1879 36 #include "runtime/signature.hpp"
stefank@1879 37 #include "runtime/stubCodeGenerator.hpp"
stefank@1879 38 #include "runtime/stubRoutines.hpp"
stefank@1879 39 #include "vmreg_sparc.inline.hpp"
stefank@1879 40 #ifdef COMPILER1
stefank@1879 41 #include "c1/c1_Runtime1.hpp"
stefank@1879 42 #include "runtime/vframeArray.hpp"
stefank@1879 43 #endif
duke@0 44
duke@0 45 void RegisterMap::pd_clear() {
duke@0 46 if (_thread->has_last_Java_frame()) {
duke@0 47 frame fr = _thread->last_frame();
duke@0 48 _window = fr.sp();
duke@0 49 } else {
duke@0 50 _window = NULL;
duke@0 51 }
duke@0 52 _younger_window = NULL;
duke@0 53 }
duke@0 54
duke@0 55
duke@0 56 // Unified register numbering scheme: each 32-bits counts as a register
duke@0 57 // number, so all the V9 registers take 2 slots.
duke@0 58 const static int R_L_nums[] = {0+040,2+040,4+040,6+040,8+040,10+040,12+040,14+040};
duke@0 59 const static int R_I_nums[] = {0+060,2+060,4+060,6+060,8+060,10+060,12+060,14+060};
duke@0 60 const static int R_O_nums[] = {0+020,2+020,4+020,6+020,8+020,10+020,12+020,14+020};
duke@0 61 const static int R_G_nums[] = {0+000,2+000,4+000,6+000,8+000,10+000,12+000,14+000};
duke@0 62 static RegisterMap::LocationValidType bad_mask = 0;
duke@0 63 static RegisterMap::LocationValidType R_LIO_mask = 0;
duke@0 64 static bool register_map_inited = false;
duke@0 65
duke@0 66 static void register_map_init() {
duke@0 67 if (!register_map_inited) {
duke@0 68 register_map_inited = true;
duke@0 69 int i;
duke@0 70 for (i = 0; i < 8; i++) {
duke@0 71 assert(R_L_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
duke@0 72 assert(R_I_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
duke@0 73 assert(R_O_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
duke@0 74 assert(R_G_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
duke@0 75 }
duke@0 76
duke@0 77 bad_mask |= (1LL << R_O_nums[6]); // SP
duke@0 78 bad_mask |= (1LL << R_O_nums[7]); // cPC
duke@0 79 bad_mask |= (1LL << R_I_nums[6]); // FP
duke@0 80 bad_mask |= (1LL << R_I_nums[7]); // rPC
duke@0 81 bad_mask |= (1LL << R_G_nums[2]); // TLS
duke@0 82 bad_mask |= (1LL << R_G_nums[7]); // reserved by libthread
duke@0 83
duke@0 84 for (i = 0; i < 8; i++) {
duke@0 85 R_LIO_mask |= (1LL << R_L_nums[i]);
duke@0 86 R_LIO_mask |= (1LL << R_I_nums[i]);
duke@0 87 R_LIO_mask |= (1LL << R_O_nums[i]);
duke@0 88 }
duke@0 89 }
duke@0 90 }
duke@0 91
duke@0 92
duke@0 93 address RegisterMap::pd_location(VMReg regname) const {
duke@0 94 register_map_init();
duke@0 95
duke@0 96 assert(regname->is_reg(), "sanity check");
duke@0 97 // Only the GPRs get handled this way
duke@0 98 if( !regname->is_Register())
duke@0 99 return NULL;
duke@0 100
duke@0 101 // don't talk about bad registers
duke@0 102 if ((bad_mask & ((LocationValidType)1 << regname->value())) != 0) {
duke@0 103 return NULL;
duke@0 104 }
duke@0 105
duke@0 106 // Convert to a GPR
duke@0 107 Register reg;
duke@0 108 int second_word = 0;
duke@0 109 // 32-bit registers for in, out and local
duke@0 110 if (!regname->is_concrete()) {
duke@0 111 // HMM ought to return NULL for any non-concrete (odd) vmreg
duke@0 112 // this all tied up in the fact we put out double oopMaps for
duke@0 113 // register locations. When that is fixed we'd will return NULL
duke@0 114 // (or assert here).
duke@0 115 reg = regname->prev()->as_Register();
duke@0 116 #ifdef _LP64
duke@0 117 second_word = sizeof(jint);
duke@0 118 #else
duke@0 119 return NULL;
duke@0 120 #endif // _LP64
duke@0 121 } else {
duke@0 122 reg = regname->as_Register();
duke@0 123 }
duke@0 124 if (reg->is_out()) {
duke@0 125 assert(_younger_window != NULL, "Younger window should be available");
duke@0 126 return second_word + (address)&_younger_window[reg->after_save()->sp_offset_in_saved_window()];
duke@0 127 }
duke@0 128 if (reg->is_local() || reg->is_in()) {
duke@0 129 assert(_window != NULL, "Window should be available");
duke@0 130 return second_word + (address)&_window[reg->sp_offset_in_saved_window()];
duke@0 131 }
duke@0 132 // Only the window'd GPRs get handled this way; not the globals.
duke@0 133 return NULL;
duke@0 134 }
duke@0 135
duke@0 136
duke@0 137 #ifdef ASSERT
duke@0 138 void RegisterMap::check_location_valid() {
duke@0 139 register_map_init();
duke@0 140 assert((_location_valid[0] & bad_mask) == 0, "cannot have special locations for SP,FP,TLS,etc.");
duke@0 141 }
duke@0 142 #endif
duke@0 143
duke@0 144 // We are shifting windows. That means we are moving all %i to %o,
duke@0 145 // getting rid of all current %l, and keeping all %g. This is only
duke@0 146 // complicated if any of the location pointers for these are valid.
duke@0 147 // The normal case is that everything is in its standard register window
duke@0 148 // home, and _location_valid[0] is zero. In that case, this routine
duke@0 149 // does exactly nothing.
duke@0 150 void RegisterMap::shift_individual_registers() {
duke@0 151 if (!update_map()) return; // this only applies to maps with locations
duke@0 152 register_map_init();
duke@0 153 check_location_valid();
duke@0 154
duke@0 155 LocationValidType lv = _location_valid[0];
duke@0 156 LocationValidType lv0 = lv;
duke@0 157
duke@0 158 lv &= ~R_LIO_mask; // clear %l, %o, %i regs
duke@0 159
duke@0 160 // if we cleared some non-%g locations, we may have to do some shifting
duke@0 161 if (lv != lv0) {
duke@0 162 // copy %i0-%i5 to %o0-%o5, if they have special locations
duke@0 163 // This can happen in within stubs which spill argument registers
duke@0 164 // around a dynamic link operation, such as resolve_opt_virtual_call.
duke@0 165 for (int i = 0; i < 8; i++) {
duke@0 166 if (lv0 & (1LL << R_I_nums[i])) {
duke@0 167 _location[R_O_nums[i]] = _location[R_I_nums[i]];
duke@0 168 lv |= (1LL << R_O_nums[i]);
duke@0 169 }
duke@0 170 }
duke@0 171 }
duke@0 172
duke@0 173 _location_valid[0] = lv;
duke@0 174 check_location_valid();
duke@0 175 }
duke@0 176
sgoldman@107 177 bool frame::safe_for_sender(JavaThread *thread) {
duke@0 178
sgoldman@107 179 address _SP = (address) sp();
sgoldman@107 180 address _FP = (address) fp();
sgoldman@107 181 address _UNEXTENDED_SP = (address) unextended_sp();
sgoldman@107 182 // sp must be within the stack
sgoldman@107 183 bool sp_safe = (_SP <= thread->stack_base()) &&
sgoldman@107 184 (_SP >= thread->stack_base() - thread->stack_size());
sgoldman@107 185
sgoldman@107 186 if (!sp_safe) {
sgoldman@107 187 return false;
sgoldman@107 188 }
sgoldman@107 189
sgoldman@107 190 // unextended sp must be within the stack and above or equal sp
sgoldman@107 191 bool unextended_sp_safe = (_UNEXTENDED_SP <= thread->stack_base()) &&
sgoldman@107 192 (_UNEXTENDED_SP >= _SP);
sgoldman@107 193
sgoldman@107 194 if (!unextended_sp_safe) return false;
sgoldman@107 195
sgoldman@107 196 // an fp must be within the stack and above (but not equal) sp
sgoldman@107 197 bool fp_safe = (_FP <= thread->stack_base()) &&
sgoldman@107 198 (_FP > _SP);
sgoldman@107 199
sgoldman@107 200 // We know sp/unextended_sp are safe only fp is questionable here
sgoldman@107 201
sgoldman@107 202 // If the current frame is known to the code cache then we can attempt to
sgoldman@107 203 // to construct the sender and do some validation of it. This goes a long way
sgoldman@107 204 // toward eliminating issues when we get in frame construction code
sgoldman@107 205
sgoldman@107 206 if (_cb != NULL ) {
sgoldman@107 207
sgoldman@107 208 // First check if frame is complete and tester is reliable
sgoldman@107 209 // Unfortunately we can only check frame complete for runtime stubs and nmethod
sgoldman@107 210 // other generic buffer blobs are more problematic so we just assume they are
sgoldman@107 211 // ok. adapter blobs never have a frame complete and are never ok.
sgoldman@107 212
sgoldman@107 213 if (!_cb->is_frame_complete_at(_pc)) {
sgoldman@107 214 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
sgoldman@107 215 return false;
duke@0 216 }
sgoldman@107 217 }
sgoldman@107 218
rbackman@4210 219 // Could just be some random pointer within the codeBlob
rbackman@4210 220 if (!_cb->code_contains(_pc)) {
rbackman@4210 221 return false;
rbackman@4210 222 }
rbackman@4210 223
sgoldman@107 224 // Entry frame checks
sgoldman@107 225 if (is_entry_frame()) {
sgoldman@107 226 // an entry frame must have a valid fp.
sgoldman@107 227
sgoldman@107 228 if (!fp_safe) {
sgoldman@107 229 return false;
sgoldman@107 230 }
sgoldman@107 231
sgoldman@107 232 // Validate the JavaCallWrapper an entry frame must have
sgoldman@107 233
sgoldman@107 234 address jcw = (address)entry_frame_call_wrapper();
sgoldman@107 235
sgoldman@107 236 bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > _FP);
sgoldman@107 237
sgoldman@107 238 return jcw_safe;
sgoldman@107 239
sgoldman@107 240 }
sgoldman@107 241
sgoldman@107 242 intptr_t* younger_sp = sp();
sgoldman@107 243 intptr_t* _SENDER_SP = sender_sp(); // sender is actually just _FP
sgoldman@107 244 bool adjusted_stack = is_interpreted_frame();
sgoldman@107 245
sgoldman@107 246 address sender_pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset;
sgoldman@107 247
sgoldman@107 248
sgoldman@107 249 // We must always be able to find a recognizable pc
sgoldman@107 250 CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
sgoldman@107 251 if (sender_pc == NULL || sender_blob == NULL) {
sgoldman@107 252 return false;
sgoldman@107 253 }
sgoldman@107 254
sla@4802 255 // Could be a zombie method
sla@4802 256 if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
sla@4802 257 return false;
sla@4802 258 }
sla@4802 259
sgoldman@107 260 // It should be safe to construct the sender though it might not be valid
sgoldman@107 261
sgoldman@107 262 frame sender(_SENDER_SP, younger_sp, adjusted_stack);
sgoldman@107 263
sgoldman@107 264 // Do we have a valid fp?
sgoldman@107 265 address sender_fp = (address) sender.fp();
sgoldman@107 266
sgoldman@107 267 // an fp must be within the stack and above (but not equal) current frame's _FP
sgoldman@107 268
sgoldman@107 269 bool sender_fp_safe = (sender_fp <= thread->stack_base()) &&
sgoldman@107 270 (sender_fp > _FP);
sgoldman@107 271
sgoldman@107 272 if (!sender_fp_safe) {
sgoldman@107 273 return false;
sgoldman@107 274 }
sgoldman@107 275
sgoldman@107 276
sgoldman@107 277 // If the potential sender is the interpreter then we can do some more checking
sgoldman@107 278 if (Interpreter::contains(sender_pc)) {
sgoldman@107 279 return sender.is_interpreted_frame_valid(thread);
sgoldman@107 280 }
sgoldman@107 281
sgoldman@107 282 // Could just be some random pointer within the codeBlob
twisti@1668 283 if (!sender.cb()->code_contains(sender_pc)) {
twisti@1668 284 return false;
twisti@1668 285 }
sgoldman@107 286
sgoldman@107 287 // We should never be able to see an adapter if the current frame is something from code cache
twisti@1668 288 if (sender_blob->is_adapter_blob()) {
sgoldman@107 289 return false;
sgoldman@107 290 }
sgoldman@107 291
sgoldman@107 292 if( sender.is_entry_frame()) {
sgoldman@107 293 // Validate the JavaCallWrapper an entry frame must have
sgoldman@107 294
sgoldman@107 295 address jcw = (address)sender.entry_frame_call_wrapper();
sgoldman@107 296
sgoldman@107 297 bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > sender_fp);
sgoldman@107 298
sgoldman@107 299 return jcw_safe;
sgoldman@107 300 }
sgoldman@107 301
sla@4802 302 // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
sgoldman@107 303 // because you must allocate window space
sgoldman@107 304
sla@4802 305 if (sender_blob->frame_size() <= 0) {
sgoldman@107 306 assert(!sender_blob->is_nmethod(), "should count return address at least");
sgoldman@107 307 return false;
sgoldman@107 308 }
sgoldman@107 309
sgoldman@107 310 // The sender should positively be an nmethod or call_stub. On sparc we might in fact see something else.
sgoldman@107 311 // The cause of this is because at a save instruction the O7 we get is a leftover from an earlier
drchase@4507 312 // window use. So if a runtime stub creates two frames (common in fastdebug/debug) then we see the
sgoldman@107 313 // stale pc. So if the sender blob is not something we'd expect we have little choice but to declare
sgoldman@107 314 // the stack unwalkable. pd_get_top_frame_for_signal_handler tries to recover from this by unwinding
sgoldman@107 315 // that initial frame and retrying.
sgoldman@107 316
sgoldman@107 317 if (!sender_blob->is_nmethod()) {
sgoldman@107 318 return false;
sgoldman@107 319 }
sgoldman@107 320
sgoldman@107 321 // Could put some more validation for the potential non-interpreted sender
sgoldman@107 322 // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
sgoldman@107 323
sgoldman@107 324 // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
sgoldman@107 325
sgoldman@107 326 // We've validated the potential sender that would be created
sgoldman@107 327
sgoldman@107 328 return true;
sgoldman@107 329
duke@0 330 }
sgoldman@107 331
sgoldman@107 332 // Must be native-compiled frame. Since sender will try and use fp to find
sgoldman@107 333 // linkages it must be safe
sgoldman@107 334
sgoldman@107 335 if (!fp_safe) return false;
sgoldman@107 336
sgoldman@107 337 // could try and do some more potential verification of native frame if we could think of some...
sgoldman@107 338
sgoldman@107 339 return true;
duke@0 340 }
duke@0 341
duke@0 342 // constructors
duke@0 343
duke@0 344 // Construct an unpatchable, deficient frame
duke@0 345 frame::frame(intptr_t* sp, unpatchable_t, address pc, CodeBlob* cb) {
duke@0 346 #ifdef _LP64
duke@0 347 assert( (((intptr_t)sp & (wordSize-1)) == 0), "frame constructor passed an invalid sp");
duke@0 348 #endif
duke@0 349 _sp = sp;
duke@0 350 _younger_sp = NULL;
duke@0 351 _pc = pc;
duke@0 352 _cb = cb;
duke@0 353 _sp_adjustment_by_callee = 0;
duke@0 354 assert(pc == NULL && cb == NULL || pc != NULL, "can't have a cb and no pc!");
duke@0 355 if (_cb == NULL && _pc != NULL ) {
duke@0 356 _cb = CodeCache::find_blob(_pc);
duke@0 357 }
duke@0 358 _deopt_state = unknown;
duke@0 359 #ifdef ASSERT
duke@0 360 if ( _cb != NULL && _cb->is_nmethod()) {
duke@0 361 // Without a valid unextended_sp() we can't convert the pc to "original"
duke@0 362 assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant broken");
duke@0 363 }
duke@0 364 #endif // ASSERT
duke@0 365 }
duke@0 366
twisti@1484 367 frame::frame(intptr_t* sp, intptr_t* younger_sp, bool younger_frame_is_interpreted) :
twisti@1484 368 _sp(sp),
twisti@1484 369 _younger_sp(younger_sp),
twisti@1484 370 _deopt_state(unknown),
twisti@1484 371 _sp_adjustment_by_callee(0) {
duke@0 372 if (younger_sp == NULL) {
duke@0 373 // make a deficient frame which doesn't know where its PC is
duke@0 374 _pc = NULL;
duke@0 375 _cb = NULL;
duke@0 376 } else {
duke@0 377 _pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset;
duke@0 378 assert( (intptr_t*)younger_sp[FP->sp_offset_in_saved_window()] == (intptr_t*)((intptr_t)sp - STACK_BIAS), "younger_sp must be valid");
duke@0 379 // Any frame we ever build should always "safe" therefore we should not have to call
duke@0 380 // find_blob_unsafe
duke@0 381 // In case of native stubs, the pc retrieved here might be
duke@0 382 // wrong. (the _last_native_pc will have the right value)
duke@0 383 // So do not put add any asserts on the _pc here.
duke@0 384 }
twisti@1484 385
twisti@1484 386 if (_pc != NULL)
twisti@1484 387 _cb = CodeCache::find_blob(_pc);
twisti@1484 388
twisti@1484 389 // Check for MethodHandle call sites.
twisti@1484 390 if (_cb != NULL) {
twisti@1484 391 nmethod* nm = _cb->as_nmethod_or_null();
twisti@1484 392 if (nm != NULL) {
twisti@1484 393 if (nm->is_deopt_mh_entry(_pc) || nm->is_method_handle_return(_pc)) {
twisti@1484 394 _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) sp[L7_mh_SP_save->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
twisti@1484 395 // The SP is already adjusted by this MH call site, don't
twisti@1484 396 // overwrite this value with the wrong interpreter value.
twisti@1484 397 younger_frame_is_interpreted = false;
twisti@1484 398 }
twisti@1484 399 }
duke@0 400 }
duke@0 401
twisti@1484 402 if (younger_frame_is_interpreted) {
twisti@1484 403 // compute adjustment to this frame's SP made by its interpreted callee
twisti@1484 404 _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) younger_sp[I5_savedSP->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
twisti@1484 405 }
duke@0 406
twisti@1484 407 // It is important that the frame is fully constructed when we do
twisti@1484 408 // this lookup as get_deopt_original_pc() needs a correct value for
twisti@1484 409 // unextended_sp() which uses _sp_adjustment_by_callee.
duke@0 410 if (_pc != NULL) {
twisti@1204 411 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1204 412 if (original_pc != NULL) {
twisti@1204 413 _pc = original_pc;
duke@0 414 _deopt_state = is_deoptimized;
duke@0 415 } else {
duke@0 416 _deopt_state = not_deoptimized;
duke@0 417 }
duke@0 418 }
duke@0 419 }
duke@0 420
duke@0 421 bool frame::is_interpreted_frame() const {
duke@0 422 return Interpreter::contains(pc());
duke@0 423 }
duke@0 424
duke@0 425 // sender_sp
duke@0 426
duke@0 427 intptr_t* frame::interpreter_frame_sender_sp() const {
duke@0 428 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 429 return fp();
duke@0 430 }
duke@0 431
duke@0 432 #ifndef CC_INTERP
duke@0 433 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
duke@0 434 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 435 Unimplemented();
duke@0 436 }
duke@0 437 #endif // CC_INTERP
duke@0 438
duke@0 439 frame frame::sender_for_entry_frame(RegisterMap *map) const {
duke@0 440 assert(map != NULL, "map must be set");
duke@0 441 // Java frame called from C; skip all C frames and return top C
duke@0 442 // frame of that chunk as the sender
duke@0 443 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
duke@0 444 assert(!entry_frame_is_first(), "next Java fp must be non zero");
duke@0 445 assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
duke@0 446 intptr_t* last_Java_sp = jfa->last_Java_sp();
duke@0 447 // Since we are walking the stack now this nested anchor is obviously walkable
duke@0 448 // even if it wasn't when it was stacked.
duke@0 449 if (!jfa->walkable()) {
duke@0 450 // Capture _last_Java_pc (if needed) and mark anchor walkable.
duke@0 451 jfa->capture_last_Java_pc(_sp);
duke@0 452 }
duke@0 453 assert(jfa->last_Java_pc() != NULL, "No captured pc!");
duke@0 454 map->clear();
duke@0 455 map->make_integer_regs_unsaved();
duke@0 456 map->shift_window(last_Java_sp, NULL);
duke@0 457 assert(map->include_argument_oops(), "should be set by clear");
duke@0 458 return frame(last_Java_sp, frame::unpatchable, jfa->last_Java_pc());
duke@0 459 }
duke@0 460
duke@0 461 frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
duke@0 462 ShouldNotCallThis();
duke@0 463 return sender(map);
duke@0 464 }
duke@0 465
duke@0 466 frame frame::sender_for_compiled_frame(RegisterMap *map) const {
duke@0 467 ShouldNotCallThis();
duke@0 468 return sender(map);
duke@0 469 }
duke@0 470
duke@0 471 frame frame::sender(RegisterMap* map) const {
duke@0 472 assert(map != NULL, "map must be set");
duke@0 473
duke@0 474 assert(CodeCache::find_blob_unsafe(_pc) == _cb, "inconsistent");
duke@0 475
duke@0 476 // Default is not to follow arguments; update it accordingly below
duke@0 477 map->set_include_argument_oops(false);
duke@0 478
duke@0 479 if (is_entry_frame()) return sender_for_entry_frame(map);
duke@0 480
twisti@1484 481 intptr_t* younger_sp = sp();
twisti@1484 482 intptr_t* sp = sender_sp();
duke@0 483
duke@0 484 // Note: The version of this operation on any platform with callee-save
duke@0 485 // registers must update the register map (if not null).
duke@0 486 // In order to do this correctly, the various subtypes of
duke@0 487 // of frame (interpreted, compiled, glue, native),
duke@0 488 // must be distinguished. There is no need on SPARC for
duke@0 489 // such distinctions, because all callee-save registers are
duke@0 490 // preserved for all frames via SPARC-specific mechanisms.
duke@0 491 //
duke@0 492 // *** HOWEVER, *** if and when we make any floating-point
duke@0 493 // registers callee-saved, then we will have to copy over
duke@0 494 // the RegisterMap update logic from the Intel code.
duke@0 495
duke@0 496 // The constructor of the sender must know whether this frame is interpreted so it can set the
duke@0 497 // sender's _sp_adjustment_by_callee field. An osr adapter frame was originally
duke@0 498 // interpreted but its pc is in the code cache (for c1 -> osr_frame_return_id stub), so it must be
duke@0 499 // explicitly recognized.
duke@0 500
never@2515 501
twisti@1484 502 bool frame_is_interpreted = is_interpreted_frame();
twisti@1484 503 if (frame_is_interpreted) {
duke@0 504 map->make_integer_regs_unsaved();
duke@0 505 map->shift_window(sp, younger_sp);
duke@0 506 } else if (_cb != NULL) {
duke@0 507 // Update the locations of implicitly saved registers to be their
duke@0 508 // addresses in the register save area.
duke@0 509 // For %o registers, the addresses of %i registers in the next younger
duke@0 510 // frame are used.
duke@0 511 map->shift_window(sp, younger_sp);
duke@0 512 if (map->update_map()) {
duke@0 513 // Tell GC to use argument oopmaps for some runtime stubs that need it.
duke@0 514 // For C1, the runtime stub might not have oop maps, so set this flag
duke@0 515 // outside of update_register_map.
duke@0 516 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
duke@0 517 if (_cb->oop_maps() != NULL) {
duke@0 518 OopMapSet::update_register_map(this, map);
duke@0 519 }
duke@0 520 }
duke@0 521 }
twisti@1484 522 return frame(sp, younger_sp, frame_is_interpreted);
duke@0 523 }
duke@0 524
duke@0 525
duke@0 526 void frame::patch_pc(Thread* thread, address pc) {
duke@0 527 if(thread == Thread::current()) {
duke@0 528 StubRoutines::Sparc::flush_callers_register_windows_func()();
duke@0 529 }
duke@0 530 if (TracePcPatching) {
duke@0 531 // QQQ this assert is invalid (or too strong anyway) sice _pc could
duke@0 532 // be original pc and frame could have the deopt pc.
duke@0 533 // assert(_pc == *O7_addr() + pc_return_offset, "frame has wrong pc");
mikael@6569 534 tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
mikael@6569 535 p2i(O7_addr()), p2i(_pc), p2i(pc));
duke@0 536 }
duke@0 537 _cb = CodeCache::find_blob(pc);
duke@0 538 *O7_addr() = pc - pc_return_offset;
duke@0 539 _cb = CodeCache::find_blob(_pc);
twisti@1204 540 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1204 541 if (original_pc != NULL) {
twisti@1204 542 assert(original_pc == _pc, "expected original to be stored before patching");
duke@0 543 _deopt_state = is_deoptimized;
duke@0 544 } else {
duke@0 545 _deopt_state = not_deoptimized;
duke@0 546 }
duke@0 547 }
duke@0 548
duke@0 549
duke@0 550 static bool sp_is_valid(intptr_t* old_sp, intptr_t* young_sp, intptr_t* sp) {
duke@0 551 return (((intptr_t)sp & (2*wordSize-1)) == 0 &&
duke@0 552 sp <= old_sp &&
duke@0 553 sp >= young_sp);
duke@0 554 }
duke@0 555
duke@0 556
duke@0 557 /*
duke@0 558 Find the (biased) sp that is just younger than old_sp starting at sp.
duke@0 559 If not found return NULL. Register windows are assumed to be flushed.
duke@0 560 */
duke@0 561 intptr_t* frame::next_younger_sp_or_null(intptr_t* old_sp, intptr_t* sp) {
duke@0 562
duke@0 563 intptr_t* previous_sp = NULL;
duke@0 564 intptr_t* orig_sp = sp;
duke@0 565
duke@0 566 int max_frames = (old_sp - sp) / 16; // Minimum frame size is 16
duke@0 567 int max_frame2 = max_frames;
duke@0 568 while(sp != old_sp && sp_is_valid(old_sp, orig_sp, sp)) {
duke@0 569 if (max_frames-- <= 0)
duke@0 570 // too many frames have gone by; invalid parameters given to this function
duke@0 571 break;
duke@0 572 previous_sp = sp;
duke@0 573 sp = (intptr_t*)sp[FP->sp_offset_in_saved_window()];
duke@0 574 sp = (intptr_t*)((intptr_t)sp + STACK_BIAS);
duke@0 575 }
duke@0 576
duke@0 577 return (sp == old_sp ? previous_sp : NULL);
duke@0 578 }
duke@0 579
duke@0 580 /*
duke@0 581 Determine if "sp" is a valid stack pointer. "sp" is assumed to be younger than
duke@0 582 "valid_sp". So if "sp" is valid itself then it should be possible to walk frames
duke@0 583 from "sp" to "valid_sp". The assumption is that the registers windows for the
duke@0 584 thread stack in question are flushed.
duke@0 585 */
duke@0 586 bool frame::is_valid_stack_pointer(intptr_t* valid_sp, intptr_t* sp) {
duke@0 587 return next_younger_sp_or_null(valid_sp, sp) != NULL;
duke@0 588 }
duke@0 589
duke@0 590
duke@0 591 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
duke@0 592 assert(is_interpreted_frame(), "must be interpreter frame");
duke@0 593 return this->fp() == fp;
duke@0 594 }
duke@0 595
duke@0 596
duke@0 597 void frame::pd_gc_epilog() {
duke@0 598 if (is_interpreted_frame()) {
duke@0 599 // set constant pool cache entry for interpreter
coleenp@3602 600 Method* m = interpreter_frame_method();
duke@0 601
duke@0 602 *interpreter_frame_cpoolcache_addr() = m->constants()->cache();
duke@0 603 }
duke@0 604 }
duke@0 605
duke@0 606
sgoldman@107 607 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
duke@0 608 #ifdef CC_INTERP
duke@0 609 // Is there anything to do?
duke@0 610 #else
duke@0 611 assert(is_interpreted_frame(), "Not an interpreted frame");
duke@0 612 // These are reasonable sanity checks
duke@0 613 if (fp() == 0 || (intptr_t(fp()) & (2*wordSize-1)) != 0) {
duke@0 614 return false;
duke@0 615 }
duke@0 616 if (sp() == 0 || (intptr_t(sp()) & (2*wordSize-1)) != 0) {
duke@0 617 return false;
duke@0 618 }
sgoldman@107 619
duke@0 620 const intptr_t interpreter_frame_initial_sp_offset = interpreter_frame_vm_local_words;
duke@0 621 if (fp() + interpreter_frame_initial_sp_offset < sp()) {
duke@0 622 return false;
duke@0 623 }
duke@0 624 // These are hacks to keep us out of trouble.
duke@0 625 // The problem with these is that they mask other problems
duke@0 626 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
duke@0 627 return false;
duke@0 628 }
sgoldman@107 629 // do some validation of frame elements
sgoldman@107 630
sgoldman@107 631 // first the method
sgoldman@107 632
coleenp@3602 633 Method* m = *interpreter_frame_method_addr();
sgoldman@107 634
sgoldman@107 635 // validate the method we'd find in this potential sender
coleenp@3860 636 if (!m->is_valid_method()) return false;
sgoldman@107 637
sgoldman@107 638 // stack frames shouldn't be much larger than max_stack elements
sgoldman@107 639
twisti@1426 640 if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
duke@0 641 return false;
duke@0 642 }
sgoldman@107 643
sgoldman@107 644 // validate bci/bcx
sgoldman@107 645
sgoldman@107 646 intptr_t bcx = interpreter_frame_bcx();
sgoldman@107 647 if (m->validate_bci_from_bcx(bcx) < 0) {
sgoldman@107 648 return false;
sgoldman@107 649 }
sgoldman@107 650
coleenp@3602 651 // validate ConstantPoolCache*
coleenp@3602 652 ConstantPoolCache* cp = *interpreter_frame_cache_addr();
coleenp@4872 653 if (cp == NULL || !cp->is_metaspace_object()) return false;
sgoldman@107 654
sgoldman@107 655 // validate locals
sgoldman@107 656
sgoldman@107 657 address locals = (address) *interpreter_frame_locals_addr();
sgoldman@107 658
sgoldman@107 659 if (locals > thread->stack_base() || locals < (address) fp()) return false;
sgoldman@107 660
sgoldman@107 661 // We'd have to be pretty unlucky to be mislead at this point
duke@0 662 #endif /* CC_INTERP */
duke@0 663 return true;
duke@0 664 }
duke@0 665
duke@0 666
duke@0 667 // Windows have been flushed on entry (but not marked). Capture the pc that
duke@0 668 // is the return address to the frame that contains "sp" as its stack pointer.
duke@0 669 // This pc resides in the called of the frame corresponding to "sp".
duke@0 670 // As a side effect we mark this JavaFrameAnchor as having flushed the windows.
duke@0 671 // This side effect lets us mark stacked JavaFrameAnchors (stacked in the
duke@0 672 // call_helper) as flushed when we have flushed the windows for the most
duke@0 673 // recent (i.e. current) JavaFrameAnchor. This saves useless flushing calls
duke@0 674 // and lets us find the pc just once rather than multiple times as it did
duke@0 675 // in the bad old _post_Java_state days.
duke@0 676 //
duke@0 677 void JavaFrameAnchor::capture_last_Java_pc(intptr_t* sp) {
duke@0 678 if (last_Java_sp() != NULL && last_Java_pc() == NULL) {
duke@0 679 // try and find the sp just younger than _last_Java_sp
duke@0 680 intptr_t* _post_Java_sp = frame::next_younger_sp_or_null(last_Java_sp(), sp);
duke@0 681 // Really this should never fail otherwise VM call must have non-standard
duke@0 682 // frame linkage (bad) or stack is not properly flushed (worse).
duke@0 683 guarantee(_post_Java_sp != NULL, "bad stack!");
duke@0 684 _last_Java_pc = (address) _post_Java_sp[ I7->sp_offset_in_saved_window()] + frame::pc_return_offset;
duke@0 685
duke@0 686 }
duke@0 687 set_window_flushed();
duke@0 688 }
duke@0 689
duke@0 690 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
duke@0 691 if (walkable()) return;
duke@0 692 // Eventually make an assert
duke@0 693 guarantee(Thread::current() == (Thread*)thread, "only current thread can flush its registers");
duke@0 694 // We always flush in case the profiler wants it but we won't mark
duke@0 695 // the windows as flushed unless we have a last_Java_frame
duke@0 696 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
duke@0 697 if (last_Java_sp() != NULL ) {
duke@0 698 capture_last_Java_pc(sp);
duke@0 699 }
duke@0 700 }
duke@0 701
duke@0 702 intptr_t* frame::entry_frame_argument_at(int offset) const {
duke@0 703 // convert offset to index to deal with tsi
duke@0 704 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@0 705
duke@0 706 intptr_t* LSP = (intptr_t*) sp()[Lentry_args->sp_offset_in_saved_window()];
duke@0 707 return &LSP[index+1];
duke@0 708 }
duke@0 709
duke@0 710
duke@0 711 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
duke@0 712 assert(is_interpreted_frame(), "interpreted frame expected");
coleenp@3602 713 Method* method = interpreter_frame_method();
duke@0 714 BasicType type = method->result_type();
duke@0 715
duke@0 716 if (method->is_native()) {
duke@0 717 // Prior to notifying the runtime of the method_exit the possible result
duke@0 718 // value is saved to l_scratch and d_scratch.
duke@0 719
duke@0 720 #ifdef CC_INTERP
duke@0 721 interpreterState istate = get_interpreterState();
duke@0 722 intptr_t* l_scratch = (intptr_t*) &istate->_native_lresult;
duke@0 723 intptr_t* d_scratch = (intptr_t*) &istate->_native_fresult;
duke@0 724 #else /* CC_INTERP */
duke@0 725 intptr_t* l_scratch = fp() + interpreter_frame_l_scratch_fp_offset;
duke@0 726 intptr_t* d_scratch = fp() + interpreter_frame_d_scratch_fp_offset;
duke@0 727 #endif /* CC_INTERP */
duke@0 728
duke@0 729 address l_addr = (address)l_scratch;
duke@0 730 #ifdef _LP64
duke@0 731 // On 64-bit the result for 1/8/16/32-bit result types is in the other
duke@0 732 // word half
duke@0 733 l_addr += wordSize/2;
duke@0 734 #endif
duke@0 735
duke@0 736 switch (type) {
duke@0 737 case T_OBJECT:
duke@0 738 case T_ARRAY: {
duke@0 739 #ifdef CC_INTERP
duke@0 740 *oop_result = istate->_oop_temp;
duke@0 741 #else
hseigel@5355 742 oop obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
duke@0 743 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
duke@0 744 *oop_result = obj;
duke@0 745 #endif // CC_INTERP
duke@0 746 break;
duke@0 747 }
duke@0 748
duke@0 749 case T_BOOLEAN : { jint* p = (jint*)l_addr; value_result->z = (jboolean)((*p) & 0x1); break; }
duke@0 750 case T_BYTE : { jint* p = (jint*)l_addr; value_result->b = (jbyte)((*p) & 0xff); break; }
duke@0 751 case T_CHAR : { jint* p = (jint*)l_addr; value_result->c = (jchar)((*p) & 0xffff); break; }
duke@0 752 case T_SHORT : { jint* p = (jint*)l_addr; value_result->s = (jshort)((*p) & 0xffff); break; }
duke@0 753 case T_INT : value_result->i = *(jint*)l_addr; break;
duke@0 754 case T_LONG : value_result->j = *(jlong*)l_scratch; break;
duke@0 755 case T_FLOAT : value_result->f = *(jfloat*)d_scratch; break;
duke@0 756 case T_DOUBLE : value_result->d = *(jdouble*)d_scratch; break;
duke@0 757 case T_VOID : /* Nothing to do */ break;
duke@0 758 default : ShouldNotReachHere();
duke@0 759 }
duke@0 760 } else {
duke@0 761 intptr_t* tos_addr = interpreter_frame_tos_address();
duke@0 762
duke@0 763 switch(type) {
duke@0 764 case T_OBJECT:
duke@0 765 case T_ARRAY: {
hseigel@5355 766 oop obj = cast_to_oop(*tos_addr);
duke@0 767 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
duke@0 768 *oop_result = obj;
duke@0 769 break;
duke@0 770 }
duke@0 771 case T_BOOLEAN : { jint* p = (jint*)tos_addr; value_result->z = (jboolean)((*p) & 0x1); break; }
duke@0 772 case T_BYTE : { jint* p = (jint*)tos_addr; value_result->b = (jbyte)((*p) & 0xff); break; }
duke@0 773 case T_CHAR : { jint* p = (jint*)tos_addr; value_result->c = (jchar)((*p) & 0xffff); break; }
duke@0 774 case T_SHORT : { jint* p = (jint*)tos_addr; value_result->s = (jshort)((*p) & 0xffff); break; }
duke@0 775 case T_INT : value_result->i = *(jint*)tos_addr; break;
duke@0 776 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
duke@0 777 case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
duke@0 778 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
duke@0 779 case T_VOID : /* Nothing to do */ break;
duke@0 780 default : ShouldNotReachHere();
duke@0 781 }
duke@0 782 };
duke@0 783
duke@0 784 return type;
duke@0 785 }
duke@0 786
duke@0 787 // Lesp pointer is one word lower than the top item on the stack.
duke@0 788 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
duke@0 789 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize) - 1;
duke@0 790 return &interpreter_frame_tos_address()[index];
duke@0 791 }
never@2433 792
never@2433 793
bdelsart@3016 794 #ifndef PRODUCT
never@2433 795
never@2433 796 #define DESCRIBE_FP_OFFSET(name) \
never@2462 797 values.describe(frame_no, fp() + frame::name##_offset, #name)
never@2433 798
never@2433 799 void frame::describe_pd(FrameValues& values, int frame_no) {
never@2433 800 for (int w = 0; w < frame::register_save_words; w++) {
never@2433 801 values.describe(frame_no, sp() + w, err_msg("register save area word %d", w), 1);
never@2433 802 }
never@2433 803
twisti@3534 804 if (is_interpreted_frame()) {
roland@6116 805 #ifndef CC_INTERP
never@2433 806 DESCRIBE_FP_OFFSET(interpreter_frame_d_scratch_fp);
never@2433 807 DESCRIBE_FP_OFFSET(interpreter_frame_l_scratch_fp);
never@2433 808 DESCRIBE_FP_OFFSET(interpreter_frame_padding);
never@2433 809 DESCRIBE_FP_OFFSET(interpreter_frame_oop_temp);
bdelsart@3010 810
bdelsart@3010 811 // esp, according to Lesp (e.g. not depending on bci), if seems valid
bdelsart@3010 812 intptr_t* esp = *interpreter_frame_esp_addr();
bdelsart@3010 813 if ((esp >= sp()) && (esp < fp())) {
bdelsart@3010 814 values.describe(-1, esp, "*Lesp");
bdelsart@3010 815 }
roland@6116 816 #endif
never@2433 817 }
never@2433 818
never@2433 819 if (!is_compiled_frame()) {
never@2433 820 if (frame::callee_aggregate_return_pointer_words != 0) {
never@2433 821 values.describe(frame_no, sp() + frame::callee_aggregate_return_pointer_sp_offset, "callee_aggregate_return_pointer_word");
never@2433 822 }
never@2433 823 for (int w = 0; w < frame::callee_register_argument_save_area_words; w++) {
never@2433 824 values.describe(frame_no, sp() + frame::callee_register_argument_save_area_sp_offset + w,
never@2433 825 err_msg("callee_register_argument_save_area_words %d", w));
never@2433 826 }
never@2433 827 }
never@2433 828 }
never@2433 829
never@2433 830 #endif
bdelsart@2695 831
bdelsart@2695 832 intptr_t *frame::initial_deoptimization_info() {
bdelsart@2695 833 // unused... but returns fp() to minimize changes introduced by 7087445
bdelsart@2695 834 return fp();
bdelsart@2695 835 }