src/share/vm/runtime/frame.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6973
4af19b914f53
parent 6876
710a3c8b516e
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, 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@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #include "precompiled.hpp"
aoqi@0 32 #include "compiler/abstractCompiler.hpp"
aoqi@0 33 #include "compiler/disassembler.hpp"
aoqi@0 34 #include "gc_interface/collectedHeap.inline.hpp"
aoqi@0 35 #include "interpreter/interpreter.hpp"
aoqi@0 36 #include "interpreter/oopMapCache.hpp"
aoqi@0 37 #include "memory/resourceArea.hpp"
aoqi@0 38 #include "memory/universe.inline.hpp"
aoqi@0 39 #include "oops/markOop.hpp"
aoqi@0 40 #include "oops/methodData.hpp"
aoqi@0 41 #include "oops/method.hpp"
aoqi@0 42 #include "oops/oop.inline.hpp"
aoqi@0 43 #include "oops/oop.inline2.hpp"
aoqi@0 44 #include "prims/methodHandles.hpp"
aoqi@0 45 #include "runtime/frame.inline.hpp"
aoqi@0 46 #include "runtime/handles.inline.hpp"
aoqi@0 47 #include "runtime/javaCalls.hpp"
aoqi@0 48 #include "runtime/monitorChunk.hpp"
aoqi@0 49 #include "runtime/sharedRuntime.hpp"
aoqi@0 50 #include "runtime/signature.hpp"
aoqi@0 51 #include "runtime/stubCodeGenerator.hpp"
aoqi@0 52 #include "runtime/stubRoutines.hpp"
aoqi@0 53 #include "utilities/decoder.hpp"
aoqi@0 54
aoqi@0 55 #ifdef TARGET_ARCH_x86
aoqi@0 56 # include "nativeInst_x86.hpp"
aoqi@0 57 #endif
aoqi@0 58 #ifdef TARGET_ARCH_sparc
aoqi@0 59 # include "nativeInst_sparc.hpp"
aoqi@0 60 #endif
aoqi@0 61 #ifdef TARGET_ARCH_zero
aoqi@0 62 # include "nativeInst_zero.hpp"
aoqi@0 63 #endif
aoqi@0 64 #ifdef TARGET_ARCH_arm
aoqi@0 65 # include "nativeInst_arm.hpp"
aoqi@0 66 #endif
aoqi@0 67 #ifdef TARGET_ARCH_ppc
aoqi@0 68 # include "nativeInst_ppc.hpp"
aoqi@0 69 #endif
aoqi@1 70 #ifdef TARGET_ARCH_mips
aoqi@1 71 # include "nativeInst_mips.hpp"
aoqi@1 72 #endif
aoqi@1 73
aoqi@0 74
aoqi@0 75 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 76
aoqi@0 77 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
aoqi@0 78 _thread = thread;
aoqi@0 79 _update_map = update_map;
aoqi@0 80 clear();
aoqi@0 81 debug_only(_update_for_id = NULL;)
aoqi@0 82 #ifndef PRODUCT
aoqi@0 83 for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;
aoqi@0 84 #endif /* PRODUCT */
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 RegisterMap::RegisterMap(const RegisterMap* map) {
aoqi@0 88 assert(map != this, "bad initialization parameter");
aoqi@0 89 assert(map != NULL, "RegisterMap must be present");
aoqi@0 90 _thread = map->thread();
aoqi@0 91 _update_map = map->update_map();
aoqi@0 92 _include_argument_oops = map->include_argument_oops();
aoqi@0 93 debug_only(_update_for_id = map->_update_for_id;)
aoqi@0 94 pd_initialize_from(map);
aoqi@0 95 if (update_map()) {
aoqi@0 96 for(int i = 0; i < location_valid_size; i++) {
aoqi@0 97 LocationValidType bits = !update_map() ? 0 : map->_location_valid[i];
aoqi@0 98 _location_valid[i] = bits;
aoqi@0 99 // for whichever bits are set, pull in the corresponding map->_location
aoqi@0 100 int j = i*location_valid_type_size;
aoqi@0 101 while (bits != 0) {
aoqi@0 102 if ((bits & 1) != 0) {
aoqi@0 103 assert(0 <= j && j < reg_count, "range check");
aoqi@0 104 _location[j] = map->_location[j];
aoqi@0 105 }
aoqi@0 106 bits >>= 1;
aoqi@0 107 j += 1;
aoqi@0 108 }
aoqi@0 109 }
aoqi@0 110 }
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 void RegisterMap::clear() {
aoqi@0 114 set_include_argument_oops(true);
aoqi@0 115 if (_update_map) {
aoqi@0 116 for(int i = 0; i < location_valid_size; i++) {
aoqi@0 117 _location_valid[i] = 0;
aoqi@0 118 }
aoqi@0 119 pd_clear();
aoqi@0 120 } else {
aoqi@0 121 pd_initialize();
aoqi@0 122 }
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 #ifndef PRODUCT
aoqi@0 126
aoqi@0 127 void RegisterMap::print_on(outputStream* st) const {
aoqi@0 128 st->print_cr("Register map");
aoqi@0 129 for(int i = 0; i < reg_count; i++) {
aoqi@0 130
aoqi@0 131 VMReg r = VMRegImpl::as_VMReg(i);
aoqi@0 132 intptr_t* src = (intptr_t*) location(r);
aoqi@0 133 if (src != NULL) {
aoqi@0 134
aoqi@0 135 r->print_on(st);
aoqi@0 136 st->print(" [" INTPTR_FORMAT "] = ", src);
aoqi@0 137 if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {
aoqi@0 138 st->print_cr("<misaligned>");
aoqi@0 139 } else {
aoqi@0 140 st->print_cr(INTPTR_FORMAT, *src);
aoqi@0 141 }
aoqi@0 142 }
aoqi@0 143 }
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 void RegisterMap::print() const {
aoqi@0 147 print_on(tty);
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 #endif
aoqi@0 151 // This returns the pc that if you were in the debugger you'd see. Not
aoqi@0 152 // the idealized value in the frame object. This undoes the magic conversion
aoqi@0 153 // that happens for deoptimized frames. In addition it makes the value the
aoqi@0 154 // hardware would want to see in the native frame. The only user (at this point)
aoqi@0 155 // is deoptimization. It likely no one else should ever use it.
aoqi@0 156
aoqi@0 157 address frame::raw_pc() const {
aoqi@0 158 if (is_deoptimized_frame()) {
aoqi@0 159 nmethod* nm = cb()->as_nmethod_or_null();
aoqi@0 160 if (nm->is_method_handle_return(pc()))
aoqi@0 161 return nm->deopt_mh_handler_begin() - pc_return_offset;
aoqi@0 162 else
aoqi@0 163 return nm->deopt_handler_begin() - pc_return_offset;
aoqi@0 164 } else {
aoqi@0 165 return (pc() - pc_return_offset);
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 // Change the pc in a frame object. This does not change the actual pc in
aoqi@0 170 // actual frame. To do that use patch_pc.
aoqi@0 171 //
aoqi@0 172 void frame::set_pc(address newpc ) {
aoqi@0 173 #ifdef ASSERT
aoqi@0 174 if (_cb != NULL && _cb->is_nmethod()) {
aoqi@0 175 assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
aoqi@0 176 }
aoqi@0 177 #endif // ASSERT
aoqi@0 178
aoqi@0 179 // Unsafe to use the is_deoptimzed tester after changing pc
aoqi@0 180 _deopt_state = unknown;
aoqi@0 181 _pc = newpc;
aoqi@0 182 _cb = CodeCache::find_blob_unsafe(_pc);
aoqi@0 183
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 // type testers
aoqi@0 187 bool frame::is_ignored_frame() const {
aoqi@0 188 return false; // FIXME: some LambdaForm frames should be ignored
aoqi@0 189 }
aoqi@0 190 bool frame::is_deoptimized_frame() const {
aoqi@0 191 assert(_deopt_state != unknown, "not answerable");
aoqi@0 192 return _deopt_state == is_deoptimized;
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 bool frame::is_native_frame() const {
aoqi@0 196 return (_cb != NULL &&
aoqi@0 197 _cb->is_nmethod() &&
aoqi@0 198 ((nmethod*)_cb)->is_native_method());
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 bool frame::is_java_frame() const {
aoqi@0 202 if (is_interpreted_frame()) return true;
aoqi@0 203 if (is_compiled_frame()) return true;
aoqi@0 204 return false;
aoqi@0 205 }
aoqi@0 206
aoqi@0 207
aoqi@0 208 bool frame::is_compiled_frame() const {
aoqi@0 209 if (_cb != NULL &&
aoqi@0 210 _cb->is_nmethod() &&
aoqi@0 211 ((nmethod*)_cb)->is_java_method()) {
aoqi@0 212 return true;
aoqi@0 213 }
aoqi@0 214 return false;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217
aoqi@0 218 bool frame::is_runtime_frame() const {
aoqi@0 219 return (_cb != NULL && _cb->is_runtime_stub());
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 bool frame::is_safepoint_blob_frame() const {
aoqi@0 223 return (_cb != NULL && _cb->is_safepoint_stub());
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 // testers
aoqi@0 227
aoqi@0 228 bool frame::is_first_java_frame() const {
aoqi@0 229 RegisterMap map(JavaThread::current(), false); // No update
aoqi@0 230 frame s;
aoqi@0 231 for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));
aoqi@0 232 return s.is_first_frame();
aoqi@0 233 }
aoqi@0 234
aoqi@0 235
aoqi@0 236 bool frame::entry_frame_is_first() const {
aoqi@0 237 return entry_frame_call_wrapper()->is_first_frame();
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {
aoqi@0 241 JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();
aoqi@0 242 address addr = (address) jcw;
aoqi@0 243
aoqi@0 244 // addr must be within the usable part of the stack
aoqi@0 245 if (thread->is_in_usable_stack(addr)) {
aoqi@0 246 return *jcw;
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 return NULL;
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 bool frame::should_be_deoptimized() const {
aoqi@0 253 if (_deopt_state == is_deoptimized ||
aoqi@0 254 !is_compiled_frame() ) return false;
aoqi@0 255 assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod");
aoqi@0 256 nmethod* nm = (nmethod *)_cb;
aoqi@0 257 if (TraceDependencies) {
aoqi@0 258 tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
aoqi@0 259 nm->print_value_on(tty);
aoqi@0 260 tty->cr();
aoqi@0 261 }
aoqi@0 262
aoqi@0 263 if( !nm->is_marked_for_deoptimization() )
aoqi@0 264 return false;
aoqi@0 265
aoqi@0 266 // If at the return point, then the frame has already been popped, and
aoqi@0 267 // only the return needs to be executed. Don't deoptimize here.
aoqi@0 268 return !nm->is_at_poll_return(pc());
aoqi@0 269 }
aoqi@0 270
aoqi@0 271 bool frame::can_be_deoptimized() const {
aoqi@0 272 if (!is_compiled_frame()) return false;
aoqi@0 273 nmethod* nm = (nmethod*)_cb;
aoqi@0 274
aoqi@0 275 if( !nm->can_be_deoptimized() )
aoqi@0 276 return false;
aoqi@0 277
aoqi@0 278 return !nm->is_at_poll_return(pc());
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 void frame::deoptimize(JavaThread* thread) {
aoqi@0 282 // Schedule deoptimization of an nmethod activation with this frame.
aoqi@0 283 assert(_cb != NULL && _cb->is_nmethod(), "must be");
aoqi@0 284 nmethod* nm = (nmethod*)_cb;
aoqi@0 285
aoqi@0 286 // This is a fix for register window patching race
aoqi@0 287 if (NeedsDeoptSuspend && Thread::current() != thread) {
aoqi@0 288 assert(SafepointSynchronize::is_at_safepoint(),
aoqi@0 289 "patching other threads for deopt may only occur at a safepoint");
aoqi@0 290
aoqi@0 291 // It is possible especially with DeoptimizeALot/DeoptimizeRandom that
aoqi@0 292 // we could see the frame again and ask for it to be deoptimized since
aoqi@0 293 // it might move for a long time. That is harmless and we just ignore it.
aoqi@0 294 if (id() == thread->must_deopt_id()) {
aoqi@0 295 assert(thread->is_deopt_suspend(), "lost suspension");
aoqi@0 296 return;
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 // We are at a safepoint so the target thread can only be
aoqi@0 300 // in 4 states:
aoqi@0 301 // blocked - no problem
aoqi@0 302 // blocked_trans - no problem (i.e. could have woken up from blocked
aoqi@0 303 // during a safepoint).
aoqi@0 304 // native - register window pc patching race
aoqi@0 305 // native_trans - momentary state
aoqi@0 306 //
aoqi@0 307 // We could just wait out a thread in native_trans to block.
aoqi@0 308 // Then we'd have all the issues that the safepoint code has as to
aoqi@0 309 // whether to spin or block. It isn't worth it. Just treat it like
aoqi@0 310 // native and be done with it.
aoqi@0 311 //
aoqi@0 312 // Examine the state of the thread at the start of safepoint since
aoqi@0 313 // threads that were in native at the start of the safepoint could
aoqi@0 314 // come to a halt during the safepoint, changing the current value
aoqi@0 315 // of the safepoint_state.
aoqi@0 316 JavaThreadState state = thread->safepoint_state()->orig_thread_state();
aoqi@0 317 if (state == _thread_in_native || state == _thread_in_native_trans) {
aoqi@0 318 // Since we are at a safepoint the target thread will stop itself
aoqi@0 319 // before it can return to java as long as we remain at the safepoint.
aoqi@0 320 // Therefore we can put an additional request for the thread to stop
aoqi@0 321 // no matter what no (like a suspend). This will cause the thread
aoqi@0 322 // to notice it needs to do the deopt on its own once it leaves native.
aoqi@0 323 //
aoqi@0 324 // The only reason we must do this is because on machine with register
aoqi@0 325 // windows we have a race with patching the return address and the
aoqi@0 326 // window coming live as the thread returns to the Java code (but still
aoqi@0 327 // in native mode) and then blocks. It is only this top most frame
aoqi@0 328 // that is at risk. So in truth we could add an additional check to
aoqi@0 329 // see if this frame is one that is at risk.
aoqi@0 330 RegisterMap map(thread, false);
aoqi@0 331 frame at_risk = thread->last_frame().sender(&map);
aoqi@0 332 if (id() == at_risk.id()) {
aoqi@0 333 thread->set_must_deopt_id(id());
aoqi@0 334 thread->set_deopt_suspend();
aoqi@0 335 return;
aoqi@0 336 }
aoqi@0 337 }
aoqi@0 338 } // NeedsDeoptSuspend
aoqi@0 339
aoqi@0 340
aoqi@0 341 // If the call site is a MethodHandle call site use the MH deopt
aoqi@0 342 // handler.
aoqi@0 343 address deopt = nm->is_method_handle_return(pc()) ?
aoqi@0 344 nm->deopt_mh_handler_begin() :
aoqi@0 345 nm->deopt_handler_begin();
aoqi@0 346
aoqi@0 347 // Save the original pc before we patch in the new one
aoqi@0 348 nm->set_original_pc(this, pc());
aoqi@0 349 patch_pc(thread, deopt);
aoqi@0 350
aoqi@0 351 #ifdef ASSERT
aoqi@0 352 {
aoqi@0 353 RegisterMap map(thread, false);
aoqi@0 354 frame check = thread->last_frame();
aoqi@0 355 while (id() != check.id()) {
aoqi@0 356 check = check.sender(&map);
aoqi@0 357 }
aoqi@0 358 assert(check.is_deoptimized_frame(), "missed deopt");
aoqi@0 359 }
aoqi@0 360 #endif // ASSERT
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 frame frame::java_sender() const {
aoqi@0 364 RegisterMap map(JavaThread::current(), false);
aoqi@0 365 frame s;
aoqi@0 366 for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;
aoqi@0 367 guarantee(s.is_java_frame(), "tried to get caller of first java frame");
aoqi@0 368 return s;
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 frame frame::real_sender(RegisterMap* map) const {
aoqi@0 372 frame result = sender(map);
aoqi@0 373 while (result.is_runtime_frame() ||
aoqi@0 374 result.is_ignored_frame()) {
aoqi@0 375 result = result.sender(map);
aoqi@0 376 }
aoqi@0 377 return result;
aoqi@0 378 }
aoqi@0 379
aoqi@0 380 // Note: called by profiler - NOT for current thread
aoqi@0 381 frame frame::profile_find_Java_sender_frame(JavaThread *thread) {
aoqi@0 382 // If we don't recognize this frame, walk back up the stack until we do
aoqi@0 383 RegisterMap map(thread, false);
aoqi@0 384 frame first_java_frame = frame();
aoqi@0 385
aoqi@0 386 // Find the first Java frame on the stack starting with input frame
aoqi@0 387 if (is_java_frame()) {
aoqi@0 388 // top frame is compiled frame or deoptimized frame
aoqi@0 389 first_java_frame = *this;
aoqi@0 390 } else if (safe_for_sender(thread)) {
aoqi@0 391 for (frame sender_frame = sender(&map);
aoqi@0 392 sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame();
aoqi@0 393 sender_frame = sender_frame.sender(&map)) {
aoqi@0 394 if (sender_frame.is_java_frame()) {
aoqi@0 395 first_java_frame = sender_frame;
aoqi@0 396 break;
aoqi@0 397 }
aoqi@0 398 }
aoqi@0 399 }
aoqi@0 400 return first_java_frame;
aoqi@0 401 }
aoqi@0 402
aoqi@0 403 // Interpreter frames
aoqi@0 404
aoqi@0 405
aoqi@0 406 void frame::interpreter_frame_set_locals(intptr_t* locs) {
aoqi@0 407 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 408 *interpreter_frame_locals_addr() = locs;
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 Method* frame::interpreter_frame_method() const {
aoqi@0 412 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 413 Method* m = *interpreter_frame_method_addr();
aoqi@0 414 assert(m->is_method(), "not a Method*");
aoqi@0 415 return m;
aoqi@0 416 }
aoqi@0 417
aoqi@0 418 void frame::interpreter_frame_set_method(Method* method) {
aoqi@0 419 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 420 *interpreter_frame_method_addr() = method;
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 void frame::interpreter_frame_set_bcx(intptr_t bcx) {
aoqi@0 424 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 425 if (ProfileInterpreter) {
aoqi@0 426 bool formerly_bci = is_bci(interpreter_frame_bcx());
aoqi@0 427 bool is_now_bci = is_bci(bcx);
aoqi@0 428 *interpreter_frame_bcx_addr() = bcx;
aoqi@0 429
aoqi@0 430 intptr_t mdx = interpreter_frame_mdx();
aoqi@0 431
aoqi@0 432 if (mdx != 0) {
aoqi@0 433 if (formerly_bci) {
aoqi@0 434 if (!is_now_bci) {
aoqi@0 435 // The bcx was just converted from bci to bcp.
aoqi@0 436 // Convert the mdx in parallel.
aoqi@0 437 MethodData* mdo = interpreter_frame_method()->method_data();
aoqi@0 438 assert(mdo != NULL, "");
aoqi@0 439 int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
aoqi@0 440 address mdp = mdo->di_to_dp(mdi);
aoqi@0 441 interpreter_frame_set_mdx((intptr_t)mdp);
aoqi@0 442 }
aoqi@0 443 } else {
aoqi@0 444 if (is_now_bci) {
aoqi@0 445 // The bcx was just converted from bcp to bci.
aoqi@0 446 // Convert the mdx in parallel.
aoqi@0 447 MethodData* mdo = interpreter_frame_method()->method_data();
aoqi@0 448 assert(mdo != NULL, "");
aoqi@0 449 int mdi = mdo->dp_to_di((address)mdx);
aoqi@0 450 interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
aoqi@0 451 }
aoqi@0 452 }
aoqi@0 453 }
aoqi@0 454 } else {
aoqi@0 455 *interpreter_frame_bcx_addr() = bcx;
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 jint frame::interpreter_frame_bci() const {
aoqi@0 460 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 461 intptr_t bcx = interpreter_frame_bcx();
aoqi@0 462 return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx);
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 void frame::interpreter_frame_set_bci(jint bci) {
aoqi@0 466 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 467 assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC");
aoqi@0 468 interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci));
aoqi@0 469 }
aoqi@0 470
aoqi@0 471 address frame::interpreter_frame_bcp() const {
aoqi@0 472 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 473 intptr_t bcx = interpreter_frame_bcx();
aoqi@0 474 return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx;
aoqi@0 475 }
aoqi@0 476
aoqi@0 477 void frame::interpreter_frame_set_bcp(address bcp) {
aoqi@0 478 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 479 assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC");
aoqi@0 480 interpreter_frame_set_bcx((intptr_t)bcp);
aoqi@0 481 }
aoqi@0 482
aoqi@0 483 void frame::interpreter_frame_set_mdx(intptr_t mdx) {
aoqi@0 484 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 485 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 486 *interpreter_frame_mdx_addr() = mdx;
aoqi@0 487 }
aoqi@0 488
aoqi@0 489 address frame::interpreter_frame_mdp() const {
aoqi@0 490 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 491 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 492 intptr_t bcx = interpreter_frame_bcx();
aoqi@0 493 intptr_t mdx = interpreter_frame_mdx();
aoqi@0 494
aoqi@0 495 assert(!is_bci(bcx), "should not access mdp during GC");
aoqi@0 496 return (address)mdx;
aoqi@0 497 }
aoqi@0 498
aoqi@0 499 void frame::interpreter_frame_set_mdp(address mdp) {
aoqi@0 500 assert(is_interpreted_frame(), "interpreted frame expected");
aoqi@0 501 if (mdp == NULL) {
aoqi@0 502 // Always allow the mdp to be cleared.
aoqi@0 503 interpreter_frame_set_mdx((intptr_t)mdp);
aoqi@0 504 }
aoqi@0 505 intptr_t bcx = interpreter_frame_bcx();
aoqi@0 506 assert(!is_bci(bcx), "should not set mdp during GC");
aoqi@0 507 interpreter_frame_set_mdx((intptr_t)mdp);
aoqi@0 508 }
aoqi@0 509
aoqi@0 510 BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {
aoqi@0 511 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 512 #ifdef ASSERT
aoqi@0 513 interpreter_frame_verify_monitor(current);
aoqi@0 514 #endif
aoqi@0 515 BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());
aoqi@0 516 return next;
aoqi@0 517 }
aoqi@0 518
aoqi@0 519 BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {
aoqi@0 520 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 521 #ifdef ASSERT
aoqi@0 522 // // This verification needs to be checked before being enabled
aoqi@0 523 // interpreter_frame_verify_monitor(current);
aoqi@0 524 #endif
aoqi@0 525 BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());
aoqi@0 526 return previous;
aoqi@0 527 }
aoqi@0 528
aoqi@0 529 // Interpreter locals and expression stack locations.
aoqi@0 530
aoqi@0 531 intptr_t* frame::interpreter_frame_local_at(int index) const {
aoqi@0 532 const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
aoqi@0 533 return &((*interpreter_frame_locals_addr())[n]);
aoqi@0 534 }
aoqi@0 535
aoqi@0 536 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
aoqi@0 537 const int i = offset * interpreter_frame_expression_stack_direction();
aoqi@0 538 const int n = i * Interpreter::stackElementWords;
aoqi@0 539 return &(interpreter_frame_expression_stack()[n]);
aoqi@0 540 }
aoqi@0 541
aoqi@0 542 jint frame::interpreter_frame_expression_stack_size() const {
aoqi@0 543 // Number of elements on the interpreter expression stack
aoqi@0 544 // Callers should span by stackElementWords
aoqi@0 545 int element_size = Interpreter::stackElementWords;
aoqi@0 546 size_t stack_size = 0;
aoqi@0 547 if (frame::interpreter_frame_expression_stack_direction() < 0) {
aoqi@0 548 stack_size = (interpreter_frame_expression_stack() -
aoqi@0 549 interpreter_frame_tos_address() + 1)/element_size;
aoqi@0 550 } else {
aoqi@0 551 stack_size = (interpreter_frame_tos_address() -
aoqi@0 552 interpreter_frame_expression_stack() + 1)/element_size;
aoqi@0 553 }
aoqi@0 554 assert( stack_size <= (size_t)max_jint, "stack size too big");
aoqi@0 555 return ((jint)stack_size);
aoqi@0 556 }
aoqi@0 557
aoqi@0 558
aoqi@0 559 // (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)
aoqi@0 560
aoqi@0 561 const char* frame::print_name() const {
aoqi@0 562 if (is_native_frame()) return "Native";
aoqi@0 563 if (is_interpreted_frame()) return "Interpreted";
aoqi@0 564 if (is_compiled_frame()) {
aoqi@0 565 if (is_deoptimized_frame()) return "Deoptimized";
aoqi@0 566 return "Compiled";
aoqi@0 567 }
aoqi@0 568 if (sp() == NULL) return "Empty";
aoqi@0 569 return "C";
aoqi@0 570 }
aoqi@0 571
aoqi@0 572 void frame::print_value_on(outputStream* st, JavaThread *thread) const {
aoqi@0 573 NOT_PRODUCT(address begin = pc()-40;)
aoqi@0 574 NOT_PRODUCT(address end = NULL;)
aoqi@0 575
aoqi@0 576 st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp());
aoqi@0 577 if (sp() != NULL)
aoqi@0 578 st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), real_fp(), pc());
aoqi@0 579
aoqi@0 580 if (StubRoutines::contains(pc())) {
aoqi@0 581 st->print_cr(")");
aoqi@0 582 st->print("(");
aoqi@0 583 StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
aoqi@0 584 st->print("~Stub::%s", desc->name());
aoqi@0 585 NOT_PRODUCT(begin = desc->begin(); end = desc->end();)
aoqi@0 586 } else if (Interpreter::contains(pc())) {
aoqi@0 587 st->print_cr(")");
aoqi@0 588 st->print("(");
aoqi@0 589 InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
aoqi@0 590 if (desc != NULL) {
aoqi@0 591 st->print("~");
aoqi@0 592 desc->print_on(st);
aoqi@0 593 NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)
aoqi@0 594 } else {
aoqi@0 595 st->print("~interpreter");
aoqi@0 596 }
aoqi@0 597 }
aoqi@0 598 st->print_cr(")");
aoqi@0 599
aoqi@0 600 if (_cb != NULL) {
aoqi@0 601 st->print(" ");
aoqi@0 602 _cb->print_value_on(st);
aoqi@0 603 st->cr();
aoqi@0 604 #ifndef PRODUCT
aoqi@0 605 if (end == NULL) {
aoqi@0 606 begin = _cb->code_begin();
aoqi@0 607 end = _cb->code_end();
aoqi@0 608 }
aoqi@0 609 #endif
aoqi@0 610 }
aoqi@0 611 NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);)
aoqi@0 612 }
aoqi@0 613
aoqi@0 614
aoqi@0 615 void frame::print_on(outputStream* st) const {
aoqi@0 616 print_value_on(st,NULL);
aoqi@0 617 if (is_interpreted_frame()) {
aoqi@0 618 interpreter_frame_print_on(st);
aoqi@0 619 }
aoqi@0 620 }
aoqi@0 621
aoqi@0 622
aoqi@0 623 void frame::interpreter_frame_print_on(outputStream* st) const {
aoqi@0 624 #ifndef PRODUCT
aoqi@0 625 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 626 jint i;
aoqi@0 627 for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
aoqi@0 628 intptr_t x = *interpreter_frame_local_at(i);
aoqi@0 629 st->print(" - local [" INTPTR_FORMAT "]", x);
aoqi@0 630 st->fill_to(23);
aoqi@0 631 st->print_cr("; #%d", i);
aoqi@0 632 }
aoqi@0 633 for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
aoqi@0 634 intptr_t x = *interpreter_frame_expression_stack_at(i);
aoqi@0 635 st->print(" - stack [" INTPTR_FORMAT "]", x);
aoqi@0 636 st->fill_to(23);
aoqi@0 637 st->print_cr("; #%d", i);
aoqi@0 638 }
aoqi@0 639 // locks for synchronization
aoqi@0 640 for (BasicObjectLock* current = interpreter_frame_monitor_end();
aoqi@0 641 current < interpreter_frame_monitor_begin();
aoqi@0 642 current = next_monitor_in_interpreter_frame(current)) {
aoqi@0 643 st->print(" - obj [");
aoqi@0 644 current->obj()->print_value_on(st);
aoqi@0 645 st->print_cr("]");
aoqi@0 646 st->print(" - lock [");
aoqi@0 647 current->lock()->print_on(st);
aoqi@0 648 st->print_cr("]");
aoqi@0 649 }
aoqi@0 650 // monitor
aoqi@0 651 st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin());
aoqi@0 652 // bcp
aoqi@0 653 st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp());
aoqi@0 654 st->fill_to(23);
aoqi@0 655 st->print_cr("; @%d", interpreter_frame_bci());
aoqi@0 656 // locals
aoqi@0 657 st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0));
aoqi@0 658 // method
aoqi@0 659 st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method());
aoqi@0 660 st->fill_to(23);
aoqi@0 661 st->print("; ");
aoqi@0 662 interpreter_frame_method()->print_name(st);
aoqi@0 663 st->cr();
aoqi@0 664 #endif
aoqi@0 665 }
aoqi@0 666
aoqi@0 667 // Return whether the frame is in the VM or os indicating a Hotspot problem.
aoqi@0 668 // Otherwise, it's likely a bug in the native library that the Java code calls,
aoqi@0 669 // hopefully indicating where to submit bugs.
aoqi@0 670 void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
aoqi@0 671 // C/C++ frame
aoqi@0 672 bool in_vm = os::address_is_in_vm(pc);
aoqi@0 673 st->print(in_vm ? "V" : "C");
aoqi@0 674
aoqi@0 675 int offset;
aoqi@0 676 bool found;
aoqi@0 677
aoqi@0 678 // libname
aoqi@0 679 found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
aoqi@0 680 if (found) {
aoqi@0 681 // skip directory names
aoqi@0 682 const char *p1, *p2;
aoqi@0 683 p1 = buf;
aoqi@0 684 int len = (int)strlen(os::file_separator());
aoqi@0 685 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
aoqi@0 686 st->print(" [%s+0x%x]", p1, offset);
aoqi@0 687 } else {
aoqi@0 688 st->print(" " PTR_FORMAT, pc);
aoqi@0 689 }
aoqi@0 690
aoqi@0 691 // function name - os::dll_address_to_function_name() may return confusing
aoqi@0 692 // names if pc is within jvm.dll or libjvm.so, because JVM only has
aoqi@0 693 // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this
aoqi@0 694 // only for native libraries.
aoqi@0 695 if (!in_vm || Decoder::can_decode_C_frame_in_vm()) {
aoqi@0 696 found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
aoqi@0 697
aoqi@0 698 if (found) {
aoqi@0 699 st->print(" %s+0x%x", buf, offset);
aoqi@0 700 }
aoqi@0 701 }
aoqi@0 702 }
aoqi@0 703
aoqi@0 704 // frame::print_on_error() is called by fatal error handler. Notice that we may
aoqi@0 705 // crash inside this function if stack frame is corrupted. The fatal error
aoqi@0 706 // handler can catch and handle the crash. Here we assume the frame is valid.
aoqi@0 707 //
aoqi@0 708 // First letter indicates type of the frame:
aoqi@0 709 // J: Java frame (compiled)
aoqi@0 710 // j: Java frame (interpreted)
aoqi@0 711 // V: VM frame (C/C++)
aoqi@0 712 // v: Other frames running VM generated code (e.g. stubs, adapters, etc.)
aoqi@0 713 // C: C/C++ frame
aoqi@0 714 //
aoqi@0 715 // We don't need detailed frame type as that in frame::print_name(). "C"
aoqi@0 716 // suggests the problem is in user lib; everything else is likely a VM bug.
aoqi@0 717
aoqi@0 718 void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {
aoqi@0 719 if (_cb != NULL) {
aoqi@0 720 if (Interpreter::contains(pc())) {
aoqi@0 721 Method* m = this->interpreter_frame_method();
aoqi@0 722 if (m != NULL) {
aoqi@0 723 m->name_and_sig_as_C_string(buf, buflen);
aoqi@0 724 st->print("j %s", buf);
aoqi@0 725 st->print("+%d", this->interpreter_frame_bci());
aoqi@0 726 } else {
aoqi@0 727 st->print("j " PTR_FORMAT, pc());
aoqi@0 728 }
aoqi@0 729 } else if (StubRoutines::contains(pc())) {
aoqi@0 730 StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
aoqi@0 731 if (desc != NULL) {
aoqi@0 732 st->print("v ~StubRoutines::%s", desc->name());
aoqi@0 733 } else {
aoqi@0 734 st->print("v ~StubRoutines::" PTR_FORMAT, pc());
aoqi@0 735 }
aoqi@0 736 } else if (_cb->is_buffer_blob()) {
aoqi@0 737 st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name());
aoqi@0 738 } else if (_cb->is_nmethod()) {
aoqi@0 739 nmethod* nm = (nmethod*)_cb;
aoqi@0 740 Method* m = nm->method();
aoqi@0 741 if (m != NULL) {
aoqi@0 742 m->name_and_sig_as_C_string(buf, buflen);
aoqi@0 743 st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
aoqi@0 744 nm->compile_id(), (nm->is_osr_method() ? "%" : ""),
aoqi@0 745 ((nm->compiler() != NULL) ? nm->compiler()->name() : ""),
aoqi@0 746 buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
aoqi@0 747 } else {
aoqi@0 748 st->print("J " PTR_FORMAT, pc());
aoqi@0 749 }
aoqi@0 750 } else if (_cb->is_runtime_stub()) {
aoqi@0 751 st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name());
aoqi@0 752 } else if (_cb->is_deoptimization_stub()) {
aoqi@0 753 st->print("v ~DeoptimizationBlob");
aoqi@0 754 } else if (_cb->is_exception_stub()) {
aoqi@0 755 st->print("v ~ExceptionBlob");
aoqi@0 756 } else if (_cb->is_safepoint_stub()) {
aoqi@0 757 st->print("v ~SafepointBlob");
aoqi@0 758 } else {
aoqi@0 759 st->print("v blob " PTR_FORMAT, pc());
aoqi@0 760 }
aoqi@0 761 } else {
aoqi@0 762 print_C_frame(st, buf, buflen, pc());
aoqi@0 763 }
aoqi@0 764 }
aoqi@0 765
aoqi@0 766
aoqi@0 767 /*
aoqi@0 768 The interpreter_frame_expression_stack_at method in the case of SPARC needs the
aoqi@0 769 max_stack value of the method in order to compute the expression stack address.
aoqi@0 770 It uses the Method* in order to get the max_stack value but during GC this
aoqi@0 771 Method* value saved on the frame is changed by reverse_and_push and hence cannot
aoqi@0 772 be used. So we save the max_stack value in the FrameClosure object and pass it
aoqi@0 773 down to the interpreter_frame_expression_stack_at method
aoqi@0 774 */
aoqi@0 775 class InterpreterFrameClosure : public OffsetClosure {
aoqi@0 776 private:
aoqi@0 777 frame* _fr;
aoqi@0 778 OopClosure* _f;
aoqi@0 779 int _max_locals;
aoqi@0 780 int _max_stack;
aoqi@0 781
aoqi@0 782 public:
aoqi@0 783 InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
aoqi@0 784 OopClosure* f) {
aoqi@0 785 _fr = fr;
aoqi@0 786 _max_locals = max_locals;
aoqi@0 787 _max_stack = max_stack;
aoqi@0 788 _f = f;
aoqi@0 789 }
aoqi@0 790
aoqi@0 791 void offset_do(int offset) {
aoqi@0 792 oop* addr;
aoqi@0 793 if (offset < _max_locals) {
aoqi@0 794 addr = (oop*) _fr->interpreter_frame_local_at(offset);
aoqi@0 795 assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
aoqi@0 796 _f->do_oop(addr);
aoqi@0 797 } else {
aoqi@0 798 addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
aoqi@0 799 // In case of exceptions, the expression stack is invalid and the esp will be reset to express
aoqi@0 800 // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
aoqi@0 801 bool in_stack;
aoqi@0 802 if (frame::interpreter_frame_expression_stack_direction() > 0) {
aoqi@0 803 in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
aoqi@0 804 } else {
aoqi@0 805 in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
aoqi@0 806 }
aoqi@0 807 if (in_stack) {
aoqi@0 808 _f->do_oop(addr);
aoqi@0 809 }
aoqi@0 810 }
aoqi@0 811 }
aoqi@0 812
aoqi@0 813 int max_locals() { return _max_locals; }
aoqi@0 814 frame* fr() { return _fr; }
aoqi@0 815 };
aoqi@0 816
aoqi@0 817
aoqi@0 818 class InterpretedArgumentOopFinder: public SignatureInfo {
aoqi@0 819 private:
aoqi@0 820 OopClosure* _f; // Closure to invoke
aoqi@0 821 int _offset; // TOS-relative offset, decremented with each argument
aoqi@0 822 bool _has_receiver; // true if the callee has a receiver
aoqi@0 823 frame* _fr;
aoqi@0 824
aoqi@0 825 void set(int size, BasicType type) {
aoqi@0 826 _offset -= size;
aoqi@0 827 if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 void oop_offset_do() {
aoqi@0 831 oop* addr;
aoqi@0 832 addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
aoqi@0 833 _f->do_oop(addr);
aoqi@0 834 }
aoqi@0 835
aoqi@0 836 public:
aoqi@0 837 InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
aoqi@0 838 // compute size of arguments
aoqi@0 839 int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
aoqi@0 840 assert(!fr->is_interpreted_frame() ||
aoqi@0 841 args_size <= fr->interpreter_frame_expression_stack_size(),
aoqi@0 842 "args cannot be on stack anymore");
aoqi@0 843 // initialize InterpretedArgumentOopFinder
aoqi@0 844 _f = f;
aoqi@0 845 _fr = fr;
aoqi@0 846 _offset = args_size;
aoqi@0 847 }
aoqi@0 848
aoqi@0 849 void oops_do() {
aoqi@0 850 if (_has_receiver) {
aoqi@0 851 --_offset;
aoqi@0 852 oop_offset_do();
aoqi@0 853 }
aoqi@0 854 iterate_parameters();
aoqi@0 855 }
aoqi@0 856 };
aoqi@0 857
aoqi@0 858
aoqi@0 859 // Entry frame has following form (n arguments)
aoqi@0 860 // +-----------+
aoqi@0 861 // sp -> | last arg |
aoqi@0 862 // +-----------+
aoqi@0 863 // : ::: :
aoqi@0 864 // +-----------+
aoqi@0 865 // (sp+n)->| first arg|
aoqi@0 866 // +-----------+
aoqi@0 867
aoqi@0 868
aoqi@0 869
aoqi@0 870 // visits and GC's all the arguments in entry frame
aoqi@0 871 class EntryFrameOopFinder: public SignatureInfo {
aoqi@0 872 private:
aoqi@0 873 bool _is_static;
aoqi@0 874 int _offset;
aoqi@0 875 frame* _fr;
aoqi@0 876 OopClosure* _f;
aoqi@0 877
aoqi@0 878 void set(int size, BasicType type) {
aoqi@0 879 assert (_offset >= 0, "illegal offset");
aoqi@0 880 if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);
aoqi@0 881 _offset -= size;
aoqi@0 882 }
aoqi@0 883
aoqi@0 884 void oop_at_offset_do(int offset) {
aoqi@0 885 assert (offset >= 0, "illegal offset");
aoqi@0 886 oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
aoqi@0 887 _f->do_oop(addr);
aoqi@0 888 }
aoqi@0 889
aoqi@0 890 public:
aoqi@0 891 EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
aoqi@0 892 _f = NULL; // will be set later
aoqi@0 893 _fr = frame;
aoqi@0 894 _is_static = is_static;
aoqi@0 895 _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
aoqi@0 896 }
aoqi@0 897
aoqi@0 898 void arguments_do(OopClosure* f) {
aoqi@0 899 _f = f;
aoqi@0 900 if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver
aoqi@0 901 iterate_parameters();
aoqi@0 902 }
aoqi@0 903
aoqi@0 904 };
aoqi@0 905
aoqi@0 906 oop* frame::interpreter_callee_receiver_addr(Symbol* signature) {
aoqi@0 907 ArgumentSizeComputer asc(signature);
aoqi@0 908 int size = asc.size();
aoqi@0 909 return (oop *)interpreter_frame_tos_at(size);
aoqi@0 910 }
aoqi@0 911
aoqi@0 912
stefank@6973 913 void frame::oops_interpreted_do(OopClosure* f, CLDClosure* cld_f,
aoqi@0 914 const RegisterMap* map, bool query_oop_map_cache) {
aoqi@0 915 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 916 assert(map != NULL, "map must be set");
aoqi@0 917 Thread *thread = Thread::current();
aoqi@0 918 methodHandle m (thread, interpreter_frame_method());
aoqi@0 919 jint bci = interpreter_frame_bci();
aoqi@0 920
aoqi@0 921 assert(!Universe::heap()->is_in(m()),
aoqi@0 922 "must be valid oop");
aoqi@0 923 assert(m->is_method(), "checking frame value");
aoqi@0 924 assert((m->is_native() && bci == 0) ||
aoqi@0 925 (!m->is_native() && bci >= 0 && bci < m->code_size()),
aoqi@0 926 "invalid bci value");
aoqi@0 927
aoqi@0 928 // Handle the monitor elements in the activation
aoqi@0 929 for (
aoqi@0 930 BasicObjectLock* current = interpreter_frame_monitor_end();
aoqi@0 931 current < interpreter_frame_monitor_begin();
aoqi@0 932 current = next_monitor_in_interpreter_frame(current)
aoqi@0 933 ) {
aoqi@0 934 #ifdef ASSERT
aoqi@0 935 interpreter_frame_verify_monitor(current);
aoqi@0 936 #endif
aoqi@0 937 current->oops_do(f);
aoqi@0 938 }
aoqi@0 939
aoqi@0 940 // process fixed part
aoqi@0 941 if (cld_f != NULL) {
aoqi@0 942 // The method pointer in the frame might be the only path to the method's
aoqi@0 943 // klass, and the klass needs to be kept alive while executing. The GCs
aoqi@0 944 // don't trace through method pointers, so typically in similar situations
aoqi@0 945 // the mirror or the class loader of the klass are installed as a GC root.
aoqi@0 946 // To minimze the overhead of doing that here, we ask the GC to pass down a
aoqi@0 947 // closure that knows how to keep klasses alive given a ClassLoaderData.
aoqi@0 948 cld_f->do_cld(m->method_holder()->class_loader_data());
aoqi@0 949 }
aoqi@0 950
aoqi@0 951 if (m->is_native() PPC32_ONLY(&& m->is_static())) {
aoqi@0 952 f->do_oop(interpreter_frame_temp_oop_addr());
aoqi@0 953 }
aoqi@0 954
aoqi@0 955 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
aoqi@0 956
aoqi@0 957 Symbol* signature = NULL;
aoqi@0 958 bool has_receiver = false;
aoqi@0 959
aoqi@0 960 // Process a callee's arguments if we are at a call site
aoqi@0 961 // (i.e., if we are at an invoke bytecode)
aoqi@0 962 // This is used sometimes for calling into the VM, not for another
aoqi@0 963 // interpreted or compiled frame.
aoqi@0 964 if (!m->is_native()) {
aoqi@0 965 Bytecode_invoke call = Bytecode_invoke_check(m, bci);
aoqi@0 966 if (call.is_valid()) {
aoqi@0 967 signature = call.signature();
aoqi@0 968 has_receiver = call.has_receiver();
aoqi@0 969 if (map->include_argument_oops() &&
aoqi@0 970 interpreter_frame_expression_stack_size() > 0) {
aoqi@0 971 ResourceMark rm(thread); // is this right ???
aoqi@0 972 // we are at a call site & the expression stack is not empty
aoqi@0 973 // => process callee's arguments
aoqi@0 974 //
aoqi@0 975 // Note: The expression stack can be empty if an exception
aoqi@0 976 // occurred during method resolution/execution. In all
aoqi@0 977 // cases we empty the expression stack completely be-
aoqi@0 978 // fore handling the exception (the exception handling
aoqi@0 979 // code in the interpreter calls a blocking runtime
aoqi@0 980 // routine which can cause this code to be executed).
aoqi@0 981 // (was bug gri 7/27/98)
aoqi@0 982 oops_interpreted_arguments_do(signature, has_receiver, f);
aoqi@0 983 }
aoqi@0 984 }
aoqi@0 985 }
aoqi@0 986
aoqi@0 987 InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
aoqi@0 988
aoqi@0 989 // process locals & expression stack
aoqi@0 990 InterpreterOopMap mask;
aoqi@0 991 if (query_oop_map_cache) {
aoqi@0 992 m->mask_for(bci, &mask);
aoqi@0 993 } else {
aoqi@0 994 OopMapCache::compute_one_oop_map(m, bci, &mask);
aoqi@0 995 }
aoqi@0 996 mask.iterate_oop(&blk);
aoqi@0 997 }
aoqi@0 998
aoqi@0 999
aoqi@0 1000 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
aoqi@0 1001 InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
aoqi@0 1002 finder.oops_do();
aoqi@0 1003 }
aoqi@0 1004
aoqi@0 1005 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
aoqi@0 1006 assert(_cb != NULL, "sanity check");
aoqi@0 1007 if (_cb->oop_maps() != NULL) {
aoqi@0 1008 OopMapSet::oops_do(this, reg_map, f);
aoqi@0 1009
aoqi@0 1010 // Preserve potential arguments for a callee. We handle this by dispatching
aoqi@0 1011 // on the codeblob. For c2i, we do
aoqi@0 1012 if (reg_map->include_argument_oops()) {
aoqi@0 1013 _cb->preserve_callee_argument_oops(*this, reg_map, f);
aoqi@0 1014 }
aoqi@0 1015 }
aoqi@0 1016 // In cases where perm gen is collected, GC will want to mark
aoqi@0 1017 // oops referenced from nmethods active on thread stacks so as to
aoqi@0 1018 // prevent them from being collected. However, this visit should be
aoqi@0 1019 // restricted to certain phases of the collection only. The
aoqi@0 1020 // closure decides how it wants nmethods to be traced.
aoqi@0 1021 if (cf != NULL)
aoqi@0 1022 cf->do_code_blob(_cb);
aoqi@0 1023 }
aoqi@0 1024
aoqi@0 1025 class CompiledArgumentOopFinder: public SignatureInfo {
aoqi@0 1026 protected:
aoqi@0 1027 OopClosure* _f;
aoqi@0 1028 int _offset; // the current offset, incremented with each argument
aoqi@0 1029 bool _has_receiver; // true if the callee has a receiver
aoqi@0 1030 bool _has_appendix; // true if the call has an appendix
aoqi@0 1031 frame _fr;
aoqi@0 1032 RegisterMap* _reg_map;
aoqi@0 1033 int _arg_size;
aoqi@0 1034 VMRegPair* _regs; // VMReg list of arguments
aoqi@0 1035
aoqi@0 1036 void set(int size, BasicType type) {
aoqi@0 1037 if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();
aoqi@0 1038 _offset += size;
aoqi@0 1039 }
aoqi@0 1040
aoqi@0 1041 virtual void handle_oop_offset() {
aoqi@0 1042 // Extract low order register number from register array.
aoqi@0 1043 // In LP64-land, the high-order bits are valid but unhelpful.
aoqi@0 1044 VMReg reg = _regs[_offset].first();
aoqi@0 1045 oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
aoqi@0 1046 _f->do_oop(loc);
aoqi@0 1047 }
aoqi@0 1048
aoqi@0 1049 public:
aoqi@0 1050 CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)
aoqi@0 1051 : SignatureInfo(signature) {
aoqi@0 1052
aoqi@0 1053 // initialize CompiledArgumentOopFinder
aoqi@0 1054 _f = f;
aoqi@0 1055 _offset = 0;
aoqi@0 1056 _has_receiver = has_receiver;
aoqi@0 1057 _has_appendix = has_appendix;
aoqi@0 1058 _fr = fr;
aoqi@0 1059 _reg_map = (RegisterMap*)reg_map;
aoqi@0 1060 _arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);
aoqi@0 1061
aoqi@0 1062 int arg_size;
aoqi@0 1063 _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);
aoqi@0 1064 assert(arg_size == _arg_size, "wrong arg size");
aoqi@0 1065 }
aoqi@0 1066
aoqi@0 1067 void oops_do() {
aoqi@0 1068 if (_has_receiver) {
aoqi@0 1069 handle_oop_offset();
aoqi@0 1070 _offset++;
aoqi@0 1071 }
aoqi@0 1072 iterate_parameters();
aoqi@0 1073 if (_has_appendix) {
aoqi@0 1074 handle_oop_offset();
aoqi@0 1075 _offset++;
aoqi@0 1076 }
aoqi@0 1077 }
aoqi@0 1078 };
aoqi@0 1079
aoqi@0 1080 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f) {
aoqi@0 1081 ResourceMark rm;
aoqi@0 1082 CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
aoqi@0 1083 finder.oops_do();
aoqi@0 1084 }
aoqi@0 1085
aoqi@0 1086
aoqi@0 1087 // Get receiver out of callers frame, i.e. find parameter 0 in callers
aoqi@0 1088 // frame. Consult ADLC for where parameter 0 is to be found. Then
aoqi@0 1089 // check local reg_map for it being a callee-save register or argument
aoqi@0 1090 // register, both of which are saved in the local frame. If not found
aoqi@0 1091 // there, it must be an in-stack argument of the caller.
aoqi@0 1092 // Note: caller.sp() points to callee-arguments
aoqi@0 1093 oop frame::retrieve_receiver(RegisterMap* reg_map) {
aoqi@0 1094 frame caller = *this;
aoqi@0 1095
aoqi@0 1096 // First consult the ADLC on where it puts parameter 0 for this signature.
aoqi@0 1097 VMReg reg = SharedRuntime::name_for_receiver();
aoqi@0 1098 oop* oop_adr = caller.oopmapreg_to_location(reg, reg_map);
aoqi@0 1099 if (oop_adr == NULL) {
aoqi@0 1100 guarantee(oop_adr != NULL, "bad register save location");
aoqi@0 1101 return NULL;
aoqi@0 1102 }
aoqi@0 1103 oop r = *oop_adr;
aoqi@0 1104 assert(Universe::heap()->is_in_or_null(r), err_msg("bad receiver: " INTPTR_FORMAT " (" INTX_FORMAT ")", (void *) r, (void *) r));
aoqi@0 1105 return r;
aoqi@0 1106 }
aoqi@0 1107
aoqi@0 1108
aoqi@0 1109 oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const {
aoqi@0 1110 if(reg->is_reg()) {
aoqi@0 1111 // If it is passed in a register, it got spilled in the stub frame.
aoqi@0 1112 return (oop *)reg_map->location(reg);
aoqi@0 1113 } else {
aoqi@0 1114 int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size;
aoqi@0 1115 return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes);
aoqi@0 1116 }
aoqi@0 1117 }
aoqi@0 1118
aoqi@0 1119 BasicLock* frame::get_native_monitor() {
aoqi@0 1120 nmethod* nm = (nmethod*)_cb;
aoqi@0 1121 assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
aoqi@0 1122 "Should not call this unless it's a native nmethod");
aoqi@0 1123 int byte_offset = in_bytes(nm->native_basic_lock_sp_offset());
aoqi@0 1124 assert(byte_offset >= 0, "should not see invalid offset");
aoqi@0 1125 return (BasicLock*) &sp()[byte_offset / wordSize];
aoqi@0 1126 }
aoqi@0 1127
aoqi@0 1128 oop frame::get_native_receiver() {
aoqi@0 1129 nmethod* nm = (nmethod*)_cb;
aoqi@0 1130 assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
aoqi@0 1131 "Should not call this unless it's a native nmethod");
aoqi@0 1132 int byte_offset = in_bytes(nm->native_receiver_sp_offset());
aoqi@0 1133 assert(byte_offset >= 0, "should not see invalid offset");
aoqi@0 1134 oop owner = ((oop*) sp())[byte_offset / wordSize];
aoqi@0 1135 assert( Universe::heap()->is_in(owner), "bad receiver" );
aoqi@0 1136 return owner;
aoqi@0 1137 }
aoqi@0 1138
aoqi@0 1139 void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) {
aoqi@0 1140 assert(map != NULL, "map must be set");
aoqi@0 1141 if (map->include_argument_oops()) {
aoqi@0 1142 // must collect argument oops, as nobody else is doing it
aoqi@0 1143 Thread *thread = Thread::current();
aoqi@0 1144 methodHandle m (thread, entry_frame_call_wrapper()->callee_method());
aoqi@0 1145 EntryFrameOopFinder finder(this, m->signature(), m->is_static());
aoqi@0 1146 finder.arguments_do(f);
aoqi@0 1147 }
aoqi@0 1148 // Traverse the Handle Block saved in the entry frame
aoqi@0 1149 entry_frame_call_wrapper()->oops_do(f);
aoqi@0 1150 }
aoqi@0 1151
aoqi@0 1152
stefank@6973 1153 void frame::oops_do_internal(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) {
aoqi@0 1154 #ifndef PRODUCT
aoqi@0 1155 // simulate GC crash here to dump java thread in error report
aoqi@0 1156 if (CrashGCForDumpingJavaThread) {
aoqi@0 1157 char *t = NULL;
aoqi@0 1158 *t = 'c';
aoqi@0 1159 }
aoqi@0 1160 #endif
aoqi@0 1161 if (is_interpreted_frame()) {
aoqi@0 1162 oops_interpreted_do(f, cld_f, map, use_interpreter_oop_map_cache);
aoqi@0 1163 } else if (is_entry_frame()) {
aoqi@0 1164 oops_entry_do(f, map);
aoqi@0 1165 } else if (CodeCache::contains(pc())) {
aoqi@0 1166 oops_code_blob_do(f, cf, map);
aoqi@0 1167 #ifdef SHARK
aoqi@0 1168 } else if (is_fake_stub_frame()) {
aoqi@0 1169 // nothing to do
aoqi@0 1170 #endif // SHARK
aoqi@0 1171 } else {
aoqi@0 1172 ShouldNotReachHere();
aoqi@0 1173 }
aoqi@0 1174 }
aoqi@0 1175
aoqi@0 1176 void frame::nmethods_do(CodeBlobClosure* cf) {
aoqi@0 1177 if (_cb != NULL && _cb->is_nmethod()) {
aoqi@0 1178 cf->do_code_blob(_cb);
aoqi@0 1179 }
aoqi@0 1180 }
aoqi@0 1181
aoqi@0 1182
aoqi@0 1183 // call f() on the interpreted Method*s in the stack.
aoqi@0 1184 // Have to walk the entire code cache for the compiled frames Yuck.
aoqi@0 1185 void frame::metadata_do(void f(Metadata*)) {
aoqi@0 1186 if (_cb != NULL && Interpreter::contains(pc())) {
aoqi@0 1187 Method* m = this->interpreter_frame_method();
aoqi@0 1188 assert(m != NULL, "huh?");
aoqi@0 1189 f(m);
aoqi@0 1190 }
aoqi@0 1191 }
aoqi@0 1192
aoqi@0 1193 void frame::gc_prologue() {
aoqi@0 1194 if (is_interpreted_frame()) {
aoqi@0 1195 // set bcx to bci to become Method* position independent during GC
aoqi@0 1196 interpreter_frame_set_bcx(interpreter_frame_bci());
aoqi@0 1197 }
aoqi@0 1198 }
aoqi@0 1199
aoqi@0 1200
aoqi@0 1201 void frame::gc_epilogue() {
aoqi@0 1202 if (is_interpreted_frame()) {
aoqi@0 1203 // set bcx back to bcp for interpreter
aoqi@0 1204 interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp());
aoqi@0 1205 }
aoqi@0 1206 // call processor specific epilog function
aoqi@0 1207 pd_gc_epilog();
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210
aoqi@0 1211 # ifdef ENABLE_ZAP_DEAD_LOCALS
aoqi@0 1212
aoqi@0 1213 void frame::CheckValueClosure::do_oop(oop* p) {
aoqi@0 1214 if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) {
aoqi@0 1215 warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
aoqi@0 1216 }
aoqi@0 1217 }
aoqi@0 1218 frame::CheckValueClosure frame::_check_value;
aoqi@0 1219
aoqi@0 1220
aoqi@0 1221 void frame::CheckOopClosure::do_oop(oop* p) {
aoqi@0 1222 if (*p != NULL && !(*p)->is_oop()) {
aoqi@0 1223 warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
aoqi@0 1224 }
aoqi@0 1225 }
aoqi@0 1226 frame::CheckOopClosure frame::_check_oop;
aoqi@0 1227
aoqi@0 1228 void frame::check_derived_oop(oop* base, oop* derived) {
aoqi@0 1229 _check_oop.do_oop(base);
aoqi@0 1230 }
aoqi@0 1231
aoqi@0 1232
aoqi@0 1233 void frame::ZapDeadClosure::do_oop(oop* p) {
aoqi@0 1234 if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p);
aoqi@0 1235 *p = cast_to_oop<intptr_t>(0xbabebabe);
aoqi@0 1236 }
aoqi@0 1237 frame::ZapDeadClosure frame::_zap_dead;
aoqi@0 1238
aoqi@0 1239 void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) {
aoqi@0 1240 assert(thread == Thread::current(), "need to synchronize to do this to another thread");
aoqi@0 1241 // Tracing - part 1
aoqi@0 1242 if (TraceZapDeadLocals) {
aoqi@0 1243 ResourceMark rm(thread);
aoqi@0 1244 tty->print_cr("--------------------------------------------------------------------------------");
aoqi@0 1245 tty->print("Zapping dead locals in ");
aoqi@0 1246 print_on(tty);
aoqi@0 1247 tty->cr();
aoqi@0 1248 }
aoqi@0 1249 // Zapping
aoqi@0 1250 if (is_entry_frame ()) zap_dead_entry_locals (thread, map);
aoqi@0 1251 else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map);
aoqi@0 1252 else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map);
aoqi@0 1253
aoqi@0 1254 else
aoqi@0 1255 // could be is_runtime_frame
aoqi@0 1256 // so remove error: ShouldNotReachHere();
aoqi@0 1257 ;
aoqi@0 1258 // Tracing - part 2
aoqi@0 1259 if (TraceZapDeadLocals) {
aoqi@0 1260 tty->cr();
aoqi@0 1261 }
aoqi@0 1262 }
aoqi@0 1263
aoqi@0 1264
aoqi@0 1265 void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) {
aoqi@0 1266 // get current interpreter 'pc'
aoqi@0 1267 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 1268 Method* m = interpreter_frame_method();
aoqi@0 1269 int bci = interpreter_frame_bci();
aoqi@0 1270
aoqi@0 1271 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
aoqi@0 1272
aoqi@0 1273 // process dynamic part
aoqi@0 1274 InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),
aoqi@0 1275 &_check_value);
aoqi@0 1276 InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(),
aoqi@0 1277 &_check_oop );
aoqi@0 1278 InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(),
aoqi@0 1279 &_zap_dead );
aoqi@0 1280
aoqi@0 1281 // get frame map
aoqi@0 1282 InterpreterOopMap mask;
aoqi@0 1283 m->mask_for(bci, &mask);
aoqi@0 1284 mask.iterate_all( &oop_blk, &value_blk, &dead_blk);
aoqi@0 1285 }
aoqi@0 1286
aoqi@0 1287
aoqi@0 1288 void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {
aoqi@0 1289
aoqi@0 1290 ResourceMark rm(thread);
aoqi@0 1291 assert(_cb != NULL, "sanity check");
aoqi@0 1292 if (_cb->oop_maps() != NULL) {
aoqi@0 1293 OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value);
aoqi@0 1294 }
aoqi@0 1295 }
aoqi@0 1296
aoqi@0 1297
aoqi@0 1298 void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) {
aoqi@0 1299 if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented");
aoqi@0 1300 }
aoqi@0 1301
aoqi@0 1302
aoqi@0 1303 void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) {
aoqi@0 1304 if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented");
aoqi@0 1305 }
aoqi@0 1306
aoqi@0 1307 # endif // ENABLE_ZAP_DEAD_LOCALS
aoqi@0 1308
aoqi@0 1309 void frame::verify(const RegisterMap* map) {
aoqi@0 1310 // for now make sure receiver type is correct
aoqi@0 1311 if (is_interpreted_frame()) {
aoqi@0 1312 Method* method = interpreter_frame_method();
aoqi@0 1313 guarantee(method->is_method(), "method is wrong in frame::verify");
aoqi@0 1314 if (!method->is_static()) {
aoqi@0 1315 // fetch the receiver
aoqi@0 1316 oop* p = (oop*) interpreter_frame_local_at(0);
aoqi@0 1317 // make sure we have the right receiver type
aoqi@0 1318 }
aoqi@0 1319 }
aoqi@0 1320 COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");)
aoqi@0 1321 oops_do_internal(&VerifyOopClosure::verify_oop, NULL, NULL, (RegisterMap*)map, false);
aoqi@0 1322 }
aoqi@0 1323
aoqi@0 1324
aoqi@0 1325 #ifdef ASSERT
aoqi@0 1326 bool frame::verify_return_pc(address x) {
aoqi@0 1327 if (StubRoutines::returns_to_call_stub(x)) {
aoqi@0 1328 return true;
aoqi@0 1329 }
aoqi@0 1330 if (CodeCache::contains(x)) {
aoqi@0 1331 return true;
aoqi@0 1332 }
aoqi@0 1333 if (Interpreter::contains(x)) {
aoqi@0 1334 return true;
aoqi@0 1335 }
aoqi@0 1336 return false;
aoqi@0 1337 }
aoqi@0 1338 #endif
aoqi@0 1339
aoqi@0 1340 #ifdef ASSERT
aoqi@0 1341 void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const {
aoqi@0 1342 assert(is_interpreted_frame(), "Not an interpreted frame");
aoqi@0 1343 // verify that the value is in the right part of the frame
aoqi@0 1344 address low_mark = (address) interpreter_frame_monitor_end();
aoqi@0 1345 address high_mark = (address) interpreter_frame_monitor_begin();
aoqi@0 1346 address current = (address) value;
aoqi@0 1347
aoqi@0 1348 const int monitor_size = frame::interpreter_frame_monitor_size();
aoqi@0 1349 guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*");
aoqi@0 1350 guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark");
aoqi@0 1351
aoqi@0 1352 guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*");
aoqi@0 1353 guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark");
aoqi@0 1354 }
aoqi@0 1355 #endif
aoqi@0 1356
aoqi@0 1357 #ifndef PRODUCT
aoqi@0 1358 void frame::describe(FrameValues& values, int frame_no) {
aoqi@0 1359 // boundaries: sp and the 'real' frame pointer
aoqi@0 1360 values.describe(-1, sp(), err_msg("sp for #%d", frame_no), 1);
aoqi@0 1361 intptr_t* frame_pointer = real_fp(); // Note: may differ from fp()
aoqi@0 1362
aoqi@0 1363 // print frame info at the highest boundary
aoqi@0 1364 intptr_t* info_address = MAX2(sp(), frame_pointer);
aoqi@0 1365
aoqi@0 1366 if (info_address != frame_pointer) {
aoqi@0 1367 // print frame_pointer explicitly if not marked by the frame info
aoqi@0 1368 values.describe(-1, frame_pointer, err_msg("frame pointer for #%d", frame_no), 1);
aoqi@0 1369 }
aoqi@0 1370
aoqi@0 1371 if (is_entry_frame() || is_compiled_frame() || is_interpreted_frame() || is_native_frame()) {
aoqi@0 1372 // Label values common to most frames
aoqi@0 1373 values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no));
aoqi@0 1374 }
aoqi@0 1375
aoqi@0 1376 if (is_interpreted_frame()) {
aoqi@0 1377 Method* m = interpreter_frame_method();
aoqi@0 1378 int bci = interpreter_frame_bci();
aoqi@0 1379
aoqi@0 1380 // Label the method and current bci
aoqi@0 1381 values.describe(-1, info_address,
aoqi@0 1382 FormatBuffer<1024>("#%d method %s @ %d", frame_no, m->name_and_sig_as_C_string(), bci), 2);
aoqi@0 1383 values.describe(-1, info_address,
aoqi@0 1384 err_msg("- %d locals %d max stack", m->max_locals(), m->max_stack()), 1);
aoqi@0 1385 if (m->max_locals() > 0) {
aoqi@0 1386 intptr_t* l0 = interpreter_frame_local_at(0);
aoqi@0 1387 intptr_t* ln = interpreter_frame_local_at(m->max_locals() - 1);
aoqi@0 1388 values.describe(-1, MAX2(l0, ln), err_msg("locals for #%d", frame_no), 1);
aoqi@0 1389 // Report each local and mark as owned by this frame
aoqi@0 1390 for (int l = 0; l < m->max_locals(); l++) {
aoqi@0 1391 intptr_t* l0 = interpreter_frame_local_at(l);
aoqi@0 1392 values.describe(frame_no, l0, err_msg("local %d", l));
aoqi@0 1393 }
aoqi@0 1394 }
aoqi@0 1395
aoqi@0 1396 // Compute the actual expression stack size
aoqi@0 1397 InterpreterOopMap mask;
aoqi@0 1398 OopMapCache::compute_one_oop_map(m, bci, &mask);
aoqi@0 1399 intptr_t* tos = NULL;
aoqi@0 1400 // Report each stack element and mark as owned by this frame
aoqi@0 1401 for (int e = 0; e < mask.expression_stack_size(); e++) {
aoqi@0 1402 tos = MAX2(tos, interpreter_frame_expression_stack_at(e));
aoqi@0 1403 values.describe(frame_no, interpreter_frame_expression_stack_at(e),
aoqi@0 1404 err_msg("stack %d", e));
aoqi@0 1405 }
aoqi@0 1406 if (tos != NULL) {
aoqi@0 1407 values.describe(-1, tos, err_msg("expression stack for #%d", frame_no), 1);
aoqi@0 1408 }
aoqi@0 1409 if (interpreter_frame_monitor_begin() != interpreter_frame_monitor_end()) {
aoqi@0 1410 values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_begin(), "monitors begin");
aoqi@0 1411 values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_end(), "monitors end");
aoqi@0 1412 }
aoqi@0 1413 } else if (is_entry_frame()) {
aoqi@0 1414 // For now just label the frame
aoqi@0 1415 values.describe(-1, info_address, err_msg("#%d entry frame", frame_no), 2);
aoqi@0 1416 } else if (is_compiled_frame()) {
aoqi@0 1417 // For now just label the frame
aoqi@0 1418 nmethod* nm = cb()->as_nmethod_or_null();
aoqi@0 1419 values.describe(-1, info_address,
aoqi@0 1420 FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for method %s%s", frame_no,
aoqi@0 1421 nm, nm->method()->name_and_sig_as_C_string(),
aoqi@0 1422 (_deopt_state == is_deoptimized) ?
aoqi@0 1423 " (deoptimized)" :
aoqi@0 1424 ((_deopt_state == unknown) ? " (state unknown)" : "")),
aoqi@0 1425 2);
aoqi@0 1426 } else if (is_native_frame()) {
aoqi@0 1427 // For now just label the frame
aoqi@0 1428 nmethod* nm = cb()->as_nmethod_or_null();
aoqi@0 1429 values.describe(-1, info_address,
aoqi@0 1430 FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for native method %s", frame_no,
aoqi@0 1431 nm, nm->method()->name_and_sig_as_C_string()), 2);
aoqi@0 1432 } else {
aoqi@0 1433 // provide default info if not handled before
aoqi@0 1434 char *info = (char *) "special frame";
aoqi@0 1435 if ((_cb != NULL) &&
aoqi@0 1436 (_cb->name() != NULL)) {
aoqi@0 1437 info = (char *)_cb->name();
aoqi@0 1438 }
aoqi@0 1439 values.describe(-1, info_address, err_msg("#%d <%s>", frame_no, info), 2);
aoqi@0 1440 }
aoqi@0 1441
aoqi@0 1442 // platform dependent additional data
aoqi@0 1443 describe_pd(values, frame_no);
aoqi@0 1444 }
aoqi@0 1445
aoqi@0 1446 #endif
aoqi@0 1447
aoqi@0 1448
aoqi@0 1449 //-----------------------------------------------------------------------------------
aoqi@0 1450 // StackFrameStream implementation
aoqi@0 1451
aoqi@0 1452 StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) {
aoqi@0 1453 assert(thread->has_last_Java_frame(), "sanity check");
aoqi@0 1454 _fr = thread->last_frame();
aoqi@0 1455 _is_done = false;
aoqi@0 1456 }
aoqi@0 1457
aoqi@0 1458
aoqi@0 1459 #ifndef PRODUCT
aoqi@0 1460
aoqi@0 1461 void FrameValues::describe(int owner, intptr_t* location, const char* description, int priority) {
aoqi@0 1462 FrameValue fv;
aoqi@0 1463 fv.location = location;
aoqi@0 1464 fv.owner = owner;
aoqi@0 1465 fv.priority = priority;
aoqi@0 1466 fv.description = NEW_RESOURCE_ARRAY(char, strlen(description) + 1);
aoqi@0 1467 strcpy(fv.description, description);
aoqi@0 1468 _values.append(fv);
aoqi@0 1469 }
aoqi@0 1470
aoqi@0 1471
aoqi@0 1472 #ifdef ASSERT
aoqi@0 1473 void FrameValues::validate() {
aoqi@0 1474 _values.sort(compare);
aoqi@0 1475 bool error = false;
aoqi@0 1476 FrameValue prev;
aoqi@0 1477 prev.owner = -1;
aoqi@0 1478 for (int i = _values.length() - 1; i >= 0; i--) {
aoqi@0 1479 FrameValue fv = _values.at(i);
aoqi@0 1480 if (fv.owner == -1) continue;
aoqi@0 1481 if (prev.owner == -1) {
aoqi@0 1482 prev = fv;
aoqi@0 1483 continue;
aoqi@0 1484 }
aoqi@0 1485 if (prev.location == fv.location) {
aoqi@0 1486 if (fv.owner != prev.owner) {
aoqi@0 1487 tty->print_cr("overlapping storage");
aoqi@0 1488 tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", prev.location, *prev.location, prev.description);
aoqi@0 1489 tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);
aoqi@0 1490 error = true;
aoqi@0 1491 }
aoqi@0 1492 } else {
aoqi@0 1493 prev = fv;
aoqi@0 1494 }
aoqi@0 1495 }
aoqi@0 1496 assert(!error, "invalid layout");
aoqi@0 1497 }
aoqi@0 1498 #endif // ASSERT
aoqi@0 1499
aoqi@0 1500 void FrameValues::print(JavaThread* thread) {
aoqi@0 1501 _values.sort(compare);
aoqi@0 1502
aoqi@0 1503 // Sometimes values like the fp can be invalid values if the
aoqi@0 1504 // register map wasn't updated during the walk. Trim out values
aoqi@0 1505 // that aren't actually in the stack of the thread.
aoqi@0 1506 int min_index = 0;
aoqi@0 1507 int max_index = _values.length() - 1;
aoqi@0 1508 intptr_t* v0 = _values.at(min_index).location;
aoqi@0 1509 intptr_t* v1 = _values.at(max_index).location;
aoqi@0 1510
aoqi@0 1511 if (thread == Thread::current()) {
aoqi@0 1512 while (!thread->is_in_stack((address)v0)) {
aoqi@0 1513 v0 = _values.at(++min_index).location;
aoqi@0 1514 }
aoqi@0 1515 while (!thread->is_in_stack((address)v1)) {
aoqi@0 1516 v1 = _values.at(--max_index).location;
aoqi@0 1517 }
aoqi@0 1518 } else {
aoqi@0 1519 while (!thread->on_local_stack((address)v0)) {
aoqi@0 1520 v0 = _values.at(++min_index).location;
aoqi@0 1521 }
aoqi@0 1522 while (!thread->on_local_stack((address)v1)) {
aoqi@0 1523 v1 = _values.at(--max_index).location;
aoqi@0 1524 }
aoqi@0 1525 }
aoqi@0 1526 intptr_t* min = MIN2(v0, v1);
aoqi@0 1527 intptr_t* max = MAX2(v0, v1);
aoqi@0 1528 intptr_t* cur = max;
aoqi@0 1529 intptr_t* last = NULL;
aoqi@0 1530 for (int i = max_index; i >= min_index; i--) {
aoqi@0 1531 FrameValue fv = _values.at(i);
aoqi@0 1532 while (cur > fv.location) {
aoqi@0 1533 tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT, cur, *cur);
aoqi@0 1534 cur--;
aoqi@0 1535 }
aoqi@0 1536 if (last == fv.location) {
aoqi@0 1537 const char* spacer = " " LP64_ONLY(" ");
aoqi@0 1538 tty->print_cr(" %s %s %s", spacer, spacer, fv.description);
aoqi@0 1539 } else {
aoqi@0 1540 tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);
aoqi@0 1541 last = fv.location;
aoqi@0 1542 cur--;
aoqi@0 1543 }
aoqi@0 1544 }
aoqi@0 1545 }
aoqi@0 1546
aoqi@0 1547 #endif // ndef PRODUCT

mercurial