duke@435: /* duke@435: * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // rframes ("recompiler frames") decorate stack frames with some extra information duke@435: // needed by the recompiler. The recompiler views the stack (at the time of recompilation) duke@435: // as a list of rframes. duke@435: duke@435: class RFrame : public ResourceObj { duke@435: protected: duke@435: const frame _fr; // my frame duke@435: JavaThread* const _thread; // thread where frame resides. duke@435: RFrame* _caller; // caller / callee rframes (or NULL) duke@435: RFrame*const _callee; duke@435: const int _num; // stack frame number (0 = most recent) duke@435: int _invocations; // current invocation estimate (for this frame) duke@435: // (i.e., how often was this frame called) duke@435: int _distance; // recompilation search "distance" (measured in # of interpreted frames) duke@435: duke@435: RFrame(frame fr, JavaThread* thread, RFrame*const callee); duke@435: virtual void init() = 0; // compute invocations, loopDepth, etc. duke@435: void print(const char* name); duke@435: duke@435: public: duke@435: duke@435: static RFrame* new_RFrame(frame fr, JavaThread* thread, RFrame*const callee); duke@435: duke@435: virtual bool is_interpreted() const { return false; } duke@435: virtual bool is_compiled() const { return false; } duke@435: int distance() const { return _distance; } duke@435: void set_distance(int d); duke@435: int invocations() const { return _invocations; } duke@435: int num() const { return _num; } duke@435: frame fr() const { return _fr; } duke@435: JavaThread* thread() const { return _thread; } duke@435: virtual int cost() const = 0; // estimated inlining cost (size) duke@435: virtual methodHandle top_method() const = 0; duke@435: virtual javaVFrame* top_vframe() const = 0; duke@435: virtual nmethod* nm() const { ShouldNotCallThis(); return NULL; } duke@435: duke@435: RFrame* caller(); duke@435: RFrame* callee() const { return _callee; } duke@435: RFrame* parent() const; // rframe containing lexical scope (if any) duke@435: virtual void print() = 0; duke@435: duke@435: static int computeSends(methodOop m); duke@435: static int computeSends(nmethod* nm); duke@435: static int computeCumulSends(methodOop m); duke@435: static int computeCumulSends(nmethod* nm); duke@435: }; duke@435: duke@435: class CompiledRFrame : public RFrame { // frame containing a compiled method duke@435: protected: duke@435: nmethod* _nm; duke@435: javaVFrame* _vf; // top vframe; may be NULL (for most recent frame) duke@435: methodHandle _method; // top method duke@435: duke@435: CompiledRFrame(frame fr, JavaThread* thread, RFrame*const callee); duke@435: void init(); duke@435: friend class RFrame; duke@435: duke@435: public: duke@435: CompiledRFrame(frame fr, JavaThread* thread); // for nmethod triggering its counter (callee == NULL) duke@435: bool is_compiled() const { return true; } duke@435: methodHandle top_method() const { return _method; } duke@435: javaVFrame* top_vframe() const { return _vf; } duke@435: nmethod* nm() const { return _nm; } duke@435: int cost() const; duke@435: void print(); duke@435: }; duke@435: duke@435: class InterpretedRFrame : public RFrame { // interpreter frame duke@435: protected: duke@435: javaVFrame* _vf; // may be NULL (for most recent frame) duke@435: methodHandle _method; duke@435: duke@435: InterpretedRFrame(frame fr, JavaThread* thread, RFrame*const callee); duke@435: void init(); duke@435: friend class RFrame; duke@435: duke@435: public: duke@435: InterpretedRFrame(frame fr, JavaThread* thread, methodHandle m); // constructor for method triggering its invocation counter duke@435: bool is_interpreted() const { return true; } duke@435: methodHandle top_method() const { return _method; } duke@435: javaVFrame* top_vframe() const { return _vf; } duke@435: int cost() const; duke@435: void print(); duke@435: }; duke@435: duke@435: // treat deoptimized frames as interpreted duke@435: class DeoptimizedRFrame : public InterpretedRFrame { duke@435: protected: duke@435: DeoptimizedRFrame(frame fr, JavaThread* thread, RFrame*const callee); duke@435: friend class RFrame; duke@435: public: duke@435: void print(); duke@435: };