annotate src/share/vm/prims/forte.cpp @ 2733:c124e2e7463e

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