src/share/vm/runtime/frame.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial