src/cpu/sparc/vm/frame_sparc.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5784
190899198332
parent 0
f90c822e73f8
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial