Path: blob/master/src/hotspot/share/jfr/periodic/sampling/jfrCallTrace.cpp
41155 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "code/debugInfoRec.hpp"26#include "code/nmethod.hpp"27#include "code/pcDesc.hpp"28#include "jfr/periodic/sampling/jfrCallTrace.hpp"29#include "jfr/utilities/jfrTypes.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"3536bool JfrGetCallTrace::find_top_frame(frame& top_frame, Method** method, frame& first_frame) {37assert(top_frame.cb() != NULL, "invariant");38RegisterMap map(_thread, false, false);39frame candidate = top_frame;40for (u4 i = 0; i < MAX_STACK_DEPTH * 2; ++i) {41if (candidate.is_entry_frame()) {42JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(_thread);43if (jcw == NULL || jcw->is_first_frame()) {44return false;45}46}4748if (candidate.is_interpreted_frame()) {49JavaThreadState state = _thread->thread_state();50const bool known_valid = (state == _thread_in_native || state == _thread_in_vm || state == _thread_blocked);51if (known_valid || candidate.is_interpreted_frame_valid(_thread)) {52Method* im = candidate.interpreter_frame_method();53if (known_valid && !Method::is_valid_method(im)) {54return false;55}56*method = im;57first_frame = candidate;58return true;59}60}6162if (candidate.cb()->is_nmethod()) {63// first check to make sure that we have a sane stack,64// the PC is actually inside the code part of the codeBlob,65// and we are past is_frame_complete_at (stack has been setup)66if (!candidate.safe_for_sender(_thread)) {67return false;68}69nmethod* nm = (nmethod*)candidate.cb();70*method = nm->method();7172if (_in_java) {73PcDesc* pc_desc = nm->pc_desc_near(candidate.pc() + 1);74if (pc_desc == NULL || pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) {75return false;76}77candidate.set_pc(pc_desc->real_pc(nm));78assert(nm->pc_desc_at(candidate.pc()) != NULL, "invalid pc");79}80first_frame = candidate;81return true;82}8384if (!candidate.safe_for_sender(_thread) ||85candidate.is_stub_frame() ||86candidate.cb()->frame_size() <= 0) {87return false;88}8990candidate = candidate.sender(&map);91if (candidate.cb() == NULL) {92return false;93}94}95return false;96}9798bool JfrGetCallTrace::get_topframe(void* ucontext, frame& topframe) {99if (!_thread->pd_get_top_frame_for_profiling(&topframe, ucontext, _in_java)) {100return false;101}102103if (topframe.cb() == NULL) {104return false;105}106107frame first_java_frame;108Method* method = NULL;109if (find_top_frame(topframe, &method, first_java_frame)) {110if (method == NULL) {111return false;112}113topframe = first_java_frame;114return true;115}116return false;117}118119120