1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/debugInfoRec.hpp"
27 #include "code/nmethod.hpp"
28 #include "code/pcDesc.hpp"
29 #include "jfr/periodic/sampling/jfrCallTrace.hpp"
30 #include "oops/method.hpp"
31 #include "runtime/javaCalls.hpp"
32 #include "runtime/frame.inline.hpp"
33 #include "runtime/registerMap.hpp"
34 #include "runtime/thread.inline.hpp"
35
36 bool JfrGetCallTrace::find_top_frame(frame& top_frame, Method** method, frame& first_frame) {
37 assert(top_frame.cb() != NULL, "invariant");
38 RegisterMap map(_thread, false);
39 frame candidate = top_frame;
40 for (int i = 0; i < MaxJavaStackTraceDepth * 2; ++i) {
41 if (candidate.is_entry_frame()) {
42 JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(_thread);
43 if (jcw == NULL || jcw->is_first_frame()) {
44 return false;
45 }
46 }
47
48 if (candidate.is_interpreted_frame()) {
49 JavaThreadState state = _thread->thread_state();
50 const bool known_valid = (state == _thread_in_native || state == _thread_in_vm || state == _thread_blocked);
51 if (known_valid || candidate.is_interpreted_frame_valid(_thread)) {
52 Method* im = candidate.interpreter_frame_method();
53 if (known_valid && !im->is_valid_method()) {
54 return false;
55 }
56 *method = im;
57 first_frame = candidate;
58 return true;
59 }
60 }
|
1 /*
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/debugInfoRec.hpp"
27 #include "code/nmethod.hpp"
28 #include "code/pcDesc.hpp"
29 #include "jfr/periodic/sampling/jfrCallTrace.hpp"
30 #include "jfr/utilities/jfrTypes.hpp"
31 #include "oops/method.hpp"
32 #include "runtime/javaCalls.hpp"
33 #include "runtime/frame.inline.hpp"
34 #include "runtime/registerMap.hpp"
35 #include "runtime/thread.inline.hpp"
36
37 bool JfrGetCallTrace::find_top_frame(frame& top_frame, Method** method, frame& first_frame) {
38 assert(top_frame.cb() != NULL, "invariant");
39 RegisterMap map(_thread, false);
40 frame candidate = top_frame;
41 for (u4 i = 0; i < MAX_STACK_DEPTH * 2; ++i) {
42 if (candidate.is_entry_frame()) {
43 JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(_thread);
44 if (jcw == NULL || jcw->is_first_frame()) {
45 return false;
46 }
47 }
48
49 if (candidate.is_interpreted_frame()) {
50 JavaThreadState state = _thread->thread_state();
51 const bool known_valid = (state == _thread_in_native || state == _thread_in_vm || state == _thread_blocked);
52 if (known_valid || candidate.is_interpreted_frame_valid(_thread)) {
53 Method* im = candidate.interpreter_frame_method();
54 if (known_valid && !im->is_valid_method()) {
55 return false;
56 }
57 *method = im;
58 first_frame = candidate;
59 return true;
60 }
61 }
|