src/share/vm/prims/forte.cpp

Mon, 03 Jun 2019 16:14:54 +0100

author
xliu
date
Mon, 03 Jun 2019 16:14:54 +0100
changeset 9689
89dcef434423
parent 7854
e8260b6328fb
child 7994
04ff2f6cd0eb
child 9846
9003f35baaa0
permissions
-rw-r--r--

8059575: JEP-JDK-8043304: Test task: Tiered Compilation level transition tests
Summary: Includes compile_id addition from JDK-8054492
Reviewed-by: andrew

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

mercurial