0N/A/*
2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "oops/oop.inline.hpp"
2062N/A#include "oops/symbol.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "runtime/rframe.hpp"
1879N/A#include "runtime/vframe.hpp"
1879N/A#include "runtime/vframe_hp.hpp"
0N/A
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) {
0N/A _caller = (RFrame*)noCallerYet;
0N/A _invocations = 0;
0N/A _distance = 0;
0N/A}
0N/A
0N/Avoid RFrame::set_distance(int d) {
0N/A assert(is_compiled() || d >= 0, "should be positive");
0N/A _distance = d;
0N/A}
0N/A
0N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, RFrame*const callee)
0N/A: RFrame(fr, thread, callee) {
0N/A RegisterMap map(thread, false);
0N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
0N/A _method = methodHandle(thread, _vf->method());
0N/A assert( _vf->is_interpreted_frame(), "must be interpreted");
0N/A init();
0N/A}
0N/A
0N/AInterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, methodHandle m)
0N/A: RFrame(fr, thread, NULL) {
0N/A RegisterMap map(thread, false);
0N/A _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread));
0N/A _method = m;
0N/A
0N/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)
0N/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) {
0N/A init();
0N/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()) {
0N/A rf = new InterpretedRFrame(fr, thread, callee);
0N/A dist++;
0N/A } else if (fr.is_compiled_frame()) {
0N/A // Even deopted frames look compiled because the deopt
0N/A // is invisible until it happens.
0N/A rf = new CompiledRFrame(fr, thread, callee);
0N/A } else {
0N/A assert(false, "Unhandled frame type");
0N/A }
0N/A rf->set_distance(dist);
0N/A rf->init();
0N/A return rf;
0N/A}
0N/A
0N/ARFrame* RFrame::caller() {
0N/A if (_caller != noCallerYet) return (_caller == noCaller) ? NULL : _caller; // already computed caller
0N/A
0N/A // caller not yet computed; do it now
0N/A if (_fr.is_first_java_frame()) {
0N/A _caller = (RFrame*)noCaller;
0N/A return NULL;
0N/A }
0N/A
0N/A RegisterMap map(_thread, false);
0N/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 }
0N/A
0N/A // Real caller is not java related
0N/A _caller = (RFrame*)noCaller;
0N/A return NULL;
0N/A}
0N/A
0N/Aint InterpretedRFrame::cost() const {
0N/A return _method->code_size(); // fix this
0N/A //return _method->estimated_inline_cost(_receiverKlass);
0N/A}
0N/A
0N/Aint CompiledRFrame::cost() const {
0N/A nmethod* nm = top_method()->code();
0N/A if (nm != NULL) {
1668N/A return nm->insts_size();
0N/A } else {
0N/A return top_method()->code_size();
0N/A }
0N/A}
0N/A
0N/Avoid CompiledRFrame::init() {
0N/A RegisterMap map(thread(), false);
0N/A vframe* vf = vframe::new_vframe(&_fr, &map, thread());
0N/A assert(vf->is_compiled_frame(), "must be compiled");
0N/A _nm = compiledVFrame::cast(vf)->code();
0N/A vf = vf->top();
0N/A _vf = javaVFrame::cast(vf);
0N/A _method = methodHandle(thread(), CodeCache::find_nmethod(_fr.pc())->method());
0N/A assert(_method(), "should have found a method");
0N/A#ifndef PRODUCT
0N/A _invocations = _method->compiled_invocation_count();
0N/A#endif
0N/A}
0N/A
0N/Avoid InterpretedRFrame::init() {
0N/A _invocations = _method->invocation_count() + _method->backedge_count();
0N/A}
0N/A
0N/Avoid RFrame::print(const char* kind) {
0N/A#ifndef PRODUCT
0N/A#ifdef COMPILER2
0N/A int cnt = top_method()->interpreter_invocation_count();
0N/A#else
0N/A int cnt = top_method()->invocation_count();
0N/A#endif
0N/A tty->print("%3d %s ", _num, is_interpreted() ? "I" : "C");
0N/A top_method()->print_short_name(tty);
0N/A tty->print_cr(": inv=%5d(%d) cst=%4d", _invocations, cnt, cost());
0N/A#endif
0N/A}
0N/A
0N/Avoid CompiledRFrame::print() {
0N/A RFrame::print("comp");
0N/A}
0N/A
0N/Avoid InterpretedRFrame::print() {
0N/A RFrame::print("int.");
0N/A}
0N/A
0N/Avoid DeoptimizedRFrame::print() {
0N/A RFrame::print("deopt.");
0N/A}