rframe.cpp revision 2273
2386N/A/*
3681N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
2386N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2386N/A *
2386N/A * This code is free software; you can redistribute it and/or modify it
2386N/A * under the terms of the GNU General Public License version 2 only, as
2386N/A * published by the Free Software Foundation.
2386N/A *
2386N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2386N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2386N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2386N/A * version 2 for more details (a copy is included in the LICENSE file that
2386N/A * accompanied this code).
2386N/A *
2386N/A * You should have received a copy of the GNU General Public License version
2386N/A * 2 along with this work; if not, write to the Free Software Foundation,
2386N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2386N/A *
2386N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2386N/A * or visit www.oracle.com if you need additional information or have any
2386N/A * questions.
2386N/A *
2386N/A */
2386N/A
2386N/A#include "precompiled.hpp"
2386N/A#include "interpreter/interpreter.hpp"
2386N/A#include "oops/oop.inline.hpp"
2386N/A#include "oops/symbol.hpp"
2386N/A#include "runtime/frame.inline.hpp"
2386N/A#include "runtime/rframe.hpp"
2386N/A#include "runtime/vframe.hpp"
2816N/A#include "runtime/vframe_hp.hpp"
2816N/A
2816N/A
2816N/Astatic RFrame*const noCaller = (RFrame*) 0x1; // no caller (i.e., initial frame)
2816N/Astatic RFrame*const noCallerYet = (RFrame*) 0x0; // caller not yet computed
2816N/A
2816N/ARFrame::RFrame(frame fr, JavaThread* thread, RFrame*const callee) :
2816N/A _fr(fr), _thread(thread), _callee(callee), _num(callee ? callee->num() + 1 : 0) {
2816N/A _caller = (RFrame*)noCallerYet;
2816N/A _invocations = 0;
2816N/A _distance = 0;
2816N/A}
2816N/A
2816N/Avoid RFrame::set_distance(int d) {
2816N/A assert(is_compiled() || d >= 0, "should be positive");
2816N/A _distance = d;
2816N/A}
2386N/A
2816N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, RFrame*const callee)
2816N/A: RFrame(fr, thread, callee) {
2816N/A RegisterMap map(thread, false);
2816N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
2816N/A _method = methodHandle(thread, _vf->method());
2816N/A assert( _vf->is_interpreted_frame(), "must be interpreted");
2816N/A init();
2816N/A}
2386N/A
2816N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, methodHandle m)
2816N/A: RFrame(fr, thread, NULL) {
2816N/A RegisterMap map(thread, false);
2816N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
2816N/A _method = m;
2386N/A
2816N/A assert( _vf->is_interpreted_frame(), "must be interpreted");
2386N/A init();
2816N/A}
2386N/A
2816N/ACompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread, RFrame*const callee)
2816N/A: RFrame(fr, thread, callee) {
2816N/A init();
2816N/A}
2816N/A
2816N/ACompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread)
2816N/A: RFrame(fr, thread, NULL) {
2816N/A init();
2816N/A}
2386N/A
2816N/ADeoptimizedRFrame::DeoptimizedRFrame(frame fr, JavaThread* thread, RFrame*const callee)
2386N/A: InterpretedRFrame(fr, thread, callee) {}
2816N/A
2816N/ARFrame* RFrame::new_RFrame(frame fr, JavaThread* thread, RFrame*const callee) {
2816N/A RFrame* rf;
2816N/A int dist = callee ? callee->distance() : -1;
2386N/A if (fr.is_interpreted_frame()) {
2816N/A rf = new InterpretedRFrame(fr, thread, callee);
2816N/A dist++;
2816N/A } else if (fr.is_compiled_frame()) {
2816N/A // Even deopted frames look compiled because the deopt
2816N/A // is invisible until it happens.
2386N/A rf = new CompiledRFrame(fr, thread, callee);
3115N/A } else {
2816N/A assert(false, "Unhandled frame type");
2816N/A }
2386N/A rf->set_distance(dist);
2816N/A rf->init();
3115N/A return rf;
3115N/A}
3115N/A
3115N/ARFrame* RFrame::caller() {
2386N/A if (_caller != noCallerYet) return (_caller == noCaller) ? NULL : _caller; // already computed caller
2816N/A
2816N/A // caller not yet computed; do it now
2816N/A if (_fr.is_first_java_frame()) {
2386N/A _caller = (RFrame*)noCaller;
2816N/A return NULL;
2816N/A }
2816N/A
2816N/A RegisterMap map(_thread, false);
2816N/A frame sender = _fr.real_sender(&map);
2816N/A if (sender.is_java_frame()) {
2816N/A _caller = new_RFrame(sender, thread(), this);
2816N/A return _caller;
2386N/A }
3863N/A
2820N/A // Real caller is not java related
2820N/A _caller = (RFrame*)noCaller;
2386N/A return NULL;
2386N/A}
2386N/A
2986N/Aint InterpretedRFrame::cost() const {
2386N/A return _method->code_size(); // fix this
2386N/A //return _method->estimated_inline_cost(_receiverKlass);
2386N/A}
2386N/A
2386N/Aint CompiledRFrame::cost() const {
2386N/A nmethod* nm = top_method()->code();
2386N/A if (nm != NULL) {
2816N/A return nm->insts_size();
2386N/A } else {
2816N/A return top_method()->code_size();
2386N/A }
2386N/A}
2386N/A
2386N/Avoid CompiledRFrame::init() {
2386N/A RegisterMap map(thread(), false);
2386N/A vframe* vf = vframe::new_vframe(&_fr, &map, thread());
2386N/A assert(vf->is_compiled_frame(), "must be compiled");
2386N/A _nm = compiledVFrame::cast(vf)->code();
2386N/A vf = vf->top();
2816N/A _vf = javaVFrame::cast(vf);
2816N/A _method = methodHandle(thread(), CodeCache::find_nmethod(_fr.pc())->method());
2816N/A assert(_method(), "should have found a method");
2816N/A#ifndef PRODUCT
2816N/A _invocations = _method->compiled_invocation_count();
2816N/A#endif
2816N/A}
2816N/A
2816N/Avoid InterpretedRFrame::init() {
3681N/A _invocations = _method->invocation_count() + _method->backedge_count();
2816N/A}
2816N/A
2816N/Avoid RFrame::print(const char* kind) {
2816N/A#ifndef PRODUCT
2816N/A#ifdef COMPILER2
2816N/A int cnt = top_method()->interpreter_invocation_count();
2816N/A#else
2816N/A int cnt = top_method()->invocation_count();
2816N/A#endif
2816N/A tty->print("%3d %s ", _num, is_interpreted() ? "I" : "C");
2816N/A top_method()->print_short_name(tty);
2386N/A tty->print_cr(": inv=%5d(%d) cst=%4d", _invocations, cnt, cost());
2386N/A#endif
2386N/A}
2386N/A
2386N/Avoid CompiledRFrame::print() {
2386N/A RFrame::print("comp");
2386N/A}
2386N/A
2386N/Avoid InterpretedRFrame::print() {
2386N/A RFrame::print("int.");
2386N/A}
2386N/A
2386N/Avoid DeoptimizedRFrame::print() {
2386N/A RFrame::print("deopt.");
2386N/A}
2816N/A