annotate src/share/vm/prims/forte.cpp @ 1563:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents cff162798819
children 395f9d4370b0 f95d63e2154a
rev   line source
duke@0 1 /*
trims@1563 2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_forte.cpp.incl"
duke@0 27
sgoldman@107 28 // These name match the names reported by the forte quality kit
sgoldman@107 29 enum {
sgoldman@107 30 ticks_no_Java_frame = 0,
sgoldman@107 31 ticks_no_class_load = -1,
sgoldman@107 32 ticks_GC_active = -2,
sgoldman@107 33 ticks_unknown_not_Java = -3,
sgoldman@107 34 ticks_not_walkable_not_Java = -4,
sgoldman@107 35 ticks_unknown_Java = -5,
sgoldman@107 36 ticks_not_walkable_Java = -6,
sgoldman@107 37 ticks_unknown_state = -7,
sgoldman@107 38 ticks_thread_exit = -8,
sgoldman@107 39 ticks_deopt = -9,
sgoldman@107 40 ticks_safepoint = -10
sgoldman@107 41 };
duke@0 42
duke@0 43 //-------------------------------------------------------
duke@0 44
duke@0 45 // Native interfaces for use by Forte tools.
duke@0 46
duke@0 47
duke@0 48 #ifndef IA64
duke@0 49
duke@0 50 class vframeStreamForte : public vframeStreamCommon {
duke@0 51 public:
duke@0 52 // constructor that starts with sender of frame fr (top_frame)
duke@0 53 vframeStreamForte(JavaThread *jt, frame fr, bool stop_at_java_call_stub);
duke@0 54 void forte_next();
duke@0 55 };
duke@0 56
duke@0 57
never@1438 58 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, nmethod* nm);
sgoldman@107 59 static bool is_decipherable_interpreted_frame(JavaThread* thread,
never@1438 60 frame* fr,
never@1438 61 methodOop* method_p,
never@1438 62 int* bci_p);
duke@0 63
duke@0 64
duke@0 65
duke@0 66
sgoldman@107 67 vframeStreamForte::vframeStreamForte(JavaThread *jt,
sgoldman@107 68 frame fr,
sgoldman@107 69 bool stop_at_java_call_stub) : vframeStreamCommon(jt) {
duke@0 70
sgoldman@107 71 _stop_at_java_call_stub = stop_at_java_call_stub;
sgoldman@107 72 _frame = fr;
duke@0 73
sgoldman@107 74 // We must always have a valid frame to start filling
duke@0 75
sgoldman@107 76 bool filled_in = fill_from_frame();
duke@0 77
sgoldman@107 78 assert(filled_in, "invariant");
duke@0 79
duke@0 80 }
duke@0 81
duke@0 82
duke@0 83 // Solaris SPARC Compiler1 needs an additional check on the grandparent
duke@0 84 // of the top_frame when the parent of the top_frame is interpreted and
duke@0 85 // the grandparent is compiled. However, in this method we do not know
duke@0 86 // the relationship of the current _frame relative to the top_frame so
duke@0 87 // we implement a more broad sanity check. When the previous callee is
duke@0 88 // interpreted and the current sender is compiled, we verify that the
duke@0 89 // current sender is also walkable. If it is not walkable, then we mark
duke@0 90 // the current vframeStream as at the end.
duke@0 91 void vframeStreamForte::forte_next() {
duke@0 92 // handle frames with inlining
duke@0 93 if (_mode == compiled_mode &&
duke@0 94 vframeStreamCommon::fill_in_compiled_inlined_sender()) {
duke@0 95 return;
duke@0 96 }
duke@0 97
duke@0 98 // handle general case
duke@0 99
duke@0 100 int loop_count = 0;
duke@0 101 int loop_max = MaxJavaStackTraceDepth * 2;
duke@0 102
duke@0 103
duke@0 104 do {
duke@0 105
sgoldman@107 106 loop_count++;
duke@0 107
sgoldman@107 108 // By the time we get here we should never see unsafe but better
sgoldman@107 109 // safe then segv'd
duke@0 110
sgoldman@107 111 if (loop_count > loop_max || !_frame.safe_for_sender(_thread)) {
duke@0 112 _mode = at_end_mode;
duke@0 113 return;
duke@0 114 }
duke@0 115
sgoldman@107 116 _frame = _frame.sender(&_reg_map);
duke@0 117
duke@0 118 } while (!fill_from_frame());
duke@0 119 }
duke@0 120
sgoldman@107 121 // Determine if 'fr' is a decipherable compiled frame. We are already
sgoldman@107 122 // assured that fr is for a java nmethod.
duke@0 123
never@1438 124 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, nmethod* nm) {
sgoldman@107 125 assert(nm->is_java_method(), "invariant");
duke@0 126
never@1438 127 if (thread->has_last_Java_frame() && thread->last_Java_pc() == fr->pc()) {
never@1438 128 // We're stopped at a call into the JVM so look for a PcDesc with
never@1438 129 // the actual pc reported by the frame.
never@1438 130 PcDesc* pc_desc = nm->pc_desc_at(fr->pc());
sgoldman@107 131
never@1438 132 // Did we find a useful PcDesc?
sgoldman@107 133 if (pc_desc != NULL &&
never@1438 134 pc_desc->scope_decode_offset() != DebugInformationRecorder::serialized_null) {
never@1438 135 return true;
duke@0 136 }
duke@0 137 }
sgoldman@107 138
never@1438 139 // We're at some random pc in the nmethod so search for the PcDesc
never@1438 140 // whose pc is greater than the current PC. It's done this way
never@1438 141 // because the extra PcDescs that are recorded for improved debug
never@1438 142 // info record the end of the region covered by the ScopeDesc
never@1438 143 // instead of the beginning.
never@1438 144 PcDesc* pc_desc = nm->pc_desc_near(fr->pc() + 1);
never@1438 145
never@1438 146 // Now do we have a useful PcDesc?
never@1438 147 if (pc_desc == NULL ||
never@1438 148 pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) {
never@1438 149 // No debug information available for this pc
never@1438 150 // vframeStream would explode if we try and walk the frames.
never@1438 151 return false;
never@1438 152 }
never@1438 153
never@1438 154 // This PcDesc is useful however we must adjust the frame's pc
never@1438 155 // so that the vframeStream lookups will use this same pc
never@1438 156 fr->set_pc(pc_desc->real_pc(nm));
sgoldman@107 157 return true;
duke@0 158 }
duke@0 159
never@1438 160
duke@0 161 // Determine if 'fr' is a walkable interpreted frame. Returns false
duke@0 162 // if it is not. *method_p, and *bci_p are not set when false is
duke@0 163 // returned. *method_p is non-NULL if frame was executing a Java
duke@0 164 // method. *bci_p is != -1 if a valid BCI in the Java method could
duke@0 165 // be found.
duke@0 166 // Note: this method returns true when a valid Java method is found
duke@0 167 // even if a valid BCI cannot be found.
duke@0 168
sgoldman@107 169 static bool is_decipherable_interpreted_frame(JavaThread* thread,
never@1438 170 frame* fr,
never@1438 171 methodOop* method_p,
never@1438 172 int* bci_p) {
duke@0 173 assert(fr->is_interpreted_frame(), "just checking");
duke@0 174
duke@0 175 // top frame is an interpreted frame
duke@0 176 // check if it is walkable (i.e. valid methodOop and valid bci)
sgoldman@107 177
sgoldman@107 178 // Because we may be racing a gc thread the method and/or bci
sgoldman@107 179 // of a valid interpreter frame may look bad causing us to
sgoldman@107 180 // fail the is_interpreted_frame_valid test. If the thread
sgoldman@107 181 // is in any of the following states we are assured that the
sgoldman@107 182 // frame is in fact valid and we must have hit the race.
sgoldman@107 183
sgoldman@107 184 JavaThreadState state = thread->thread_state();
sgoldman@107 185 bool known_valid = (state == _thread_in_native ||
sgoldman@107 186 state == _thread_in_vm ||
sgoldman@107 187 state == _thread_blocked );
sgoldman@107 188
sgoldman@107 189 if (known_valid || fr->is_interpreted_frame_valid(thread)) {
sgoldman@107 190
sgoldman@107 191 // The frame code should completely validate the frame so that
sgoldman@107 192 // references to methodOop and bci are completely safe to access
sgoldman@107 193 // If they aren't the frame code should be fixed not this
sgoldman@107 194 // code. However since gc isn't locked out the values could be
sgoldman@107 195 // stale. This is a race we can never completely win since we can't
sgoldman@107 196 // lock out gc so do one last check after retrieving their values
sgoldman@107 197 // from the frame for additional safety
sgoldman@107 198
sgoldman@107 199 methodOop method = fr->interpreter_frame_method();
sgoldman@107 200
sgoldman@107 201 // We've at least found a method.
sgoldman@107 202 // NOTE: there is something to be said for the approach that
sgoldman@107 203 // if we don't find a valid bci then the method is not likely
sgoldman@107 204 // a valid method. Then again we may have caught an interpreter
sgoldman@107 205 // frame in the middle of construction and the bci field is
sgoldman@107 206 // not yet valid.
sgoldman@107 207
sgoldman@107 208 *method_p = method;
sgoldman@107 209
sgoldman@107 210 // See if gc may have invalidated method since we validated frame
sgoldman@107 211
sgoldman@107 212 if (!Universe::heap()->is_valid_method(method)) return false;
sgoldman@107 213
sgoldman@107 214 intptr_t bcx = fr->interpreter_frame_bcx();
sgoldman@107 215
sgoldman@107 216 int bci = method->validate_bci_from_bcx(bcx);
sgoldman@107 217
sgoldman@107 218 // note: bci is set to -1 if not a valid bci
sgoldman@107 219 *bci_p = bci;
sgoldman@107 220 return true;
duke@0 221 }
sgoldman@107 222
duke@0 223 return false;
duke@0 224 }
duke@0 225
duke@0 226
sgoldman@107 227 // Determine if 'fr' can be used to find an initial Java frame.
sgoldman@107 228 // Return false if it can not find a fully decipherable Java frame
sgoldman@107 229 // (in other words a frame that isn't safe to use in a vframe stream).
sgoldman@107 230 // Obviously if it can't even find a Java frame false will also be returned.
duke@0 231 //
sgoldman@107 232 // If we find a Java frame decipherable or not then by definition we have
sgoldman@107 233 // identified a method and that will be returned to the caller via method_p.
sgoldman@107 234 // If we can determine a bci that is returned also. (Hmm is it possible
sgoldman@107 235 // to return a method and bci and still return false? )
sgoldman@107 236 //
sgoldman@107 237 // The initial Java frame we find (if any) is return via initial_frame_p.
sgoldman@107 238 //
duke@0 239
sgoldman@107 240 static bool find_initial_Java_frame(JavaThread* thread,
sgoldman@107 241 frame* fr,
sgoldman@107 242 frame* initial_frame_p,
sgoldman@107 243 methodOop* method_p,
sgoldman@107 244 int* bci_p) {
sgoldman@107 245
sgoldman@107 246 // It is possible that for a frame containing an nmethod
sgoldman@107 247 // we can capture the method but no bci. If we get no
sgoldman@107 248 // bci the frame isn't walkable but the method is usable.
sgoldman@107 249 // Therefore we init the returned methodOop to NULL so the
sgoldman@107 250 // caller can make the distinction.
sgoldman@107 251
sgoldman@107 252 *method_p = NULL;
sgoldman@107 253
sgoldman@107 254 // On the initial call to this method the frame we get may not be
sgoldman@107 255 // recognizable to us. This should only happen if we are in a JRT_LEAF
sgoldman@107 256 // or something called by a JRT_LEAF method.
sgoldman@107 257
sgoldman@107 258
sgoldman@107 259
sgoldman@107 260 frame candidate = *fr;
sgoldman@107 261
sgoldman@107 262 // If the starting frame we were given has no codeBlob associated with
sgoldman@107 263 // it see if we can find such a frame because only frames with codeBlobs
sgoldman@107 264 // are possible Java frames.
sgoldman@107 265
sgoldman@107 266 if (fr->cb() == NULL) {
sgoldman@107 267
sgoldman@107 268 // See if we can find a useful frame
sgoldman@107 269 int loop_count;
sgoldman@107 270 int loop_max = MaxJavaStackTraceDepth * 2;
sgoldman@107 271 RegisterMap map(thread, false);
sgoldman@107 272
sgoldman@107 273 for (loop_count = 0; loop_count < loop_max; loop_count++) {
sgoldman@107 274 if (!candidate.safe_for_sender(thread)) return false;
sgoldman@107 275 candidate = candidate.sender(&map);
sgoldman@107 276 if (candidate.cb() != NULL) break;
sgoldman@107 277 }
sgoldman@107 278 if (candidate.cb() == NULL) return false;
duke@0 279 }
duke@0 280
sgoldman@107 281 // We have a frame known to be in the codeCache
sgoldman@107 282 // We will hopefully be able to figure out something to do with it.
sgoldman@107 283 int loop_count;
sgoldman@107 284 int loop_max = MaxJavaStackTraceDepth * 2;
sgoldman@107 285 RegisterMap map(thread, false);
sgoldman@107 286
sgoldman@107 287 for (loop_count = 0; loop_count < loop_max; loop_count++) {
sgoldman@107 288
sgoldman@107 289 if (candidate.is_first_frame()) {
sgoldman@107 290 // If initial frame is frame from StubGenerator and there is no
sgoldman@107 291 // previous anchor, there are no java frames associated with a method
sgoldman@107 292 return false;
sgoldman@107 293 }
sgoldman@107 294
sgoldman@107 295 if (candidate.is_interpreted_frame()) {
sgoldman@107 296 if (is_decipherable_interpreted_frame(thread, &candidate, method_p, bci_p)) {
sgoldman@107 297 *initial_frame_p = candidate;
sgoldman@107 298 return true;
sgoldman@107 299 }
sgoldman@107 300
sgoldman@107 301 // Hopefully we got some data
sgoldman@107 302 return false;
sgoldman@107 303 }
sgoldman@107 304
sgoldman@107 305 if (candidate.cb()->is_nmethod()) {
sgoldman@107 306
sgoldman@107 307 nmethod* nm = (nmethod*) candidate.cb();
sgoldman@107 308 *method_p = nm->method();
sgoldman@107 309
sgoldman@107 310 // If the frame isn't fully decipherable then the default
sgoldman@107 311 // value for the bci is a signal that we don't have a bci.
sgoldman@107 312 // If we have a decipherable frame this bci value will
sgoldman@107 313 // not be used.
sgoldman@107 314
sgoldman@107 315 *bci_p = -1;
sgoldman@107 316
sgoldman@107 317 *initial_frame_p = candidate;
sgoldman@107 318
sgoldman@107 319 // Native wrapper code is trivial to decode by vframeStream
sgoldman@107 320
sgoldman@107 321 if (nm->is_native_method()) return true;
sgoldman@107 322
sgoldman@107 323 // If it isn't decipherable then we have found a pc that doesn't
sgoldman@107 324 // have a PCDesc that can get us a bci however we did find
sgoldman@107 325 // a method
sgoldman@107 326
never@1438 327 if (!is_decipherable_compiled_frame(thread, &candidate, nm)) {
sgoldman@107 328 return false;
sgoldman@107 329 }
sgoldman@107 330
sgoldman@107 331 // is_decipherable_compiled_frame may modify candidate's pc
sgoldman@107 332 *initial_frame_p = candidate;
sgoldman@107 333
never@1438 334 assert(nm->pc_desc_at(candidate.pc()) != NULL, "if it's decipherable then pc must be valid");
never@1438 335
sgoldman@107 336 return true;
sgoldman@107 337 }
sgoldman@107 338
sgoldman@107 339 // Must be some stub frame that we don't care about
sgoldman@107 340
sgoldman@107 341 if (!candidate.safe_for_sender(thread)) return false;
sgoldman@107 342 candidate = candidate.sender(&map);
sgoldman@107 343
sgoldman@107 344 // If it isn't in the code cache something is wrong
sgoldman@107 345 // since once we find a frame in the code cache they
sgoldman@107 346 // all should be there.
sgoldman@107 347
sgoldman@107 348 if (candidate.cb() == NULL) return false;
sgoldman@107 349
duke@0 350 }
duke@0 351
sgoldman@107 352 return false;
duke@0 353
duke@0 354 }
duke@0 355
duke@0 356
duke@0 357 // call frame copied from old .h file and renamed
duke@0 358 typedef struct {
duke@0 359 jint lineno; // line number in the source file
duke@0 360 jmethodID method_id; // method executed in this frame
duke@0 361 } ASGCT_CallFrame;
duke@0 362
duke@0 363 // call trace copied from old .h file and renamed
duke@0 364 typedef struct {
duke@0 365 JNIEnv *env_id; // Env where trace was recorded
duke@0 366 jint num_frames; // number of frames in this trace
duke@0 367 ASGCT_CallFrame *frames; // frames
duke@0 368 } ASGCT_CallTrace;
duke@0 369
duke@0 370 static void forte_fill_call_trace_given_top(JavaThread* thd,
sgoldman@107 371 ASGCT_CallTrace* trace,
sgoldman@107 372 int depth,
sgoldman@107 373 frame top_frame) {
duke@0 374 NoHandleMark nhm;
duke@0 375
sgoldman@107 376 frame initial_Java_frame;
duke@0 377 methodOop method;
duke@0 378 int bci;
duke@0 379 int count;
duke@0 380
duke@0 381 count = 0;
duke@0 382 assert(trace->frames != NULL, "trace->frames must be non-NULL");
duke@0 383
sgoldman@107 384 bool fully_decipherable = find_initial_Java_frame(thd, &top_frame, &initial_Java_frame, &method, &bci);
sgoldman@107 385
sgoldman@107 386 // The frame might not be walkable but still recovered a method
sgoldman@107 387 // (e.g. an nmethod with no scope info for the pc
sgoldman@107 388
sgoldman@107 389 if (method == NULL) return;
sgoldman@107 390
sgoldman@107 391 CollectedHeap* ch = Universe::heap();
sgoldman@107 392
sgoldman@107 393 // The method is not stored GC safe so see if GC became active
sgoldman@107 394 // after we entered AsyncGetCallTrace() and before we try to
sgoldman@107 395 // use the methodOop.
sgoldman@107 396 // Yes, there is still a window after this check and before
sgoldman@107 397 // we use methodOop below, but we can't lock out GC so that
sgoldman@107 398 // has to be an acceptable risk.
sgoldman@107 399 if (!ch->is_valid_method(method)) {
sgoldman@107 400 trace->num_frames = ticks_GC_active; // -2
duke@0 401 return;
duke@0 402 }
duke@0 403
sgoldman@107 404 // We got a Java frame however it isn't fully decipherable
sgoldman@107 405 // so it won't necessarily be safe to use it for the
sgoldman@107 406 // initial frame in the vframe stream.
duke@0 407
sgoldman@107 408 if (!fully_decipherable) {
sgoldman@107 409 // Take whatever method the top-frame decoder managed to scrape up.
sgoldman@107 410 // We look further at the top frame only if non-safepoint
sgoldman@107 411 // debugging information is available.
sgoldman@107 412 count++;
sgoldman@107 413 trace->num_frames = count;
sgoldman@107 414 trace->frames[0].method_id = method->find_jmethod_id_or_null();
sgoldman@107 415 if (!method->is_native()) {
sgoldman@107 416 trace->frames[0].lineno = bci;
sgoldman@107 417 } else {
sgoldman@107 418 trace->frames[0].lineno = -3;
duke@0 419 }
duke@0 420
sgoldman@107 421 if (!initial_Java_frame.safe_for_sender(thd)) return;
sgoldman@107 422
sgoldman@107 423 RegisterMap map(thd, false);
sgoldman@107 424 initial_Java_frame = initial_Java_frame.sender(&map);
duke@0 425 }
duke@0 426
sgoldman@107 427 vframeStreamForte st(thd, initial_Java_frame, false);
duke@0 428
duke@0 429 for (; !st.at_end() && count < depth; st.forte_next(), count++) {
duke@0 430 bci = st.bci();
duke@0 431 method = st.method();
duke@0 432
duke@0 433 // The method is not stored GC safe so see if GC became active
duke@0 434 // after we entered AsyncGetCallTrace() and before we try to
duke@0 435 // use the methodOop.
duke@0 436 // Yes, there is still a window after this check and before
duke@0 437 // we use methodOop below, but we can't lock out GC so that
duke@0 438 // has to be an acceptable risk.
duke@0 439 if (!ch->is_valid_method(method)) {
duke@0 440 // we throw away everything we've gathered in this sample since
duke@0 441 // none of it is safe
sgoldman@107 442 trace->num_frames = ticks_GC_active; // -2
duke@0 443 return;
duke@0 444 }
duke@0 445
duke@0 446 trace->frames[count].method_id = method->find_jmethod_id_or_null();
duke@0 447 if (!method->is_native()) {
duke@0 448 trace->frames[count].lineno = bci;
duke@0 449 } else {
duke@0 450 trace->frames[count].lineno = -3;
duke@0 451 }
duke@0 452 }
duke@0 453 trace->num_frames = count;
duke@0 454 return;
duke@0 455 }
duke@0 456
duke@0 457
duke@0 458 // Forte Analyzer AsyncGetCallTrace() entry point. Currently supported
duke@0 459 // on Linux X86, Solaris SPARC and Solaris X86.
duke@0 460 //
duke@0 461 // Async-safe version of GetCallTrace being called from a signal handler
duke@0 462 // when a LWP gets interrupted by SIGPROF but the stack traces are filled
duke@0 463 // with different content (see below).
duke@0 464 //
duke@0 465 // This function must only be called when JVM/TI
duke@0 466 // CLASS_LOAD events have been enabled since agent startup. The enabled
duke@0 467 // event will cause the jmethodIDs to be allocated at class load time.
duke@0 468 // The jmethodIDs cannot be allocated in a signal handler because locks
duke@0 469 // cannot be grabbed in a signal handler safely.
duke@0 470 //
duke@0 471 // void (*AsyncGetCallTrace)(ASGCT_CallTrace *trace, jint depth, void* ucontext)
duke@0 472 //
duke@0 473 // Called by the profiler to obtain the current method call stack trace for
duke@0 474 // a given thread. The thread is identified by the env_id field in the
duke@0 475 // ASGCT_CallTrace structure. The profiler agent should allocate a ASGCT_CallTrace
duke@0 476 // structure with enough memory for the requested stack depth. The VM fills in
duke@0 477 // the frames buffer and the num_frames field.
duke@0 478 //
duke@0 479 // Arguments:
duke@0 480 //
duke@0 481 // trace - trace data structure to be filled by the VM.
duke@0 482 // depth - depth of the call stack trace.
duke@0 483 // ucontext - ucontext_t of the LWP
duke@0 484 //
duke@0 485 // ASGCT_CallTrace:
duke@0 486 // typedef struct {
duke@0 487 // JNIEnv *env_id;
duke@0 488 // jint num_frames;
duke@0 489 // ASGCT_CallFrame *frames;
duke@0 490 // } ASGCT_CallTrace;
duke@0 491 //
duke@0 492 // Fields:
duke@0 493 // env_id - ID of thread which executed this trace.
duke@0 494 // num_frames - number of frames in the trace.
duke@0 495 // (< 0 indicates the frame is not walkable).
duke@0 496 // frames - the ASGCT_CallFrames that make up this trace. Callee followed by callers.
duke@0 497 //
duke@0 498 // ASGCT_CallFrame:
duke@0 499 // typedef struct {
duke@0 500 // jint lineno;
duke@0 501 // jmethodID method_id;
duke@0 502 // } ASGCT_CallFrame;
duke@0 503 //
duke@0 504 // Fields:
duke@0 505 // 1) For Java frame (interpreted and compiled),
duke@0 506 // lineno - bci of the method being executed or -1 if bci is not available
duke@0 507 // method_id - jmethodID of the method being executed
duke@0 508 // 2) For native method
duke@0 509 // lineno - (-3)
duke@0 510 // method_id - jmethodID of the method being executed
duke@0 511
duke@0 512 extern "C" {
duke@0 513 void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
sgoldman@107 514
sgoldman@107 515 // This is if'd out because we no longer use thread suspension.
sgoldman@107 516 // However if someone wanted to backport this to a 5.0 jvm then this
sgoldman@107 517 // code would be important.
sgoldman@107 518 #if 0
duke@0 519 if (SafepointSynchronize::is_synchronizing()) {
duke@0 520 // The safepoint mechanism is trying to synchronize all the threads.
duke@0 521 // Since this can involve thread suspension, it is not safe for us
duke@0 522 // to be here. We can reduce the deadlock risk window by quickly
duke@0 523 // returning to the SIGPROF handler. However, it is still possible
duke@0 524 // for VMThread to catch us here or in the SIGPROF handler. If we
duke@0 525 // are suspended while holding a resource and another thread blocks
duke@0 526 // on that resource in the SIGPROF handler, then we will have a
duke@0 527 // three-thread deadlock (VMThread, this thread, the other thread).
sgoldman@107 528 trace->num_frames = ticks_safepoint; // -10
duke@0 529 return;
duke@0 530 }
sgoldman@107 531 #endif
duke@0 532
duke@0 533 JavaThread* thread;
duke@0 534
duke@0 535 if (trace->env_id == NULL ||
duke@0 536 (thread = JavaThread::thread_from_jni_environment(trace->env_id)) == NULL ||
duke@0 537 thread->is_exiting()) {
duke@0 538
duke@0 539 // bad env_id, thread has exited or thread is exiting
sgoldman@107 540 trace->num_frames = ticks_thread_exit; // -8
duke@0 541 return;
duke@0 542 }
duke@0 543
duke@0 544 if (thread->in_deopt_handler()) {
duke@0 545 // thread is in the deoptimization handler so return no frames
sgoldman@107 546 trace->num_frames = ticks_deopt; // -9
duke@0 547 return;
duke@0 548 }
duke@0 549
duke@0 550 assert(JavaThread::current() == thread,
duke@0 551 "AsyncGetCallTrace must be called by the current interrupted thread");
duke@0 552
duke@0 553 if (!JvmtiExport::should_post_class_load()) {
sgoldman@107 554 trace->num_frames = ticks_no_class_load; // -1
duke@0 555 return;
duke@0 556 }
duke@0 557
duke@0 558 if (Universe::heap()->is_gc_active()) {
sgoldman@107 559 trace->num_frames = ticks_GC_active; // -2
duke@0 560 return;
duke@0 561 }
duke@0 562
duke@0 563 switch (thread->thread_state()) {
duke@0 564 case _thread_new:
duke@0 565 case _thread_uninitialized:
duke@0 566 case _thread_new_trans:
duke@0 567 // We found the thread on the threads list above, but it is too
duke@0 568 // young to be useful so return that there are no Java frames.
duke@0 569 trace->num_frames = 0;
duke@0 570 break;
duke@0 571 case _thread_in_native:
duke@0 572 case _thread_in_native_trans:
duke@0 573 case _thread_blocked:
duke@0 574 case _thread_blocked_trans:
duke@0 575 case _thread_in_vm:
duke@0 576 case _thread_in_vm_trans:
duke@0 577 {
duke@0 578 frame fr;
duke@0 579
duke@0 580 // param isInJava == false - indicate we aren't in Java code
duke@0 581 if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, false)) {
sgoldman@107 582 trace->num_frames = ticks_unknown_not_Java; // -3 unknown frame
sgoldman@107 583 } else {
duke@0 584 if (!thread->has_last_Java_frame()) {
sgoldman@107 585 trace->num_frames = 0; // No Java frames
duke@0 586 } else {
sgoldman@107 587 trace->num_frames = ticks_not_walkable_not_Java; // -4 non walkable frame by default
sgoldman@107 588 forte_fill_call_trace_given_top(thread, trace, depth, fr);
sgoldman@107 589
sgoldman@107 590 // This assert would seem to be valid but it is not.
sgoldman@107 591 // It would be valid if we weren't possibly racing a gc
sgoldman@107 592 // thread. A gc thread can make a valid interpreted frame
sgoldman@107 593 // look invalid. It's a small window but it does happen.
sgoldman@107 594 // The assert is left here commented out as a reminder.
sgoldman@107 595 // assert(trace->num_frames != ticks_not_walkable_not_Java, "should always be walkable");
sgoldman@107 596
duke@0 597 }
duke@0 598 }
duke@0 599 }
duke@0 600 break;
duke@0 601 case _thread_in_Java:
duke@0 602 case _thread_in_Java_trans:
duke@0 603 {
duke@0 604 frame fr;
duke@0 605
duke@0 606 // param isInJava == true - indicate we are in Java code
duke@0 607 if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, true)) {
sgoldman@107 608 trace->num_frames = ticks_unknown_Java; // -5 unknown frame
duke@0 609 } else {
sgoldman@107 610 trace->num_frames = ticks_not_walkable_Java; // -6, non walkable frame by default
duke@0 611 forte_fill_call_trace_given_top(thread, trace, depth, fr);
duke@0 612 }
duke@0 613 }
duke@0 614 break;
duke@0 615 default:
duke@0 616 // Unknown thread state
sgoldman@107 617 trace->num_frames = ticks_unknown_state; // -7
duke@0 618 break;
duke@0 619 }
duke@0 620 }
duke@0 621
duke@0 622
duke@0 623 #ifndef _WINDOWS
duke@0 624 // Support for the Forte(TM) Peformance Tools collector.
duke@0 625 //
duke@0 626 // The method prototype is derived from libcollector.h. For more
duke@0 627 // information, please see the libcollect man page.
duke@0 628
duke@0 629 // Method to let libcollector know about a dynamically loaded function.
duke@0 630 // Because it is weakly bound, the calls become NOP's when the library
duke@0 631 // isn't present.
duke@0 632 void collector_func_load(char* name,
duke@0 633 void* null_argument_1,
duke@0 634 void* null_argument_2,
duke@0 635 void *vaddr,
duke@0 636 int size,
duke@0 637 int zero_argument,
duke@0 638 void* null_argument_3);
duke@0 639 #pragma weak collector_func_load
duke@0 640 #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
duke@0 641 ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
duke@0 642 #endif // !_WINDOWS
duke@0 643
duke@0 644 } // end extern "C"
duke@0 645 #endif // !IA64
duke@0 646
duke@0 647 void Forte::register_stub(const char* name, address start, address end) {
duke@0 648 #if !defined(_WINDOWS) && !defined(IA64)
duke@0 649 assert(pointer_delta(end, start, sizeof(jbyte)) < INT_MAX,
jcoomes@1500 650 "Code size exceeds maximum range");
duke@0 651
duke@0 652 collector_func_load((char*)name, NULL, NULL, start,
duke@0 653 pointer_delta(end, start, sizeof(jbyte)), 0, NULL);
duke@0 654 #endif // !_WINDOWS && !IA64
duke@0 655 }