rframe.cpp revision 0
0N/A/*
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
873N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
3215N/A# include "incls/_precompiled.incl"
0N/A
0N/A#include "incls/_rframe.cpp.incl"
0N/A
0N/Astatic RFrame*const noCaller = (RFrame*) 0x1; // no caller (i.e., initial frame)
0N/Astatic RFrame*const noCallerYet = (RFrame*) 0x0; // caller not yet computed
0N/A
0N/ARFrame::RFrame(frame fr, JavaThread* thread, RFrame*const callee) :
0N/A _fr(fr), _thread(thread), _callee(callee), _num(callee ? callee->num() + 1 : 0) {
3012N/A _caller = (RFrame*)noCallerYet;
3012N/A _invocations = 0;
3381N/A _distance = 0;
3349N/A}
3349N/A
3012N/Avoid RFrame::set_distance(int d) {
1083N/A assert(is_compiled() || d >= 0, "should be positive");
1083N/A _distance = d;
1083N/A}
1083N/A
1083N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, RFrame*const callee)
1083N/A: RFrame(fr, thread, callee) {
1083N/A RegisterMap map(thread, false);
1083N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
3090N/A _method = methodHandle(thread, _vf->method());
3090N/A assert( _vf->is_interpreted_frame(), "must be interpreted");
3214N/A init();
3764N/A}
1083N/A
1083N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, methodHandle m)
1083N/A: RFrame(fr, thread, NULL) {
1083N/A RegisterMap map(thread, false);
233N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
712N/A _method = m;
1177N/A
564N/A assert( _vf->is_interpreted_frame(), "must be interpreted");
0N/A init();
0N/A}
0N/A
0N/ACompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread, RFrame*const callee)
712N/A: RFrame(fr, thread, callee) {
0N/A init();
0N/A}
0N/A
0N/ACompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread)
0N/A: RFrame(fr, thread, NULL) {
233N/A init();
233N/A}
0N/A
0N/ADeoptimizedRFrame::DeoptimizedRFrame(frame fr, JavaThread* thread, RFrame*const callee)
0N/A: InterpretedRFrame(fr, thread, callee) {}
0N/A
0N/ARFrame* RFrame::new_RFrame(frame fr, JavaThread* thread, RFrame*const callee) {
0N/A RFrame* rf;
0N/A int dist = callee ? callee->distance() : -1;
0N/A if (fr.is_interpreted_frame()) {
567N/A rf = new InterpretedRFrame(fr, thread, callee);
567N/A dist++;
567N/A } else if (fr.is_compiled_frame()) {
567N/A // Even deopted frames look compiled because the deopt
2046N/A // is invisible until it happens.
2046N/A rf = new CompiledRFrame(fr, thread, callee);
1210N/A } else {
2033N/A assert(false, "Unhandled frame type");
712N/A }
2033N/A rf->set_distance(dist);
2046N/A rf->init();
712N/A return rf;
675N/A}
675N/A
712N/ARFrame* RFrame::caller() {
675N/A if (_caller != noCallerYet) return (_caller == noCaller) ? NULL : _caller; // already computed caller
567N/A
0N/A // caller not yet computed; do it now
422N/A if (_fr.is_first_java_frame()) {
712N/A _caller = (RFrame*)noCaller;
422N/A return NULL;
0N/A }
422N/A
0N/A RegisterMap map(_thread, false);
422N/A frame sender = _fr.real_sender(&map);
0N/A if (sender.is_java_frame()) {
0N/A _caller = new_RFrame(sender, thread(), this);
0N/A return _caller;
0N/A }
902N/A
902N/A // Real caller is not java related
902N/A _caller = (RFrame*)noCaller;
902N/A return NULL;
0N/A}
0N/A
0N/Aint InterpretedRFrame::cost() const {
0N/A return _method->code_size(); // fix this
233N/A //return _method->estimated_inline_cost(_receiverKlass);
233N/A}
233N/A
233N/Aint CompiledRFrame::cost() const {
730N/A nmethod* nm = top_method()->code();
730N/A if (nm != NULL) {
730N/A return nm->code_size();
0N/A } else {
729N/A return top_method()->code_size();
729N/A }
729N/A}
0N/A
0N/Avoid CompiledRFrame::init() {
0N/A RegisterMap map(thread(), false);
110N/A vframe* vf = vframe::new_vframe(&_fr, &map, thread());
110N/A assert(vf->is_compiled_frame(), "must be compiled");
121N/A _nm = compiledVFrame::cast(vf)->code();
699N/A vf = vf->top();
0N/A _vf = javaVFrame::cast(vf);
0N/A _method = methodHandle(thread(), CodeCache::find_nmethod(_fr.pc())->method());
1008N/A assert(_method(), "should have found a method");
1008N/A#ifndef PRODUCT
1008N/A _invocations = _method->compiled_invocation_count();
1008N/A#endif
3214N/A}
3381N/A
2086N/Avoid InterpretedRFrame::init() {
3646N/A _invocations = _method->invocation_count() + _method->backedge_count();
3646N/A}
3646N/A
2086N/Avoid RFrame::print(const char* kind) {
3646N/A#ifndef PRODUCT
1177N/A#ifdef COMPILER2
3349N/A int cnt = top_method()->interpreter_invocation_count();
3349N/A#else
3349N/A int cnt = top_method()->invocation_count();
3349N/A#endif
3349N/A tty->print("%3d %s ", _num, is_interpreted() ? "I" : "C");
3349N/A top_method()->print_short_name(tty);
3381N/A tty->print_cr(": inv=%5d(%d) cst=%4d", _invocations, cnt, cost());
3381N/A#endif
3349N/A}
3381N/A
0N/Avoid CompiledRFrame::print() {
0N/A RFrame::print("comp");
0N/A}
0N/A
3381N/Avoid InterpretedRFrame::print() {
3381N/A RFrame::print("int.");
3381N/A}
3381N/A
0N/Avoid DeoptimizedRFrame::print() {
1344N/A RFrame::print("deopt.");
1177N/A}
1177N/A